JHotDraw 7.4.1

org.jhotdraw.util.prefs
Class PreferencesUtil

java.lang.Object
  extended by java.util.prefs.Preferences
      extended by org.jhotdraw.util.prefs.PreferencesUtil

public class PreferencesUtil
extends java.util.prefs.Preferences

PreferencesUtil provides utility methods for java.util.prefs.Preferences, and can be used as a proxy when the system preferences are not available due to security restrictions.

Version:
$Id: PreferencesUtil.java 596 2009-12-24 14:58:45Z rawcoder $
Author:
Werner Randelshofer

Field Summary
 
Fields inherited from class java.util.prefs.Preferences
MAX_KEY_LENGTH, MAX_NAME_LENGTH, MAX_VALUE_LENGTH
 
Constructor Summary
PreferencesUtil(boolean isUserNode)
           
 
Method Summary
 java.lang.String absolutePath()
           
 void addNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
           
 void addPreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
           
 java.lang.String[] childrenNames()
           
 void clear()
           
 void exportNode(java.io.OutputStream os)
           
 void exportSubtree(java.io.OutputStream os)
           
 void flush()
           
 java.lang.String get(java.lang.String key, java.lang.String def)
           
 boolean getBoolean(java.lang.String key, boolean def)
           
 byte[] getByteArray(java.lang.String key, byte[] def)
           
 double getDouble(java.lang.String key, double def)
           
 float getFloat(java.lang.String key, float def)
           
 int getInt(java.lang.String key, int def)
           
 long getLong(java.lang.String key, long def)
           
static void installFramePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, java.awt.Window window)
          Installs a frame preferences handler.
static void installFramePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, java.awt.Window window, java.awt.Dimension defaultSize)
          Installs a frame preferences handler.
static void installInternalFramePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, javax.swing.JInternalFrame window, javax.swing.JDesktopPane desktop)
          Installs an intenal frame preferences handler.
static void installPalettePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, java.awt.Window window)
          Installs a palette preferences handler.
static void installPalettePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, java.awt.Window window, int x)
           
static void installPrefsHandler(java.util.prefs.Preferences prefs, java.lang.String string, javax.swing.JTabbedPane tabbedPane)
           
static void installTabbedPanePrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, javax.swing.JTabbedPane tabbedPane)
          Installs a JTabbedPane preferences handler.
static void installToolBarPrefsHandler(java.util.prefs.Preferences prefs, java.lang.String name, javax.swing.JToolBar toolbar)
          Installs a toolbar preferences handler.
 boolean isUserNode()
           
 java.lang.String[] keys()
           
 java.lang.String name()
           
 java.util.prefs.Preferences node(java.lang.String pathName)
           
 boolean nodeExists(java.lang.String pathName)
           
 java.util.prefs.Preferences parent()
           
 void put(java.lang.String key, java.lang.String value)
           
 void putBoolean(java.lang.String key, boolean value)
           
 void putByteArray(java.lang.String key, byte[] value)
           
 void putDouble(java.lang.String key, double value)
           
 void putFloat(java.lang.String key, float value)
           
 void putInt(java.lang.String key, int value)
           
 void putLong(java.lang.String key, long value)
           
 void remove(java.lang.String key)
           
 void removeNode()
           
 void removeNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
           
 void removePreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
           
 void sync()
           
static java.util.prefs.Preferences systemNodeForPackage(java.lang.Class<?> c)
          Gets the system node for the package of the class if permitted, gets a proxy otherwise.
 java.lang.String toString()
           
static java.util.prefs.Preferences userNodeForPackage(java.lang.Class<?> c)
          Gets the user node for the package of the class if permitted, gets a proxy otherwise.
 
Methods inherited from class java.util.prefs.Preferences
importPreferences, systemRoot, userRoot
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PreferencesUtil

public PreferencesUtil(boolean isUserNode)
Method Detail

put

public void put(java.lang.String key,
                java.lang.String value)
Specified by:
put in class java.util.prefs.Preferences

get

public java.lang.String get(java.lang.String key,
                            java.lang.String def)
Specified by:
get in class java.util.prefs.Preferences

remove

public void remove(java.lang.String key)
Specified by:
remove in class java.util.prefs.Preferences

clear

public void clear()
           throws java.util.prefs.BackingStoreException
Specified by:
clear in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

putInt

public void putInt(java.lang.String key,
                   int value)
Specified by:
putInt in class java.util.prefs.Preferences

getInt

public int getInt(java.lang.String key,
                  int def)
Specified by:
getInt in class java.util.prefs.Preferences

putLong

public void putLong(java.lang.String key,
                    long value)
Specified by:
putLong in class java.util.prefs.Preferences

getLong

public long getLong(java.lang.String key,
                    long def)
Specified by:
getLong in class java.util.prefs.Preferences

putBoolean

public void putBoolean(java.lang.String key,
                       boolean value)
Specified by:
putBoolean in class java.util.prefs.Preferences

getBoolean

public boolean getBoolean(java.lang.String key,
                          boolean def)
Specified by:
getBoolean in class java.util.prefs.Preferences

putFloat

public void putFloat(java.lang.String key,
                     float value)
Specified by:
putFloat in class java.util.prefs.Preferences

getFloat

public float getFloat(java.lang.String key,
                      float def)
Specified by:
getFloat in class java.util.prefs.Preferences

putDouble

public void putDouble(java.lang.String key,
                      double value)
Specified by:
putDouble in class java.util.prefs.Preferences

getDouble

public double getDouble(java.lang.String key,
                        double def)
Specified by:
getDouble in class java.util.prefs.Preferences

putByteArray

public void putByteArray(java.lang.String key,
                         byte[] value)
Specified by:
putByteArray in class java.util.prefs.Preferences

getByteArray

public byte[] getByteArray(java.lang.String key,
                           byte[] def)
Specified by:
getByteArray in class java.util.prefs.Preferences

keys

public java.lang.String[] keys()
                        throws java.util.prefs.BackingStoreException
Specified by:
keys in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

childrenNames

public java.lang.String[] childrenNames()
                                 throws java.util.prefs.BackingStoreException
Specified by:
childrenNames in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

parent

public java.util.prefs.Preferences parent()
Specified by:
parent in class java.util.prefs.Preferences

node

public java.util.prefs.Preferences node(java.lang.String pathName)
Specified by:
node in class java.util.prefs.Preferences

nodeExists

public boolean nodeExists(java.lang.String pathName)
                   throws java.util.prefs.BackingStoreException
Specified by:
nodeExists in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

removeNode

public void removeNode()
                throws java.util.prefs.BackingStoreException
Specified by:
removeNode in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

name

public java.lang.String name()
Specified by:
name in class java.util.prefs.Preferences

absolutePath

public java.lang.String absolutePath()
Specified by:
absolutePath in class java.util.prefs.Preferences

isUserNode

public boolean isUserNode()
Specified by:
isUserNode in class java.util.prefs.Preferences

toString

public java.lang.String toString()
Specified by:
toString in class java.util.prefs.Preferences

flush

public void flush()
           throws java.util.prefs.BackingStoreException
Specified by:
flush in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

sync

public void sync()
          throws java.util.prefs.BackingStoreException
Specified by:
sync in class java.util.prefs.Preferences
Throws:
java.util.prefs.BackingStoreException

addPreferenceChangeListener

public void addPreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
Specified by:
addPreferenceChangeListener in class java.util.prefs.Preferences

removePreferenceChangeListener

public void removePreferenceChangeListener(java.util.prefs.PreferenceChangeListener pcl)
Specified by:
removePreferenceChangeListener in class java.util.prefs.Preferences

addNodeChangeListener

public void addNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
Specified by:
addNodeChangeListener in class java.util.prefs.Preferences

removeNodeChangeListener

public void removeNodeChangeListener(java.util.prefs.NodeChangeListener ncl)
Specified by:
removeNodeChangeListener in class java.util.prefs.Preferences

exportNode

public void exportNode(java.io.OutputStream os)
                throws java.io.IOException,
                       java.util.prefs.BackingStoreException
Specified by:
exportNode in class java.util.prefs.Preferences
Throws:
java.io.IOException
java.util.prefs.BackingStoreException

exportSubtree

public void exportSubtree(java.io.OutputStream os)
                   throws java.io.IOException,
                          java.util.prefs.BackingStoreException
Specified by:
exportSubtree in class java.util.prefs.Preferences
Throws:
java.io.IOException
java.util.prefs.BackingStoreException

systemNodeForPackage

public static java.util.prefs.Preferences systemNodeForPackage(java.lang.Class<?> c)
Gets the system node for the package of the class if permitted, gets a proxy otherwise.

Returns:
system node or a proxy.

userNodeForPackage

public static java.util.prefs.Preferences userNodeForPackage(java.lang.Class<?> c)
Gets the user node for the package of the class if permitted, gets a proxy otherwise.

Returns:
user node or a proxy.

installPrefsHandler

public static void installPrefsHandler(java.util.prefs.Preferences prefs,
                                       java.lang.String string,
                                       javax.swing.JTabbedPane tabbedPane)

installFramePrefsHandler

public static void installFramePrefsHandler(java.util.prefs.Preferences prefs,
                                            java.lang.String name,
                                            java.awt.Window window)
Installs a frame preferences handler. On first run, sets the window to its preferred size at the top left corner of the screen. On subsequent runs, sets the window the last size and location where the user had placed it before.

If no preferences are stored yet for this window, a default size of 400 x 300 pixels is used.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
window - The window for which to track preferences.

installFramePrefsHandler

public static void installFramePrefsHandler(java.util.prefs.Preferences prefs,
                                            java.lang.String name,
                                            java.awt.Window window,
                                            java.awt.Dimension defaultSize)
Installs a frame preferences handler. On first run, sets the window to its preferred size at the top left corner of the screen. On subsequent runs, sets the window the last size and location where the user had placed it before.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
window - The window for which to track preferences.
defaultSize - This size is used when no prefences are stored yet for this window.

installPalettePrefsHandler

public static void installPalettePrefsHandler(java.util.prefs.Preferences prefs,
                                              java.lang.String name,
                                              java.awt.Window window)
Installs a palette preferences handler. On first run, sets the palette to its preferred location at the top left corner of the screen. On subsequent runs, sets the palette the last location where the user had placed it before.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
window - The window for which to track preferences.

installPalettePrefsHandler

public static void installPalettePrefsHandler(java.util.prefs.Preferences prefs,
                                              java.lang.String name,
                                              java.awt.Window window,
                                              int x)

installInternalFramePrefsHandler

public static void installInternalFramePrefsHandler(java.util.prefs.Preferences prefs,
                                                    java.lang.String name,
                                                    javax.swing.JInternalFrame window,
                                                    javax.swing.JDesktopPane desktop)
Installs an intenal frame preferences handler. On first run, sets the frame to its preferred size at the top left corner of the desktop pane. On subsequent runs, sets the frame the last size and location where the user had placed it before.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
window - The window for which to track preferences.

installToolBarPrefsHandler

public static void installToolBarPrefsHandler(java.util.prefs.Preferences prefs,
                                              java.lang.String name,
                                              javax.swing.JToolBar toolbar)
Installs a toolbar preferences handler. On first run, sets the toolbar to BorderLayout.TOP. On subsequent runs, set the toolbar to the last BorderLayout location.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
toolbar - The JToolBar for which to track preferences.

installTabbedPanePrefsHandler

public static void installTabbedPanePrefsHandler(java.util.prefs.Preferences prefs,
                                                 java.lang.String name,
                                                 javax.swing.JTabbedPane tabbedPane)
Installs a JTabbedPane preferences handler. On first run, sets the JTabbedPane to its preferred tab.

Parameters:
prefs - Preferences for storing/retrieving preferences values.
name - Base name of the preference.
tabbedPane - The JTabbedPane for which to track preferences.

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.