|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
edu.neu.ccs.gui.DisplayPanel
edu.neu.ccs.gui.BasePane
edu.neu.ccs.gui.MultiColorView
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.
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 javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
private int GAP
private ColorView[] colorviews
private Annotation[] annotations
private int viewcount
private TablePanel colorpanel
private ActionSequence setColorActions
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 |
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.
colors - the colors to initialize the ColorView objectslabels - the labels for the ColorView objects| Method Detail |
public final int getViewCount()
Returns the number of ColorView objects
in this panel.
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.
index - the index of the desired color
public final void setColor(int index,
Color color)
Set the color of the ColorView at the
given index to the given color.
Requires:
nullDoes nothing if these requirements are not met.
Perform the actions attached to this view if a new color is set.
index - the index of the desired colorcolor - the color to set
public final void setColorHelper(int index,
Color color)
Set the color of the ColorView at the
given index to the given color.
Requires:
nullDoes nothing if these requirements are not met.
Does not perform the actions attached to this view.
index - the index of the desired colorcolor - the color to setpublic final Color[] getColors()
Returns an array with the current colors represented
in the ColorView objects.
public final void addAction(ActionListener action)
Append an action listener to be performed when the color
of any internal ColorView is set.
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.
public final ColorView getColorView(int i)
Returns the i-th ColorView in this object
or null if i is out of range.
i - the index of the desired color viewprivate 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.
colors - the colors to initialize the ColorView objectsprivate 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.
labels - the labels for the ColorView objects
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.
index - the index of the labellabel - the labelprivate void createColorPanel()
Creates the color table panel with labels and
ColorView objects assuming that the
individual objects have already been constructed.
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.
args - ignored
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||