Now remembers the last library display mode that was selected.

This commit is contained in:
neviyn 2016-02-26 22:00:33 +00:00
parent 35c953f473
commit f97a302c79
2 changed files with 29 additions and 6 deletions

View File

@ -15,6 +15,7 @@ public final class ConfigManager {
// Config Keys
static final String foldersKey = "libraryFolders";
static final String databaseKey = "databaseDir";
static final String libraryDisplayKey = "libraryDisplayKey";
public static List<File> getLibraryDirectories(){
try(FileInputStream inputStream = new FileInputStream(propertiesFile)){
@ -60,4 +61,24 @@ public final class ConfigManager {
e.printStackTrace();
}
}
public static int getLastDisplayTypeIndex(){
try (FileInputStream inputStream = new FileInputStream(propertiesFile)) {
librarySettings.load(inputStream);
if (librarySettings.containsKey(libraryDisplayKey)) {
return Integer.parseInt(librarySettings.getProperty(libraryDisplayKey));
}
} catch (IOException ignored) {
}
return 0;
}
public static void setLastDisplayTypeIndex(Integer index){
librarySettings.setProperty(libraryDisplayKey, index.toString());
try(FileWriter fileWriter = new FileWriter(settingsFilename)){
librarySettings.store(fileWriter, "");
} catch (IOException e) {
e.printStackTrace();
}
}
}

View File

@ -33,14 +33,12 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
private static DefaultMutableTreeNode updatingNode = new DefaultMutableTreeNode();
private boolean libraryUpdating = false;
private Map<String, Runnable> libraryDisplayVariants;
private Map<String, Runnable> libraryDisplayVariants = createDisplayVariantMap();
public PlayerGUI() {
createUI();
DatabaseManager.init();
resetTree();
libraryDisplayVariants = createDisplayVariantMap();
libraryDisplayVariants.keySet().forEach(libraryDisplayType::addItem);
Thread seekBarUpdater = new Thread(() -> {
boolean running = true;
while (running) {
@ -53,7 +51,6 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
}
});
seekBarUpdater.start();
createMenuBar();
refreshLibrary();
}
@ -256,9 +253,14 @@ public class PlayerGUI implements PlayerCallbackInterface, LibraryCallbackInterf
final JPanel libraryAndComboboxPane = new JPanel();
libraryAndComboboxPane.setLayout(new BorderLayout(0, 0));
libraryAndPlaylistPane.setLeftComponent(libraryAndComboboxPane);
libraryDisplayVariants.keySet().forEach(libraryDisplayType::addItem);
libraryDisplayType.setSelectedIndex(ConfigManager.getLastDisplayTypeIndex());
libraryDisplayType.addItemListener(e -> {
if (!libraryUpdating && e.getStateChange() == ItemEvent.SELECTED)
if (e.getStateChange() == ItemEvent.SELECTED) {
ConfigManager.setLastDisplayTypeIndex(libraryDisplayType.getSelectedIndex());
if(!libraryUpdating)
libraryDisplayVariants.get(libraryDisplayType.getSelectedItem().toString()).run();
}
});
libraryAndComboboxPane.add(libraryDisplayType, BorderLayout.NORTH);
final JScrollPane libraryPane = new JScrollPane();