edu.rice.cs.drjava.config
Class Option
java.lang.Object
|
+--edu.rice.cs.drjava.config.OptionParser
|
+--edu.rice.cs.drjava.config.Option
- All Implemented Interfaces:
- FormatStrategy, ParseStrategy
- Direct Known Subclasses:
- BooleanOption, ColorOption, FileOption, FontOption, IntegerOption, KeyStrokeOption, StringOption, VectorOption
- public abstract class Option
- extends OptionParser
- implements FormatStrategy
Represents a configurable option in DrJava that has a static (programmatic) type of T.
Classes can magically extend this class and the entire rest of the Configuration magic
typing framework will work for it. Named subclasses aren't even necessary -- but
may be convenient in order to re-use code. For example, to make an anonymous class
that handled options of static type Integer, with the name "indent.level", you use the
following code:
Option<Integer> INDENT_LEVEL = new Option<Integer>("indent.level") {
public Integer parse(String s) {
return new Integer(s);
}
};
the above example is simple because Integers (like most Java(tm) standard-lib data-type
classes) have handy toString() / parsing methods/constructors.
- Version:
- $Id: Option.java,v 1.9 2002/06/20 17:05:51 csreis Exp $
Field Summary |
(package private) gj.util.Hashtable |
listeners
a hashtablethat maps Configuration Objects to a list of listeners for this
particular option. |
Constructor Summary |
Option(String name,
Object def)
constructor that takes in a name and default value |
Methods inherited from class java.lang.Object |
, clone, equals, finalize, getClass, hashCode, notify, notifyAll, registerNatives, toString, wait, wait, wait |
listeners
final gj.util.Hashtable listeners
- a hashtablethat maps Configuration Objects to a list of listeners for this
particular option. Part of the magic inner workings of this package.
Option
public Option(String name,
Object def)
- constructor that takes in a name and default value
- Parameters:
name
- the name of this option (eg. "indent.level");def
- the default value for this option (eg. "2")
format
public String format(Object value)
- the ability to format a statically typed T value to a String. Since T is an Object,
the default implementation uses the .toString() method.
- Specified by:
format
in interface FormatStrategy
- Parameters:
value
- the statically-typed value to format into a String- Throws:
NullPointerException
- if value is null
getDefaultString
public String getDefaultString()
- Overrides:
getDefaultString
in class OptionParser
- Following copied from class:
edu.rice.cs.drjava.config.OptionParser
- Returns:
- the default value as a string
getString
String getString(DefaultOptionMap om)
- uses format() and getOption() so that any changes in format will automatically
be applied to getString().
- Overrides:
getString
in class OptionParser
notifyListeners
void notifyListeners(Configuration config,
Object val)
addListener
void addListener(Configuration c,
OptionListener l)
- magic listener-bag adder
removeListener
void removeListener(Configuration c,
OptionListener l)
- magic listener-bag remover