org.jhotdraw.text
Class ColorFormatter
- java.lang.Object
-
- javax.swing.JFormattedTextField.AbstractFormatter
-
- javax.swing.text.DefaultFormatter
-
- org.jhotdraw.text.ColorFormatter
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
- Direct Known Subclasses:
- ColorToolTipTextFormatter
public class ColorFormatter extends javax.swing.text.DefaultFormatterColorFormatteris used to format colors into a textual representation which can be edited in an entry field.The following formats are supported:
- Format.RGB_HEX -
"#"rrggbbor"#"rgb.
If 6 digits are entered, each pair of hexadecimal digits, in the range 0 to F, represents one sRGB color component in the order red, green and blue. The digits A to F may be given in either uppercase or lowercase.
If only 3 digits are entered, they are expanded to 6 digits by replicating each digit.
This syntactical form can represent 16777216 colors. Examples:#9400D3(i.e. a dark violet),#FFD700(i.e. a golden color),#000(i.e. black)#fff(i.e. white). - Format.RGB_INTEGER_SHORT -
red green blue, orred green blueoptionally separated by commas.
Each value represents one sRGB color component. Each value is in the range 0 to 255. This syntactical form can represent 16777216 colors. Examples:233 150 122(i.e. a salmon pink),255 165 0(i.e. an orange). - Format.RGB_INTEGER -
"rgb" red green blue, orred green blueoptionally separated by commas.
Each value represents one sRGB color component. Each value is in the range 0 to 255. This syntactical form can represent 16777216 colors. Examples:rgb 233 150 122(i.e. a salmon pink),rgb 255 165 0(i.e. an orange). - Format.RGB_PERCENTAGE -
"rgb%" red green blue, orred"%" green"%" blue"%"optionally separated by commas.
Each value represents one sRGB color component. Each value is in the range 0.0 to 100.0. This syntactical form can represent 10^9 colors. - Format.GRAY_PERCENTAGE -
"gray" brightness.
The value represents the brightness in the range from 0.0 to 100.0. - Format.HSB_PERCENTAGE -
"hsb" hue saturation brightness.
Each integer represents one HSV component in the order hue, saturation and value, separated by a comma and optionally by white space. Hue is in the range from 0.0 to 359.0, saturation and brightness in the range from 0.0 to 100.0.
By default, the formatter is adaptive, meaning that the format depends on the
ColorSpaceof the currentColorvalue.FIXME - This class does too much work. It should be split up into individual classes for each of the supported formats.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class and Description static classColorFormatter.FormatSpecifies the formats supported by ColorFormatter.
-
Constructor Summary
Constructors Constructor and Description ColorFormatter()ColorFormatter(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static javax.swing.JFormattedTextField.AbstractFormatterFactorycreateFormatterFactory()Convenience method for creating a formatter factory with aColorFormatter.static javax.swing.JFormattedTextField.AbstractFormatterFactorycreateFormatterFactory(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)Convenience method for creating a formatter factory with a 8@code ColorFormatter}.booleangetAllowsNullValue()Returns true, if null value is allowed.ColorFormatter.FormatgetLastUsedInputFormat()Gets the last used input format.ColorFormatter.FormatgetOutputFormat()Gets the output format.booleanisAdaptive()Returns true, if the color formatter is adaptive.voidsetAdaptive(boolean newValue)Sets whether the color formatter adaptively selects its output format depending on the last input format used by the user.voidsetAllowsNullValue(boolean newValue)Sets whether a null value is allowed.voidsetOutputFormat(ColorFormatter.Format newValue)Sets the output format.java.lang.ObjectstringToValue(java.lang.String str)java.lang.StringvalueToString(java.lang.Object value)
-
-
-
Constructor Detail
-
ColorFormatter
public ColorFormatter()
-
ColorFormatter
public ColorFormatter(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)
-
-
Method Detail
-
setOutputFormat
public void setOutputFormat(ColorFormatter.Format newValue)
Sets the output format.- Parameters:
newValue-
-
getOutputFormat
public ColorFormatter.Format getOutputFormat()
Gets the output format.
-
getLastUsedInputFormat
public ColorFormatter.Format getLastUsedInputFormat()
Gets the last used input format.
-
setAllowsNullValue
public void setAllowsNullValue(boolean newValue)
Sets whether a null value is allowed.- Parameters:
newValue-
-
getAllowsNullValue
public boolean getAllowsNullValue()
Returns true, if null value is allowed.
-
setAdaptive
public void setAdaptive(boolean newValue)
Sets whether the color formatter adaptively selects its output format depending on the last input format used by the user.- Parameters:
newValue-
-
isAdaptive
public boolean isAdaptive()
Returns true, if the color formatter is adaptive.
-
stringToValue
public java.lang.Object stringToValue(java.lang.String str) throws java.text.ParseException- Overrides:
stringToValuein classjavax.swing.text.DefaultFormatter- Throws:
java.text.ParseException
-
valueToString
public java.lang.String valueToString(java.lang.Object value) throws java.text.ParseException- Overrides:
valueToStringin classjavax.swing.text.DefaultFormatter- Throws:
java.text.ParseException
-
createFormatterFactory
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory()
Convenience method for creating a formatter factory with aColorFormatter. Uses the RGB_INTEGER_SHORT format, allows null values and is adaptive.
-
createFormatterFactory
public 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}.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG