edu.neu.ccs.gui
Class MultiColorView

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.MultiColorView
All Implemented Interfaces:
Accessible, AlertListener, Displayable, EventListener, ImageObserver, JPTConstants, MalformedDataListener, MenuContainer, Serializable, SwingConstants

public class MultiColorView
extends BasePane

Class MultiColorView provides a view in which there is a table with labels in column 0 and corresponding ColorView objects in column 1. This class enables a user to set multiples colors using a single panel.

Unlike ColorView, MultiColorView does not implement the interface TypedView. Rather, an object of this class can return either an individual color based on an index or an array of all colors represented in the view.

As of 2.6.0a, one may add one or more action listeners to respond if any color view within the multi-color view is changed. To keep things simple, we decided against an implementation that would single out which internal color view has changed.

To add an action listener that applies to one color view within this object, use the method getColorView to access the view and then add the action listener directly to the particular view.

Since:
2.6.0
Version:
2.6.0a
See Also:
ColorView, 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
private  Annotation[] annotations
          The array of all Annotation objects used for the labels.
private  TablePanel colorpanel
          The internal TablePanel that holds the color views and the labels.
private  ColorView[] colorviews
          The array of all ColorView objects.
private  int GAP
          The gap between the cells in the internal TablePanel.
private  ActionSequence setColorActions
          The action sequence for handling set color action listeners.
static Color[] testcolors
          A static array of colors for test purposes in the main program.
private  int viewcount
          The number of ColorView objects in this panel.
 
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
MultiColorView(Color[] colors, String[] labels)
          The MultiColorView constructor creates a panel with a vertical collection of ColorView objects initialized with the given colors array and a corresponding set of labels initialized with the given labels.
 
Method Summary
 void addAction(ActionListener action)
          Append an action listener to be performed when the color of any internal ColorView is set.
private  void createColorPanel()
          Creates the color table panel with labels and ColorView objects assuming that the individual objects have already been constructed.
 Color getColor(int index)
          Returns the color corresponding to the given index.
 Color[] getColors()
          Returns an array with the current colors represented in the ColorView objects.
 ColorView getColorView(int i)
          Returns the i-th ColorView in this object or null if i is out of range.
 int getViewCount()
          Returns the number of ColorView objects in this panel.
private  void initializeAnnotations(String[] labels)
          Initialize the labels for the ColorView objects in the panel using the given labels array.
private  void initializeColorViews(Color[] colors)
          Initialize the ColorView objects in the panel using the given colors array.
static void main(String[] args)
          A test program that displays a MultiColorView using the internal static array testcolors for the initialization.
private  void makeAnnotation(int index, String label)
          Initialize the annotation at the given index using the given label.
 boolean removeAction(ActionListener action)
          Remove an action listener that was to be performed when the color of any internal ColorView is set.
 void setColor(int index, Color color)
          Set the color of the ColorView at the given index to the given color.
 void setColorHelper(int index, Color color)
          Set the color of the ColorView at the given index to the given 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

GAP

private int GAP
The gap between the cells in the internal TablePanel.


colorviews

private ColorView[] colorviews
The array of all ColorView objects.


annotations

private Annotation[] annotations
The array of all Annotation objects used for the labels.


viewcount

private int viewcount
The number of ColorView objects in this panel.


colorpanel

private TablePanel colorpanel
The internal TablePanel that holds the color views and the labels.


setColorActions

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


testcolors

public static Color[] testcolors

A static array of colors for test purposes in the main program.

The initial colors in this array are:

This array is intentionally not final so a caller may change it and run additional tests.

Constructor Detail

MultiColorView

public MultiColorView(Color[] colors,
                      String[] labels)

The MultiColorView constructor creates a panel with a vertical collection of ColorView objects initialized with the given colors array and a corresponding set of labels initialized with the given labels. The labels are placed in column 0 and the ColorView objects in column 1.

The constructor does significant error checking that will be described below.

If colors is null, or of length 0, or has no non-null Color entries, then then initialization will take place as if exactly one color was supplied, namely, red. In effect, this raises a “red flag” during development.

Otherwise, the count of ColorView objects in the panel will equal the number of non-null Color entries in the colors array.

Next, the labels array will be scanned and its non-null strings will be used in succession to provide labels for the corresponding ColorView objects. If there are no labels or not enough labels then labels of the form “Color n” will be created.

Obviously, for best results, the colors and labels arrays should be non-null, of the same size, and have all non-null entries.

Parameters:
colors - the colors to initialize the ColorView objects
labels - the labels for the ColorView objects
Method Detail

getViewCount

public final int getViewCount()

Returns the number of ColorView objects in this panel.


getColor

public final Color getColor(int index)

Returns the color corresponding to the given index.

To facilitate a situation in which the caller wants more colors than are available in this view, the index will be reduced modulo the viewcount before the color is returned. This design means the colors will, in effect, be recycled as index exceeds viewcount.

Parameters:
index - the index of the desired color

setColor

public final void setColor(int index,
                           Color color)

Set the color of the ColorView at the given index to the given color.

Requires:

Does nothing if these requirements are not met.

Perform the actions attached to this view if a new color is set.

Parameters:
index - the index of the desired color
color - the color to set

setColorHelper

public final void setColorHelper(int index,
                                 Color color)

Set the color of the ColorView at the given index to the given color.

Requires:

Does nothing if these requirements are not met.

Does not perform the actions attached to this view.

Parameters:
index - the index of the desired color
color - the color to set

getColors

public final Color[] getColors()

Returns an array with the current colors represented in the ColorView objects.


addAction

public final void addAction(ActionListener action)

Append an action listener to be performed when the color of any internal ColorView is set.


removeAction

public final boolean removeAction(ActionListener action)

Remove an action listener that was to be performed when the color of any internal ColorView is set.

Returns true if removal was successful and false otherwise.


getColorView

public final ColorView getColorView(int i)

Returns the i-th ColorView in this object or null if i is out of range.

Parameters:
i - the index of the desired color view

initializeColorViews

private void initializeColorViews(Color[] colors)

Initialize the ColorView objects in the panel using the given colors array.

For notes on error checking, see the comments for the constructor.

Parameters:
colors - the colors to initialize the ColorView objects

initializeAnnotations

private void initializeAnnotations(String[] labels)

Initialize the labels for the ColorView objects in the panel using the given labels array.

For notes on error checking, see the comments for the constructor.

Parameters:
labels - the labels for the ColorView objects

makeAnnotation

private void makeAnnotation(int index,
                            String label)

Initialize the annotation at the given index using the given label.

Assumes 0 <= index < viewcount.

Assumes label is non-null.

Parameters:
index - the index of the label
label - the label

createColorPanel

private void createColorPanel()

Creates the color table panel with labels and ColorView objects assuming that the individual objects have already been constructed.


main

public static void main(String[] args)

A test program that displays a MultiColorView using the internal static array testcolors for the initialization.

The caller is permitted to modify testcolors to run additional tests.

No labels are supplied for this test so the default labels are used.

Parameters:
args - ignored