edu.neu.ccs.gui
Class SwatchNameRenderer

java.lang.Object
  extended byedu.neu.ccs.gui.SwatchNameRenderer
All Implemented Interfaces:
ListCellRenderer

public class SwatchNameRenderer
extends Object
implements ListCellRenderer

Class SwatchNameRenderer is designed to implement ListCellRenderer by providing pairs each with a paint swatch and its name.

Since:
2.3.2
Version:
2.3.3

Field Summary
private  Dimension maxDimension
          The maximum dimension of all swatch-name pairs.
private  StringObjectMap nameCellMap
          The hash table of color names and swatch-name pairs.
 
Constructor Summary
SwatchNameRenderer()
          This constructor provides a renderer for swatch-name pairs generated from the color names obtained via Colors.getColorNamesAsArray.
 
Method Summary
private  SwatchNamePair getListCellFromMap(String name)
          Returns the list cell corresponding to the given color name.
 Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus)
          Returns the swatch name pair component associated with the given String value in the given list; sets the foreground and background of the swatch name pair depending on the given isSelected parameter.
 Dimension getMaximumPreferredSize()
          Returns the maximum preferred size of all swatch-name pairs in this renderer.
 String[] getStrings()
          Returns the array of color name strings installed in this renderer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nameCellMap

private StringObjectMap nameCellMap
The hash table of color names and swatch-name pairs.


maxDimension

private Dimension maxDimension
The maximum dimension of all swatch-name pairs.

Constructor Detail

SwatchNameRenderer

public SwatchNameRenderer()

This constructor provides a renderer for swatch-name pairs generated from the color names obtained via Colors.getColorNamesAsArray.

Method Detail

getListCellFromMap

private SwatchNamePair getListCellFromMap(String name)

Returns the list cell corresponding to the given color name.

Parameters:
name - the color name

getStrings

public String[] getStrings()

Returns the array of color name strings installed in this renderer. This returns the strings installed at construction and avoids problems if additional color name pairs are later installed globally.

Returns:
the array of color name strings

getMaximumPreferredSize

public Dimension getMaximumPreferredSize()

Returns the maximum preferred size of all swatch-name pairs in this renderer.

Returns:
the maximum preferred size of all swatch-name pairs

getListCellRendererComponent

public Component getListCellRendererComponent(JList list,
                                              Object value,
                                              int index,
                                              boolean isSelected,
                                              boolean cellHasFocus)

Returns the swatch name pair component associated with the given String value in the given list; sets the foreground and background of the swatch name pair depending on the given isSelected parameter.

This method implements the ListCellRenderer interface.

Returns null if an unexpected error occurs.

Specified by:
getListCellRendererComponent in interface ListCellRenderer
Parameters:
list - the JList to paint
value - the value returned by list.getModel().getElementAt(index)
index - the index of the cell
isSelected - true if the specified cell was selected
cellHasFocus - true if the specified cell has the focus
Returns:
this object as the list cell renderer component