public class ColorFormatter
extends javax.swing.text.DefaultFormatter
ColorFormatter
is used to format colors into a textual representation
which can be edited in an entry field.
The following formats are supported:
"#"rrggbb
or "#"rgb
.#9400D3
(i.e. a dark violet), #FFD700
(i.e. a golden color), #000
(i.e. black) #fff
(i.e. white).
red green blue
,
or red green blue
optionally separated by commas.233 150 122
(i.e. a salmon pink), 255 165 0
(i.e. an orange).
"rgb" red green blue
,
or red green blue
optionally separated by commas.rgb 233 150 122
(i.e. a salmon pink), rgb 255 165 0
(i.e. an orange).
"rgb%" red green blue
,
or red"%" green"%" blue"%"
optionally separated by commas."gray" brightness
."hsb" hue saturation brightness
.
By default, the formatter is adaptive, meaning that the format depends
on the ColorSpace
of the current Color
value.
FIXME - This class does too much work. It should be split up into individual classes for each of the supported formats.
Modifier and Type | Class and Description |
---|---|
static class |
ColorFormatter.Format
Specifies the formats supported by ColorFormatter.
|
Modifier and Type | Field and Description |
---|---|
protected boolean |
allowsNullValue
Specifies whether the formatter allows null values.
|
protected static java.util.regex.Pattern |
grayPercentagePattern
This regular expression is used for parsing the GRAY_PERCENTAGE format.
|
protected static java.util.regex.Pattern |
hsbPercentagePattern
This regular expression is used for parsing the HSB_PERCENTAGE format.
|
protected boolean |
isAdaptive
Specifies whether the formatter should adaptively change its output
format depending on the last input format used by the user.
|
protected ColorFormatter.Format |
lastUsedInputFormat
Specifies the last used input format.
|
protected java.text.DecimalFormat |
numberFormat |
protected ColorFormatter.Format |
outputFormat
Specifies the preferred output format.
|
protected java.util.prefs.Preferences |
prefs
Preferences used for storing the last used input format.
|
protected static java.util.regex.Pattern |
rgbHexPattern
This regular expression is used for parsing the RGB_HEX format.
|
protected static java.util.regex.Pattern |
rgbIntegerPattern
This regular expression is used for parsing the RGB_INTEGER format.
|
protected static java.util.regex.Pattern |
rgbIntegerShortPattern
This regular expression is used for parsing the RGB_INTEGER format.
|
protected static java.util.regex.Pattern |
rgbPercentagePattern
This regular expression is used for parsing the RGB_PERCENTAGE format.
|
Constructor and Description |
---|
ColorFormatter() |
ColorFormatter(ColorFormatter.Format outputFormat,
boolean allowsNullValue,
boolean isAdaptive) |
Modifier and Type | Method and Description |
---|---|
static javax.swing.JFormattedTextField.AbstractFormatterFactory |
createFormatterFactory()
Convenience method for creating a formatter factory with a
ColorFormatter . |
static javax.swing.JFormattedTextField.AbstractFormatterFactory |
createFormatterFactory(ColorFormatter.Format outputFormat,
boolean allowsNullValue,
boolean isAdaptive)
Convenience method for creating a formatter factory with a
8@code ColorFormatter}.
|
boolean |
getAllowsNullValue()
Returns true, if null value is allowed.
|
ColorFormatter.Format |
getLastUsedInputFormat()
Gets the last used input format.
|
ColorFormatter.Format |
getOutputFormat()
Gets the output format.
|
boolean |
isAdaptive()
Returns true, if the color formatter is adaptive.
|
void |
setAdaptive(boolean newValue)
Sets whether the color formatter adaptively selects its output
format depending on the last input format used by the user.
|
void |
setAllowsNullValue(boolean newValue)
Sets whether a null value is allowed.
|
void |
setOutputFormat(ColorFormatter.Format newValue)
Sets the output format.
|
java.lang.Object |
stringToValue(java.lang.String str) |
java.lang.String |
valueToString(java.lang.Object value) |
clone, getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
protected ColorFormatter.Format outputFormat
protected ColorFormatter.Format lastUsedInputFormat
protected static final java.util.regex.Pattern rgbHexPattern
protected static final java.util.regex.Pattern rgbIntegerShortPattern
protected static final java.util.regex.Pattern rgbIntegerPattern
protected static final java.util.regex.Pattern rgbPercentagePattern
protected static final java.util.regex.Pattern hsbPercentagePattern
protected static final java.util.regex.Pattern grayPercentagePattern
protected boolean allowsNullValue
protected boolean isAdaptive
protected java.util.prefs.Preferences prefs
protected java.text.DecimalFormat numberFormat
public ColorFormatter()
public ColorFormatter(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)
public void setOutputFormat(ColorFormatter.Format newValue)
newValue
- public ColorFormatter.Format getOutputFormat()
public ColorFormatter.Format getLastUsedInputFormat()
public void setAllowsNullValue(boolean newValue)
newValue
- public boolean getAllowsNullValue()
public void setAdaptive(boolean newValue)
newValue
- public boolean isAdaptive()
public java.lang.Object stringToValue(java.lang.String str) throws java.text.ParseException
stringToValue
in class javax.swing.text.DefaultFormatter
java.text.ParseException
public java.lang.String valueToString(java.lang.Object value) throws java.text.ParseException
valueToString
in class javax.swing.text.DefaultFormatter
java.text.ParseException
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory()
ColorFormatter
.
Uses the RGB_INTEGER_SHORT format, allows null values and is adaptive.public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)