From ccee051cb4eddb9b10069ced416eaded10f145a7 Mon Sep 17 00:00:00 2001 From: Nathan Cannon Date: Sat, 2 Apr 2016 19:28:04 +0100 Subject: [PATCH] Centralised declaration of valid engine names. --- .../musicplayer/swingui/LibraryConfigGUI.java | 3 +-- .../java/musicplayer/util/ConfigManager.java | 25 ++++++++++++++++--- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/src/main/java/musicplayer/swingui/LibraryConfigGUI.java b/src/main/java/musicplayer/swingui/LibraryConfigGUI.java index cd610e7..3db264e 100644 --- a/src/main/java/musicplayer/swingui/LibraryConfigGUI.java +++ b/src/main/java/musicplayer/swingui/LibraryConfigGUI.java @@ -12,7 +12,6 @@ class LibraryConfigGUI { private JList listLibraryFolders; private final LibraryListModel listModel = new LibraryListModel<>(); private JPanel mainPanel; - private static final String[] engineNames = {"GStreamer", "VLC"}; public LibraryConfigGUI(){ JFrame frame = new JFrame(); @@ -52,7 +51,7 @@ class LibraryConfigGUI { private JPanel engineConfigUI() { JPanel container = new JPanel(new BorderLayout()); container.add(new JLabel("Select Engine: "), BorderLayout.WEST); - JComboBox comboBox = new JComboBox<>(engineNames); + JComboBox comboBox = new JComboBox<>(ConfigManager.engineNames); comboBox.setSelectedItem(ConfigManager.getPlayerEngine()); comboBox.addActionListener(e -> { ConfigManager.setPlayerEngine((String)comboBox.getSelectedItem()); diff --git a/src/main/java/musicplayer/util/ConfigManager.java b/src/main/java/musicplayer/util/ConfigManager.java index 53671e3..d187b12 100644 --- a/src/main/java/musicplayer/util/ConfigManager.java +++ b/src/main/java/musicplayer/util/ConfigManager.java @@ -21,6 +21,7 @@ public final class ConfigManager { private static final String libraryDisplayKey = "libraryDisplayKey"; private static final String lastVolumeKey = "volume"; private static final String engineKey = "engine"; + public static final String[] engineNames = {"GStreamer", "VLC"}; /** * @return List of directories used for music library indexing. @@ -85,6 +86,9 @@ public final class ConfigManager { writeSettings(); } + /** + * @return The volume the player was last set to. + */ public static int getLastVolume(){ try (FileInputStream inputStream = new FileInputStream(propertiesFile)) { librarySettings.load(inputStream); @@ -96,11 +100,18 @@ public final class ConfigManager { return 0; } - public static void setLastVolume(Integer index){ - librarySettings.setProperty(lastVolumeKey, index.toString()); + /** + * Set the volume that should be used on startup. + * @param volume New volume value. + */ + public static void setLastVolume(Integer volume){ + librarySettings.setProperty(lastVolumeKey, volume.toString()); writeSettings(); } + /** + * @return Name of playback engine to use for music playback. + */ public static String getPlayerEngine(){ try (FileInputStream inputStream = new FileInputStream(propertiesFile)) { librarySettings.load(inputStream); @@ -112,9 +123,15 @@ public final class ConfigManager { return "GStreamer"; } + /** + * Set the engine to use for music playback on application start. + * @param engineName Name of engine. + */ public static void setPlayerEngine(String engineName){ - librarySettings.setProperty(engineKey, engineName); - writeSettings(); + if(Arrays.asList(engineNames).contains(engineName)) { + librarySettings.setProperty(engineKey, engineName); + writeSettings(); + } } private static void writeSettings() {