Documentation of 'org.jhotdraw.text.ColorFormatter' Java class
ColorFormatter
org.jhotdraw.text

Class ColorFormatter

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    ColorToolTipTextFormatter


    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:

    • Format.RGB_HEX - "#"rrggbb or "#"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, or red green blue optionally 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, or red green blue optionally 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, or red"%" 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 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.

    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class and Description
      static class  ColorFormatter.Format
      Specifies the formats supported by ColorFormatter.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      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) 
      • Methods inherited from class javax.swing.text.DefaultFormatter

        clone, getAllowsInvalid, getCommitsOnValidEdit, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
      • Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter

        uninstall
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • 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 -
      • 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:
        stringToValue in class javax.swing.text.DefaultFormatter
        Throws:
        java.text.ParseException
      • valueToString

        public java.lang.String valueToString(java.lang.Object value)
                                       throws java.text.ParseException
        Overrides:
        valueToString in class javax.swing.text.DefaultFormatter
        Throws:
        java.text.ParseException
      • createFormatterFactory

        public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory()
        Convenience method for creating a formatter factory with a ColorFormatter. 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

Ads help maintain this website.