Preferences

processing.app

## Class Preferences

- Object
- - Preferences

-     public class Preferences
      extends Object

  Storage class for user preferences and environment settings.

  This class no longer uses the Properties class, since properties files are iso8859-1, which is highly likely to be a problem when trying to save sketch folders and locations.

  The GUI portion in here is really ugly, as it uses exact layout. This was done in frustration one evening (and pre-Swing), but that's long since past, and it should all be moved to a proper swing layout like BoxLayout.

  This is very poorly put together, that the preferences panel and the actual preferences i/o is part of the same code. But there hasn't yet been a compelling reason to bother with the separation aside from concern about being lectured by strangers who feel that it doesn't look like what they learned in CS class.

  We don't use the Java Preferences API because it would entail writing to the registry (on Windows), or an obscure file location (on Mac OS X) and make it far more difficult (impossible) to remove the preferences.txt to reset them (when they become corrupt), or to find the the file to make edits for numerous obscure preferences that are not part of the preferences window. If we added a generic editor (e.g. about:config in Mozilla) for such things, we could start using the Java Preferences API. But wow, that sounds like a lot of work. Not unlike writing this paragraph.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static int` | `BUTTON_HEIGHT` Standardized button height.
    `static int` | `BUTTON_WIDTH` Standardized width for buttons.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `Preferences(Base base)`

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `static String` | `get(String attribute)`
    `static boolean` | `getBoolean(String attribute)`
    `static Color` | `getColor(String name)`
    `static String` | `getDefault(String attribute)`
    `static Font` | `getFont(String attr)`
    `static int` | `getInteger(String attribute)`
    `Dimension` | `getPreferredSize()`
    `static void` | `init()`
    `static void` | `load(InputStream input)`
    `static void` | `set(String attribute, String value)`
    `static void` | `setBoolean(String attribute, boolean value)`
    `static void` | `setColor(String attr, Color what)`
    `static void` | `setInteger(String key, int value)`
    `void` | `sketchbookCallback(File file)`
    `static void` | `unset(String attribute)`

    - ### Methods inherited from class Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### BUTTON_WIDTH

          public static int BUTTON_WIDTH

      Standardized width for buttons. Mac OS X 10.3 wants 70 as its default, Windows XP needs 66, and my Ubuntu machine needs 80+, so 80 seems proper.

    - #### BUTTON_HEIGHT

          public static int BUTTON_HEIGHT

      Standardized button height. Mac OS X 10.3 (Java 1.4) wants 29, presumably because it now includes the blue border, where it didn't in Java 1.3. Windows XP only wants 23 (not sure what default Linux would be). Because of the disparity, on Mac OS X, it will be set inside a static block.

  - ### Constructor Detail

    - #### Preferences

          public Preferences(Base base)

  - ### Method Detail

    - #### init

          public static void init()

    - #### sketchbookCallback

          public void sketchbookCallback(File file)

    - #### getPreferredSize

          public Dimension getPreferredSize()

    - #### load

          public static void load(InputStream input)
                           throws IOException

      Throws:
        `IOException`

    - #### get

          public static String get(String attribute)

    - #### getDefault

          public static String getDefault(String attribute)

    - #### set

          public static void set(String attribute,
                 String value)

    - #### unset

          public static void unset(String attribute)

    - #### getBoolean

          public static boolean getBoolean(String attribute)

    - #### setBoolean

          public static void setBoolean(String attribute,
                        boolean value)

    - #### getInteger

          public static int getInteger(String attribute)

    - #### setInteger

          public static void setInteger(String key,
                        int value)

    - #### getColor

          public static Color getColor(String name)

    - #### setColor

          public static void setColor(String attr,
                      Color what)

    - #### getFont

          public static Font getFont(String attr)