Centralised declaration of valid engine names.
This commit is contained in:
parent
ae0947a570
commit
ccee051cb4
@ -12,7 +12,6 @@ class LibraryConfigGUI {
|
|||||||
private JList<File> listLibraryFolders;
|
private JList<File> listLibraryFolders;
|
||||||
private final LibraryListModel<File> listModel = new LibraryListModel<>();
|
private final LibraryListModel<File> listModel = new LibraryListModel<>();
|
||||||
private JPanel mainPanel;
|
private JPanel mainPanel;
|
||||||
private static final String[] engineNames = {"GStreamer", "VLC"};
|
|
||||||
|
|
||||||
public LibraryConfigGUI(){
|
public LibraryConfigGUI(){
|
||||||
JFrame frame = new JFrame();
|
JFrame frame = new JFrame();
|
||||||
@ -52,7 +51,7 @@ class LibraryConfigGUI {
|
|||||||
private JPanel engineConfigUI() {
|
private JPanel engineConfigUI() {
|
||||||
JPanel container = new JPanel(new BorderLayout());
|
JPanel container = new JPanel(new BorderLayout());
|
||||||
container.add(new JLabel("Select Engine: "), BorderLayout.WEST);
|
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.setSelectedItem(ConfigManager.getPlayerEngine());
|
||||||
comboBox.addActionListener(e -> {
|
comboBox.addActionListener(e -> {
|
||||||
ConfigManager.setPlayerEngine((String)comboBox.getSelectedItem());
|
ConfigManager.setPlayerEngine((String)comboBox.getSelectedItem());
|
||||||
|
@ -21,6 +21,7 @@ public final class ConfigManager {
|
|||||||
private static final String libraryDisplayKey = "libraryDisplayKey";
|
private static final String libraryDisplayKey = "libraryDisplayKey";
|
||||||
private static final String lastVolumeKey = "volume";
|
private static final String lastVolumeKey = "volume";
|
||||||
private static final String engineKey = "engine";
|
private static final String engineKey = "engine";
|
||||||
|
public static final String[] engineNames = {"GStreamer", "VLC"};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return List of directories used for music library indexing.
|
* @return List of directories used for music library indexing.
|
||||||
@ -85,6 +86,9 @@ public final class ConfigManager {
|
|||||||
writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return The volume the player was last set to.
|
||||||
|
*/
|
||||||
public static int getLastVolume(){
|
public static int getLastVolume(){
|
||||||
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
|
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
|
||||||
librarySettings.load(inputStream);
|
librarySettings.load(inputStream);
|
||||||
@ -96,11 +100,18 @@ public final class ConfigManager {
|
|||||||
return 0;
|
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();
|
writeSettings();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Name of playback engine to use for music playback.
|
||||||
|
*/
|
||||||
public static String getPlayerEngine(){
|
public static String getPlayerEngine(){
|
||||||
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
|
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
|
||||||
librarySettings.load(inputStream);
|
librarySettings.load(inputStream);
|
||||||
@ -112,10 +123,16 @@ public final class ConfigManager {
|
|||||||
return "GStreamer";
|
return "GStreamer";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the engine to use for music playback on application start.
|
||||||
|
* @param engineName Name of engine.
|
||||||
|
*/
|
||||||
public static void setPlayerEngine(String engineName){
|
public static void setPlayerEngine(String engineName){
|
||||||
|
if(Arrays.asList(engineNames).contains(engineName)) {
|
||||||
librarySettings.setProperty(engineKey, engineName);
|
librarySettings.setProperty(engineKey, engineName);
|
||||||
writeSettings();
|
writeSettings();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void writeSettings() {
|
private static void writeSettings() {
|
||||||
try (FileWriter fileWriter = new FileWriter(settingsFilename)) {
|
try (FileWriter fileWriter = new FileWriter(settingsFilename)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user