diff --git a/src/main/java/com/zhangmeng/tools/controller/Md5Controller.java b/src/main/java/com/zhangmeng/tools/controller/Md5Controller.java index 29175d6..43b63fe 100644 --- a/src/main/java/com/zhangmeng/tools/controller/Md5Controller.java +++ b/src/main/java/com/zhangmeng/tools/controller/Md5Controller.java @@ -1,5 +1,6 @@ package com.zhangmeng.tools.controller; +import com.zhangmeng.tools.utils.AlertUtils; import com.zhangmeng.tools.utils.EncryptUtils; import javafx.fxml.FXML; import javafx.scene.control.*; @@ -29,19 +30,11 @@ public class Md5Controller { button.setOnAction(event -> { String text = text_filed.getText(); if (text.length() == 0) { - alert(); + AlertUtils.alert_warning("请输入将要加密的字符!"); return; } md5_32.setText(EncryptUtils.md5(text)); md5_16.setText(EncryptUtils.md5_16(text)); }); } - - private void alert() { - Alert alert = new Alert(Alert.AlertType.WARNING); - alert.initModality(Modality.APPLICATION_MODAL); - alert.setContentText("请输入将要加密的字符!"); - alert.setHeaderText(null); - alert.show(); - } } diff --git a/src/main/java/com/zhangmeng/tools/controller/MusicController.java b/src/main/java/com/zhangmeng/tools/controller/MusicController.java index b092b1a..dc3d953 100644 --- a/src/main/java/com/zhangmeng/tools/controller/MusicController.java +++ b/src/main/java/com/zhangmeng/tools/controller/MusicController.java @@ -1,11 +1,10 @@ package com.zhangmeng.tools.controller; -import com.leewyatt.rxcontrols.controls.RXAudioSpectrum; +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.io.resource.Resource; import com.leewyatt.rxcontrols.controls.RXLrcView; import com.leewyatt.rxcontrols.controls.RXMediaProgressBar; import com.leewyatt.rxcontrols.pojo.LrcDoc; -import com.leewyatt.rxcontrols.utils.RXResources; -import com.leewyatt.rxcontrols.utils.StyleUtil; import com.zhangmeng.tools.utils.*; import javafx.beans.property.SimpleBooleanProperty; import javafx.beans.property.SimpleDoubleProperty; @@ -18,40 +17,39 @@ import javafx.collections.ListChangeListener; import javafx.collections.ObservableList; import javafx.event.ActionEvent; import javafx.event.EventHandler; +import javafx.event.EventType; import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; import javafx.geometry.Insets; import javafx.geometry.Pos; import javafx.scene.Node; +import javafx.scene.Scene; import javafx.scene.control.*; -import javafx.scene.effect.BoxBlur; import javafx.scene.image.Image; import javafx.scene.image.ImageView; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Background; -import javafx.scene.layout.BackgroundFill; -import javafx.scene.layout.CornerRadii; -import javafx.scene.layout.HBox; +import javafx.scene.layout.*; import javafx.scene.media.AudioSpectrumListener; import javafx.scene.media.Media; import javafx.scene.media.MediaPlayer; import javafx.scene.paint.Color; -import javafx.scene.shape.Polygon; import javafx.scene.shape.Rectangle; -import javafx.scene.shape.Shape; import javafx.scene.text.Font; import javafx.scene.text.Text; import javafx.scene.text.TextAlignment; -import javafx.stage.FileChooser; +import javafx.stage.Stage; import javafx.stage.Window; import javafx.util.Callback; import javafx.util.Duration; +import lombok.extern.slf4j.Slf4j; import java.io.*; import java.net.URL; import java.net.URLDecoder; import java.nio.file.Files; import java.nio.file.Paths; +import java.util.Properties; import java.util.Random; import java.util.ResourceBundle; @@ -60,6 +58,7 @@ import java.util.ResourceBundle; * @version : 1.0 * @date : 2023-02-16 11:09 */ +@Slf4j public class MusicController { private static ObservableList dirs = FXCollections.observableArrayList(); @@ -81,6 +80,8 @@ public class MusicController { private ObservableList height; private final double width = SpectrumUtils.CELL_WIDTH; + private double sl_vol_num = 0.30; + public ObservableList getHeight() { return height; } @@ -148,11 +149,6 @@ public class MusicController { */ private final SimpleIntegerProperty cycletype = new SimpleIntegerProperty(0); - /** - * 光谱显示 - */ - private HBox spectrum; - @FXML private ListView listView; @@ -192,18 +188,15 @@ public class MusicController { this.mp = null; this.sb = new StringBuffer(""); } else { - this.mp = new MediaPlayer((Media) medias.get(this.playindex.get())); + this.mp = new MediaPlayer(medias.get(this.playindex.get())); //加载歌词 load_lyric(); - this.sb = new StringBuffer(((File) files.get(this.playindex.get())).getName()); + this.sb = new StringBuffer(files.get(this.playindex.get()).getName()); this.sb = new StringBuffer(this.sb.substring(0, this.sb.length() - 4)); + this.mp.setVolume(sl_vol_num); } - this.playindex.addListener(new ChangeListener() { - public void changed(ObservableValue observable, Number oldValue, Number newValue) { - MusicController.this.myPlay(); - } - }); + this.playindex.addListener((observable, oldValue, newValue) -> MusicController.this.myPlay()); //设置按钮 set_button(); @@ -253,15 +246,13 @@ public class MusicController { Image list_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_LIST)); this.iv_list = new ImageView(list_white); - this.iv_list.hoverProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue) { - MusicController.this.iv_list.setImage(list_black); - } + this.iv_list.hoverProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + MusicController.this.iv_list.setImage(list_black); + } - if (!newValue) { - MusicController.this.iv_list.setImage(list_white); - } + if (!newValue) { + MusicController.this.iv_list.setImage(list_white); } }); } @@ -273,19 +264,30 @@ public class MusicController { Image set_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_SET)); Image set_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_SET)); - this.iv_set = new ImageView(set_white); - this.iv_set.hoverProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue) { - MusicController.this.iv_set.setImage(set_black); - } - if (!newValue) { - MusicController.this.iv_set.setImage(set_white); + this.iv_set.hoverProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + MusicController.this.iv_set.setImage(set_black); + } + if (!newValue) { + MusicController.this.iv_set.setImage(set_white); + } + }); + + this.iv_set.setOnMouseClicked(event -> { + if (event.getClickCount() == 1 && event.getButton() == MouseButton.PRIMARY) { + AnchorPane root = null; + try { + root = FXMLLoader.load(ResourcesUtils.getResource("music-set")); + } catch (IOException e) { + e.printStackTrace(); } + Stage primaryStage= (Stage) MusicController.this.listView.getScene().getWindow(); + AlertUtils.alert("设置",root,primaryStage); } }); } + /** * 播放器底部 重复按钮 */ @@ -293,24 +295,21 @@ public class MusicController { Image cycle_icon_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_REPEAT)); Image cycle_icon_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_REPEAT)); + Image ICON_WHITE_RANDOM = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_RANDOM)); - this.iv_cycle = new ImageView(cycle_icon_white); - this.iv_cycle.hoverProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue) { - MusicController.this.iv_cycle.setImage(cycle_icon_black); - } - if (!newValue) { - MusicController.this.iv_cycle.setImage(cycle_icon_white); - } + this.iv_cycle.hoverProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + MusicController.this.iv_cycle.setImage(cycle_icon_black); + } + if (!newValue) { + MusicController.this.iv_cycle.setImage(cycle_icon_white); } }); - this.iv_cycle.setOnMouseClicked(new EventHandler() { - public void handle(MouseEvent event) { - if (event.getButton().equals(MouseButton.PRIMARY)) { - MusicController.this.cycletype.set((MusicController.this.cycletype.get() + 1) % 3); - MusicController.this.iv_cycle.setImage(cycle_icon_black); - } + this.iv_cycle.setOnMouseClicked(event -> { + if (event.getButton().equals(MouseButton.PRIMARY)) { + log.info("随机播放按钮:{}","cycle_button"); + MusicController.this.cycletype.set((MusicController.this.cycletype.get() + 1) % 3); + MusicController.this.iv_cycle.setImage(ICON_WHITE_RANDOM); } }); } @@ -323,7 +322,6 @@ public class MusicController { Image last_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_LAST)); Image last_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_LAST)); - this.iv_last = new ImageView(last_white); this.iv_last.hoverProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { if (newValue) { @@ -334,11 +332,9 @@ public class MusicController { } } }); - this.iv_last.setOnMouseClicked(new EventHandler() { - public void handle(MouseEvent event) { - if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { - MusicController.this.playindex.set((MusicController.this.playindex.get() - 1 + medias.size()) % medias.size()); - } + this.iv_last.setOnMouseClicked(event -> { + if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { + MusicController.this.playindex.set((MusicController.this.playindex.get() - 1 + medias.size()) % medias.size()); } }); } @@ -351,7 +347,6 @@ public class MusicController { Image next_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_NEXT)); Image next_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_NEXT)); - this.iv_next = new ImageView(next_white); this.iv_next.hoverProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { if (newValue) { @@ -366,7 +361,7 @@ public class MusicController { public void handle(MouseEvent event) { if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { if (MusicController.this.cycletype.get() == 0 || MusicController.this.cycletype.get() == 1) { - MusicController.this.playindex.set((MusicController.this.playindex.get() + 1) % MusicController.this.medias.size()); + MusicController.this.playindex.set((MusicController.this.playindex.get() + 1) % medias.size()); } if (MusicController.this.cycletype.get() == 2) { MusicController.this.playindex.set(MusicController.this.ran.nextInt(MusicController.this.medias.size())); @@ -387,9 +382,9 @@ public class MusicController { Image mute_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_MUTE)); Image mute_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_MUTE)); - this.iv_vol = new ImageView(vol_white); this.iv_vol.hoverProperty().addListener(new ChangeListener() { public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { + log.info("静音按钮:{}" , newValue); if (newValue) { if (MusicController.this.iv_vol.getImage().equals(vol_white)) { MusicController.this.iv_vol.setImage(vol_black); @@ -408,16 +403,15 @@ public class MusicController { } }); - this.iv_vol.setOnMouseClicked(new EventHandler() { - public void handle(MouseEvent event) { - if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { - if (MusicController.this.mp.isMute()) { - MusicController.this.mp.setMute(false); - MusicController.this.iv_vol.setImage(vol_black); - } else { - MusicController.this.mp.setMute(true); - MusicController.this.iv_vol.setImage(mute_black); - } + this.iv_vol.setOnMouseClicked(event -> { + log.info("音量按钮:{}" , event.getButton().name()); + if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { + if (MusicController.this.mp.isMute()) { + MusicController.this.mp.setMute(false); + MusicController.this.iv_vol.setImage(vol_black); + } else { + MusicController.this.mp.setMute(true); + MusicController.this.iv_vol.setImage(mute_black); } } }); @@ -427,8 +421,8 @@ public class MusicController { * 音量刻度 */ public void sl_vol_button() { - this.sl_vol = new Slider(0.0D, 1.0D, 0.1D); this.sl_vol.setPrefWidth(100.0D); + this.sl_vol.setValue(sl_vol_num); } @@ -443,104 +437,92 @@ public class MusicController { Image pause_white = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_WHITE_PAUSE)); Image pause_black = new Image(ImagePath.path(ImagePath.ImagePathType.ICON_BLACK_PAUSE)); - this.iv_play.hoverProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue) { - if (MusicController.this.isplaying.get()) { - MusicController.this.iv_play.setImage(pause_black); - } - - if (!MusicController.this.isplaying.get()) { - MusicController.this.iv_play.setImage(play_black); - } - } - if (!newValue) { - if (MusicController.this.isplaying.get()) { - MusicController.this.iv_play.setImage(pause_white); - } - if (!MusicController.this.isplaying.get()) { - MusicController.this.iv_play.setImage(play_white); - } - } - } - }); - this.iv_play.setOnMouseClicked(new EventHandler() { - public void handle(MouseEvent event) { - - System.out.println(6666); - - if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { - MusicController.this.isplaying.set(!MusicController.this.isplaying.get()); - if (MusicController.this.isplaying.get()) { - MusicController.this.iv_play.setImage(pause_white); - } else { - MusicController.this.iv_play.setImage(play_white); - } - } - } - }); - this.isplaying.addListener(new ChangeListener() { - public void changed(ObservableValue observable, Boolean oldValue, Boolean newValue) { - if (newValue) { - MusicController.this.iv_play.setImage(pause_white); - if (MusicController.this.mp.getStatus().equals(MediaPlayer.Status.PAUSED)) { - MusicController.this.mp.play(); - } else { - MusicController.this.myPlay(); - } - } - if (!newValue) { + this.iv_play.hoverProperty().addListener((observable, oldValue, newValue) -> { + if (newValue) { + if (MusicController.this.isplaying.get()) { MusicController.this.iv_play.setImage(pause_black); - MusicController.this.mp.pause(); } + + if (!MusicController.this.isplaying.get()) { + MusicController.this.iv_play.setImage(play_black); + } + } + if (!newValue) { + if (MusicController.this.isplaying.get()) { + MusicController.this.iv_play.setImage(pause_white); + } + if (!MusicController.this.isplaying.get()) { + MusicController.this.iv_play.setImage(play_white); + } + } + }); + this.iv_play.setOnMouseClicked(event -> { + if (event.getButton().equals(MouseButton.PRIMARY) && MusicController.this.mp != null) { + MusicController.this.isplaying.set(!MusicController.this.isplaying.get()); + if (MusicController.this.isplaying.get()) { + MusicController.this.iv_play.setImage(pause_white); + } else { + MusicController.this.iv_play.setImage(play_white); + } + } + }); + this.isplaying.addListener((observable, oldValue, newValue) -> { + if (newValue) { + MusicController.this.iv_play.setImage(pause_white); + if (MusicController.this.mp.getStatus().equals(MediaPlayer.Status.PAUSED)) { + MusicController.this.mp.play(); + } else { + MusicController.this.myPlay(); + } + } + if (!newValue) { + MusicController.this.iv_play.setImage(pause_black); + MusicController.this.mp.pause(); } }); } public void myPlay() { this.mp.dispose(); - this.mp = new MediaPlayer((Media) this.medias.get(this.playindex.get())); + this.mp = new MediaPlayer(this.medias.get(this.playindex.get())); initProgressBar(mp); - this.mp.setOnReady(new Runnable() { - public void run() { - MusicController.this.mp.play(); - MusicController.this.isplaying.set(true); - load_lyric(); - } + this.mp.setOnReady(() -> { + MusicController.this.mp.play(); + MusicController.this.isplaying.set(true); + load_lyric(); }); this.isplaying.set(true); - this.sb = new StringBuffer(((File) this.files.get(this.playindex.get())).getName()); + this.sb = new StringBuffer(files.get(this.playindex.get()).getName()); this.label_name.setText(this.sb.substring(0, this.sb.length() - 4)); - this.mp.volumeProperty().bind(this.sl_vol.valueProperty()); - this.mp.currentTimeProperty().addListener(new ChangeListener() { - public void changed(ObservableValue observable, Duration oldValue, Duration newValue) { - MusicController.this.playprogress.set(newValue.toSeconds() / MusicController.this.mp.getTotalDuration().toSeconds()); - int m1 = (int) newValue.toMinutes(); - int s1 = (int) (newValue.toSeconds() % 60.0D); - int m2 = (int) MusicController.this.mp.getTotalDuration().toMinutes(); - int s2 = (int) (MusicController.this.mp.getTotalDuration().toSeconds() % 60.0D); - MusicController.this.label_time.setText(m1 + ":" + s1 + " / " + m2 + ":" + s2); + + this.mp.setVolume(sl_vol_num); + + this.sl_vol.valueProperty().addListener((observableValue, number, t1) -> { + log.info("音量调节:{}",t1.doubleValue()); + MusicController.this.mp.setVolume(t1.doubleValue() / 100); + }); + + this.mp.currentTimeProperty().addListener((observable, oldValue, newValue) -> { + MusicController.this.playprogress.set(newValue.toSeconds() / MusicController.this.mp.getTotalDuration().toSeconds()); + int m1 = (int) newValue.toMinutes(); + int s1 = (int) (newValue.toSeconds() % 60.0D); + int m2 = (int) MusicController.this.mp.getTotalDuration().toMinutes(); + int s2 = (int) (MusicController.this.mp.getTotalDuration().toSeconds() % 60.0D); + MusicController.this.label_time.setText(m1 + ":" + s1 + " / " + m2 + ":" + s2); + }); + this.mp.setAudioSpectrumListener((timestamp, duration, magnitudes, phases) -> { + for (int i = 0; i < 100; ++i) { + MusicController.this.getHeight().get(i).set((magnitudes[i] + 60.0F) * 2.0F); } }); - this.mp.setAudioSpectrumListener(new AudioSpectrumListener() { - public void spectrumDataUpdate(double timestamp, double duration, float[] magnitudes, float[] phases) { - for (int i = 0; i < 100; ++i) { - ((SimpleFloatProperty) MusicController.this.getHeight().get(i)).set((magnitudes[i] + 60.0F) * 2.0F); - } -// Mp3Cover.getRx().set(150.0F + phases[0] * 5.0F); -// Mp3Cover.getRy().set(150.0F + phases[0] * 5.0F); - } - }); - this.mp.setOnEndOfMedia(new Runnable() { - public void run() { - if (MusicController.this.cycletype.get() == 0) { - MusicController.this.playindex.set((MusicController.this.playindex.get() + 1) % medias.size()); - } else if (MusicController.this.cycletype.get() == 1) { - MusicController.this.playindex.set(MusicController.this.playindex.get()); - MusicController.this.myPlay(); - } else { - MusicController.this.playindex.set(MusicController.this.playindex.get() + MusicController.this.ran.nextInt(medias.size()) % medias.size()); - } + this.mp.setOnEndOfMedia(() -> { + if (MusicController.this.cycletype.get() == 0) { + MusicController.this.playindex.set((MusicController.this.playindex.get() + 1) % medias.size()); + } else if (MusicController.this.cycletype.get() == 1) { + MusicController.this.playindex.set(MusicController.this.playindex.get()); + MusicController.this.myPlay(); + } else { + MusicController.this.playindex.set(MusicController.this.playindex.get() + MusicController.this.ran.nextInt(medias.size()) % medias.size()); } }); @@ -553,15 +535,19 @@ public class MusicController { placehold.setFont(Font.font(19.0D)); listView.setPlaceholder(placehold); - listView.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, (CornerRadii)null, (Insets)null))); + listView.setBackground(new Background(new BackgroundFill(Color.TRANSPARENT, null, null))); listView.setFixedCellSize(40.0D); + list_cell(); + } + + private void list_cell(){ listView.setCellFactory(new Callback, ListCell>() { public ListCell call(ListView param) { final ListCell cell = new ListCell() { protected void updateItem(File item, boolean empty) { super.updateItem(item, empty); if (!empty && item != null) { - StringBuffer sb = new StringBuffer(item.getName()); + sb = new StringBuffer(item.getName()); Text text = new Text(sb.substring(0, sb.length() - 4)); text.setWrappingWidth(300.0D); text.setTextAlignment(TextAlignment.CENTER); @@ -620,7 +606,6 @@ public class MusicController { return cell; } }); - } private void initProgressBar(MediaPlayer player) { @@ -676,7 +661,7 @@ public class MusicController { if (dirs.size() != 0) { return dirs; } else { - String dir = "D:\\KwDownload\\song"; + String dir = config_path(); File file = new File(dir); if (file.exists() && file.isDirectory()) { dirs.add(file); @@ -685,6 +670,18 @@ public class MusicController { } } + public static String config_path(){ + Resource resource = new ClassPathResource("music.properties"); + InputStream inputStream = resource.getStream(); + Properties properties = new Properties(); + try { + properties.load(inputStream); + } catch (IOException e) { + e.printStackTrace(); + } + return properties.getProperty("base.music.path"); + } + public static ObservableList getMusicMedias() { if (medias.size() == 0) { getDirsList().forEach((dir) -> { @@ -694,14 +691,12 @@ public class MusicController { return name.endsWith("mp3"); } }); - for (File file : files) { String uri = file.toURI().toASCIIString(); Media media = new Media(uri); medias.add(media); } } - }); return medias; } else { @@ -720,7 +715,6 @@ public class MusicController { }); files.addAll(mfiles); } - }); return files; } else { @@ -795,6 +789,5 @@ public class MusicController { } catch (IOException var2) { var2.printStackTrace(); } - } } diff --git a/src/main/java/com/zhangmeng/tools/controller/MusicSetController.java b/src/main/java/com/zhangmeng/tools/controller/MusicSetController.java new file mode 100644 index 0000000..cf60bdc --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/controller/MusicSetController.java @@ -0,0 +1,109 @@ +package com.zhangmeng.tools.controller; + +import cn.hutool.core.io.resource.ClassPathResource; +import cn.hutool.core.io.resource.Resource; +import com.leewyatt.rxcontrols.pojo.PathInfo; +import com.leewyatt.rxcontrols.utils.SvgUtil; +import com.zhangmeng.tools.utils.AlertUtils; +import com.zhangmeng.tools.utils.ImagePath; +import com.zhangmeng.tools.utils.ResourcesUtils; +import com.zhangmeng.tools.utils.SvgUtils; +import javafx.fxml.FXML; +import javafx.fxml.FXMLLoader; +import javafx.scene.Scene; +import javafx.scene.control.Button; +import javafx.scene.control.ListView; +import javafx.scene.control.TextField; +import javafx.scene.image.Image; +import javafx.scene.image.ImageView; +import javafx.scene.layout.AnchorPane; +import javafx.scene.shape.SVGPath; +import javafx.stage.DirectoryChooser; +import javafx.stage.Stage; +import javafx.stage.Window; +import lombok.extern.slf4j.Slf4j; +import org.apache.xmlgraphics.util.ClasspathResource; + +import java.awt.event.InputEvent; +import java.io.*; +import java.util.ArrayList; +import java.util.Properties; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-17 10:42 + */ +@Slf4j +public class MusicSetController { + + @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); + } + } + + @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 stageOwner = (Stage) stage.getOwner(); + 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.music.path"); + log.info("path:{}",value); + properties.setProperty("base.music.path",path); + log.info("properties:{}",properties); + String out_path = Thread.currentThread().getContextClassLoader().getResource("").getPath() + "music.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/java/com/zhangmeng/tools/utils/AlertUtils.java b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java new file mode 100644 index 0000000..6ec0058 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/utils/AlertUtils.java @@ -0,0 +1,43 @@ +package com.zhangmeng.tools.utils; + +import javafx.scene.Parent; +import javafx.scene.Scene; +import javafx.scene.control.Alert; +import javafx.stage.Modality; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-17 09:59 + */ +public class AlertUtils { + + /** + * 警告弹窗 + */ + public static void alert_warning(String msg) { + Alert alert = new Alert(Alert.AlertType.WARNING); + alert.initModality(Modality.APPLICATION_MODAL); + alert.setContentText(msg); + alert.setHeaderText(null); + alert.show(); + } + + public static void alert(String title, Parent node, Stage primaryStage){ + alert(title,node,600,400,primaryStage); + } + public static void alert(String title, Parent node, int width, int height, Stage primaryStage) { + Scene scene = new Scene(node); + Stage stage = new Stage(); + stage.setScene(scene); + stage.setTitle(title); + stage.setWidth(width); + stage.setHeight(height); + stage.initStyle(StageStyle.UTILITY); + stage.initOwner(primaryStage); + stage.initModality(Modality.APPLICATION_MODAL); + stage.show(); + } +} diff --git a/src/main/java/com/zhangmeng/tools/utils/ImagePath.java b/src/main/java/com/zhangmeng/tools/utils/ImagePath.java index bc798ca..313d87c 100644 --- a/src/main/java/com/zhangmeng/tools/utils/ImagePath.java +++ b/src/main/java/com/zhangmeng/tools/utils/ImagePath.java @@ -47,6 +47,8 @@ public class ImagePath { ICON_WHITE_RANDOM("随机白色图标"), ICON_BLACK_RANDOM("随机黑色图标"), + IMAGE_FILE("文件图标"), + ICON_NULL_COVER(""); private String desc; @@ -218,6 +220,8 @@ public class ImagePath { public static String ICON_NULL_COVER = "bgimg/2041075.jpg"; + public static String SVG_FILE = "svg/file.png"; + public static String path(ImagePathType type) { String path = null; @@ -341,6 +345,9 @@ public class ImagePath { case TOP_VIEW_Full_BLACK: path = ImagePath.TOP_VIEW_Full_BLACK; break; + case IMAGE_FILE: + path = ImagePath.SVG_FILE; + break; } return "static/" + path; } diff --git a/src/main/java/com/zhangmeng/tools/utils/MusicConstant.java b/src/main/java/com/zhangmeng/tools/utils/MusicConstant.java index 3d917b6..0518816 100644 --- a/src/main/java/com/zhangmeng/tools/utils/MusicConstant.java +++ b/src/main/java/com/zhangmeng/tools/utils/MusicConstant.java @@ -42,7 +42,6 @@ public class MusicConstant { public static OS getOS(){ String property = System.getProperty("os.name"); - System.out.println(property); if (property.contains("Windows")){ return OS.windows; } diff --git a/src/main/java/com/zhangmeng/tools/utils/SvgUtils.java b/src/main/java/com/zhangmeng/tools/utils/SvgUtils.java new file mode 100644 index 0000000..e7997a2 --- /dev/null +++ b/src/main/java/com/zhangmeng/tools/utils/SvgUtils.java @@ -0,0 +1,20 @@ +package com.zhangmeng.tools.utils; + +import javafx.scene.Group; +import javafx.scene.Parent; +import javafx.scene.shape.SVGPath; + +/** + * @author : 芊芊墨客 + * @version : 1.0 + * @date : 2023-02-17 10:58 + */ +public class SvgUtils { + + public static Parent svg(String content) { + SVGPath svgPath = new SVGPath(); + svgPath.setContent(content); + return new Group(svgPath); + } + +} diff --git a/src/main/resources/fxml/music-set.fxml b/src/main/resources/fxml/music-set.fxml new file mode 100644 index 0000000..9f3d8d3 --- /dev/null +++ b/src/main/resources/fxml/music-set.fxml @@ -0,0 +1,15 @@ + + + + + + + + + +