List of usage examples for java.util.prefs Preferences get
public abstract String get(String key, String def);
From source file:de.tbuchloh.kiskis.util.Settings.java
public static Preferences initPreferences() { final Preferences n = Preferences.userNodeForPackage(Settings.class); final String newVersion = BuildProperties.getVersion(); final String previousVersion = n.get(K_PROGRAM_VERSION, newVersion); if (LOG.isDebugEnabled()) { LOG.debug(String.format("oldVersion=%1$s, newVersion=%2$s", previousVersion, newVersion)); }// w w w .ja va 2s.co m if (!VersionTools.isCompatible(previousVersion, newVersion)) { LOG.debug("Versions not compatible! Recreating preference node for version=" + newVersion); try { n.removeNode(); } catch (final BackingStoreException e) { LOG.error("Could not remove preference node", e); } final Preferences newN = Preferences.userNodeForPackage(Settings.class); newN.put(K_PROGRAM_VERSION, newVersion); return newN; } LOG.debug("Preferences seem to be compatible"); return n; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
public static String getPreferredLookAndFeel() { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); if (prefs != null) { return prefs.get(LOOK_AND_FEEL_KEY, DEFAULT_LOOK_AND_FEEL); }//from ww w . j av a2s . c om return DEFAULT_LOOK_AND_FEEL; }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
public static GraphPanel load(Preferences p, SystemState state, GraphsPanel gps) { DataSampler sampler = (DataSampler) state.getItemByID(DataSampler.ID, StatefulItemClass.WORKFLOW); GraphPanel g = new GraphPanel(state, gps); int ec = p.getInt("enabledCount", 0); for (int i = 0; i < ec; i++) { Preferences gp = p.node("series" + i); String key = gp.get("key", null); if (key == null) { throw new RuntimeException("Null series key"); }//w w w. j a va 2s . c o m int cr = gp.getInt("color.r", 255); int cg = gp.getInt("color.g", 0); int cb = gp.getInt("color.b", 0); g.enable(sampler.getSeries(key), false); g.setColor(key, new Color(cr, cg, cb)); } return g; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * @return true if the last time the application was closed, advanced mode * was in use/* w ww . j a v a 2 s . c o m*/ */ public static boolean getPreviousApplicationMode() { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); if (prefs != null) { String previouslyUsedMode = prefs.get(MODE_PREF_KEY, ""); if (!StringUtils.isEmpty(previouslyUsedMode)) { return previouslyUsedMode.equals(ADVANCED_MODE_PREF_VALUE); } } return false; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * @return the parent directory for the dataset that was most recently * opened using intkey/*from www . j av a 2 s. c o m*/ */ public static File getSavedLastOpenedDatasetDirectory() { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); if (prefs != null) { String lastOpenedDirectoryPath = prefs.get(LAST_OPENED_DATASET_LOCATION_PREF_KEY, ""); if (!StringUtils.isEmpty(lastOpenedDirectoryPath)) { return new File(lastOpenedDirectoryPath); } } return null; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
public static List<Pair<String, String>> getPreviouslyUsedFiles() { List<Pair<String, String>> retList = new ArrayList<Pair<String, String>>(); Preferences prefs = Preferences.userNodeForPackage(Intkey.class); if (prefs != null) { try {//from w w w . j a va 2s. c om String mru = prefs.get(MRU_FILES_PREF_KEY, ""); if (!StringUtils.isEmpty(mru)) { String[] mruFiles = mru.split(MRU_FILES_SEPARATOR); for (String mruFile : mruFiles) { String[] mruFileItems = mruFile.split(MRU_ITEM_SEPARATOR); retList.add(new Pair<String, String>(mruFileItems[0], mruFileItems[1])); } } } catch (Exception e) { // An error occurred. Clear the most recently used files list and return an empty list. prefs.remove(MRU_FILES_PREF_KEY); try { prefs.sync(); } catch (BackingStoreException bse) { throw new RuntimeException(bse); } return Collections.EMPTY_LIST; } } return retList; }
From source file:org.broad.igv.DirectoryManager.java
private static File getIgvDirectoryOverride() { Preferences userPrefs = null; File override = null;/*from w w w .j a v a2 s .co m*/ try { // See if an override location has been specified. This is stored with the Java Preferences API userPrefs = Preferences.userNodeForPackage(Globals.class); String userDir = userPrefs.get(IGV_DIR_USERPREF, null); if (userDir != null) { override = new File(userDir); if (!override.exists()) { override = null; userPrefs.remove(IGV_DIR_USERPREF); } } } catch (Exception e) { userPrefs.remove(IGV_DIR_USERPREF); override = null; System.err.println("Error creating user directory"); e.printStackTrace(); } return override; }
From source file:au.org.ala.delta.intkey.ui.UIUtils.java
/** * Gets the dataset index from preferences * /* www.j a v a 2 s.c o m*/ * @return The dataset index - a list of dataset description, dataset path * value pairs */ public static List<Pair<String, String>> readDatasetIndex() { Preferences prefs = Preferences.userNodeForPackage(Intkey.class); List<Pair<String, String>> indexList = new ArrayList<Pair<String, String>>(); if (prefs != null) { String datasetIndexJSON = prefs.get(DATASET_INDEX_PREF_KEY, ""); if (!StringUtils.isEmpty(datasetIndexJSON)) { List<List<String>> deserializedJSON = (List<List<String>>) JSONSerializer .toJava(JSONArray.fromObject(datasetIndexJSON)); for (List<String> datasetInfoList : deserializedJSON) { indexList.add(new Pair<String, String>(datasetInfoList.get(0), datasetInfoList.get(1))); } } } return indexList; }
From source file:org.apache.cayenne.modeler.ModelerPreferences.java
public static List<String> getLastProjFiles() { Preferences filesPrefs = getLastProjFilesPref(); ArrayList<String> arrayLastProjFiles = new ArrayList<>(); String[] keys = null;/*w w w .j a v a 2s . c om*/ try { keys = filesPrefs.keys(); } catch (BackingStoreException e) { logObj.warn("Error reading preferences file.", e); } if (keys != null) { int len = keys.length; ArrayList<Integer> keysInteger = new ArrayList<>(); for (int i = 0; i < len; i++) { keysInteger.add(new Integer(i)); } Collections.sort(keysInteger); for (int i = 0; i < len; i++) { arrayLastProjFiles.add(filesPrefs.get(keysInteger.get(i).toString(), "")); } } return arrayLastProjFiles; }
From source file:org.apache.cayenne.modeler.preferences.ModelerPreferences.java
public static List<String> getLastProjFiles() { Preferences filesPrefs = getLastProjFilesPref(); ArrayList<String> arrayLastProjFiles = new ArrayList<String>(); String[] keys = null;/*from w w w . j av a 2 s. c o m*/ try { keys = filesPrefs.keys(); } catch (BackingStoreException e) { logObj.warn("Error reading preferences file.", e); } if (keys != null) { int len = keys.length; ArrayList<Integer> keysInteger = new ArrayList<Integer>(); for (int i = 0; i < len; i++) { keysInteger.add(new Integer(i)); } Collections.sort(keysInteger); for (int i = 0; i < len; i++) { arrayLastProjFiles.add(filesPrefs.get(keysInteger.get(i).toString(), "")); } } return arrayLastProjFiles; }