mystyle-java-fx-tools/src/main/java/com/zhangmeng/tools/controller/PlayerController.java

158 lines
4.3 KiB
Java
Raw Normal View History

package com.zhangmeng.tools.controller;
import com.zhangmeng.tools.utils.ResourcesUtils;
import javafx.beans.property.SimpleDoubleProperty;
import javafx.beans.property.SimpleObjectProperty;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.fxml.FXML;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.scene.control.ListView;
import javafx.scene.control.SplitPane;
import javafx.scene.layout.AnchorPane;
import javafx.stage.Stage;
import java.io.IOException;
import java.util.Arrays;
/**
* @author :
* @version : 1.0
* @date : 2023-02-16 10:04
*/
public class PlayerController {
private SimpleDoubleProperty width = new SimpleDoubleProperty(0.0);
private SimpleDoubleProperty height = new SimpleDoubleProperty(0.0);
private AnchorPane root;
@FXML
private ListView<ResourcesUtils.Player> listView;
@FXML
private SplitPane splitPane;
@FXML
public void md5_menu_item(){
load_encrypt();
}
@FXML
public void spring_security_menu_item(){
load_encrypt();
}
@FXML
public void video_menu_item(){
video();
}
@FXML
public void music_menu_item(){
music();
}
@FXML
public void vip_parser_menu_item(){
vip_parser();
}
public void load_encrypt(){
Stage stage = (Stage) splitPane.getScene().getWindow();
AnchorPane fx = null;
try {
fx = FXMLLoader.load(ResourcesUtils.getResource("home"));
} catch (IOException e) {
e.printStackTrace();
}
Scene scene = new Scene(fx);
stage.setScene(scene);
}
@FXML
public void initialize() {
init();
listView.getSelectionModel().selectedItemProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
if (newValue.getIndex() == 0 ){
video();
}
if (newValue.getIndex() == 1 ){
music();
}
if (newValue.getIndex() == 2){
vip_parser();
}
}
});
}
public void init() {
ResourcesUtils.Player[] values = ResourcesUtils.Player.values();
ObservableList<ResourcesUtils.Player> list = FXCollections.observableArrayList();
list.addAll(Arrays.asList(values));
listView.setItems(list);
video();
}
private void music(){
listView.getSelectionModel().select(1);
try {
root = FXMLLoader.load(ResourcesUtils.getResource("music"));
} catch (IOException e) {
e.printStackTrace();
}
common_method();
}
private void vip_parser(){
listView.getSelectionModel().select(2);
try {
root = FXMLLoader.load(ResourcesUtils.getResource("vip-parser"));
} catch (IOException e) {
e.printStackTrace();
}
common_method();
}
private void common_method(){
splitPane.getItems().remove(1);
splitPane.getItems().add(1, root);
root.widthProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
double width = splitPane.getWidth();
PlayerController.this.width.set(width);
}
});
root.heightProperty().addListener((observable, oldValue, newValue) -> {
if (newValue != null) {
double height = splitPane.getHeight();
PlayerController.this.height.set(height);
}
});
this.width.addListener((observable, oldValue, newValue) -> {
PlayerController.this.root.setPrefWidth(newValue.doubleValue() - listView.getWidth());
});
this.height.addListener((observable, oldValue, newValue) -> {
PlayerController.this.root.setPrefHeight(newValue.doubleValue() - listView.getHeight());
});
}
private void video(){
//默认选择第一个
listView.getSelectionModel().select(0);
try {
root = FXMLLoader.load(ResourcesUtils.getResource("video"));
} catch (IOException e) {
e.printStackTrace();
}
common_method();
}
}