List of usage examples for java.util.prefs Preferences put
public abstract void put(String key, String value);
From source file:org.apache.cayenne.modeler.preferences.UpgradeCayennePreference.java
public void upgrade() { try {// ww w . java 2 s .co m 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) { LOGGER.error(e); } catch (IOException e) { LOGGER.error(e); } } } } catch (BackingStoreException e) { // do nothing } }
From source file:codeswarm.ui.MainView.java
/** * gets called when the user presses the "Go"-Button.<br /> * It manages fetching the repository entries and serving it to * {@link code_swarm}. It starts code_swarm after fetching the repository * entries./*from ww w . ja v a 2s . c om*/ * @param evt The ActionEvent from Swing */ private void goButtonActionPerformed(/*java.awt.event.ActionEvent evt*/) {//GEN-FIRST:event_goButtonActionPerformed Runnable run = new Runnable() { public void run() { goButton.setEnabled(false); clearCache.setEnabled(false); Preferences p = Preferences.userNodeForPackage(MainView.class); String username = userName.getText(); String passwd = String.valueOf(password.getPassword()); String url = repositoryURL.getText(); p.put("username", username); p.put("repositoryURL", url); SVNHistory hist = new SVNHistory("realtime_sample"); hist.run(url, username, passwd); try { CodeSwarmConfig cfg = new CodeSwarmConfig(args[0]); cfg.setInputFile(hist.getFilePath()); code_swarm.start(cfg); dispose(); } catch (IOException e) { System.err.println("Failed due to exception: " + e.getMessage()); goButton.setEnabled(true); clearCache.setEnabled(true); } } }; new Thread(run).start(); }
From source file:de.thomasbolz.renamer.RenamerGUI.java
private void setSourceDirectoryToPrefs(String path) { final Preferences preferences = getPreferences(); preferences.put(SRC_DIR, path); }
From source file:de.thomasbolz.renamer.RenamerGUI.java
private void setTargetDirectoryToPrefs(String path) { final Preferences preferences = getPreferences(); preferences.put(TARGET_DIR, path); }
From source file:com.concursive.connect.config.ApplicationPrefs.java
/** * Save a name/value pair to the Java Preferences store * * @param instanceName Description of the Parameter * @param fileLibraryLocation Description of the Parameter * @return Description of the Return Value *///from ww w . ja v a 2 s .c om public static boolean saveFileLibraryLocation(String instanceName, String fileLibraryLocation) { try { if (instanceName == null || fileLibraryLocation == null) { LOG.error("Invalid parameters: " + instanceName + "=" + fileLibraryLocation); } Preferences javaPrefs = Preferences.userNodeForPackage(ApplicationPrefs.class); if (javaPrefs == null) { LOG.error("Couldn't create java preferences for: " + ApplicationPrefs.class); } if (instanceName.length() <= Preferences.MAX_KEY_LENGTH) { javaPrefs.put(instanceName, fileLibraryLocation); } else { javaPrefs.put(instanceName.substring(instanceName.length() - Preferences.MAX_KEY_LENGTH), fileLibraryLocation); } javaPrefs.flush(); return true; } catch (Exception e) { LOG.error("saveFileLibraryLocation", e); e.printStackTrace(System.out); return false; } }
From source file:com.example.app.profile.ui.user.UserPropertyEditor.java
@SuppressWarnings("Duplicates") @Override/* w w w . j ava 2 s.c om*/ 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 { boolean result = true; EmailAddress emailAddress = ContactUtil .getEmailAddress(user.getPrincipal().getContact(), ContactDataCategory.values()) .orElseThrow(() -> new IllegalStateException( "Email Address was null on PrincipalValueEditor. This should not happen.")); if (user.getPrincipal().getPasswordCredentials() == null) { String randomPassword = UUID.randomUUID().toString(); List<Notification> notifications = new ArrayList<>(); result = _principalDAO.setNewPassword(user.getPrincipal(), emailAddress.getEmail(), notifications, randomPassword); if (result) { user.setPrincipal(_er.reattachIfNecessary(user.getPrincipal())); user.getPrincipal().getCredentials().forEach(cred -> { if (_er.narrowProxyIfPossible(cred) instanceof PasswordCredentials) { Calendar cal = Calendar.getInstance(); cal.add(Calendar.DAY_OF_YEAR, -10); cred.setExpireDate(cal.getTime()); } }); _principalDAO.savePrincipal(user.getPrincipal()); } else { final Notifiable notifiable = getNotifiable(); notifications.forEach(notifiable::sendNotification); } } else { PasswordCredentials creds = user.getPrincipal().getPasswordCredentials(); creds.setUsername(emailAddress.getEmail()); _principalDAO.savePrincipal(user.getPrincipal()); } if (!_principalDAO.getAllRoles(user.getPrincipal()) .contains(_appUtil.getFrontEndAccessRole())) { user.getPrincipal().getChildren().add(_appUtil.getFrontEndAccessRole()); _principalDAO.savePrincipal(user.getPrincipal()); } user = _userDAO.mergeUser(user); Company userProfile = _uiPreferences.getSelectedCompany(); if (userProfile != null && !userProfile.getUsers().contains(user) && _newUser) { _companyDAO.addUserToCompany(userProfile, user); List<MembershipType> coachingMemTypes = editor.commitValueCoachingMemType(); final User finalUser = user; coachingMemTypes.forEach(coachingMemType -> _profileDAO.saveMembership( _profileDAO.createMembership(userProfile, finalUser, coachingMemType, ZonedDateTime.now(getSession().getTimeZone().toZoneId()), true))); } if (editor.getPictureEditor().getModificationState().isModified()) { _userDAO.saveUserImage(user, editor.getPictureEditor().commitValue()); } success = result; if (success) { setSaved(user); } } 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(); } if (success) { _uiPreferences.addMessage( new NotificationImpl(NotificationType.INFO, INFO_SHOULD_PICK_ONE_ROLE_NEW_USER())); } return success; })); saveAction.configure().toPage(ApplicationFunctions.User.VIEW).withSourceComponent(this); saveAction.setPropertyValueResolver(new CurrentURLPropertyValueResolver() { @Override public Map<String, Object> resolve(PropertyValueResolverParameter parameter) { Map<String, Object> map = super.resolve(parameter); map.put(URLProperties.USER, _saved); return map; } }); saveAction.setTarget(this, "close"); NavigationAction cancelAction = CommonActions.CANCEL.navAction(); cancelAction.configure().toReturnPath(ApplicationFunctions.User.MANAGEMENT).usingCurrentURLData() .withSourceComponent(this); cancelAction.setTarget(this, "close"); setPersistenceActions(saveAction, cancelAction); _notifications.forEach(notification -> getNotifiable().sendNotification(notification)); }
From source file:com.igormaznitsa.nbmindmap.nb.swing.PlainTextEditor.java
private void writeWrappingCode(final Wrapping code) { final Preferences docPreferences = CodeStylePreferences.get(this.document).getPreferences(); docPreferences.put(SimpleValueNames.TEXT_LINE_WRAP, code.getValue()); try {//ww w.j a va2 s . c om docPreferences.flush(); } catch (BackingStoreException ex) { LOGGER.error("Can't write wrapping code", ex); } }
From source file:net.sf.ginp.setup.SetupManagerImpl.java
/** * @param configUrl/*from ww w .j a v a2s. c om*/ * @param configuration * @return the saves prefs object */ private Preferences storeConfig(final URL configUrl, final String configuration) { Preferences preferences = Preferences.userNodeForPackage(SetupManagerImpl.class); preferences.put(configUrl.toExternalForm(), configuration); return preferences; }
From source file:org.griphyn.vdl.karajan.monitor.monitors.swing.GraphPanel.java
public void store(Preferences p) { p.putInt("enabledCount", enabled.size()); for (int i = 0; i < enabled.size(); i++) { Preferences gp = p.node("series" + i); gp.put("key", enabled.get(i)); Color color = (Color) chart.getPlot().getLegendItems().get(i).getLinePaint(); gp.putInt("color.r", color.getRed()); gp.putInt("color.g", color.getGreen()); gp.putInt("color.b", color.getBlue()); }//ww w . j a va2 s . c o m }
From source file:net.chaosserver.timelord.swingui.Timelord.java
/** * Sets the annoyance mode. This should be one of the constants else things * will behave erradically./*w ww .j ava 2 s. c om*/ * * @param annoyanceMode the annoyance mode */ public void setAnnoyanceMode(String annoyanceMode) { Preferences preferences = Preferences.userNodeForPackage(this.getClass()); preferences.put(ANNOYANCE_MODE, annoyanceMode); }