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.