List of usage examples for java.util.prefs Preferences put
public abstract void put(String key, String value);
From source file:org.docx4all.ui.main.WordMLApplet.java
private void openLocalFile(WordMLEditor editor, String urlParam) { ResourceMap rm = editor.getContext().getResourceMap(WordMLEditor.class); String localFileUrl = urlParam; if (System.getProperty("os.name").toLowerCase().startsWith("windows")) { if (urlParam.startsWith("file:///")) { ;//pass } else {/* ww w . j av a 2 s.c o m*/ localFileUrl = "file:///" + urlParam.substring(7); } } String errMsg = null; try { FileObject fo = VFSUtils.getFileSystemManager().resolveFile(urlParam); if (fo.exists()) { Preferences prefs = Preferences.userNodeForPackage(FileMenu.class); localFileUrl = fo.getName().getURI(); prefs.put(Constants.LAST_OPENED_FILE, localFileUrl); prefs.put(Constants.LAST_OPENED_LOCAL_FILE, localFileUrl); PreferenceUtil.flush(prefs); log.info("\n\n Opening " + urlParam); editor.createInternalFrame(fo); } else { errMsg = rm.getString("Application.applet.initialisation.file.not.found.message", urlParam); } } catch (FileSystemException exc) { exc.printStackTrace(); errMsg = rm.getString("Application.applet.initialisation.file.io.error.message", urlParam); } if (errMsg != null) { String title = rm.getString("Application.applet.initialisation.Action.text"); editor.showMessageDialog(title, errMsg, JOptionPane.ERROR_MESSAGE); } }
From source file:org.pdfsam.module.PreferencesUsageDataStore.java
public void incrementUsageFor(String moduleId) { Preferences node = Preferences.userRoot().node(USAGE_PATH).node(moduleId); String json = node.get(MODULE_USAGE_KEY, ""); try {//from w ww. j av a 2 s .c om if (isNotBlank(json)) { node.put(MODULE_USAGE_KEY, JSON.std.asString(JSON.std.beanFrom(ModuleUsage.class, json).inc())); } else { node.put(MODULE_USAGE_KEY, JSON.std.asString(ModuleUsage.fistUsage(moduleId))); } LOG.trace("Usage incremented for module {}", moduleId); } catch (IOException e) { LOG.error("Unable to increment modules usage statistics", e); } finally { incrementTotalUsage(); } }
From source file:org.pentaho.reporting.designer.extensions.pentaho.repository.util.PublishSettings.java
private void put(final String key, final Collection<String> values) { // noinspection ConstantConditions if (key == null) { throw new IllegalArgumentException("key must not be null"); }/*from w w w .j a v a 2 s . co m*/ // noinspection ConstantConditions if (values == null) { throw new IllegalArgumentException("values must not be null"); } final String[] strings = values.toArray(new String[values.size()]); final Preferences preferences = properties.node(key); for (int i = 0; i < strings.length; i++) { final String string = strings[i]; preferences.put(String.valueOf(i), string); } fireSettingsChanged(); }
From source file:com.example.app.profile.ui.user.MyAccountEdit.java
@SuppressWarnings("Duplicates") @Override// w w w . j a va2 s . c o m public void init() { super.init(); NavigationAction saveAction = CommonActions.SAVE.navAction(); saveAction.onCondition(input -> persist(user -> { assert user != null : "User should not be null if you are persisting!"; UserValueEditor editor = getValueEditor(); User currentUser = _userDAO.getAssertedCurrentUser(); _sessionHelper.beginTransaction(); boolean success = false; try { if (Objects.equals(currentUser.getId(), user.getId())) { user.setPreferredContactMethod(editor.commitValuePreferredContactMethod()); final Link link = editor.commitValueLoginLandingPage(); if (link != null) { Preferences userPref = Preferences.userRoot().node(User.LOGIN_PREF_NODE); userPref.put(User.LOGIN_PREF_NODE_LANDING_PAGE, link.getURIAsString()); } } user = _userDAO.mergeUser(user); try { EmailAddress emailAddress = ContactUtil .getEmailAddress(user.getPrincipal().getContact(), ContactDataCategory.values()) .orElseThrow(() -> new IllegalStateException( "Email Address was null on PrincipalValueEditor. This should not happen.")); PasswordCredentials creds = user.getPrincipal().getPasswordCredentials(); creds.setUsername(emailAddress.getEmail()); _principalDAO.savePrincipal(user.getPrincipal()); user = _userDAO.mergeUser(user); if (editor.getPictureEditor().getModificationState().isModified()) { _userDAO.saveUserImage(user, editor.getPictureEditor().commitValue()); } success = true; } catch (NonUniqueCredentialsException e) { _logger.error("Unable to persist changes to the Principal.", e); getNotifiable().sendNotification(error(ERROR_MESSAGE_USERNAME_EXISTS_FMT(USER()))); } _sessionHelper.commitTransaction(); } finally { if (!success) _sessionHelper.recoverableRollbackTransaction(); } return success; })); saveAction.configure().toReturnPath(ApplicationFunctions.User.MY_ACCOUNT_VIEW).usingCurrentURLData() .withSourceComponent(this); saveAction.setTarget(this, "close"); NavigationAction cancelAction = CommonActions.CANCEL.navAction(); cancelAction.configure().toReturnPath(ApplicationFunctions.User.MY_ACCOUNT_VIEW).usingCurrentURLData() .withSourceComponent(this); cancelAction.setTarget(this, "close"); setPersistenceActions(saveAction, cancelAction); }
From source file:org.settings4j.connector.PreferencesConnector.java
/** * Resolve the given path and key against the given Preferences. * * @param path the preferences path (placeholder part before '/') * @param key the preferences key (placeholder part after '/') * @param value the Value to store./*from w w w.j a v a 2 s . c o m*/ * @param preferences the Preferences to resolve against */ protected void setPreferenceValue(final String path, final String key, final String value, final Preferences preferences) { if (path != null) { preferences.node(path).put(key, value); } else { preferences.put(key, value); } try { preferences.flush(); } catch (final BackingStoreException e) { throw new RuntimeException("Cannot access specified node path [" + path + "]", e); } }
From source file:smarthome.FXMLDocumentController.java
public void setPreference(String arg1, String arg2, String arg3) { Preferences prefs = Preferences.userNodeForPackage(SmartHome.class); prefs.put("ipaddress", arg1); prefs.put("videolink", arg2); prefs.put("voiceflag", arg3); }
From source file:org.pdfsam.ui.PreferencesRecentWorkspacesService.java
@PreDestroy public void flush() { Preferences prefs = Preferences.userRoot().node(WORKSPACES_PATH); LOG.trace("Flushing recently used workspaces"); try {//from ww w .jav a 2s . com 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); } }
From source file:com.github.fritaly.dualcommander.UserPreferences.java
public void saveState(Preferences preferences) { assertInitialized();// w ww .j av a 2 s. c o m Validate.notNull(preferences, "The given preferences is null"); preferences.putBoolean(PROPERTY_SHOW_HIDDEN, this.showHidden); preferences.put(PROPERTY_EDIT_FILE_COMMAND, this.editFileCommand); preferences.put(PROPERTY_VIEW_FILE_COMMAND, this.viewFileCommand); if (logger.isInfoEnabled()) { logger.info("Saved user preferences"); } }
From source file:org.apache.cayenne.pref.UpgradeCayennePreference.java
public void upgrade() { try {//from w ww.ja v a 2 s . c om if (!Preferences.userRoot().nodeExists(CAYENNE_PREFERENCES_PATH)) { File prefsFile = new File(preferencesDirectory(), PREFERENCES_NAME_OLD); if (prefsFile.exists()) { ExtendedProperties ep = new ExtendedProperties(); try { ep.load(new FileInputStream(prefsFile)); Preferences prefEditor = Preferences.userRoot().node(CAYENNE_PREFERENCES_PATH).node(EDITOR); prefEditor.putBoolean(ModelerPreferences.EDITOR_LOGFILE_ENABLED, ep.getBoolean(EDITOR_LOGFILE_ENABLED_OLD)); prefEditor.put(ModelerPreferences.EDITOR_LOGFILE, ep.getString(EDITOR_LOGFILE_OLD)); Preferences frefLastProjFiles = prefEditor.node(LAST_PROJ_FILES); Vector arr = ep.getVector(LAST_PROJ_FILES_OLD); while (arr.size() > ModelerPreferences.LAST_PROJ_FILES_SIZE) { arr.remove(arr.size() - 1); } frefLastProjFiles.clear(); int size = arr.size(); for (int i = 0; i < size; i++) { frefLastProjFiles.put(String.valueOf(i), arr.get(i).toString()); } } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } } catch (BackingStoreException e) { // do nothing } }
From source file:com.github.fritaly.dualcommander.TabbedPane.java
public void saveState(Preferences preferences) { Validate.notNull(preferences, "The given preferences is null"); preferences.putInt("tab.count", getTabCount()); for (int i = 0; i < getTabCount(); i++) { preferences.put(String.format("tab.%d.directory", i), getBrowserAt(i).getDirectory().getAbsolutePath()); }/*w w w. java 2 s .c o m*/ }