y.option
Class OptionHandler

java.lang.Object
  |
  +--y.option.OptionHandler

public class OptionHandler
extends Object

A class that manages a set of parameters. It provides an editor component for the set of parameters that allows to modify the values interactively. The parameters are arranged in sections, each section is displayed by a proper card in a tabbed pane layout. Each section contains a set of parameters. They are arranged in top down fashion, each parameter in a line, on the left side a name for the parameter, on the right side an input mask for the parameter.


Field Summary
protected  GuiFactory guiFactory
          the guifactory used for constructing the panel
static byte OK_APPLY_CANCEL_BUTTONS
          Button mask for the editor dialog.
static byte OK_CANCEL_BUTTONS
          Button mask for the editor dialog.
static byte OK_RESET_APPLY_CANCEL_BUTTONS
          Button mask for the editor dialog.
static byte OK_RESET_CANCEL_BUTTONS
          Button mask for the editor dialog.
protected  OptionsIOHandler optionsIOHandler
          the iohandler used for serializing the values
 
Constructor Summary
OptionHandler(GuiFactory factory, InputStream is)
          Deprecated. use the OptionsIOhandler way
OptionHandler(GuiFactory factory, OptionsIOHandler optionsIOHandler, String name)
          Create a new OptionHandler instance with a given name using the given IOHandler and GUIFactory.
OptionHandler(InputStream is)
          Deprecated. use the OptionsIOhandler way
OptionHandler(String name)
          Create a new OptionHandler instance with a given name, no (default) GuiFactory and no (default) OptionsIOHandler.
 
Method Summary
 OptionItem addBool(String name, boolean value)
          Adds a boolean option item
 OptionItem addColor(String name, Object value)
          Adds a color option item.
 OptionItem addColor(String name, Object value, boolean showPopup)
          Adds a color option item.
 OptionItem addColor(String name, Object value, boolean showNoColor, boolean showSomeColors, boolean showMostRecentlyUsedColors, boolean showMoreColors)
          Adds a color option item.
 void addComment(String text)
          Adds a commentary text to the option editor.
 void addComment(String text, int fontSize)
          Adds a commentary text to the option editor.
 OptionItem addDouble(String name, double value)
          Adds a double option item
 OptionItem addDouble(String name, double value, double minValue, double maxValue)
          Adds a double option item that has a lower and upper value bound
 OptionItem addDouble(String name, double value, double minValue, double maxValue, int precision)
          Like OptionHandler.addDouble(String,double,double,double).
 EnumOptionItem addEnum(String name)
          Adds an empty enumeration option item.
 EnumOptionItem addEnum(String name, Object[] enum, int valueIndex)
          Adds an enumeration option item.
 EnumOptionItem addEnum(String name, Object[] enum, Object defaultValue, ListCellRenderer renderer)
          Adds an enumeration option item.
 FileOptionItem addFile(String name, String value)
          Adds a file name option item
 OptionItem addInt(String name, int value)
          Adds an integer option item
 OptionItem addInt(String name, int value, int minValue, int maxValue)
          Adds an integer option item that has a lower and upper value bound
 OptionItem addItem(OptionItem it)
          Adds a generic option item.
 void addOptionHandler(OptionHandler childHandler, String defaultName)
          Adds all the sections of another optionhandler to this one.
 OptionItem addString(String name, String value)
          Adds a string option item.
 OptionItem addString(String name, String value, int rowCount)
          Adds a string option item whose text editor has a specific number of rows.
 boolean checkValues()
          Checks if the values in the option editor are valid.
 void clear()
          Removes all sections and option items from this option handler
 void commitValues()
          Commits all values that where modified with the option editor to the corresponding option items.
 Object get(String name)
          Returns the value of the option item that has the given identifying name.
 Object get(String section, String name)
          Returns the value of an option item
 boolean getBool(String name)
          Returns the boolean value of an option item.
 boolean getBool(String section, String name)
          Returns the boolean value of an option item.
static GuiFactory getDefaultGuiFactory()
          getter for the default GUIFactory
static OptionsIOHandler getDefaultOptionsIOHandler()
          getter for the default OptionsIOhandler
 double getDouble(String name)
          Returns the double value of an option item.
 double getDouble(String section, String name)
          Returns the double value of an option item.
 JComponent getEditor()
          Returns the editor component of thjis option handler.
 int getEnum(String name)
          Returns the index value of an enumeration item.
 int getEnum(String section, String name)
          Returns the index value of an enumeration item.
 GuiFactory getGuiFactory()
          Getter for property guiFactory.
static byte getIndex(Object[] enum, Object value)
          Returns the index for the given array at which the given value is found.
 int getInt(String name)
          Returns the integer value of an option item.
 int getInt(String section, String name)
          Returns the integer value of an option item.
 OptionItem getItem(String name)
          Returns the option item tha thas the given identifying name.
 OptionItem getItem(String section, String name)
          Returns the option item found in the given section under the given name.
 String getName()
          Returns the name of the option handler
 OptionsIOHandler getOptionsIOHandler()
          Getter for property OptionsIOHandler.
static List getRegisteredOptionHandlers()
          This method returns a list of all non-garbagecollected instances of OptionHandlers, which have been instanciated during this session.
 String getString(String name)
          Returns the String value of an option item.
 String getString(String section, String name)
          Returns the String value of an option item.
 Object getStringValue(String section, String name)
          Returns the stringified value of an option item
static void installDefaultGuiFactory(GuiFactory guiFactory)
          Static method to install a default GUIFactory for all optionhandlers, which will be used if no specific GUIFactory is provided for each instance.
static void installDefaultOptionsIOHandler(OptionsIOHandler OptionsIOHandler)
          Static method to install a default IOHandler for all optionhandlers, which will be used if no specific instance is provided for each instance.
static void main(String[] args)
          Test method.
 boolean read()
          reads in the values for the items from the installd IOHandler
 boolean read(OptionsIOHandler ioh)
          reads in the values for the items from the given IOHandler
 void resetValues()
          Resets all option values to their original settings.
 OptionSection section(int index)
          Returns the option section at position index the first section has the index 0
 OptionSection section(String name)
          Returns the option section that has the given name.
 int sectionCount()
          Returns the number of sections of this option handler
 void set(String name, Object value)
          Sets the value for the option that has the given name.
 void set(String section, String name, Object value)
          Sets the value for the option that has the given name in the given section
 void setGuiFactory(GuiFactory guiFactory)
          Setter for property guiFactory.
 void setName(String name)
          Sets the name of the option handler
 void setOptionsIOHandler(OptionsIOHandler optionsIOHandler)
          Setter for property OptionsIOHandler.
 void setPreferredEditorWidth(int width)
          Sets the preferred width of the option editor
 void setStringValue(String section, String name, String value)
          Sets the value for the option that has the given name in the given section
 boolean showEditor()
          Displays the editor for this option handler as a modal dialog window It uses OptionHandler.OK_RESET_CANCEL_BUTTONS as button mask.
 boolean showEditor(Frame frame)
          Displays the editor for this option handler as a modal dialog window It uses OptionHandler.OK_RESET_CANCEL_BUTTONS as button mask.
 boolean showEditor(Frame frame, byte buttonMask)
          Displays the editor for this option handler as a modal dialog window
 String toString()
          Returns a String that contains what would be written out by OptionHandler.write(OutputStream).
 OptionSection useSection(String name)
          Switch to specific section.
 void write(OptionsIOHandler ioh)
          writes out the values from the items to the given IOHandler
 void write(OutputStream os)
          Deprecated. use the OptionsIOhandler way
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

guiFactory

protected GuiFactory guiFactory
the guifactory used for constructing the panel


optionsIOHandler

protected OptionsIOHandler optionsIOHandler
the iohandler used for serializing the values


OK_RESET_CANCEL_BUTTONS

public static final byte OK_RESET_CANCEL_BUTTONS
Button mask for the editor dialog. Adds an OK button, a Reset button and a Cancel button.

See Also:
Constant Field Values

OK_APPLY_CANCEL_BUTTONS

public static final byte OK_APPLY_CANCEL_BUTTONS
Button mask for the editor dialog. Adds an OK button, an Apply button, and a Cancel button.

See Also:
Constant Field Values

OK_CANCEL_BUTTONS

public static final byte OK_CANCEL_BUTTONS
Button mask for the editor dialog. Adds an OK button and a Cancel button.

See Also:
Constant Field Values

OK_RESET_APPLY_CANCEL_BUTTONS

public static final byte OK_RESET_APPLY_CANCEL_BUTTONS
Button mask for the editor dialog. Adds an OK button, a Reset button, an Apply button, and a Cancel button.

See Also:
Constant Field Values
Constructor Detail

OptionHandler

public OptionHandler(String name)
Create a new OptionHandler instance with a given name, no (default) GuiFactory and no (default) OptionsIOHandler. The handler will be registered and added to the list of all active OptionHandlers.


OptionHandler

public OptionHandler(GuiFactory factory,
                     OptionsIOHandler optionsIOHandler,
                     String name)
Create a new OptionHandler instance with a given name using the given IOHandler and GUIFactory. The handler will be registered and added to the list of all active OptionHandlers.

Parameters:
factory -
optionsIOHandler -
name -

OptionHandler

public OptionHandler(InputStream is)
Deprecated. use the OptionsIOhandler way

Creates a new OptionHandler from an input stream. The input stream must provide access to a option handler format as created by OptionHandler.write(OutputStream).


OptionHandler

public OptionHandler(GuiFactory factory,
                     InputStream is)
Deprecated. use the OptionsIOhandler way

Creates a new OptionHandler from an input stream. The input stream must provide access to a option handler format as created by OptionHandler.write(OutputStream).

Parameters:
factory - the default factory
is -
Method Detail

installDefaultGuiFactory

public static void installDefaultGuiFactory(GuiFactory guiFactory)
Static method to install a default GUIFactory for all optionhandlers, which will be used if no specific GUIFactory is provided for each instance.

Parameters:
guiFactory - the default factory

installDefaultOptionsIOHandler

public static void installDefaultOptionsIOHandler(OptionsIOHandler OptionsIOHandler)
Static method to install a default IOHandler for all optionhandlers, which will be used if no specific instance is provided for each instance.

Parameters:
OptionsIOHandler - the default handler

getDefaultOptionsIOHandler

public static OptionsIOHandler getDefaultOptionsIOHandler()
getter for the default OptionsIOhandler

Returns:
the current default

getDefaultGuiFactory

public static GuiFactory getDefaultGuiFactory()
getter for the default GUIFactory

Returns:
the current default

getRegisteredOptionHandlers

public static List getRegisteredOptionHandlers()
This method returns a list of all non-garbagecollected instances of OptionHandlers, which have been instanciated during this session. If mutlitple handlers with the same name have been instanciated, only the last one will be returned.

Returns:
a list of OptionHandlers

setName

public void setName(String name)
Sets the name of the option handler


getName

public String getName()
Returns the name of the option handler


addFile

public FileOptionItem addFile(String name,
                              String value)
Adds a file name option item

Parameters:
name - the identifier of this option
value - the initial path to the file

addInt

public OptionItem addInt(String name,
                         int value)
Adds an integer option item

Parameters:
name - the identifier of this option
value - the initial value of the option

addInt

public OptionItem addInt(String name,
                         int value,
                         int minValue,
                         int maxValue)
Adds an integer option item that has a lower and upper value bound

Parameters:
name - the identifier of this option
value - the initial value of the option
minValue - the minimal value of the option
maxValue - the maximal value of the option

addDouble

public OptionItem addDouble(String name,
                            double value)
Adds a double option item

Parameters:
name - the identifier of this option
value - the initial value of the option

addDouble

public OptionItem addDouble(String name,
                            double value,
                            double minValue,
                            double maxValue)
Adds a double option item that has a lower and upper value bound

Parameters:
name - the identifier of this option
value - the initial value of the option
minValue - the minimal value of the option
maxValue - the maximal value of the option

addDouble

public OptionItem addDouble(String name,
                            double value,
                            double minValue,
                            double maxValue,
                            int precision)
Like OptionHandler.addDouble(String,double,double,double). Additionally the precicion of the double can be specified as the number of decimal places.


addEnum

public EnumOptionItem addEnum(String name,
                              Object[] enum,
                              int valueIndex)
Adds an enumeration option item.

Parameters:
name - the identifier of this option
enum - an array that holds all possible values for this item.
valueIndex - the array index of the initial value.

addEnum

public EnumOptionItem addEnum(String name)
Adds an empty enumeration option item.

Parameters:
name - the identifier of this option

addEnum

public EnumOptionItem addEnum(String name,
                              Object[] enum,
                              Object defaultValue,
                              ListCellRenderer renderer)
Adds an enumeration option item.

Parameters:
name - the identifier of this option
enum - an array that holds all possible values for this item.
defaultValue - the initial value chosen (must be found in enum!)
renderer - The renderer being used in the editor component to display the values of the enumeration.

addBool

public OptionItem addBool(String name,
                          boolean value)
Adds a boolean option item

Parameters:
name - the identifier of this option
value - the initial value of the option

addItem

public OptionItem addItem(OptionItem it)
Adds a generic option item. This method can be used to home cooked option items

Parameters:
it - an option item.

addString

public OptionItem addString(String name,
                            String value)
Adds a string option item.

Parameters:
name - the identifier of this option
value - the initial value of the option

addString

public OptionItem addString(String name,
                            String value,
                            int rowCount)
Adds a string option item whose text editor has a specific number of rows.

Parameters:
name - the identifier of this option
value - the initial value of the option
rowCount - the number of rows of the text editor

addColor

public OptionItem addColor(String name,
                           Object value)
Adds a color option item.

Parameters:
name - the identifier of this option
value - the initial value of the option

addColor

public OptionItem addColor(String name,
                           Object value,
                           boolean showPopup)
Adds a color option item.

Parameters:
name - the identifier of this option
value - the initial value of the option

addColor

public OptionItem addColor(String name,
                           Object value,
                           boolean showNoColor,
                           boolean showSomeColors,
                           boolean showMostRecentlyUsedColors,
                           boolean showMoreColors)
Adds a color option item.

Parameters:
name - the identifier of this option
value - the initial value of the option

addComment

public void addComment(String text,
                       int fontSize)
Adds a commentary text to the option editor.

Parameters:
text - the text of the comment
fontSize - the size of the text font used

addComment

public void addComment(String text)
Adds a commentary text to the option editor.

Parameters:
text - the text of the comment

addOptionHandler

public void addOptionHandler(OptionHandler childHandler,
                             String defaultName)
Adds all the sections of another optionhandler to this one.


set

public void set(String name,
                Object value)
Sets the value for the option that has the given name.


set

public void set(String section,
                String name,
                Object value)
Sets the value for the option that has the given name in the given section


setStringValue

public void setStringValue(String section,
                           String name,
                           String value)
Sets the value for the option that has the given name in the given section


getInt

public int getInt(String section,
                  String name)
Returns the integer value of an option item.

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getInt

public int getInt(String name)
Returns the integer value of an option item.

Parameters:
name - the identifying name of the item

getDouble

public double getDouble(String section,
                        String name)
Returns the double value of an option item.

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getDouble

public double getDouble(String name)
Returns the double value of an option item.

Parameters:
name - the identifying name of the item

getBool

public boolean getBool(String name)
Returns the boolean value of an option item.

Parameters:
name - the identifying name of the item

getBool

public boolean getBool(String section,
                       String name)
Returns the boolean value of an option item.

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getString

public String getString(String name)
Returns the String value of an option item.

Parameters:
name - the identifying name of the item

getString

public String getString(String section,
                        String name)
Returns the String value of an option item.

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getEnum

public int getEnum(String name)
Returns the index value of an enumeration item.

Parameters:
name - the identifying name of the item

getEnum

public int getEnum(String section,
                   String name)
Returns the index value of an enumeration item.

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

get

public Object get(String section,
                  String name)
Returns the value of an option item

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getStringValue

public Object getStringValue(String section,
                             String name)
Returns the stringified value of an option item

Parameters:
section - the name of the section where the item resides
name - the identifying name of the item

getIndex

public static byte getIndex(Object[] enum,
                            Object value)
Returns the index for the given array at which the given value is found. If the value is not found at all -1 is returned. Conveniance method for enumeration option items.


getItem

public OptionItem getItem(String section,
                          String name)
Returns the option item found in the given section under the given name.


get

public Object get(String name)
Returns the value of the option item that has the given identifying name.


getItem

public OptionItem getItem(String name)
Returns the option item tha thas the given identifying name.


setPreferredEditorWidth

public void setPreferredEditorWidth(int width)
Sets the preferred width of the option editor


clear

public void clear()
Removes all sections and option items from this option handler


useSection

public OptionSection useSection(String name)
Switch to specific section. When a new option is inserted, and the section name is not provided, it is inserted in this section. When no section with this names exists a new one with that name will be created.


section

public OptionSection section(int index)
Returns the option section at position index the first section has the index 0


sectionCount

public int sectionCount()
Returns the number of sections of this option handler


section

public OptionSection section(String name)
Returns the option section that has the given name.


showEditor

public boolean showEditor()
Displays the editor for this option handler as a modal dialog window It uses OptionHandler.OK_RESET_CANCEL_BUTTONS as button mask.


showEditor

public boolean showEditor(Frame frame)
Displays the editor for this option handler as a modal dialog window It uses OptionHandler.OK_RESET_CANCEL_BUTTONS as button mask.

Parameters:
frame - centers the dialog relative to this frame

showEditor

public boolean showEditor(Frame frame,
                          byte buttonMask)
Displays the editor for this option handler as a modal dialog window

Parameters:
frame - centers the dialog relative to this frame
buttonMask - the button layout and functionality for the dialog.

getEditor

public JComponent getEditor()
Returns the editor component of thjis option handler.


commitValues

public void commitValues()
Commits all values that where modified with the option editor to the corresponding option items.


checkValues

public boolean checkValues()
Checks if the values in the option editor are valid.


resetValues

public void resetValues()
Resets all option values to their original settings.


write

public void write(OutputStream os)
Deprecated. use the OptionsIOhandler way

Writes out this option handler in an XML like format.


toString

public String toString()
Returns a String that contains what would be written out by OptionHandler.write(OutputStream).

Overrides:
toString in class Object

read

public boolean read(OptionsIOHandler ioh)
reads in the values for the items from the given IOHandler

Parameters:
ioh - the ioHandler to write to
Returns:
whether the reading was successful

read

public boolean read()
reads in the values for the items from the installd IOHandler

Returns:
whether the reading was successful

write

public void write(OptionsIOHandler ioh)
writes out the values from the items to the given IOHandler

Parameters:
ioh - the iohandler to use

getGuiFactory

public GuiFactory getGuiFactory()
Getter for property guiFactory.

Returns:
Value of property guiFactory.

setGuiFactory

public void setGuiFactory(GuiFactory guiFactory)
Setter for property guiFactory.

Parameters:
guiFactory - New value of property guiFactory.

getOptionsIOHandler

public OptionsIOHandler getOptionsIOHandler()
Getter for property OptionsIOHandler.

Returns:
Value of property OptionsIOHandler.

setOptionsIOHandler

public void setOptionsIOHandler(OptionsIOHandler optionsIOHandler)
Setter for property OptionsIOHandler.

Parameters:
optionsIOHandler - New value of property OptionsIOHandler.

main

public static void main(String[] args)
                 throws IOException
Test method. Don't bother.

IOException

© Copyright 2000-2003,
yWorks GmbH.
All rights reserved.

2003