Skip to content

Commit

Permalink
test with java prefs api // refs #41
Browse files Browse the repository at this point in the history
  • Loading branch information
tofi86 committed Feb 7, 2019
1 parent 67a5283 commit 57d26e4
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
import javax.swing.JFrame;
import javax.swing.UIManager;

import de.paginagmbh.epubchecker.PreferenceManager.Preference;



/**
Expand Down Expand Up @@ -131,6 +133,8 @@ public PaginaEPUBChecker(String[] args) {

// write window dimension and position to config file
StringHelper.writeStringToFile(FileManager.path_WindowFile, (int)MainGuiDimension.getWidth() + "x" + (int)MainGuiDimension.getHeight() + "@" + (int)MainGuiPosition.getX() + "," + (int)MainGuiPosition.getY());
PreferenceManager.savePref(Preference.WINDOWPOSITION, (int)MainGuiPosition.getX() + "," + (int)MainGuiPosition.getY());
System.out.println(PreferenceManager.getPref(Preference.WINDOWPOSITION));
}
});
}
Expand Down
29 changes: 29 additions & 0 deletions src/main/java/de/paginagmbh/epubchecker/PreferenceManager.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.paginagmbh.epubchecker;

import java.util.prefs.BackingStoreException;
import java.util.prefs.Preferences;


public class PreferenceManager {

private static String prefsNode = "de/paginagmbh/epubchecker";
public enum Preference {
WINDOWPOSITION;
}

public static String getPref(Preference pref) {
Preferences prefs = Preferences.userRoot().node(prefsNode);
return prefs.get(pref.toString().toLowerCase(), null);
}

public static void savePref(Preference pref, String value) {
Preferences prefs = Preferences.userRoot().node(prefsNode);
prefs.put(pref.toString().toLowerCase(), value);
try {
prefs.flush();
} catch (BackingStoreException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}

0 comments on commit 57d26e4

Please sign in to comment.