com.taco.swinger.text2gui
Class StringToColorConverter
java.lang.Object
com.taco.text.AbstractStringToObjectConverter
com.taco.swinger.text2gui.StringToColorConverter
- All Implemented Interfaces:
- IStringToObjectConverter, IObjectMapper
public class StringToColorConverter
- extends AbstractStringToObjectConverter
A converter from strings to colors, using Color.decode()
.
Constructor Summary |
protected |
StringToColorConverter()
Since this class is implemented as a singleton, its sole constructor
is protected. |
Method Summary |
static void |
main(java.lang.String[] args)
|
static java.awt.Color |
toColor(java.lang.String s)
If s is empty, throw a ParseException . |
java.lang.Object |
toObject(java.lang.String s)
Return the result of toColor(s) . |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
instance
public static final StringToColorConverter instance
- The singleton instance of this class.
StringToColorConverter
protected StringToColorConverter()
- Since this class is implemented as a singleton, its sole constructor
is protected.
toObject
public java.lang.Object toObject(java.lang.String s)
throws java.text.ParseException
- Return the result of
toColor(s)
.
- Throws:
java.text.ParseException
toColor
public static final java.awt.Color toColor(java.lang.String s)
throws java.text.ParseException
- If
s
is empty, throw a ParseException
.
Otherwise, check if s
starts with a letter. If so, use
reflection to return static field of Color
that
s
refers to. Otherwise, assume s
is a number
string, and return the result of Color.decode(s)
.
- Throws:
java.lang.NullPointerException
- if s
is null
.
java.text.ParseException
main
public static void main(java.lang.String[] args)