List of usage examples for java.util.prefs Preferences putBoolean
public abstract void putBoolean(String key, boolean value);
From source file:Main.java
public static void main(String[] argv) throws Exception { Preferences prefs = Preferences.userNodeForPackage(String.class); // Save some values prefs.put("myString", "a string"); // String prefs.putBoolean("myBoolean", true); // boolean prefs.putInt("myInt", 123); // int prefs.putLong("myLong", 123L); // long prefs.putFloat("myFloat", 12.3F); // float prefs.putDouble("myDouble", 12.3); // double byte[] bytes = new byte[10]; prefs.putByteArray("myByteArray", bytes); // byte[] // Export the node to a file prefs.exportNode(new FileOutputStream("output.xml")); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Preferences prefs = Preferences.userNodeForPackage(String.class); // Save some values prefs.put("myString", "a string"); // String prefs.putBoolean("myBoolean", true); // boolean prefs.putInt("myInt", 123); // int prefs.putLong("myLong", 123L); // long // Save some values in the parent node prefs = prefs.parent();//from w ww . j ava2s .c om prefs.putFloat("myFloat", 12.3F); // float prefs.putDouble("myDouble", 12.3); // double byte[] bytes = new byte[10]; prefs.putByteArray("myByteArray", bytes); // byte[] prefs.exportSubtree(new FileOutputStream("output.xml")); }
From source file:Main.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(Main.class); prefs.put("key1", "value1"); prefs.put("key2", "value2"); prefs.putInt("intValue", 4); prefs.putBoolean("booleanValue", true); int usageCount = prefs.getInt("intValue", 0); usageCount++;//w ww .java 2 s. c o m prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } System.out.println(prefs.getInt("booleanValue", 0)); }
From source file:MainClass.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(MainClass.class); prefs.put("key1", "value1"); prefs.put("key2", "value2"); prefs.putInt("intValue", 4); prefs.putBoolean("booleanValue", true); int usageCount = prefs.getInt("intValue", 0); usageCount++;/* w w w .jav a2s .com*/ prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } System.out.println(prefs.getInt("booleanValue", 0)); }
From source file:PreferencesDemo.java
public static void main(String[] args) throws Exception { Preferences prefs = Preferences.userNodeForPackage(PreferencesDemo.class); prefs.put("Location", "Oz"); prefs.put("Footwear", "Ruby Slippers"); prefs.putInt("Companions", 4); prefs.putBoolean("Are there witches?", true); int usageCount = prefs.getInt("UsageCount", 0); usageCount++;/*w ww.ja v a 2 s. com*/ prefs.putInt("UsageCount", usageCount); Iterator it = Arrays.asList(prefs.keys()).iterator(); while (it.hasNext()) { String key = it.next().toString(); System.out.println(key + ": " + prefs.get(key, null)); } // You must always provide a default value: System.out.println("How many companions does Dorothy have? " + prefs.getInt("Companions", 0)); }
From source file:Main.java
public static void main(String[] argv) throws Exception { Preferences prefs = Preferences.userNodeForPackage(Main.class); // Preference key name final String PREF_NAME = "name_of_preference"; // Save/* w w w . j a v a 2 s . c o m*/ prefs.put(PREF_NAME, "a string"); // String prefs.putBoolean(PREF_NAME, true); // boolean prefs.putInt(PREF_NAME, 123); // int prefs.putLong(PREF_NAME, 123L); // long prefs.putFloat(PREF_NAME, 12.3F); // float prefs.putDouble(PREF_NAME, 12.3); // double byte[] bytes = new byte[1024]; prefs.putByteArray(PREF_NAME, bytes); // byte[] // Retrieve String s = prefs.get(PREF_NAME, "a string"); // String boolean b = prefs.getBoolean(PREF_NAME, true); // boolean int i = prefs.getInt(PREF_NAME, 123); // int long l = prefs.getLong(PREF_NAME, 123L); // long float f = prefs.getFloat(PREF_NAME, 12.3F); // float double d = prefs.getDouble(PREF_NAME, 12.3); // double bytes = prefs.getByteArray(PREF_NAME, bytes); // byte[] }
From source file:com.github.fritaly.dualcommander.UserPreferences.java
public void saveState(Preferences preferences) { assertInitialized();/*from w w w .j a va 2s . 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:de.thomasbolz.renamer.RenamerGUI.java
private void confirmDisclaimer() { final Preferences preferences = getPreferences(); preferences.putBoolean(DISCLAIMER, true); }
From source file:hr.fer.zemris.vhdllab.platform.gui.dialog.save.SaveDialog.java
public SaveDialog(LocalizationSource source, SaveContext context) { super(source); Validate.notNull(context, "Save variant can't be null"); // setup label JLabel label = new JLabel(getMainMessage(source, context)); int width = DIALOG_WIDTH - 2 * BORDER; int height = LABEL_HEIGHT - 2 * BORDER; label.setPreferredSize(new Dimension(width, height)); label.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup check box list list = new CheckBoxList(); width = DIALOG_WIDTH - 2 * BORDER;//ww w . j ava 2 s. c o m height = 0; // because list is a center component and it doesnt need // height list.setPreferredSize(new Dimension(width, height)); list.setBorder(BorderFactory.createEmptyBorder(BORDER, BORDER, BORDER, BORDER)); // setup select all and deselect all buttons JButton selectAll = new JButton(source.getMessage(SELECT_ALL_MESSAGE)); selectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); selectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(true); } }); JButton deselectAll = new JButton(source.getMessage(DESELECT_ALL_MESSAGE)); deselectAll.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); deselectAll.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { list.setSelectionToAll(false); } }); Box selectBox = Box.createHorizontalBox(); selectBox.add(selectAll); selectBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); selectBox.add(deselectAll); selectBox.setBorder(BorderFactory.createEmptyBorder(0, 0, BORDER, 0)); // setup ok and cancel buttons JButton ok = new JButton(source.getMessage(OK_MESSAGE)); ok.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); ok.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(new ArrayList<File>()); } }); JButton cancel = new JButton(source.getMessage(CANCEL_MESSAGE)); cancel.setPreferredSize(new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT)); cancel.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { closeDialog(null); } }); Box actionBox = Box.createHorizontalBox(); actionBox.add(ok); actionBox.add(Box.createRigidArea(new Dimension(BORDER, BUTTON_HEIGHT))); actionBox.add(cancel); actionBox.setBorder(BorderFactory.createEmptyBorder(BORDER, 0, BORDER, 0)); JPanel selectPanel = new JPanel(new BorderLayout()); selectPanel.add(selectBox, BorderLayout.EAST); JPanel actionPanel = new JPanel(new BorderLayout()); actionPanel.add(actionBox, BorderLayout.EAST); JCheckBox alwaysSave = new JCheckBox(source.getMessage(ALWAYS_SAVE_MESSAGE)); alwaysSave.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox checkBox = (JCheckBox) e.getSource(); Preferences preferences = Preferences.userNodeForPackage(SaveDialog.class); preferences.putBoolean(SHOULD_AUTO_SAVE, checkBox.isSelected()); } }); alwaysSave.setSelected(false); JPanel alwaysSavePanel = new JPanel(new BorderLayout()); alwaysSavePanel.add(alwaysSave, BorderLayout.WEST); JPanel lowerPanel = new JPanel(new BorderLayout()); lowerPanel.add(selectPanel, BorderLayout.NORTH); lowerPanel.add(alwaysSavePanel, BorderLayout.CENTER); lowerPanel.add(actionPanel, BorderLayout.SOUTH); this.setLayout(new BorderLayout()); JPanel messagePanel = new JPanel(new BorderLayout()); messagePanel.add(label, BorderLayout.NORTH); messagePanel.add(list, BorderLayout.CENTER); messagePanel.add(lowerPanel, BorderLayout.SOUTH); this.getContentPane().add(messagePanel, BorderLayout.CENTER); this.getRootPane().setDefaultButton(ok); this.setPreferredSize(new Dimension(DIALOG_WIDTH, DIALOG_HEIGHT)); this.setTitle(getTitle(source, context)); }
From source file:com.moteiv.trawler.Trawler.java
private void savePrefs() { Preferences prefs = Preferences.userNodeForPackage(com.moteiv.trawler.Trawler.class); prefs.putBoolean(PREF_V_SAVE, vSave.isSelected()); prefs.putBoolean(PREF_V_BLINK, vBlink.isSelected()); prefs.putBoolean(PREF_V_LABELS, vLabels.isSelected()); prefs.putBoolean(PREF_E_LABELS, eLabels.isSelected()); prefs.putBoolean(PREF_E_FILTER, eFilter.isSelected()); prefs.putInt(PREF_V_DISPOSE, vDispose.getValue()); prefs.putInt(PREF_E_DISPOSE, eDispose.getValue()); }