JHotDraw 7.3.1

org.jhotdraw.text
Class ColorFormatter

java.lang.Object
  extended by javax.swing.JFormattedTextField.AbstractFormatter
      extended by javax.swing.text.DefaultFormatter
          extended by org.jhotdraw.text.ColorFormatter
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

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:

By default, the formatter formats Color objects with Format.RGB_INTEGER.

Version:
$Id: ColorFormatter.java 529 2009-06-08 21:12:23Z rawcoder $
Author:
Werner Randelshofer
See Also:
Serialized Form

Nested Class Summary
static class ColorFormatter.Format
          Specifies the formats supported by ColorFormatter.
 
Constructor Summary
ColorFormatter()
           
ColorFormatter(ColorFormatter.Format outputFormat, boolean allowsNullValue, boolean isAdaptive)
           
 
Method Summary
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, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, install, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode, setValueClass
 
Methods inherited from class javax.swing.JFormattedTextField.AbstractFormatter
getActions, getFormattedTextField, invalidEdit, setEditValid, uninstall
 
Methods inherited from class java.lang.Object
equals, finalize, 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 -

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:
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 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}.


Copyright 1996-2009 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.