qflib 0.98.1

de.qfs.lib.option
Class Option

java.lang.Object
  |
  +--java.util.Observable
        |
        +--de.qfs.lib.option.Option
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable
Direct Known Subclasses:
BooleanOption, ChoiceOption, FileOption, IntegerOption, KeyOption, NestedOption, StringOption, TableOption

public class Option
extends java.util.Observable
implements java.io.Serializable, java.lang.Cloneable

An Option is a value with a name and some possible constraints. Its main intention is to be used as a user editable option in a GUI application, but it is also useful for configuration in general.

Options can be grouped together into an OptionSet and edited with the help of an OptionGroup. A component to edit a single Option can be created with OptionEdit.makeEdit.

Options are serializable as long as their values are.

Version:
$Revision: 1.9 $
Author:
Gregor Schmid
See Also:
Serialized Form

Constructor Summary
Option()
          Create a new Option.
Option(java.lang.String name, java.lang.Object value)
          Create a new Option with a name and a value.
Option(java.lang.String name, java.lang.Object value, boolean nullOK)
          Create a new Option with a name and a value and the nullOK flag.
 
Method Summary
static void addResources(java.util.ResourceBundle resources)
          Add some resources for the de.qfs.lib.option package.
 void addValidator(OptionValidator validator)
          Add an OptionValidator to the Option.
 boolean checkValue(java.awt.Component component, java.lang.Object value)
          Check, whether the Option accepts a value.
 java.lang.Object clone()
          Create a shallow copy of the Option.
 boolean equals(java.lang.Object object)
          Two Options are considered equal if their names and values are equal.
 java.lang.String getName()
          Get the name of the Option.
static MapResourceBundle getResources()
          Get the resources for the de.qfs.lib.option package.
 java.lang.Object getValue()
          Get the value of the Option.
 int hashCode()
          An Option's hashCode is generated from its name and value.
 boolean isNullOK()
          Query whether null is a legal value for the Option.
 void removeValidator(OptionValidator validator)
          Remove an OptionValidator from the Option.
 void setName(java.lang.String name)
          Set the name of the Option.
 void setNullOK(boolean nullOK)
          Set whether null is a legal value for the Option.
static void setResources(java.util.ResourceBundle resources)
          Set the resources of the de.qfs.lib.option package.
 void setValue(java.lang.Object value)
          Set the value of the Option.
 java.lang.String toString()
          Get a String representation for the Option.
 
Methods inherited from class java.util.Observable
addObserver, clearChanged, countObservers, deleteObserver, deleteObservers, hasChanged, notifyObservers, notifyObservers, setChanged
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Option

public Option()
Create a new Option.

Option

public Option(java.lang.String name,
              java.lang.Object value)
Create a new Option with a name and a value.
Parameters:
name - The name to use.
value - The value to use.

Option

public Option(java.lang.String name,
              java.lang.Object value,
              boolean nullOK)
Create a new Option with a name and a value and the nullOK flag.
Parameters:
name - The name to use.
value - The value to use.
nullOK - True to allow null values.
Method Detail

getResources

public static final MapResourceBundle getResources()
Get the resources for the de.qfs.lib.option package. See the package documentation for details about the resource names used.
Returns:
The resources for the package.

setResources

public static final void setResources(java.util.ResourceBundle resources)
Set the resources of the de.qfs.lib.option package. See the package documentation for details about the resource names used.
Parameters:
resources - The resources to set.

addResources

public static final void addResources(java.util.ResourceBundle resources)
Add some resources for the de.qfs.lib.option package. See the package documentation for details about the resource names used.
Parameters:
resources - The resources to add.

getName

public java.lang.String getName()
Get the name of the Option.
Returns:
The name of the Option.

setName

public void setName(java.lang.String name)
Set the name of the Option.
Parameters:
name - The name to set.

getValue

public java.lang.Object getValue()
Get the value of the Option.
Returns:
The value of the Option.

setValue

public void setValue(java.lang.Object value)
Set the value of the Option.
Parameters:
value - The value to set.

isNullOK

public boolean isNullOK()
Query whether null is a legal value for the Option.
Returns:
True if null is OK.

setNullOK

public void setNullOK(boolean nullOK)
Set whether null is a legal value for the Option.
Parameters:
nullOK - True to allow null values.

checkValue

public boolean checkValue(java.awt.Component component,
                          java.lang.Object value)
Check, whether the Option accepts a value. If it does not, the reason should be explained in a message dialog unless component is null.
Parameters:
component - The Component in which the Option is being edited.
value - The value to check.
Returns:
True, if the value is acceptable.

addValidator

public void addValidator(OptionValidator validator)
Add an OptionValidator to the Option.
Parameters:
validator - The OptionValidator to add.

removeValidator

public void removeValidator(OptionValidator validator)
Remove an OptionValidator from the Option.
Parameters:
validator - The OptionValidator to remove.

toString

public java.lang.String toString()
Get a String representation for the Option.
Overrides:
toString in class java.lang.Object
Returns:
The String representation.

hashCode

public int hashCode()
An Option's hashCode is generated from its name and value.
Overrides:
hashCode in class java.lang.Object
Returns:
The hashCode.

equals

public boolean equals(java.lang.Object object)
Two Options are considered equal if their names and values are equal.
Overrides:
equals in class java.lang.Object
Parameters:
object - The object to compare to.
Returns:
True if objects are equal

clone

public java.lang.Object clone()
Create a shallow copy of the Option. The option's value is not cloned.
Overrides:
clone in class java.lang.Object
Returns:
The copy.

qflib 0.98.1