edu.neu.ccs.gui
Class ColorView

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byedu.neu.ccs.gui.DisplayPanel
                      extended byedu.neu.ccs.gui.ColorView
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants, TypedView

public class ColorView
extends DisplayPanel
implements TypedView

A TypedView for the input of a Color that contains an optional color swatch on the left that displays the selected color and an optional dropdown view on the right that allows for both the direct input of numeric color data (rgba or hex) and for the selection of certain colors using swatch-name pairs shown in the dropdown.

The option to permit the color swatch on the left to be optional was introduced in 2.6.0 without any change to the public interface of this class. Instead, if a constructor is passed a swatch width or height that is less than or equal to zero then the swatch will exist but will not be installed in the GUI. The same will be true if the width or height is passed within a Dimension object. As in the past, if a null Dimension object is passed, then that will be treated as a signal for the default swatch size not zero swatch size.

Whether or not the optional dropdown view is shown continues to be controlled by the constructor parameter showDropdown. If a constructor does not have this parameter, then the default is true.

The currently selected color value may be changed through a ColorPaneDialog dialog. As of 2.6.0, this dialog replaced the use of JColorChooser since that Java dialog did not permit the setting of the alpha parameter. The ColorPaneDialog dialog is opened by clicking on the color swatch in the main GUI.

The currently selected color value may be changed in the dropdown view by selecting a color swatch-name pair or by entering the color data into the editable text field in one of the following formats.

Data format 1: A comma and/or blank separated text string with 3 int components: red, green, blue or 4 int components: red, green, blue, alpha.

The int components should be in the range [0, 255].

If the alpha component is omitted then it is assumed to be 255.

Data format 2: A String of the form #rRgGbB or #rRgGbBaA where r, R, g, G, b, B, a, A are hex digits with red = rR, green = gG, blue = bB, alpha = aA.

Data format 3: A String of the form #rgb or #rgba that is interpreted as #rrggbb or #rrggbbaa respectively.

Data format 4: A color name that is contained in the internal static structure of the class Colors. An array with the currently valid installed color names can be obtained via the call:

Colors.getColorNamesAsArray()

Although the user can type in a color name in the dropdown view text area, the same result can be obtained more quickly by using the dropdown list.

Changes to the input state in the dropdown view take effect when a swatch-name selection is made or when the user presses the Return key in the dropdown view text area.

Since:
1.0
Version:
2.6.0
See Also:
ColorPane, ColorPaneDialog, MultiColorView, VisualColorList, VisualColorSampler, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
static int BOX_SIZE
          The default size for the color box.
static String CHOOSER_CLICK_COUNT
          Bound property name for the chooser click count property.
private  int chooserClickCount
          The click count to trigger the color chooser.
private  PaintSwatch colorBox
          The color box view to display the current color.
private  MouseAction colorBoxAction
          The standard color box action.
private  MouseActionAdapter colorBoxActions
          The mouse action adapter for the color box view.
private  DropdownView colorDropdownView
          The dropdown view.
private  ColorPaneDialog colorPaneDialog
          The color pane dialog for use if the swatch is clicked.
private  Color currentColor
          The current color for this view.
static int DEFAULT_CHOOSER_CLICK_COUNT
          The default click count to trigger the color chooser.
static Color DEFAULT_COLOR
          The initial color and initial default color for the view.
static Dimension DEFAULT_DIMENSION
          The default dimension for the color view box.
static int DEFAULT_WIDTH
          The default width for the dropdown view.
private  Color defaultColor
          The default color for this view.
private  SwatchNameRenderer renderer
          The swatch-name renderer.
static String SET_CURRENT_COLOR
          Bound property name for set current color.
static String SET_DEFAULT_COLOR
          Bound property name for set default color.
private  ActionSequence setColorActions
          The action sequence for handling set color action listeners.
private  Action setColorFromDropdownView
          Action triggering the task of setting the current color to the color represented by input in the dropdown view.
 
Fields inherited from class edu.neu.ccs.gui.DisplayPanel
background, codec, CODEC
 
Fields inherited from class javax.swing.JPanel
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
Fields inherited from class java.awt.Container
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface edu.neu.ccs.gui.TypedView
DATA_TYPE
 
Fields inherited from interface edu.neu.ccs.gui.Displayable
DEFAULT_VIEW_STATE, VIEW_STATE
 
Fields inherited from interface edu.neu.ccs.util.JPTConstants
ABOVE, ALIGNMENT, BELOW, BOTTOM_LEFT, BOTTOM_RIGHT, DEFAULT, FONT, INPUT_PROPERTIES, MANDATORY, OPTIONAL, ORIENTATION, TOP_LEFT, TOP_RIGHT, VALUE
 
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ColorView()
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data.
ColorView(Color color)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color.
ColorView(Color color, boolean showDropdown)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color.
ColorView(Color color, boolean showDropdown, Dimension dimension)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension.
ColorView(Color color, boolean showDropdown, Dimension dimension, int minWidth)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension; the minimum width of the dropdown editable area is the given minWidth.
ColorView(Color color, boolean showDropdown, int width, int height)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height.
ColorView(Color color, boolean showDropdown, int width, int height, int minWidth)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height; the minimum width of the dropdown editable area is the given minWidth.
ColorView(Color color, Dimension dimension)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension.
ColorView(Color color, Dimension dimension, int minWidth)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension; the minimum width of the dropdown editable area is the given minWidth.
ColorView(Color color, int width, int height)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height.
ColorView(Color color, int width, int height, int minWidth)
          Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height; the minimum width of the dropdown editable area is the given minWidth.
 
Method Summary
 void addAction(ActionListener action)
          Append an action listener to be performed when the method setColor is called.
 void addAction(int index, ActionListener action)
          Add an action listener to be performed when the method setColor is called and place this action listener at the given index in the set color actions sequence.
private  void colorBoxAction(MouseEvent evt)
          The standard color box action method.
 Stringable demandObject()
          Returns an XColor object whose state is set to the view state of this view.
 int getChooserClickCount()
          Return the chooser click count.
 Color getColor()
          Returns the current color.
 PaintSwatch getColorBox()
          Returns the internal JPTComponent that represents the color box in the view.
 DropdownView getColorDropdownView()
          Returns the internal DropdownView that may be used to choose the color via a String representation.
 Class getDataType()
          Returns the XColor class object.
 Color getDefaultColor()
          Returns the default color.
 String getDefaultViewState()
          Returns a String encapsulation of the state of the default Color for this view.
 InputProperties getInputProperties()
          Returns the input properties of the internal color dropdown view.
 MouseActionAdapter getMouseActionAdapter()
          Returns the mouse action adapter for the color box in this color view.
 ActionSequence getSetColorActions()
          Returns the ActionSequence that holds the actions to be performed when the method setColor is called.
 String getViewState()
          Returns a String encapsulation of the state of the current Color for this view.
protected  void installColorBox(Color color, Dimension dimension)
          Installs the color box for this view.
protected  void installColorBoxActions()
          Installs the color box mouse actions triggered by mouse events targeted on the color box contained in this view.
protected  void installColorDropdownView(boolean showDropdown, int minWidth)
          Installs the color dropdown view.
 boolean removeAction(ActionListener action)
          Remove an action listener that was to be performed when the method setColor is called.
 ActionListener removeAction(int index)
          Remove an action listener at the given index position that was to be performed when the method setColor is called.
 Stringable requestObject()
          Returns an XColor object whose state is set to the view state of this view.
 void reset()
          Resets the color to the default color.
 void setChooserClickCount(int count)
          Sets the number of mouse clicks required to bring up the color chooser dialog.
 void setColor(Color color)
          Sets the current color to the given color.
protected  void setColorFromDropdownView()
          Sets the current color for this view to the color represented by the input in its color dropdown view.
 void setColorHelper(Color color)
          Sets the current color to the given color.
 void setDefaultColor(Color color)
          Sets the default color to the given color.
 void setDefaultViewState(String data)
          Sets the default view state for this view to the Color represented by the given String data.
 void setInputProperties(InputProperties p)
          Sets the input properties of the internal color dropdown view and fires a property change if the input properties have changed.
 void setViewState(String data)
          Sets the current view state for this view to the Color represented by the given String data.
 
Methods inherited from class edu.neu.ccs.gui.DisplayPanel
add, add, add, add, add, addBorder, addObject, addObject, addObject, addObject, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderLowered, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, bevelBorderRaised, compoundBorder, compoundBorder, dataMalformed, emptyBorder, emptyBorder, emptyBorder, endAlert, etchBorderLowered, etchBorderLowered, etchBorderLowered, etchBorderRaised, etchBorderRaised, etchBorderRaised, frame, frame, frame, frame, frame, frame, generalDialog, generalDialog, generalDialog, generalDialog, getCodec, getDefaultViewStates, getDisplayables, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewStates, setEnabled, setViewStates, startAlert, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, titleBorder, uniformizeHeight, uniformizeSize, uniformizeWidth, YesNoCancelDialog, YesNoCancelDialog
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface edu.neu.ccs.gui.Displayable
setEnabled
 

Field Detail

CHOOSER_CLICK_COUNT

public static final String CHOOSER_CLICK_COUNT
Bound property name for the chooser click count property.

See Also:
Constant Field Values

SET_CURRENT_COLOR

public static final String SET_CURRENT_COLOR
Bound property name for set current color.

See Also:
Constant Field Values

SET_DEFAULT_COLOR

public static final String SET_DEFAULT_COLOR
Bound property name for set default color.

See Also:
Constant Field Values

DEFAULT_COLOR

public static final Color DEFAULT_COLOR
The initial color and initial default color for the view.


DEFAULT_CHOOSER_CLICK_COUNT

public static final int DEFAULT_CHOOSER_CLICK_COUNT
The default click count to trigger the color chooser.

See Also:
Constant Field Values

BOX_SIZE

public static final int BOX_SIZE
The default size for the color box.

See Also:
Constant Field Values

DEFAULT_DIMENSION

public static final Dimension DEFAULT_DIMENSION
The default dimension for the color view box.


DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
The default width for the dropdown view.

See Also:
Constant Field Values

currentColor

private Color currentColor
The current color for this view.


defaultColor

private Color defaultColor
The default color for this view.


chooserClickCount

private int chooserClickCount
The click count to trigger the color chooser.


colorBox

private PaintSwatch colorBox
The color box view to display the current color.


colorBoxActions

private MouseActionAdapter colorBoxActions
The mouse action adapter for the color box view.


colorBoxAction

private MouseAction colorBoxAction
The standard color box action.


colorPaneDialog

private ColorPaneDialog colorPaneDialog
The color pane dialog for use if the swatch is clicked.


renderer

private SwatchNameRenderer renderer
The swatch-name renderer.


colorDropdownView

private DropdownView colorDropdownView
The dropdown view.


setColorFromDropdownView

private Action setColorFromDropdownView
Action triggering the task of setting the current color to the color represented by input in the dropdown view.


setColorActions

private ActionSequence setColorActions
The action sequence for handling set color action listeners.

Constructor Detail

ColorView

public ColorView()

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data.

Other constructors:


ColorView

public ColorView(Color color)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 Dimension dimension)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
dimension - the dimension of the color swatch
Since:
2.3.3
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 Dimension dimension,
                 int minWidth)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension; the minimum width of the dropdown editable area is the given minWidth.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

The minimal width of the dropdown view is computed internally to ensure that each color swatch and name pair is fully visible. If the given minWidth is greater than this minimal width then the dropdown view is further widened.

Parameters:
color - the color to be displayed
dimension - the dimension of the color swatch
minWidth - the minimum width of the dropdown editable area
Since:
2.3.3
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 int width,
                 int height)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
width - the width of the color swatch
height - the height of the color swatch
Since:
2.3.3
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 int width,
                 int height,
                 int minWidth)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height; the minimum width of the dropdown editable area is the given minWidth.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

The minimal width of the dropdown view is computed internally to ensure that each color swatch and name pair is fully visible. If the given minWidth is greater than this minimal width then the dropdown view is further widened.

Parameters:
color - the color to be displayed
width - the width of the color swatch
height - the height of the color swatch
minWidth - the minimum width of the dropdown editable area
Since:
2.3.3
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 boolean showDropdown)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
showDropdown - whether or not the dropdown is in the view
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 boolean showDropdown,
                 Dimension dimension)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
showDropdown - whether or not the dropdown is in the view
dimension - the dimension of the color swatch
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 boolean showDropdown,
                 Dimension dimension,
                 int minWidth)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given dimension; the minimum width of the dropdown editable area is the given minWidth.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

The minimal width of the dropdown view is computed internally to ensure that each color swatch and name pair is fully visible. If the given minWidth is greater than this minimal width then the dropdown view is further widened.

Parameters:
color - the color to be displayed
showDropdown - whether or not the dropdown is in the view
dimension - the dimension of the color swatch
minWidth - the minimum width of the dropdown editable area
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 boolean showDropdown,
                 int width,
                 int height)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

Parameters:
color - the color to be displayed
showDropdown - whether or not the dropdown is in the view
width - the width of the color swatch
height - the height of the color swatch
See Also:
ColorView()

ColorView

public ColorView(Color color,
                 boolean showDropdown,
                 int width,
                 int height,
                 int minWidth)

Constructs a view displaying a color swatch with the default color (black) that when clicked will activate a JColorChooser and, if showDropdown is true, a color dropdown for the precise entry of color data; the initial color to be displayed is the given color; the size of the color swatch is provided by the given width and height; the minimum width of the dropdown editable area is the given minWidth.

If the given color is null, the default color (black) is used.

If the given color is non-null, the default color is reset to the given color.

The minimal width of the dropdown view is computed internally to ensure that each color swatch and name pair is fully visible. If the given minWidth is greater than this minimal width then the dropdown view is further widened.

Parameters:
color - the color to be displayed
showDropdown - whether or not the dropdown is in the view
width - the width of the color swatch
height - the height of the color swatch
minWidth - the minimum width of the dropdown editable area
See Also:
ColorView()
Method Detail

getColorBox

public PaintSwatch getColorBox()

Returns the internal JPTComponent that represents the color box in the view.

As of 2.3.2, returns PaintSwatch rather than its base class JPTComponent.

Returns:
the internal color box

getColorDropdownView

public DropdownView getColorDropdownView()

Returns the internal DropdownView that may be used to choose the color via a String representation.

By default, this view is not visible. The view is made visible by passing true in the constructor parameter showDropdown.

Returns:
the internal color dropdown view

setColor

public void setColor(Color color)

Sets the current color to the given color.

If the given color is null or is equal to the current color, then does nothing.

Performs the color actions attached to this view and fires property change: SET_CURRENT_COLOR.

Parameters:
color - the new current color for this view
See Also:
setColorHelper(Color), getColor(), setDefaultColor(Color), getDefaultColor()

setColorHelper

public void setColorHelper(Color color)

Sets the current color to the given color.

If the given color is null or is equal to the current color, then does nothing.

Does not perform the color actions attached to this view and does not fire a property change event.

This method is made available as a public method for those situations in which the color is being updated by other means and this view is being synchronized. In that case, it would be an error to perform the color actions and fire a property change event.

Parameters:
color - the new current color for this view
See Also:
setColor(Color), getColor(), setDefaultColor(Color), getDefaultColor()

getColor

public Color getColor()
Returns the current color.

See Also:
setColor(Color), setDefaultColor(Color), getDefaultColor()

setDefaultColor

public void setDefaultColor(Color color)

Sets the default color to the given color.

If the given color is null or is equal to the default color, then does nothing.

Fires property change: SET_DEFAULT_COLOR.

Parameters:
color - the new default color for this view
See Also:
getDefaultColor(), setColor(Color), getColor()

getDefaultColor

public Color getDefaultColor()
Returns the default color.

See Also:
setDefaultColor(Color), setColor(Color), getColor()

getSetColorActions

public ActionSequence getSetColorActions()
Returns the ActionSequence that holds the actions to be performed when the method setColor is called.


addAction

public void addAction(ActionListener action)
Append an action listener to be performed when the method setColor is called.

Parameters:
action - the action listener to append
See Also:
addAction(int, ActionListener)

addAction

public void addAction(int index,
                      ActionListener action)
Add an action listener to be performed when the method setColor is called and place this action listener at the given index in the set color actions sequence.

Parameters:
index - the place in the sequence to add the listener
action - the action listener to add
See Also:
addAction(ActionListener)

removeAction

public boolean removeAction(ActionListener action)

Remove an action listener that was to be performed when the method setColor is called.

Returns true if removal was successful and false otherwise.

Parameters:
action - the action listener to remove
See Also:
removeAction(int)

removeAction

public ActionListener removeAction(int index)

Remove an action listener at the given index position that was to be performed when the method setColor is called.

Returns the ActionListener removed or null.

Parameters:
index - the index of the action listener to remove
See Also:
removeAction(ActionListener)

getMouseActionAdapter

public MouseActionAdapter getMouseActionAdapter()
Returns the mouse action adapter for the color box in this color view.

Returns:
the mouse action adapter

setChooserClickCount

public void setChooserClickCount(int count)

Sets the number of mouse clicks required to bring up the color chooser dialog.

The valid click counts are:

If the given click count is less than 1, it is set to 1.

If the given click count is greater than 2, it is set to 2.

As of 2.3.2, the default click count is 1.

See Also:
getChooserClickCount()

getChooserClickCount

public int getChooserClickCount()
Return the chooser click count.

See Also:
setChooserClickCount(int)

demandObject

public Stringable demandObject()

Returns an XColor object whose state is set to the view state of this view.

Specified by:
demandObject in interface TypedView
Returns:
a Stringable model object
See Also:
requestObject(), TypedView

requestObject

public Stringable requestObject()

Returns an XColor object whose state is set to the view state of this view.

There is no need for a CancelledException since the current view state cannot be invalid.

Specified by:
requestObject in interface TypedView
Returns:
a Stringable model object
See Also:
demandObject(), TypedView

setInputProperties

public void setInputProperties(InputProperties p)
Sets the input properties of the internal color dropdown view and fires a property change if the input properties have changed.

Specified by:
setInputProperties in interface TypedView
Parameters:
p - the new input properties to set
See Also:
TypedView

getInputProperties

public InputProperties getInputProperties()
Returns the input properties of the internal color dropdown view.

Specified by:
getInputProperties in interface TypedView
Returns:
the current input properties
See Also:
TypedView

getDataType

public Class getDataType()
Returns the XColor class object.

Specified by:
getDataType in interface TypedView
Returns:
the current class of a model object
See Also:
TypedView

setViewState

public void setViewState(String data)

Sets the current view state for this view to the Color represented by the given String data.

Does nothing if the String data fails to parse into a valid Color.

Specified by:
setViewState in interface Displayable
Overrides:
setViewState in class DisplayPanel
Parameters:
data - the new view state
See Also:
getViewState(), Displayable

getViewState

public String getViewState()
Returns a String encapsulation of the state of the current Color for this view.

Specified by:
getViewState in interface Displayable
Overrides:
getViewState in class DisplayPanel
See Also:
setViewState(String), Displayable

setDefaultViewState

public void setDefaultViewState(String data)

Sets the default view state for this view to the Color represented by the given String data.

Does nothing if the String data fails to parse into a valid Color.

Specified by:
setDefaultViewState in interface Displayable
Overrides:
setDefaultViewState in class DisplayPanel
Parameters:
data - the new view state
See Also:
getViewState(), Displayable

getDefaultViewState

public String getDefaultViewState()
Returns a String encapsulation of the state of the default Color for this view.

Specified by:
getDefaultViewState in interface Displayable
Overrides:
getDefaultViewState in class DisplayPanel
See Also:
setViewState(String), Displayable

reset

public void reset()
Resets the color to the default color.

Specified by:
reset in interface Displayable
Overrides:
reset in class DisplayPanel

setColorFromDropdownView

protected void setColorFromDropdownView()
Sets the current color for this view to the color represented by the input in its color dropdown view.


installColorBox

protected void installColorBox(Color color,
                               Dimension dimension)

Installs the color box for this view.

As of 2.6.0, if the dimension is non-null and its width or height is less than or equal to zero then the color box is not installed in the GUI. It still exists as an object in the internal data structure.


installColorDropdownView

protected void installColorDropdownView(boolean showDropdown,
                                        int minWidth)
Installs the color dropdown view.


installColorBoxActions

protected void installColorBoxActions()
Installs the color box mouse actions triggered by mouse events targeted on the color box contained in this view.


colorBoxAction

private void colorBoxAction(MouseEvent evt)
The standard color box action method.