Java Code Examples for java.util.prefs.Preferences#clear()
The following examples show how to use
java.util.prefs.Preferences#clear() .
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: ProjectSelection.java From marathonv5 with Apache License 2.0 | 6 votes |
private void storeFileNames() { Preferences p = Preferences.userNodeForPackage(this.getClass()); try { p.clear(); p.flush(); p = Preferences.userNodeForPackage(this.getClass()); int itemCount = projectInfotable.getItems().size(); int selected = projectInfotable.getSelectionModel().getSelectedIndex(); if (selected == -1) selected = 0; ProjectInfo pi = projectInfotable.getItems().get(selected); p.put("dirName0", pi.getFolder()); for (int i = 0, j = 1; i < itemCount; i++) { if (i != selected) { p.put("dirName" + j++, projectInfotable.getItems().get(i).getFolder()); } } p.flush(); } catch (BackingStoreException e) { return; } }
Example 2
Source File: Java14ConfigStorage.java From pentaho-reporting with GNU Lesser General Public License v2.1 | 6 votes |
/** * Stores the given properties on the defined path. * * @param configPath * the path on where to store the properties. * @param config * the properties which should be stored. * @throws ConfigStoreException * if an error occurred. */ public void store( final String configPath, final Configuration config ) throws ConfigStoreException { if ( ConfigFactory.isValidPath( configPath ) == false ) { throw new IllegalArgumentException( "The give path is not valid." ); } try { final Enumeration keys = config.getConfigProperties(); final Preferences pref = base.node( configPath ); pref.clear(); while ( keys.hasMoreElements() ) { final String key = (String) keys.nextElement(); final String value = config.getConfigProperty( key ); if ( value != null ) { pref.put( key, value ); } } pref.sync(); } catch ( BackingStoreException be ) { throw new ConfigStoreException( "Failed to store config" + configPath, be ); } }
Example 3
Source File: LazyInstallUnitWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
public static void storeUpdateElements (OperationType operationType, Collection<UpdateElement> elements) { Preferences p = getPreferences (operationType); try { if (p.keys ().length > 0) { p.clear (); } } catch (BackingStoreException ex) { Logger.getLogger (LazyInstallUnitWizardIterator.class.getName ()).log (Level.WARNING, ex.getLocalizedMessage (), ex); } if (elements == null) { return ; } for (UpdateElement el : elements) { p.put (el.getCodeName (), toString (el)); } }
Example 4
Source File: LazyInstallUnitWizardIterator.java From netbeans with Apache License 2.0 | 6 votes |
public static void storeLazyUnits (OperationType operationType, Collection<LazyUnit> units) { Preferences p = getPreferences (operationType); try { if (p.keys ().length > 0) { p.clear (); } } catch (BackingStoreException ex) { Logger.getLogger (LazyInstallUnitWizardIterator.class.getName ()).log (Level.WARNING, ex.getLocalizedMessage (), ex); } if (units == null) { return ; } for (LazyUnit u : units) { p.put (u.getCodeName (), u.toString ()); } }
Example 5
Source File: FallbackProvider.java From netbeans with Apache License 2.0 | 6 votes |
private boolean promptToDelete(Preferences prefs) { Object result = DialogDisplayer.getDefault().notify(new NotifyDescriptor.Confirmation( NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.msg_clear_keys"), NbBundle.getMessage(FallbackProvider.class, "FallbackProvider.title_clear_keys"), NotifyDescriptor.OK_CANCEL_OPTION)); if (result == NotifyDescriptor.OK_OPTION) { try { LOG.log(Level.FINE, "agreed to delete stored passwords: {0}", Arrays.asList(prefs.keys())); prefs.clear(); return testSampleKey(prefs); } catch (BackingStoreException x) { LOG.log(Level.INFO, null, x); } } else { LOG.fine("refused to delete stored passwords"); } return false; }
Example 6
Source File: FilterRepository.java From netbeans with Apache License 2.0 | 6 votes |
public void save() throws IOException { try { Preferences prefs = NbPreferences.forModule(FilterRepository.class); prefs = prefs.node("Filters"); //NOI18N prefs.clear(); prefs.putBoolean("firstTimeStart", false); //NOI18N prefs.putBoolean("firstTimeStartWithIssue", false); //NOI18N prefs.putInt("count", filters.size()); //NOI18N prefs.putInt("active", active); //NOI18N for (int i = 0; i < filters.size(); i++) { NotificationFilter filter = filters.get(i); filter.save(prefs, "Filter_" + i); //NOI18N } } catch (BackingStoreException bsE) { throw new IOException("Cannot save filter repository", bsE); } }
Example 7
Source File: FilterRepository.java From netbeans with Apache License 2.0 | 6 votes |
public void save() throws IOException { try { Preferences prefs = NbPreferences.forModule( FilterRepository.class ); prefs = prefs.node( "Filters" ); //NOI18N prefs.clear(); prefs.putBoolean( "firstTimeStart", false ); //NOI18N prefs.putBoolean( "firstTimeStartWithIssue", false ); //NOI18N prefs.putInt( "count", filters.size() ); //NOI18N prefs.putInt( "active", active ); //NOI18N for( int i=0; i<filters.size(); i++ ) { TaskFilter filter = filters.get( i ); filter.save( prefs, "Filter_" + i ); //NOI18N } } catch( BackingStoreException bsE ) { IOException ioE = new IOException( "Cannot save filter repository" ); //NOI18N ioE.initCause( bsE ); throw ioE; } }
Example 8
Source File: AppPreferences.java From Logisim with GNU General Public License v3.0 | 6 votes |
private static Preferences getPrefs(boolean shouldClear) { if (prefs == null) { synchronized (AppPreferences.class) { if (prefs == null) { Preferences p = Preferences.userNodeForPackage(Main.class); if (shouldClear) { try { p.clear(); } catch (BackingStoreException e) { } } myListener = new MyListener(); p.addPreferenceChangeListener(myListener); prefs = p; setTemplateFile(convertFile(p.get(TEMPLATE_FILE, null))); setLibrariesFolder(convertFile(p.get(LIBRARIES_FOLDER_PATH, null))); setTemplateType(p.getInt(TEMPLATE_TYPE, TEMPLATE_PLAIN)); } } } return prefs; }
Example 9
Source File: AppSettings.java From jmonkeyengine with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Saves settings into the Java preferences. * <p> * On the Windows operating system, the preferences are saved in the registry * at the following key:<br> * <code>HKEY_CURRENT_USER\Software\JavaSoft\Prefs\[preferencesKey]</code> * * @param preferencesKey The preferences key to save at. Generally the * application's unique name. * * @throws BackingStoreException If an exception occurs with the preferences */ public void save(String preferencesKey) throws BackingStoreException { Preferences prefs = Preferences.userRoot().node(preferencesKey); // Clear any previous settings set before saving, this will // purge any other parameters set in older versions of the app, so // that they don't leak onto the AppSettings of newer versions. prefs.clear(); for (String key : keySet()) { Object val = get(key); if (val instanceof Integer) { prefs.putInt("I_" + key, (Integer) val); } else if (val instanceof Float) { prefs.putFloat("F_" + key, (Float) val); } else if (val instanceof String) { prefs.put("S_" + key, (String) val); } else if (val instanceof Boolean) { prefs.putBoolean("B_" + key, (Boolean) val); } // NOTE: Ignore any parameters of unsupported types instead // of throwing exception. This is specifically for handling // BufferedImage which is used in setIcons(), as you do not // want to export such data in the preferences. } // Ensure the data is properly written into preferences before // continuing. prefs.sync(); }
Example 10
Source File: MRUFilesOptions.java From opensim-gui with Apache License 2.0 | 5 votes |
protected void store() { Preferences prefs = getPreferences(); // clear the backing store try { prefs.clear(); } catch (BackingStoreException ex) { } for (int i = 0; i < mruFileList.size(); i++) { String str = mruFileList.get(i); prefs.put(MRU_FILE_LIST_PROPERTY + i, str); } }
Example 11
Source File: MRUScriptsOptions.java From opensim-gui with Apache License 2.0 | 5 votes |
protected void store() { Preferences prefs = getPreferences(); // clear the backing store try { prefs.clear(); } catch (BackingStoreException ex) { } for (int i = 0; i < mruFileList.size(); i++) { String str = mruFileList.get(i); prefs.put(MRU_SCRIPT_LIST_PROPERTY + i, str); } }
Example 12
Source File: MainForm.java From Gaalop with GNU Lesser General Public License v3.0 | 5 votes |
public void saveOpenedFiles() { List<SourceFilePanel> panels = new ArrayList<SourceFilePanel>(tabbedPane.getTabCount()); for (int i = 0; i < tabbedPane.getTabCount(); ++i) { Component component = tabbedPane.getComponentAt(i); if (component instanceof SourceFilePanel) { panels.add((SourceFilePanel) component); } } Preferences prefs = Preferences.userNodeForPackage(MainForm.class); try { prefs.clear(); int count = 0; for (SourceFilePanel panel : panels) { if (panel.getFileState() != FileState.UNSAVED) { File file = panel.getFile(); prefs.put("file" + count, file.getAbsolutePath()); CodeParserPlugin plugin = panel.getParserPlugin(); prefs.put("plugin" + count, plugin.getClass().getName()); count++; } } prefs.putInt("count", count); } catch (BackingStoreException e) { log.warn("Unable to save opened files.", e); } }
Example 13
Source File: ProfilerPresets.java From visualvm with GNU General Public License v2.0 | 5 votes |
private void doSavePresets(PresetsModel toSave) { Preferences p = prefs(); try { p.clear(); } catch (Exception e) {} int count = toSave.size(); for (int i = 0; i < count; i++) { String prefix = i + "_"; // NOI18N p.put(prefix + PROP_PRESET_HEADER, ""); // NOI18N ProfilerPreset preset = (ProfilerPreset)toSave.get(i); preset.toPreferences(p, prefix); // NOI18N } }
Example 14
Source File: RecentMenu.java From ApkToolPlus with Apache License 2.0 | 5 votes |
/** Save the list of recently used workspaces to the preferences store. @param preferences the preferences node */ public void save(Preferences preferences) { Preferences recentNode = preferences.node(SETTINGS_RECENT_WORKSPACES); try { recentNode.clear(); } catch (BackingStoreException e) { } int count = 0; Iterator it = recentWorkspaces.iterator(); while (it.hasNext()) { String fileName = (String)it.next(); recentNode.put(String.valueOf(count++), fileName); } }
Example 15
Source File: AppPreferences.java From Logisim with GNU General Public License v3.0 | 5 votes |
public static void clear() { Preferences p = getPrefs(true); try { p.clear(); } catch (BackingStoreException e) { } }
Example 16
Source File: PreferencesRecentWorkspacesService.java From pdfsam with GNU Affero General Public License v3.0 | 5 votes |
public void flush() { Preferences prefs = Preferences.userRoot().node(WORKSPACES_PATH); LOG.trace("Flushing recently used workspaces"); try { prefs.clear(); for (Entry<String, String> entry : cache.entrySet()) { prefs.put(entry.getValue(), entry.getKey()); } prefs.flush(); } catch (BackingStoreException e) { LOG.error("Error storing recently used workspace", e); } }
Example 17
Source File: TestPreferences.java From netbeans with Apache License 2.0 | 5 votes |
public void testClear() throws Exception { testKeys(); Preferences pref = getPreferencesNode(); pref.clear(); assertEquals(0,pref.keys().length); assertNull(pref.get("key1", null)); assertNull(pref.get("key2", null)); }
Example 18
Source File: Debug.java From netcdf-java with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static void removeAll(Preferences prefs, boolean delete) throws BackingStoreException { String[] kidName = prefs.childrenNames(); for (String aKidName : kidName) { Preferences pkid = prefs.node(aKidName); removeAll(pkid, true); } if (delete) prefs.removeNode(); else prefs.clear(); }
Example 19
Source File: PreferencesStorageReset.java From PreferencesFX with Apache License 2.0 | 4 votes |
/** * Clears the currently saved preferences. * For testing purposes only. */ public static void main(String[] args) throws BackingStoreException { Preferences preferences = Preferences.userNodeForPackage(AppStarter.class); preferences.clear(); }
Example 20
Source File: ChatIgnoreListTest.java From triplea with GNU General Public License v3.0 | 4 votes |
private static void clearStore() throws BackingStoreException { final Preferences prefs = ChatIgnoreList.getPrefNode(); prefs.clear(); prefs.flush(); }