From f521588043517a81d94a21baf9a4573c918d82bd Mon Sep 17 00:00:00 2001 From: zhangmeng <1334717033@qq.com> Date: Sat, 18 Feb 2023 11:48:27 +0800 Subject: [PATCH] =?UTF-8?q?2023=E5=B9=B42=E6=9C=8818=E6=97=A511:44:54?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/controller/VideoSetController.java | 97 +++++++++++++++++++ src/main/resources/fxml/video-set.fxml | 15 +++ 2 files changed, 112 insertions(+) create mode 100644 src/main/java/com/zhangmeng/tools/controller/VideoSetController.java create mode 100644 src/main/resources/fxml/video-set.fxml diff --git a/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java b/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java new file mode 100644 index 0000000..7d6d79d --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/VideoSetController.java @@ -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(); + } + } + } +} diff --git a/src/main/resources/fxml/video-set.fxml b/src/main/resources/fxml/video-set.fxml new file mode 100644 index 0000000..bd487f3 --- /dev/null +++ b/src/main/resources/fxml/video-set.fxml @@ -0,0 +1,15 @@ + + + + + + + + + +