List of usage examples for java.util.prefs Preferences get
public abstract String get(String key, String def);
From source file:fll.subjective.SubjectiveFrame.java
/** * Get the initial directory to which file dialogs should open. This supports * opening to a better directory across sessions. * /*from ww w . ja v a 2s. c o m*/ * @return the File for the initial directory */ private static File getInitialDirectory() { final Preferences preferences = Preferences.userNodeForPackage(SubjectiveFrame.class); final String path = preferences.get(INITIAL_DIRECTORY_PREFERENCE_KEY, null); File dir = null; if (null != path) { dir = new File(path); } return dir; }
From source file:fll.subjective.SubjectiveFrame.java
/** * Set the initial directory preference. This supports opening new file * dialogs to a (hopefully) better default in the user's next session. * /*w ww.j a v a 2 s. c o m*/ * @param dir the File for the directory in which file dialogs should open */ private static void setInitialDirectory(final File dir) { // Store only directories final File directory; if (dir.isDirectory()) { directory = dir; } else { directory = dir.getParentFile(); } final Preferences preferences = Preferences.userNodeForPackage(SubjectiveFrame.class); final String previousPath = preferences.get(INITIAL_DIRECTORY_PREFERENCE_KEY, null); if (!directory.toString().equals(previousPath)) { preferences.put(INITIAL_DIRECTORY_PREFERENCE_KEY, directory.toString()); } }
From source file:edu.umd.cs.findbugs.gui2.GUISaveState.java
public static void loadInstance() { GUISaveState newInstance = new GUISaveState(); newInstance.recentFiles = new ArrayList<File>(); Preferences p = Preferences.userNodeForPackage(GUISaveState.class); newInstance.tabSize = p.getInt(TAB_SIZE, 4); newInstance.fontSize = p.getFloat(FONT_SIZE, 12.0f); newInstance.starterDirectoryForLoadBugs = new File( p.get(GUISaveState.STARTERDIRECTORY, SystemProperties.getProperty("user.dir"))); int prevCommentsSize = p.getInt(GUISaveState.PREVCOMMENTSSIZE, 0); for (int x = 0; x < prevCommentsSize; x++) { String comment = p.get(GUISaveState.COMMENTKEYS[x], ""); newInstance.previousComments.add(comment); }//ww w. j av a 2 s. c om int size = Math.min(MAXNUMRECENTPROJECTS, p.getInt(GUISaveState.NUMPROJECTS, 0)); for (int x = 0; x < size; x++) { newInstance.addRecentFile(new File(p.get(GUISaveState.RECENTPROJECTKEYS[x], ""))); } int sorterSize = p.getInt(GUISaveState.SORTERTABLELENGTH, -1); if (sorterSize != -1) { ArrayList<Sortables> sortColumns = new ArrayList<Sortables>(); String[] sortKeys = GUISaveState.generateSorterKeys(sorterSize); for (int x = 0; x < sorterSize; x++) { Sortables s = Sortables.getSortableByPrettyName(p.get(sortKeys[x], "*none*")); if (s == null) { if (MainFrame.GUI2_DEBUG) { System.err.println("Sort order was corrupted, using default sort order"); } newInstance.useDefault = true; break; } sortColumns.add(s); } if (!newInstance.useDefault) { // add in default columns Set<Sortables> missingSortColumns = new HashSet<Sortables>(Arrays.asList(DEFAULT_COLUMN_HEADERS)); missingSortColumns.removeAll(sortColumns); sortColumns.addAll(missingSortColumns); newInstance.sortColumns = sortColumns.toArray(new Sortables[sortColumns.size()]); } } else { newInstance.useDefault = true; } newInstance.dockingLayout = p.getByteArray(DOCKINGLAYOUT, new byte[0]); String boundsString = p.get(FRAME_BOUNDS, null); Rectangle r = new Rectangle(0, 0, 800, 650); if (boundsString != null) { String[] a = boundsString.split(",", 4); if (a.length > 0) { try { r.x = Math.max(0, Integer.parseInt(a[0])); } catch (NumberFormatException nfe) { assert true; } } if (a.length > 1) { try { r.y = Math.max(0, Integer.parseInt(a[1])); } catch (NumberFormatException nfe) { assert true; } } if (a.length > 2) { try { r.width = Math.max(40, Integer.parseInt(a[2])); } catch (NumberFormatException nfe) { assert true; } } if (a.length > 3) { try { r.height = Math.max(40, Integer.parseInt(a[3])); } catch (NumberFormatException nfe) { assert true; } } } newInstance.frameBounds = r; newInstance.extendedWindowState = p.getInt(EXTENDED_WINDOW_STATE, Frame.NORMAL); newInstance.splitMain = p.getInt(SPLIT_MAIN, 400); newInstance.splitSummary = p.getInt(SPLIT_SUMMARY_NEW, 400); newInstance.splitTop = p.getInt(SPLIT_TOP, -1); newInstance.splitTreeComments = p.getInt(SPLIT_TREE_COMMENTS, 250); newInstance.packagePrefixSegments = p.getInt(PACKAGE_PREFIX_SEGEMENTS, 3); String plugins = p.get(CUSTOM_PLUGINS, ""); if (plugins.length() > 0) { for (String s : plugins.split(" ")) { try { URI u = new URI(s); Plugin.addCustomPlugin(u); newInstance.customPlugins.add(u); } catch (PluginException e) { assert true; } catch (URISyntaxException e) { assert true; } } } String enabledPluginsString = p.get(ENABLED_PLUGINS, ""); String disabledPluginsString = p.get(DISABLED_PLUGINS, ""); newInstance.enabledPlugins = new ArrayList<String>(Arrays.asList(enabledPluginsString.split(","))); newInstance.disabledPlugins = new ArrayList<String>(Arrays.asList(disabledPluginsString.split(","))); instance = newInstance; }
From source file:org.esa.snap.smart.configurator.PerformanceParameters.java
/** * * Reads the parameters files and system settings to retrieve the actual performance parameters. * It updates the "actualParameters" according to the configuration loaded. * * @return the actual performance parameters, loaded by this method *///w w w . j a v a 2 s . co m synchronized static PerformanceParameters loadConfiguration() { Config configuration = Config.instance().load(); Preferences preferences = configuration.preferences(); PerformanceParameters actualParameters = new PerformanceParameters(); VMParameters netBeansVmParameters = VMParameters.load(); actualParameters.setVMParameters(netBeansVmParameters.toString()); actualParameters.setCachePath(SystemUtils.getCacheDir().toPath()); final int defaultNbThreads = JavaSystemInfos.getInstance().getNbCPUs(); actualParameters .setNbThreads(preferences.getInt(SystemUtils.SNAP_PARALLELISM_PROPERTY_NAME, defaultNbThreads)); //actualParameters.setDefaultTileSize(preferences.getInt(PROPERTY_DEFAULT_TILE_SIZE, 0)); actualParameters.setTileWidth(preferences.get(SYSPROP_READER_TILE_WIDTH, null)); actualParameters.setTileHeight(preferences.get(SYSPROP_READER_TILE_HEIGHT, null)); actualParameters.setCacheSize(preferences.getInt(PROPERTY_JAI_CACHE_SIZE, 1024)); return actualParameters; }
From source file:com.diversityarrays.dal.db.TestDalDatabase.java
@SuppressWarnings({ "rawtypes", "unchecked" }) static private DalDatabase createKddartDalDatabase() throws DalDbException { Preferences preferences = Preferences.userNodeForPackage(DalServer.class); DalDbProviderService service = new KddartDalDbProviderService(); Map<Parameter<?>, ParameterValue<?>> parameterValues = new HashMap<Parameter<?>, ParameterValue<?>>(); Preferences serviceNode = preferences.node("service/" + service.getClass().getName()); for (Parameter<?> param : service.getParametersRequired()) { String s = serviceNode.get(param.name, null); try {/*from www . j a va2 s . c om*/ Object value = param.stringToValue(s); parameterValues.put(param, new ParameterValue(param, value)); if (KddartDalDatabase.PARAM_USERNAME.equals(param.name)) { USERNAME = s; } else if (KddartDalDatabase.PARAM_PASSWORD.equals(param.name)) { PASSWORD = s; } } catch (ParameterException e) { Throwable t = e.getCause(); if (t == null) { t = e; } if (t instanceof RuntimeException) { throw ((RuntimeException) t); } throw new RuntimeException(t); } } KddartDalDatabase result = (KddartDalDatabase) service.createDatabase(parameterValues.values(), ClosureUtils.nopClosure(), false); System.out.println(TestDalDatabase.class.getName() + " for KDDart: " + result.getDatabaseName()); result.setAutoSwitchGroupOnLogin(true); return result; }
From source file:de.dal33t.powerfolder.util.ConfigurationLoader.java
/** * PUBLIC because of tests. DO NOT USE. Use * {@link #merge(Properties, Properties, Preferences, boolean)} instead. * <p>/*from ww w . j ava 2s . c om*/ * Merges the give pre configuration properties into the target preferences. * It can be choosen if existing keys in the target preferences should be * replaced or not. Will only set those values from preConfig where the key * begins with "pref." and cut it off. "pref.xxx=true" will be set to * "xxx=true" in preferences. * * @param preConfig * the pre config * @param targetPreferences * the preferences to set the pre-configuration values into. * @param replaceExisting * if existing key/value pairs will be overwritten by pairs of * pre config. * @return the number of merged entries. */ public static int mergePreferences(Properties preConfig, Preferences targetPreferences, boolean replaceExisting) { Reject.ifNull(preConfig, "PreConfig is null"); Reject.ifNull(targetPreferences, "TargetPreferences is null"); int n = 0; for (Object obj : preConfig.keySet()) { String key = (String) obj; String value = preConfig.getProperty(key); if (!key.startsWith(PREFERENCES_PREFIX)) { continue; } else { key = key.substring(PREFERENCES_PREFIX.length(), key.length()); } boolean entryMissing = "-XXWEIRED-DEFAULT-VALUE" .equals(targetPreferences.get(key, "-XXWEIRED-DEFAULT-VALUE")); if (entryMissing || replaceExisting) { targetPreferences.put(key, value); n++; LOG.finer("Preconfigured " + key + "=" + value); } } if (n > 0) { LOG.fine(n + " default preferences set"); } else { LOG.finer("No additional default preferences set"); } return n; }
From source file:org.pentaho.di.core.util.StringPluginProperty.java
/** * {@inheritDoc}//from w ww .java 2 s. c om * * @see at.aschauer.commons.pentaho.plugin.PluginProperty#readFromPreferences(java.util.prefs.Preferences) */ public void readFromPreferences(final Preferences node) { this.setValue(node.get(this.getKey(), this.getValue())); }
From source file:com.moss.jdbcdrivers.JdbcConnectionConfig.java
public void loadFromPrefs(Preferences node) { jdbcUrl = node.get("url", ""); jdbcDriverClassName = node.get("driver", ""); logon = node.get("logon", ""); password = node.get("password", ""); }
From source file:de.nrw.hbz.regal.sync.MyPreferences.java
MyPreferences(Class<?> cl) { try {/*from w ww. j av a2s .c o m*/ Preferences p = Preferences.userNodeForPackage(cl); for (String preference : p.keys()) { this.addProperty(preference, p.get(preference, null)); } } catch (BackingStoreException e) { // empty preferences are ok } }
From source file:org.pdfsam.ui.DefaultStageService.java
public StageStatus getLatestStatus() { Preferences node = Preferences.userRoot().node(STAGE_PATH); try {// w w w . j av a2s. c o m String statusString = node.get(STAGE_STATUS_KEY, ""); if (isNotBlank(statusString)) { return JSON.std.beanFrom(StageStatus.class, statusString); } } catch (IOException e) { LOG.error("Unable to get latest stage status", e); } return StageStatus.NULL; }