public Preferences preferencesForModule(Class cls) { return Preferences.userNodeForPackage(cls); }
/** * Set the header width. This is the default value to use for {@link #margin} for next {@link * Log4JFormatter} to be created. * * @param margin the size of the margin to set. */ static void setHeaderWidth(final int margin) { Preferences.userNodeForPackage(Log4JFormatter.class).putInt("logging.header", margin); }
// Retrieve the user preference node for the package com.mycompany Preferences prefs = Preferences.userNodeForPackage(com.mycompany.MyClass.class); // Preference key name final String PREF_NAME = "name_of_preference"; // Set the value of the preference String newValue = "a string"; prefs.put(PREF_NAME, newValue); // Get the value of the preference; // default value is returned if the preference does not exist String defaultValue = "default string"; String propertyValue = prefs.get(PREF_NAME, defaultValue); // "a string"
import java.util.prefs.Preferences; public class DemoApplication { Preferences preferences = Preferences.userNodeForPackage(DemoApplication.class); public void setCredentials(String username, String password) { preferences.put("db_username", username); preferences.put("db_password", password); } public String getUsername() { return preferences.get("db_username", null); } public String getPassword() { return preferences.get("db_password", null); } // your code here }
public void changedUpdate(DocumentEvent documentEvent) { documentChangedSinceLastRepaint = true; int width = 3 * Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12); numbersPanel.setPreferredSize(new Dimension(width, width)); } });
public LineNumbersPanel() { int initialSize = 3 * Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12); setMinimumSize(new Dimension(initialSize, initialSize)); setPreferredSize(new Dimension(initialSize, initialSize)); }
public void actionPerformed(ActionEvent e) { JFileChooser fc = new JFileChooser(); fc.setDialogTitle("Select a Java installation directory..."); fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fc.setAcceptAllFileFilterUsed(false); Preferences p = Preferences.userNodeForPackage(Installer.class); final String prefID = "defaultDirectory"; fc.setCurrentDirectory(new File(p.get(prefID, "."))); if (fc.showOpenDialog(parent) == JFileChooser.APPROVE_OPTION) { Path dir = fc.getSelectedFile().toPath(); p.put(prefID, dir.getParent().toString()); try { installations.add(new Installation(config, dir)); } catch (IOException ex) { MainWindow.showInstallerException(ex, parent); } } } }
/** * Read properties from preferences. */ public void readFromPreferences() { final Preferences node = Preferences.userNodeForPackage( this.getClass() ); this.getProperties().walk( new ReadFromPreferences( node ) ); }
/** * Saves properties to preferences. * * @throws BackingStoreException * ... */ public void saveAsPreferences() throws BackingStoreException { final Preferences node = Preferences.userNodeForPackage( this.getClass() ); this.getProperties().walk( new SaveToPreferences( node ) ); node.flush(); }
gamePanel.add(rendererCanvas.getCanvas()); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor));
gamePanel.add(rendererCanvas.getCanvas()); prefs = Preferences.userNodeForPackage(Hiero.class); java.awt.Color backgroundColor = EffectUtil.fromString(prefs.get("background", "000000")); backgroundColorLabel.setIcon(getColorIcon(backgroundColor));
public void saveConfig() { // Registry path on Windows Xp: // HKEY_CURRENT_USER/Software/JavaSoft/Prefs/us/deathmarine/luyten try { Preferences prefs = Preferences.userNodeForPackage(ConfigSaver.class); prefs.putBoolean(FLATTEN_SWITCH_BLOCKS_ID, decompilerSettings.getFlattenSwitchBlocks()); prefs.putBoolean(FORCE_EXPLICIT_IMPORTS_ID, decompilerSettings.getForceExplicitImports()); prefs.putBoolean(SHOW_SYNTHETIC_MEMBERS_ID, decompilerSettings.getShowSyntheticMembers()); prefs.putBoolean(EXCLUDE_NESTED_TYPES_ID, decompilerSettings.getExcludeNestedTypes()); prefs.putBoolean(FORCE_EXPLICIT_TYPE_ARGUMENTS_ID, decompilerSettings.getForceExplicitTypeArguments()); prefs.putBoolean(RETAIN_REDUNDANT_CASTS_ID, decompilerSettings.getRetainRedundantCasts()); prefs.putBoolean(INCLUDE_ERROR_DIAGNOSTICS_ID, decompilerSettings.getIncludeErrorDiagnostics()); prefs.putBoolean(UNICODE_REPLACE_ENABLED_ID, decompilerSettings.isUnicodeOutputEnabled()); prefs.put(LANGUAGE_NAME_ID, decompilerSettings.getLanguage().getName()); saveWindowPosition(prefs, MAIN_WINDOW_ID_PREFIX, mainWindowPosition); saveWindowPosition(prefs, FIND_WINDOW_ID_PREFIX, findWindowPosition); saveLuytenPreferences(prefs); } catch (Exception e) { Luyten.showExceptionDialog("Exception!", e); } }
Preferences.userNodeForPackage(Console.class).getInt("fontSize", 12)));
findWindowPosition = new WindowPosition(); try { Preferences prefs = Preferences.userNodeForPackage(ConfigSaver.class); if (!prefs.get(LANGUAGE_NAME_ID, decompilerSettings.getLanguage().getName()) .equals(decompilerSettings.getLanguage().getName()))
private void readPreferences() { this.preferences = Preferences.userNodeForPackage(Application.class); }
/** * Set the default value for indentation. * * @throws SecurityException if a security manager is present and it denies <code> * RuntimePermission("preferences")</code>. */ static void setIndentation(final int indentation) throws SecurityException { Preferences.userNodeForPackage(Formattable.class).putInt(INDENTATION, indentation); }
/** Returns the default indentation. */ static int getIndentation() { try { return Preferences.userNodeForPackage(Formattable.class).getInt(INDENTATION, 2); } catch (SecurityException ignore) { // Ignore. Will fallback on the default indentation. return 2; } }
public Updater(Host host) { this.host = host; automaticCheck = true; Class hostClass = host.getClass(); this.preferences = Preferences.userNodeForPackage(hostClass); }
/** * Load the preferences and make them available to the Application object. */ private void applyPreferences() { Preferences preferences = Preferences.userNodeForPackage(Application.class); ENABLE_DEVICE_SUPPORT = Boolean.valueOf(preferences.get(Application.PREFERENCE_ENABLE_DEVICE_SUPPORT, "false")); }
/** Returns the WKT for this transform. */ public String toWKT() { int indentation = 2; try { indentation = Preferences.userNodeForPackage(org.geotools.referencing.wkt.Formattable.class) .getInt("Indentation", indentation); } catch (SecurityException ignore) { // Ignore. Will fallback on the default indentation. } final Formatter formatter = new Formatter(Symbols.DEFAULT, indentation); formatter.append(this); return formatter.toString(); }