Java Code Examples for java.util.prefs.Preferences#flush()
The following examples show how to use
java.util.prefs.Preferences#flush() .
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: ProxyPreferencesTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRemoveNode() throws BackingStoreException { Preferences orig = Preferences.userRoot().node(getName()); Preferences origChild = orig.node("child"); Preferences test = ProxyPreferences.getProxyPreferences(this, orig); assertTrue("Test child shoculd exist", test.nodeExists("child")); Preferences testChild = test.node("child"); testChild.removeNode(); assertFalse("Removed test child should not exist", testChild.nodeExists("")); assertFalse("Removed test child should not exist in parent", test.nodeExists("child")); test.flush(); assertFalse("Test.flush did not remove orig child", origChild.nodeExists("")); assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child")); }
Example 2
Source File: ProxyPreferencesImplTest.java From netbeans with Apache License 2.0 | 6 votes |
public void testRemoveNode() throws BackingStoreException { Preferences orig = Preferences.userRoot().node(getName()); Preferences origChild = orig.node("child"); Preferences test = ProxyPreferencesImpl.getProxyPreferences(this, orig); assertTrue("Test child shoculd exist", test.nodeExists("child")); Preferences testChild = test.node("child"); testChild.removeNode(); assertFalse("Removed test child should not exist", testChild.nodeExists("")); assertFalse("Removed test child should not exist in parent", test.nodeExists("child")); test.flush(); assertFalse("Test.flush did not remove orig child", origChild.nodeExists("")); assertFalse("Test.flush did not remove orig child from parent", orig.nodeExists("child")); }
Example 3
Source File: Whyline.java From whyline with MIT License | 6 votes |
private static String loadPreferences() { UI.class.getName(); // Load the preferences, if there are any. Preferences userPrefs = getPreferences(); // If no preference is set, use the current working directory. String WHYLINE_HOME = userPrefs.get(WHYLINE_HOME_PATH_KEY, System.getProperty("user.dir") + File.separatorChar + "whyline" + File.separatorChar); // Now store the preference, in case it wasn't stored before userPrefs.put(WHYLINE_HOME_PATH_KEY, WHYLINE_HOME); try { userPrefs.flush(); } catch (BackingStoreException e) { e.printStackTrace(); } return WHYLINE_HOME; }
Example 4
Source File: PreferencesRecentWorkspacesService.java From pdfsam with GNU Affero General Public License v3.0 | 5 votes |
@Override public void clear() { Preferences prefs = Preferences.userRoot().node(WORKSPACES_PATH); cache.clear(); try { prefs.removeNode(); prefs.flush(); } catch (BackingStoreException e) { LOG.error("Unable to clear recently used workspaces", e); } }
Example 5
Source File: TileImageFactory.java From triplea with GNU General Public License v3.0 | 5 votes |
public static void setShowMapBlends(final boolean showMapBlends) { isDirty |= TileImageFactory.showMapBlends != showMapBlends; TileImageFactory.showMapBlends = showMapBlends; final Preferences prefs = Preferences.userNodeForPackage(TileImageFactory.class); prefs.putBoolean(SHOW_MAP_BLENDS_PREFERENCE, TileImageFactory.showMapBlends); try { prefs.flush(); } catch (final BackingStoreException ex) { log.log(Level.SEVERE, "failed to save value: " + showMapBlends, ex); } }
Example 6
Source File: ConverterPreferences.java From phoebus with Eclipse Public License 1.0 | 5 votes |
public static void setAutoConverterDir(final String path) { auto_converter_dir = new File(path); final Preferences prefs = Preferences.userNodeForPackage(ConverterPreferences.class); prefs.put("auto_converter_dir", path); try { prefs.flush(); } catch (Exception ex) { logger.log(Level.WARNING, "Cannot update auto_converter_dir", ex); } }
Example 7
Source File: ControlsDialog.java From halfnes with GNU General Public License v3.0 | 5 votes |
private void jButtonOKActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonOKActionPerformed // if ("OK".equals(evt.getActionCommand())) { //here we go... save everything and hide the window Preferences prefs = PrefsSingleton.get(); prefs.putInt("keyUp1", keys[0][0]); prefs.putInt("keyDown1", keys[0][1]); prefs.putInt("keyLeft1", keys[0][2]); prefs.putInt("keyRight1", keys[0][3]); prefs.putInt("keyA1", keys[0][4]); prefs.putInt("keyB1", keys[0][5]); prefs.putInt("keySelect1", keys[0][6]); prefs.putInt("keyStart1", keys[0][7]); prefs.putInt("keyUp2", keys[1][0]); prefs.putInt("keyDown2", keys[1][1]); prefs.putInt("keyLeft2", keys[1][2]); prefs.putInt("keyRight2", keys[1][3]); prefs.putInt("keyA2", keys[1][4]); prefs.putInt("keyB2", keys[1][5]); prefs.putInt("keySelect2", keys[1][6]); prefs.putInt("keyStart2", keys[1][7]); try { prefs.flush(); } catch (BackingStoreException ex) { Logger.getLogger(ControlsDialog.class.getName()).log(Level.SEVERE, null, ex); } okClicked = true; this.setVisible(false); // } }
Example 8
Source File: InstancePropertiesManager.java From netbeans with Apache License 2.0 | 5 votes |
/** * Creates and returns properties in the given namespace. It is * perfectly legal to call this method multiple times with the same * namespace as a parameter - it will always create new instance * of InstanceProperties. Returned properties should serve for persistence * of the single server instance. * * @param namespace string identifying the namespace of created InstanceProperties * @return new InstanceProperties logically placed in the given namespace */ public InstanceProperties createProperties(String namespace) { Preferences prefs = NbPreferences.forModule(InstancePropertiesManager.class); try { prefs = prefs.node(namespace); boolean next = true; String id = null; synchronized (this) { while (next) { id = Integer.toString(random.nextInt(Integer.MAX_VALUE)); next = prefs.nodeExists(id); } prefs = prefs.node(id); prefs.flush(); InstanceProperties created = new DefaultInstanceProperties(id, this, prefs); cache.put(prefs, created); return created; } } catch (BackingStoreException ex) { LOGGER.log(Level.INFO, null, ex); throw new IllegalStateException(ex); } }
Example 9
Source File: ClientSetting.java From triplea with GNU General Public License v3.0 | 5 votes |
private static void flush(final Preferences preferences) { try { preferences.flush(); } catch (final BackingStoreException e) { log.log(Level.SEVERE, "Failed to persist client settings", e); } }
Example 10
Source File: CheckUserPrefLater.java From jdk8u-jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); String result = prefs.get("Check", null); if ((result == null) || !(result.equals("Success"))) throw new RuntimeException("User pref not stored!"); prefs.remove("Check"); prefs.flush(); }
Example 11
Source File: ProxyPreferencesTest.java From netbeans with Apache License 2.0 | 5 votes |
public void testSimpleFlush() throws BackingStoreException { Preferences orig = Preferences.userRoot().node(getName()); assertNull("Original contains value", orig.get("key-1", null)); Preferences test = ProxyPreferences.getProxyPreferences(this, orig); assertNull("Test should not contains pair", orig.get("key-1", null)); test.put("key-1", "xyz"); assertEquals("Test doesn't contain new pair", "xyz", test.get("key-1", null)); test.flush(); assertEquals("Test should still contain the pair", "xyz", test.get("key-1", null)); assertEquals("Test didn't flush the pair", "xyz", orig.get("key-1", null)); }
Example 12
Source File: CheckUserPrefLater.java From openjdk-8 with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); String result = prefs.get("Check", null); if ((result == null) || !(result.equals("Success"))) throw new RuntimeException("User pref not stored!"); prefs.remove("Check"); prefs.flush(); }
Example 13
Source File: ClipPlayer.java From triplea with GNU General Public License v3.0 | 5 votes |
/** * Flushes sounds preferences to persisted data store. This method is *slow* and resource * expensive. */ void saveSoundPreferences() { final Preferences prefs = Preferences.userNodeForPackage(ClipPlayer.class); try { prefs.flush(); } catch (final BackingStoreException e) { log.log(Level.SEVERE, "Failed to flush preferences: " + prefs.absolutePath(), e); } }
Example 14
Source File: HuffmanTree.java From elexis-3-core with Eclipse Public License 1.0 | 5 votes |
/** * compute a frequency table from an InputStream and save a compacted representation of this * table in the system preferences. (To be used later by @see #useStandardTable(String) ) * * @param name * name to give the table. * @param in * InputStream * @return true on success * @throws Exception */ public static boolean CreateStandardTableFromStream(String name, InputStream in) throws Exception{ int[] tbl = new int[TABLESIZE]; while (in.available() != 0) { int c = in.read(); tbl[c]++; } byte[] dest = HuffmanTree.compactTable(tbl); Preferences pref = Preferences.userNodeForPackage(Huff.class); Preferences node = pref.node("StandardTables"); node.putByteArray(name, dest); pref.flush(); return true; }
Example 15
Source File: CheckUserPrefLater.java From hottub with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); String result = prefs.get("Check", null); if ((result == null) || !(result.equals("Success"))) throw new RuntimeException("User pref not stored!"); prefs.remove("Check"); prefs.flush(); }
Example 16
Source File: CheckUserPrefLater.java From dragonwell8_jdk with GNU General Public License v2.0 | 5 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); String result = prefs.get("Check", null); if ((result == null) || !(result.equals("Success"))) throw new RuntimeException("User pref not stored!"); prefs.remove("Check"); prefs.flush(); }
Example 17
Source File: SizeSaver.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void store() { Dimension size = comp.getSize(); try { savedSize = new Dimension(size.width, size.height); Preferences prefs = getPrefs(); if(comp instanceof JFrame) { Point p = ((JFrame)comp).getLocationOnScreen(); // System.out.println(id + ": store pos " + p); prefs.put(KEY_X, Integer.toString((int)p.getX())); prefs.put(KEY_Y, Integer.toString((int)p.getY())); Toolkit tk = Toolkit.getDefaultToolkit(); if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) || tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) || tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) { int state = ((Frame)comp).getExtendedState(); prefs.put(KEY_STATE, Integer.toString(state)); } } // System.out.println(id + ": store " + size); prefs.put(KEY_WIDTH, Integer.toString(size.width)); prefs.put(KEY_HEIGHT, Integer.toString(size.height)); if(comp instanceof JSplitPane) { JSplitPane split = (JSplitPane)comp; prefs.put(KEY_SPLITPOS, Integer.toString(split.getDividerLocation())); // System.out.println(id + ": store split=" + split.getDividerLocation()); } prefs.flush(); } catch (Exception e) { errCount++; if(errCount < maxErr) { Activator.log.warn("Failed to store id=" + id + ", size=" + size, e); } } }
Example 18
Source File: CheckUserPrefFirst.java From jdk8u-jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); prefs.put("Check", "Success"); prefs.flush(); }
Example 19
Source File: AuxiliaryConfigBasedPreferencesProviderTest.java From netbeans with Apache License 2.0 | 4 votes |
public void testNoSaveWhenNotModified() throws IOException, BackingStoreException { lookup.setDelegates(Lookups.fixed(new TestAuxiliaryConfigurationImpl())); AuxiliaryConfiguration ac = p.getLookup().lookup(AuxiliaryConfiguration.class); assertNotNull(ac); final AtomicInteger putCount = new AtomicInteger(); ac = new CountingAuxiliaryConfiguration(ac, putCount); AuxiliaryConfigBasedPreferencesProvider provider = new AuxiliaryConfigBasedPreferencesProvider(p, ac, null, true); Preferences pref = provider.findModule("test"); pref.put("test", "test"); pref.node("subnode1/subnode2").put("somekey", "somevalue"); assertEquals(0, putCount.get()); pref.flush(); assertEquals(1, putCount.get()); pref.flush(); assertEquals(1, putCount.get()); }
Example 20
Source File: CheckUserPrefFirst.java From dragonwell8_jdk with GNU General Public License v2.0 | 4 votes |
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(CheckUserPrefFirst.class); prefs.put("Check", "Success"); prefs.flush(); }