List of usage examples for java.util.prefs Preferences putBoolean
public abstract void putBoolean(String key, boolean value);
From source file:de._692b8c32.cdlauncher.MainController.java
public MainController(Application application, Preferences preferences) { this.application = application; this.preferences = preferences; if (preferences.get("basedir", null) == null) { while (new OptionsController(application, preferences).selectDirectory() == null) { new Alert(Alert.AlertType.ERROR, "The launcher needs a directory to store temporary files. Press cancel if you want to close the application.", ButtonType.CANCEL, ButtonType.PREVIOUS).showAndWait().ifPresent(button -> { if (button == ButtonType.CANCEL) { throw new RuntimeException("User requested abort."); }//from w w w. j av a2 s . co m }); } new Alert(Alert.AlertType.INFORMATION, "Do you want to use a prebuilt version of OpenRA? This is recommended unless you are an OpenRA developer.", ButtonType.NO, ButtonType.YES).showAndWait().ifPresent(button -> { if (button == ButtonType.YES) { preferences.putBoolean("buildFromSources", false); } if (button == ButtonType.NO) { preferences.putBoolean("buildFromSources", true); } }); if (System.getProperty("os.name").toLowerCase().contains("win")) { preferences.put("commandMono", ""); preferences.put("commandMake", ""); } } }
From source file:com.marginallyclever.makelangelo.MainGUI.java
protected void AdjustGraphics() { final Preferences graphics_prefs = Preferences.userRoot().node("DrawBot").node("Graphics"); final JDialog driver = new JDialog(mainframe, translator.get("MenuGraphicsTitle"), true); driver.setLayout(new GridBagLayout()); //final JCheckBox allow_metrics = new JCheckBox(String.valueOf("I want to add the distance drawn to the // total")); //allow_metrics.setSelected(allowMetrics); final JCheckBox show_pen_up = new JCheckBox(translator.get("MenuGraphicsPenUp")); final JCheckBox antialias_on = new JCheckBox(translator.get("MenuGraphicsAntialias")); final JCheckBox speed_over_quality = new JCheckBox(translator.get("MenuGraphicsSpeedVSQuality")); final JCheckBox draw_all_while_running = new JCheckBox(translator.get("MenuGraphicsDrawWhileRunning")); show_pen_up.setSelected(graphics_prefs.getBoolean("show pen up", false)); antialias_on.setSelected(graphics_prefs.getBoolean("antialias", true)); speed_over_quality.setSelected(graphics_prefs.getBoolean("speed over quality", true)); draw_all_while_running.setSelected(graphics_prefs.getBoolean("Draw all while running", true)); final JButton cancel = new JButton(translator.get("Cancel")); final JButton save = new JButton(translator.get("Save")); GridBagConstraints c = new GridBagConstraints(); //c.gridwidth=4; c.gridx=0; c.gridy=0; driver.add(allow_metrics,c); int y = 0;//from w ww. java 2 s . co m c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(show_pen_up, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(draw_all_while_running, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(antialias_on, c); y++; c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 1; c.gridy = y; driver.add(speed_over_quality, c); y++; c.anchor = GridBagConstraints.EAST; c.gridwidth = 1; c.gridx = 2; c.gridy = y; driver.add(save, c); c.anchor = GridBagConstraints.WEST; c.gridwidth = 1; c.gridx = 3; c.gridy = y; driver.add(cancel, c); ActionListener driveButtons = new ActionListener() { public void actionPerformed(ActionEvent e) { Object subject = e.getSource(); if (subject == save) { //allowMetrics = allow_metrics.isSelected(); graphics_prefs.putBoolean("show pen up", show_pen_up.isSelected()); graphics_prefs.putBoolean("antialias", antialias_on.isSelected()); graphics_prefs.putBoolean("speed over quality", speed_over_quality.isSelected()); graphics_prefs.putBoolean("Draw all while running", draw_all_while_running.isSelected()); previewPane.setShowPenUp(show_pen_up.isSelected()); driver.dispose(); } if (subject == cancel) { driver.dispose(); } } }; save.addActionListener(driveButtons); cancel.addActionListener(driveButtons); driver.getRootPane().setDefaultButton(save); driver.pack(); driver.setVisible(true); }
From source file:org.apache.cayenne.modeler.preferences.UpgradeCayennePreference.java
public void upgrade() { try {//from w ww . j a va2 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) { LOGGER.error(e); } catch (IOException e) { LOGGER.error(e); } } } } catch (BackingStoreException e) { // do nothing } }
From source file:org.apache.cayenne.pref.CayennePreferenceEditor.java
public void save() { cayenneProjectPreferences.getDetailObject(DBConnectionInfo.class).save(); if (restartRequired) { restart();/*from www . j a v a 2 s. c o m*/ } // update boolean preferences Iterator it = changedBooleanPreferences.entrySet().iterator(); while (it.hasNext()) { Map.Entry entry = (Map.Entry) it.next(); Preferences pref = (Preferences) entry.getKey(); Map<String, Boolean> map = (Map<String, Boolean>) entry.getValue(); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry en = (Map.Entry) iterator.next(); String key = (String) en.getKey(); Boolean value = (Boolean) en.getValue(); pref.putBoolean(key, value); } } // update string preferences Iterator iter = changedPreferences.entrySet().iterator(); while (iter.hasNext()) { Map.Entry entry = (Map.Entry) iter.next(); Preferences pref = (Preferences) entry.getKey(); Map<String, String> map = (Map<String, String>) entry.getValue(); Iterator iterator = map.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry en = (Map.Entry) iterator.next(); String key = (String) en.getKey(); String value = (String) en.getValue(); pref.put(key, value); } } // remove string preferences Iterator iterator = removedPreferences.entrySet().iterator(); while (iterator.hasNext()) { Map.Entry entry = (Map.Entry) iterator.next(); Preferences pref = (Preferences) entry.getKey(); Map<String, String> map = (Map<String, String>) entry.getValue(); Iterator itRem = map.entrySet().iterator(); while (itRem.hasNext()) { Map.Entry en = (Map.Entry) itRem.next(); String key = (String) en.getKey(); pref.remove(key); } } // remove preferences node Iterator<Preferences> iteratorNode = removedNode.iterator(); while (iteratorNode.hasNext()) { Preferences pref = iteratorNode.next(); try { pref.removeNode(); } catch (BackingStoreException e) { logger.warn("Error removing preferences"); } } Application.getInstance().initClassLoader(); }
From source file:org.apache.cayenne.pref.UpgradeCayennePreference.java
public void upgrade() { try {//from w w w. ja va2s.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:org.domainmath.gui.MainFrame.java
public void exitApp() { int j = fileTab.getTabCount() - 1; while (j != -1) { askSave(j);// w w w. j a v a2 s. c om j--; } ShutDown shutDown = new ShutDown(this, "DomainMath IDE", "Really do you want to exit?"); JButton yes = new JButton("Yes"); JButton no = new JButton("No"); JCheckBox confirmation = shutDown.getCheckBox(); Preferences pr2 = Preferences.userNodeForPackage(this.getClass()); boolean skipConfirmation = pr2.getBoolean("skip_confirmation", false); confirmation.addItemListener((ItemEvent e) -> { if (ItemEvent.DESELECTED == e.getStateChange()) { pr2.putBoolean("skip_confirmation", false); } else { pr2.putBoolean("skip_confirmation", true); } }); yes.addActionListener((ActionEvent e) -> { exitFinal(shutDown); }); no.addActionListener((ActionEvent e) -> { shutDown.dispose(); }); if (false == skipConfirmation) { shutDown.addButton(yes); shutDown.addButton(no); shutDown.setVisible(true); } else { exitFinal(shutDown); } }
From source file:org.rhq.server.control.command.AbstractInstall.java
private void configureAgent(File agentBasedir, CommandLine commandLine) throws Exception { // If the user provided us with an agent config file, we will use it. // Otherwise, we are going to use the out-of-box agent config file. ///*from www .j a v a 2 s. co m*/ // Because we want to accept all defaults and consider the agent fully configured, we need to set // rhq.agent.configuration-setup-flag=true // This tells the agent not to ask any setup questions at startup. // We do this whether using a custom config file or the default config file - this is because // we cannot allow the agent to ask the setup questions (rhqctl doesn't support that). // // Note that agent preferences found in the config file can be overridden with // the AGENT_PREFERENCE settings (you can set more than one). try { File agentConfDir = new File(agentBasedir, "conf"); File agentConfigFile = new File(agentConfDir, "agent-configuration.xml"); if (commandLine.hasOption(AGENT_CONFIG_OPTION)) { log.info("Configuring the RHQ agent with custom configuration file: " + commandLine.getOptionValue(AGENT_CONFIG_OPTION)); replaceAgentConfigIfNecessary(commandLine); } else { log.info("Configuring the RHQ agent with default configuration file: " + agentConfigFile); } // we require our agent preference node to be the user node called "default" Preferences preferencesNode = getAgentPreferences(); // read the comments in AgentMain.loadConfigurationFile(String) to know why we do all of this String securityToken = preferencesNode.get(PREF_RHQ_AGENT_SECURITY_TOKEN, null); ByteArrayOutputStream rawConfigFileData = new ByteArrayOutputStream(); StreamUtil.copy(new FileInputStream(agentConfigFile), rawConfigFileData, true); String newConfig = rawConfigFileData.toString().replace("${rhq.agent.preferences-node}", "default"); ByteArrayInputStream newConfigInputStream = new ByteArrayInputStream(newConfig.getBytes()); Preferences.importPreferences(newConfigInputStream); if (securityToken != null) { preferencesNode.put(PREF_RHQ_AGENT_SECURITY_TOKEN, securityToken); } // get the configured server endpoint information and tell the agent so it knows where the server is. Properties serverEndpoint = getAgentServerEndpoint(); String endpointTransport = serverEndpoint.getProperty(PREF_RHQ_AGENT_SERVER_TRANSPORT); String endpointAddress = serverEndpoint.getProperty(PREF_RHQ_AGENT_SERVER_BINDADDRESS); String endpointPort = serverEndpoint.getProperty(PREF_RHQ_AGENT_SERVER_BINDPORT); String endpointParams = serverEndpoint.getProperty(PREF_RHQ_AGENT_SERVER_TRANSPORTPARAMS); if (endpointTransport != null) { preferencesNode.put(PREF_RHQ_AGENT_SERVER_TRANSPORT, endpointTransport); } if (endpointAddress != null) { preferencesNode.put(PREF_RHQ_AGENT_SERVER_BINDADDRESS, endpointAddress); } if (endpointPort != null) { preferencesNode.put(PREF_RHQ_AGENT_SERVER_BINDPORT, endpointPort); } if (endpointParams != null) { preferencesNode.put(PREF_RHQ_AGENT_SERVER_TRANSPORTPARAMS, endpointParams); } // if the user provided any overrides to the agent config, use them. overrideAgentPreferences(commandLine, preferencesNode); // set some prefs that must be a specific value // - do not tell this agent to auto-update itself - this agent must be managed by rhqctl only // - set the config setup flag to true to prohibit the agent from asking setup questions at startup String agentUpdateEnabledPref = PREF_RHQ_AGENT_AUTO_UPDATE_FLAG; preferencesNode.putBoolean(agentUpdateEnabledPref, false); String setupPref = PREF_RHQ_AGENT_CONFIGURATION_SETUP_FLAG; preferencesNode.putBoolean(setupPref, true); try { preferencesNode.flush(); preferencesNode.sync(); } catch (BackingStoreException bse) { log.error("Failed to store agent preferences, for Linux systems we require writable user.home [" + System.getProperty("user.home") + "]. You can also set different location for agent preferences by setting \"-Djava.util.prefs.userRoot=/some/path/\"" + " java system property. You may need to put this property to RHQ_CONTROL_ADDIDIONAL_JAVA_OPTS and RHQ_AGENT_ADDIDIONAL_JAVA_OPTS env variables."); throw bse; } log.info("Finished configuring the agent"); } catch (Exception e) { log.error("An error occurred while configuring the agent: " + e.getMessage()); throw e; } }
From source file:org.tros.logo.swing.LogoMenuBar.java
/** * Constructor.//from w w w . j a v a 2 s . com * * @param parent * @param controller * @param canvas */ @SuppressWarnings("OverridableMethodCallInConstructor") public LogoMenuBar(Component parent, Controller controller, LogoCanvas canvas) { super(parent, controller); this.canvas = canvas; add(setupExportMenu()); add(setupToolsMenu()); JMenu menu = new JMenu("Logo Options"); menu.add(setupMenu("Examples From Tortue", "logo/examples/tortue")); menu.add(setupMenu("Examples From ANTLR", "logo/examples/antlr")); final java.util.prefs.Preferences prefs = java.util.prefs.Preferences.userNodeForPackage(LogoMenuBar.class); final JCheckBoxMenuItem speedMenu = new JCheckBoxMenuItem("Wait for Repaint"); boolean checked = prefs.getBoolean(WAIT_FOR_REPAINT, true); speedMenu.setSelected(checked); speedMenu.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { prefs.putBoolean(WAIT_FOR_REPAINT, speedMenu.isSelected()); } }); menu.add(speedMenu); add(menu); }