2023年2月18日11:44:54
parent
5bb53a5d51
commit
f521588043
|
|
@ -0,0 +1,97 @@
|
||||||
|
package com.zhangmeng.tools.controller;
|
||||||
|
|
||||||
|
import cn.hutool.core.io.resource.ClassPathResource;
|
||||||
|
import cn.hutool.core.io.resource.Resource;
|
||||||
|
import com.zhangmeng.tools.utils.AlertUtils;
|
||||||
|
import com.zhangmeng.tools.utils.ImagePath;
|
||||||
|
import javafx.fxml.FXML;
|
||||||
|
import javafx.scene.control.Button;
|
||||||
|
import javafx.scene.control.TextField;
|
||||||
|
import javafx.scene.image.Image;
|
||||||
|
import javafx.scene.image.ImageView;
|
||||||
|
import javafx.stage.DirectoryChooser;
|
||||||
|
import javafx.stage.Stage;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
import java.io.*;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author : 芊芊墨客
|
||||||
|
* @version : 1.0
|
||||||
|
* @date : 2023-02-18 11:46
|
||||||
|
*/
|
||||||
|
@Slf4j
|
||||||
|
public class VideoSetController {
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private Button file_choose_button;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
private TextField text_file;
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void initialize(){
|
||||||
|
log.info("music set ....");
|
||||||
|
file_choose_button.setText(null);
|
||||||
|
ImageView iv = new ImageView(new Image(ImagePath.path(ImagePath.ImagePathType.IMAGE_FILE)));
|
||||||
|
iv.setPreserveRatio(true);
|
||||||
|
iv.setFitWidth(18);
|
||||||
|
file_choose_button.setGraphic(iv);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void choose_file(){
|
||||||
|
Stage stage = (Stage) file_choose_button.getScene().getWindow();
|
||||||
|
DirectoryChooser dc = new DirectoryChooser();
|
||||||
|
dc.setTitle("文件夹选择器");
|
||||||
|
File file = dc.showDialog(stage);
|
||||||
|
if (file != null){
|
||||||
|
String path = file.getAbsolutePath();
|
||||||
|
text_file.setText(path);
|
||||||
|
}
|
||||||
|
VideoController.addDir(file);
|
||||||
|
}
|
||||||
|
|
||||||
|
@FXML
|
||||||
|
public void commit() throws FileNotFoundException {
|
||||||
|
String path = text_file.getText();
|
||||||
|
if (path.length() == 0 ){
|
||||||
|
AlertUtils.alert_warning("请选择文件夹");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setPath(path);
|
||||||
|
//关闭
|
||||||
|
Stage stage = (Stage) text_file.getScene().getWindow();
|
||||||
|
stage.close();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setPath(String path){
|
||||||
|
Resource resource = new ClassPathResource("music.properties");
|
||||||
|
InputStream inputStream = resource.getStream();
|
||||||
|
FileOutputStream fileOutputStream = null;
|
||||||
|
Properties properties = new Properties();
|
||||||
|
try {
|
||||||
|
properties.load(inputStream);
|
||||||
|
String value = properties.getProperty("base.video.path");
|
||||||
|
log.info("path:{}",value);
|
||||||
|
properties.setProperty("base.video.path",path);
|
||||||
|
log.info("properties:{}",properties);
|
||||||
|
String out_path = Thread.currentThread().getContextClassLoader().getResource("").getPath() + "video.properties";
|
||||||
|
fileOutputStream = new FileOutputStream(out_path);
|
||||||
|
properties.store(fileOutputStream,"保存");
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.info("选择路径出错!");
|
||||||
|
}finally {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
if (fileOutputStream != null){
|
||||||
|
fileOutputStream.close();
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,15 @@
|
||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
|
||||||
|
<?import javafx.scene.control.Button?>
|
||||||
|
<?import javafx.scene.control.Label?>
|
||||||
|
<?import javafx.scene.control.TextField?>
|
||||||
|
<?import javafx.scene.layout.AnchorPane?>
|
||||||
|
|
||||||
|
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/19" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.zhangmeng.tools.controller.VideoSetController">
|
||||||
|
<children>
|
||||||
|
<Label layoutX="84.0" layoutY="131.0" text="视频目录" AnchorPane.topAnchor="131.0" />
|
||||||
|
<TextField fx:id="text_file" layoutX="148.0" layoutY="127.0" prefHeight="25.0" prefWidth="305.0" />
|
||||||
|
<Button fx:id="file_choose_button" layoutX="472.0" layoutY="127.0" mnemonicParsing="false" onAction="#choose_file" text="Button" />
|
||||||
|
<Button layoutX="256.0" layoutY="250.0" mnemonicParsing="false" onAction="#commit" prefHeight="31.0" prefWidth="105.0" text="应用" />
|
||||||
|
</children>
|
||||||
|
</AnchorPane>
|
||||||
Loading…
Reference in New Issue