Java Code Examples for java.util.prefs.Preferences#node()
The following examples show how to use
java.util.prefs.Preferences#node() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void write(Preferences prefs, String[] tree) { for(String s : tree) { int equalIdx = s.lastIndexOf('='); assertTrue(equalIdx != -1); String value = s.substring(equalIdx + 1); String key; String nodePath; int slashIdx = s.lastIndexOf('/', equalIdx); if (slashIdx != -1) { key = s.substring(slashIdx + 1, equalIdx); nodePath = s.substring(0, slashIdx); } else { key = s.substring(0, equalIdx); nodePath = ""; } Preferences node = prefs.node(nodePath); node.put(key, value); } }
Example 2
Source File: PreferenceUtilites.java From constellation with Apache License 2.0 | 6 votes |
/** * Add a PreferenceChangeListener to a specified preference node. * <p> * For example, to listen for font size changes, listen to * "org/netbeans/core/output2". * * @param preferenceNode The preference node to listen to. * @param pcl A PreferenceChangeListener * * @return True if the addPreferenceChangeListener() worked, false * otherwise. */ public static boolean addPreferenceChangeListener(final String preferenceNode, final PreferenceChangeListener pcl) { try { Preferences p = NbPreferences.root(); if (p.nodeExists(preferenceNode)) { p = p.node(preferenceNode); p.addPreferenceChangeListener(pcl); return true; } } catch (BackingStoreException ex) { Exceptions.printStackTrace(ex); } return false; }
Example 3
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void write(Preferences prefs, String[] tree) { for(String s : tree) { int equalIdx = s.lastIndexOf('='); assertTrue(equalIdx != -1); String value = s.substring(equalIdx + 1); String key; String nodePath; int slashIdx = s.lastIndexOf('/', equalIdx); if (slashIdx != -1) { key = s.substring(slashIdx + 1, equalIdx); nodePath = s.substring(0, slashIdx); } else { key = s.substring(0, equalIdx); nodePath = ""; } Preferences node = prefs.node(nodePath); node.put(key, value); } }
Example 4
Source File: GraphPanel.java From swift-k with Apache License 2.0 | 6 votes |
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"); } 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; }
Example 5
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void checkContains(Preferences prefs, String[] tree, String prefsId) throws BackingStoreException { for(String s : tree) { int equalIdx = s.lastIndexOf('='); assertTrue(equalIdx != -1); String value = s.substring(equalIdx + 1); String key; String nodePath; int slashIdx = s.lastIndexOf('/', equalIdx); if (slashIdx != -1) { key = s.substring(slashIdx + 1, equalIdx); nodePath = s.substring(0, slashIdx); } else { key = s.substring(0, equalIdx); nodePath = ""; } assertTrue(prefsId + " doesn't contain node '" + nodePath + "'", prefs.nodeExists(nodePath)); Preferences node = prefs.node(nodePath); String realValue = node.get(key, null); assertNotNull(prefsId + ", '" + nodePath + "' node doesn't contain key '" + key + "'", realValue); assertEquals(prefsId + ", '" + nodePath + "' node, '" + key + "' contains wrong value", value, realValue); } }
Example 6
Source File: ProjectManager.java From markdown-writer-fx with BSD 2-Clause "Simplified" License | 6 votes |
private static List<File> getRecentProjects() { Preferences state = getProjectsState(); ArrayList<File> projects = new ArrayList<>(); try { String[] childrenNames = state.childrenNames(); for (String childName : childrenNames) { Preferences child = state.node(childName); String path = child.get(KEY_PATH, null); if (path != null) projects.add(new File(path)); } } catch (BackingStoreException ex) { // ignore ex.printStackTrace(); } return projects; }
Example 7
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
private void checkEquals(String msg, Preferences expected, Preferences test) throws BackingStoreException { assertEquals("Won't compare two Preferences with different absolutePath", expected.absolutePath(), test.absolutePath()); // check the keys and their values for(String key : expected.keys()) { String expectedValue = expected.get(key, null); assertNotNull(msg + "; Expected:" + expected.absolutePath() + " has no '" + key + "'", expectedValue); String value = test.get(key, null); assertNotNull(msg + "; Test:" + test.absolutePath() + " has no '" + key + "'", value); assertEquals(msg + "; Test:" + test.absolutePath() + "/" + key + " has wrong value", expectedValue, value); } // check the children for(String child : expected.childrenNames()) { assertTrue(msg + "; Expected:" + expected.absolutePath() + " has no '" + child + "' subnode", expected.nodeExists(child)); Preferences expectedChild = expected.node(child); assertTrue(msg + "; Test:" + test.absolutePath() + " has no '" + child + "' subnode", test.nodeExists(child)); Preferences testChild = test.node(child); checkEquals(msg, expectedChild, testChild); } }
Example 8
Source File: InputContext.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 9
Source File: JdbcConnectionDefinitionManager.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 5 votes |
/** * Adds or updates the source list with the specified source entry. If the entry exists (has the same name), the new * entry will replace the old entry. If the enrty does not already exist, the new entry will be added to the list. <br> * Since the definition of the ConnectionDefintion ensures that it will be valid, no testing will be performed on the * contents of the ConnectionDefintion. * * @param source * the entry to add/update in the list * @throws IllegalArgumentException * indicates the source is <code>null</code> */ private boolean updateSourceList( final DriverConnectionDefinition source ) throws IllegalArgumentException { if ( source == null ) { throw new IllegalArgumentException( "The provided source is null" ); } // Update the node in the list final boolean updateExisting = ( connectionDefinitions.put( source.getName(), source ) != null ); // Update the information in the preferences try { final Preferences node = userPreferences.node( source.getName() ); put( node, TYPE_KEY, "local" ); put( node, DRIVER_KEY, source.getDriverClass() ); put( node, URL_KEY, source.getConnectionString() ); put( node, USERNAME_KEY, source.getUsername() ); put( node, PASSWORD_KEY, source.getPassword() ); put( node, HOSTNAME_KEY, source.getHostName() ); put( node, PORT_KEY, source.getPort() ); put( node, DATABASE_TYPE_KEY, source.getDatabaseType() ); put( node, DATABASE_NAME_KEY, source.getDatabaseName() ); final Preferences preferences = node.node( "properties" ); final Properties properties = source.getProperties(); final Iterator entryIterator = properties.entrySet().iterator(); while ( entryIterator.hasNext() ) { final Map.Entry entry = (Map.Entry) entryIterator.next(); put( preferences, String.valueOf( entry.getKey() ), String.valueOf( entry.getValue() ) ); } node.flush(); } catch ( BackingStoreException e ) { log.error( "Could not add/update connection entry [" + source.getName() + ']', e ); } return updateExisting; }
Example 10
Source File: InputContext.java From openjdk-jdk8u-backup with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 11
Source File: InputContext.java From jdk8u-dev-jdk with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 12
Source File: TestPreferences.java From netbeans with Apache License 2.0 | 5 votes |
public void testParent() { Preferences pref = getPreferencesNode(); Preferences pref2 = pref.node("1/2/3"); assertNotSame(pref, pref2); for (int i = 0; i < 3; i++) { pref2 = pref2.parent(); } assertSame(pref2.absolutePath(), pref, pref2); }
Example 13
Source File: UiOptions.java From netbeans with Apache License 2.0 | 5 votes |
private static synchronized Preferences getNode() { if ( node == null ) { Preferences p = NbPreferences.forModule(UiOptions.class); node = p.node(GO_TO_TYPE_DIALOG); } return node; }
Example 14
Source File: InputContext.java From hottub with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 15
Source File: InputContext.java From openjdk-jdk8u with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 16
Source File: InputContext.java From jdk8u60 with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 17
Source File: InputContext.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) { try { if (root.nodeExists(inputMethodSelectionKeyPath)) { Preferences node = root.node(inputMethodSelectionKeyPath); int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED); if (keyCode != KeyEvent.VK_UNDEFINED) { int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0); return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers); } } } catch (BackingStoreException bse) { } return null; }
Example 18
Source File: CIOptions.java From nb-ci-plugin with GNU General Public License v2.0 | 5 votes |
public void putEntries(final CIEntry.Type type, List<CIEntry> entries) { Preferences parent = getPreferences().node(getNodePath(type)); for (CIEntry entry : entries) { Preferences child = parent.node(entry.getName()); child.put(KEY_ENTRY_PATH, entry.getPath()); child.put(KEY_ENTRY_BRANCH, entry.getBranch()); child.put(KEY_ENTRY_VERSION, entry.getVersion()); } }
Example 19
Source File: TestFrame.java From ensemble-clustering with MIT License | 5 votes |
private void saveGeometry () { Preferences p = Preferences.userRoot(); Preferences oculus = p.node("com.oculusinfo"); Preferences test = oculus.node("testing"); Dimension size = getSize(); Point location = getLocation(); test.putInt("test.frame.x", location.x); test.putInt("test.frame.y", location.y); test.putInt("test.frame.width", size.width); test.putInt("test.frame.height", size.height); }
Example 20
Source File: GoToSettings.java From netbeans with Apache License 2.0 | 4 votes |
@NonNull private Preferences getSortingNode() { final Preferences prefs = NbPreferences.forModule(GoToSettings.class); return prefs.node(NODE_SORTING); }