Centralised declaration of valid engine names.

This commit is contained in:
neviyn 2016-04-02 19:28:04 +01:00
parent ae0947a570
commit ccee051cb4
2 changed files with 22 additions and 6 deletions

View File

@ -12,7 +12,6 @@ class LibraryConfigGUI {
private JList<File> listLibraryFolders;
private final LibraryListModel<File> 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<String> comboBox = new JComboBox<>(engineNames);
JComboBox<String> comboBox = new JComboBox<>(ConfigManager.engineNames);
comboBox.setSelectedItem(ConfigManager.getPlayerEngine());
comboBox.addActionListener(e -> {
ConfigManager.setPlayerEngine((String)comboBox.getSelectedItem());

View File

@ -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() {