edu.neu.ccs.gui
Class ColorPane

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.BasePane
                          extended byedu.neu.ccs.gui.ColorPane
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants

public class ColorPane
extends BasePane

Class ColorPane provides a pane that may be used to interactively set a color by setting the red, green, blue, and alpha components using 4 SliderView sliders. The sliders are set to a width of 256 pixels so that there is a 1-to-1 correspondance between pixels and color component values. The slider tracks use gradient paints to reinforce which color component is being chosen.

The pane presents 2 color swatches. The upper swatch shows the initial color in the pane and the lower swatch shows the current color as it evolves under the movements of the 4 sliders or of the dropdown view.

The pane provides a ColorView with only its dropdown list visible. This enables a user to start with a specific named color or a specific color given by its color components and to then make changes from there.

Buttons are provided to set the selected (lower) color from the original (upper) color and vice versa.

The caller may supply press, sliding, and release actions. Each such action will be installed in all 4 sliders. This allows the caller to listen to the changing color behavior in this pane and react accordingly.

Since:
2.6.0
Version:
2.6.0
See Also:
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
protected  Color A_Color
          The common color for the alpha slider.
protected  Annotation A_Label
          The label for the alpha slider.
protected  Paint A_Paint
          The gradient paint for the alpha slider track.
protected  SliderView A_Slider
          The alpha slider.
protected  Color B_Color
          The common color for the blue slider.
protected  Annotation B_Label
          The label for the blue slider.
protected  Paint B_Paint
          The gradient paint for the blue slider track.
protected  SliderView B_Slider
          The blue slider.
protected  ColorView colorview
          The color view with only the dropdown color name list.
protected  Annotation colorviewLabel
          The label for the colorview.
protected  HTable colorviewPanel
          The panel with the color view and its label.
protected  Object[] colorviewStuff
          The array with the color view and its label.
protected  SimpleAction currentToInitialAction
          The action to reset the current color to the initial color.
protected  JButton currentToInitialButton
          The button to reset the current color to the initial color.
protected  Color G_Color
          The common color for the green slider.
protected  Annotation G_Label
          The label for the green slider.
protected  Paint G_Paint
          The gradient paint for the green slider track.
protected  SliderView G_Slider
          The green slider.
protected  SimpleAction initialToCurrentAction
          The action to reset the current color to the initial color.
protected  JButton initialToCurrentButton
          The button to reset the current color to the initial color.
protected  HTable labelSwatchPanel
          The panel for the labels and swatch panel.
protected  Object[] labelSwatchStuff
          The array for the labels and swatch panel.
protected  PaintSwatch lowerSwatch
          The lower paint swatch for the current color.
protected  VTable mainPanel
          The panel with the main GUI components.
protected  Object[] mainStuff
          The array with the main GUI components.
protected  ActionSequence pressActions
          The caller-defined actions performed when the slider thumb is pressed in any of the 4 sliders.
protected  Color R_Color
          The common color for the red slider.
protected  Annotation R_Label
          The label for the red slider.
protected  Paint R_Paint
          The gradient paint for the red slider track.
protected  SliderView R_Slider
          The red slider.
protected  ActionSequence releaseActions
          The caller-defined actions performed when the slider thumb is released in any of the 4 sliders.
protected  SimpleAction setColorFromColorViewAction
          The action to set the color using the color view.
protected  SimpleAction setColorFromSlidersAction
          The action to set the color using the slider settings.
static int SIZE
          The size of the square that contains the upper and lower swatches: 200.
protected  TablePanel sliderPanel
          The panel with sliders and their labels.
protected  Object[][] sliderStuff
          The array with sliders and their labels.
protected  ActionSequence slidingActions
          The caller-defined actions performed when the slider thumb is sliding in any of the 4 sliders.
protected  PaintableComponent swatchLabelComponent
          The labels for the panel with the pair of swatches.
protected  VTable swatchPanel
          The panel with the pair of swatches.
protected  Object[] swatchStuff
          The array for the pair of swatches.
static int THICK
          The swatch border thickness: 2.
protected  PaintSwatch upperSwatch
          The upper paint swatch for the initial color.
 
Fields inherited from class edu.neu.ccs.gui.BasePane
baseFontSize, buttonFont, DEFAULT_BASE_FONT_SIZE, fieldFont, fontSize, gap, labelFont, largeFieldWidth, mediumFieldWidth, MINIMUM_FONT_SIZE, monospacedFontName, sansserifFontName, serifFontName, smallFieldWidth
 
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.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
ColorPane()
          The default ColorPane constructor that sets the initial color to white.
ColorPane(Color color)
          The ColorPane constructor that sets the initial color to the given color.
 
Method Summary
 void addPressAction(ActionListener a)
          Adds the given action listener to the sequence of actions that is performed when slider is pressed in its active area (thumb or track) in any of the 4 sliders.
 void addReleaseAction(ActionListener a)
          Adds the given action listener to the sequence of actions that is performed when slider is released after being pressed in its active area (thumb or track) in any of the 4 sliders.
 void addSlidingAction(ActionListener a)
          Adds the given action listener to the sequence of actions that is performed when slider is sliding after being pressed in its active area (thumb or track) in any of the 4 sliders.
 Color getColor()
          Returns the current color.
 Color getInitialColor()
          Returns the initial color which is the color of the upper swatch.
static void main(String[] args)
          For test purposes, this main program creates a ColorPane whose initial color has random RGB components and has alpha=255.
protected  PaintableComponent makeSwatchPanelLabels()
          Make the labels for the swatch panel.
 void removePressAction(ActionListener a)
          Removes the given action listener from the press actions.
 void removeReleaseAction(ActionListener a)
          Removes the given action listener from the release actions.
 void removeSlidingAction(ActionListener a)
          Removes the given action listener from the sliding actions.
 void setColor(Color color)
          Algorithmically sets the current color and adjusts the 4 sliders, the lower swatch, and the color view appropriately.
protected  void setColorFromColorView()
          Sets the current color from the color view.
protected  void setColorFromSliders()
          Sets the current color from the settings in the 4 sliders.
 void setCurrentFromInitial()
          Set the current color from the initial color.
 void setInitialColor(Color color)
          Sets the initial color which is the color of the upper swatch.
 void setInitialFromCurrent()
          Set the initial color from the current color.
 
Methods inherited from class edu.neu.ccs.gui.BasePane
getButtonFont, getFieldFont, getFontSize, getGap, getLabelFont, getLargeFieldWidth, getMediumFieldWidth, getSmallFieldWidth, initializeBasePane
 
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, getDefaultViewState, getDefaultViewStates, getDisplayables, getViewState, getViewStates, lineBorder, lineBorder, lineBorder, lineBorder, makeComponent, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, matteBorder, OKCancelDialog, OKCancelDialog, OKDialog, OKDialog, refreshComponent, remove, remove, removeAll, removeBorder, reset, sandwichBorder, setCodec, setDeepBackground, setDeepBackground, setDefaultViewState, setDefaultViewStates, setEnabled, setViewState, 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
 

Field Detail

SIZE

public static final int SIZE
The size of the square that contains the upper and lower swatches: 200.

See Also:
Constant Field Values

THICK

public static final int THICK
The swatch border thickness: 2.

See Also:
Constant Field Values

upperSwatch

protected PaintSwatch upperSwatch
The upper paint swatch for the initial color.


lowerSwatch

protected PaintSwatch lowerSwatch
The lower paint swatch for the current color.


swatchStuff

protected Object[] swatchStuff
The array for the pair of swatches.


swatchPanel

protected VTable swatchPanel
The panel with the pair of swatches.


swatchLabelComponent

protected PaintableComponent swatchLabelComponent
The labels for the panel with the pair of swatches.


labelSwatchStuff

protected Object[] labelSwatchStuff
The array for the labels and swatch panel.


labelSwatchPanel

protected HTable labelSwatchPanel
The panel for the labels and swatch panel.


R_Paint

protected Paint R_Paint
The gradient paint for the red slider track.


G_Paint

protected Paint G_Paint
The gradient paint for the green slider track.


B_Paint

protected Paint B_Paint
The gradient paint for the blue slider track.


A_Paint

protected Paint A_Paint
The gradient paint for the alpha slider track.


R_Color

protected Color R_Color
The common color for the red slider.


G_Color

protected Color G_Color
The common color for the green slider.


B_Color

protected Color B_Color
The common color for the blue slider.


A_Color

protected Color A_Color
The common color for the alpha slider.


R_Slider

protected SliderView R_Slider
The red slider.


G_Slider

protected SliderView G_Slider
The green slider.


B_Slider

protected SliderView B_Slider
The blue slider.


A_Slider

protected SliderView A_Slider
The alpha slider.


R_Label

protected Annotation R_Label
The label for the red slider.


G_Label

protected Annotation G_Label
The label for the green slider.


B_Label

protected Annotation B_Label
The label for the blue slider.


A_Label

protected Annotation A_Label
The label for the alpha slider.


sliderStuff

protected Object[][] sliderStuff
The array with sliders and their labels.


sliderPanel

protected TablePanel sliderPanel
The panel with sliders and their labels.


colorview

protected ColorView colorview
The color view with only the dropdown color name list.


colorviewLabel

protected Annotation colorviewLabel
The label for the colorview.


colorviewStuff

protected Object[] colorviewStuff
The array with the color view and its label.


colorviewPanel

protected HTable colorviewPanel
The panel with the color view and its label.


initialToCurrentAction

protected SimpleAction initialToCurrentAction
The action to reset the current color to the initial color.


initialToCurrentButton

protected JButton initialToCurrentButton
The button to reset the current color to the initial color.


currentToInitialAction

protected SimpleAction currentToInitialAction
The action to reset the current color to the initial color.


currentToInitialButton

protected JButton currentToInitialButton
The button to reset the current color to the initial color.


mainStuff

protected Object[] mainStuff
The array with the main GUI components.


mainPanel

protected VTable mainPanel
The panel with the main GUI components.


setColorFromSlidersAction

protected SimpleAction setColorFromSlidersAction
The action to set the color using the slider settings.


setColorFromColorViewAction

protected SimpleAction setColorFromColorViewAction
The action to set the color using the color view.


pressActions

protected ActionSequence pressActions
The caller-defined actions performed when the slider thumb is pressed in any of the 4 sliders.


slidingActions

protected ActionSequence slidingActions
The caller-defined actions performed when the slider thumb is sliding in any of the 4 sliders.


releaseActions

protected ActionSequence releaseActions
The caller-defined actions performed when the slider thumb is released in any of the 4 sliders.

Constructor Detail

ColorPane

public ColorPane()
The default ColorPane constructor that sets the initial color to white.


ColorPane

public ColorPane(Color color)
The ColorPane constructor that sets the initial color to the given color.

Parameters:
color - the initial color of the color pane
Method Detail

getColor

public Color getColor()
Returns the current color.


setColor

public void setColor(Color color)

Algorithmically sets the current color and adjusts the 4 sliders, the lower swatch, and the color view appropriately.

Parameters:
color - the color to set as the current color

getInitialColor

public Color getInitialColor()

Returns the initial color which is the color of the upper swatch.

The call resetColor() is equivalent to setColor(getInitialColor()).


setInitialColor

public void setInitialColor(Color color)

Sets the initial color which is the color of the upper swatch.

This method does not change the 4 sliders or the lower swatch. No actions are executed.

Parameters:
color -

setCurrentFromInitial

public void setCurrentFromInitial()
Set the current color from the initial color.


setInitialFromCurrent

public void setInitialFromCurrent()
Set the initial color from the current color.


setColorFromSliders

protected void setColorFromSliders()
Sets the current color from the settings in the 4 sliders.


setColorFromColorView

protected void setColorFromColorView()
Sets the current color from the color view.


addPressAction

public void addPressAction(ActionListener a)

Adds the given action listener to the sequence of actions that is performed when slider is pressed in its active area (thumb or track) in any of the 4 sliders.

Parameters:
a - the press action listener to add

addSlidingAction

public void addSlidingAction(ActionListener a)

Adds the given action listener to the sequence of actions that is performed when slider is sliding after being pressed in its active area (thumb or track) in any of the 4 sliders.

Parameters:
a - the sliding action listener to add

addReleaseAction

public void addReleaseAction(ActionListener a)

Adds the given action listener to the sequence of actions that is performed when slider is released after being pressed in its active area (thumb or track) in any of the 4 sliders.

Parameters:
a - the release action listener to add

removePressAction

public void removePressAction(ActionListener a)
Removes the given action listener from the press actions.

Parameters:
a - the press action listener to remove

removeSlidingAction

public void removeSlidingAction(ActionListener a)
Removes the given action listener from the sliding actions.

Parameters:
a - the sliding action listener to remove

removeReleaseAction

public void removeReleaseAction(ActionListener a)
Removes the given action listener from the release actions.

Parameters:
a - the release action listener to remove

makeSwatchPanelLabels

protected PaintableComponent makeSwatchPanelLabels()
Make the labels for the swatch panel.


main

public static void main(String[] args)
For test purposes, this main program creates a ColorPane whose initial color has random RGB components and has alpha=255. The pane is then installed in a frame.

Parameters:
args - ignored