com.spelunkcomputing.color
Class ColorSpelunker

java.lang.Object
  extended by com.spelunkcomputing.color.ColorSpelunker

public class ColorSpelunker
extends java.lang.Object

Displays a collection of controls for selecting a color or coordinated palette of colors. The controls can be packaged in a dialog of an accordion pane (stack of collapsible panels). The following illustrates usage of the ColorSpelunker dialog to selected a single color:

    ColorSpelunker colorSpelunker = new ColorSpelunker(Color.blue, false);
    colorSpelunker.showDialog(mQuestPanel, StringResources.getString("title.ChooseShapeColor"))) {
    Color selectedColor = colorSpelunker.getSelectedColor();
 
Color palette selection via the dialog could look like this:
    ColorSpelunker colorSpelunker = new ColorSpelunker(Color.red, true);
    colorSpelunker.showDialog(mQuestPanel, StringResources.getString("title.ChooseShapeColor"))) {
    ColorPalette selectedPalette = colorSpelunker.getSelectedPalette();
 
Use of the accordion pane presentaton could look like this:
    Color colorSpelunker = new ColorSpelunker(initialColor, true);
    JPanel panel = new JPanel(new BorderLayout());
    panel.add(colorSpelunker.getAccordionPane(), BorderLayout.WEST);
    colorSpelunker.getPaletteModel().addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent event) {
           . . .
        }
    };
 


Constructor Summary
ColorSpelunker(java.awt.Color initialColor, boolean showPalettes)
          Constructor
 
Method Summary
 javax.swing.JComponent getAccordionPane()
          Returns an accordian pane (a stack of collapsible panels) containing the color selection controls
 javax.swing.colorchooser.ColorSelectionModel getColorModel()
          Returns the ColorSelectionModel that the ColorSpelunker is updating and tracking
 javax.swing.JComponent getDialogPane()
          Returns a pane suitable for display in a dialog, containing the color selection controls
 java.io.Serializable getPaletteCollectionState()
          Returns a opaque object the captures the collection of palettes.
 PaletteSelectionModel getPaletteModel()
          Returns the PaletteSelectionModel that the ColorSpelunker is updating and tracking
 java.awt.Color getSelectedColor()
          Returns the current color
 ColorPalette getSelectedPalette()
          Returns the current palette
 java.io.Serializable getState()
          Returns an opaque object that captures the current state of the ColorSpelunker including the current color, palette (if any), custom swatches and custom palettes
 void setPaletteCollectionState(java.io.Serializable state)
          Restores the palette collection to a previous state
 void setPreferredGridWidth(int width)
          Sets the preferred with for the swatch and palette grids.
 void setSelectedColor(java.awt.Color color)
          Sets the color of the underlying ColorSelectionModel
 void setSelectedPalette(ColorPalette palette)
          Sets the palette of the underlying PaletteSelectionModel
 void setState(java.io.Serializable state)
          Restores the ColorSpelunker to a previous state.
 boolean showDialog(java.awt.Component component, java.lang.String title)
          Displays the ColorSpelunker pane in a modal dialog.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ColorSpelunker

public ColorSpelunker(java.awt.Color initialColor,
                      boolean showPalettes)
Constructor

Parameters:
initialColor - the initial color.
showPalettes - true if the color spelunker should display panels for selecting and specifying palettes of colors
Method Detail

getColorModel

public javax.swing.colorchooser.ColorSelectionModel getColorModel()
Returns the ColorSelectionModel that the ColorSpelunker is updating and tracking

Returns:
the ColorSelectionModel

getPaletteModel

public PaletteSelectionModel getPaletteModel()
Returns the PaletteSelectionModel that the ColorSpelunker is updating and tracking

Returns:
the PaletteSelectionModel (null if the ColorSpelunker is not showing palettes)

getSelectedColor

public java.awt.Color getSelectedColor()
Returns the current color

Returns:
the current color

setSelectedColor

public void setSelectedColor(java.awt.Color color)
Sets the color of the underlying ColorSelectionModel

Parameters:
color - the color to set

getSelectedPalette

public ColorPalette getSelectedPalette()
Returns the current palette

Returns:
the current palette (can be null)

setSelectedPalette

public void setSelectedPalette(ColorPalette palette)
Sets the palette of the underlying PaletteSelectionModel

Parameters:
palette - the palette to set

setPreferredGridWidth

public void setPreferredGridWidth(int width)
Sets the preferred with for the swatch and palette grids.

Parameters:
width - the preferred width

getAccordionPane

public javax.swing.JComponent getAccordionPane()
Returns an accordian pane (a stack of collapsible panels) containing the color selection controls

Returns:
the accordion pane

getDialogPane

public javax.swing.JComponent getDialogPane()
Returns a pane suitable for display in a dialog, containing the color selection controls

Returns:
the dialog pane

showDialog

public boolean showDialog(java.awt.Component component,
                          java.lang.String title)
Displays the ColorSpelunker pane in a modal dialog. Blocks until the dialog has been dismissed, returning true if the user pressed the "OK" button and false if the user pressed the "Cancel" button.

Parameters:
component - the parent component for the dialog
title - the dialog's title string
Returns:
true if the user selected a color, false if the user cancelled without making a selection.

getState

public java.io.Serializable getState()
Returns an opaque object that captures the current state of the ColorSpelunker including the current color, palette (if any), custom swatches and custom palettes

Returns:
A serializable object that encapsulates the state of the current selection controls

setState

public void setState(java.io.Serializable state)
Restores the ColorSpelunker to a previous state. See getState() for more details.

Parameters:
state - an object previously obtained from getState

getPaletteCollectionState

public java.io.Serializable getPaletteCollectionState()
Returns a opaque object the captures the collection of palettes. Generally the getState() method should be called instead. The method exists primarily to facilitate bootstrapping of the factory palette collection.

Returns:
A serializable object the captures the collection of palettes

setPaletteCollectionState

public void setPaletteCollectionState(java.io.Serializable state)
Restores the palette collection to a previous state

Parameters:
state - an object previously obtained from getPaletteCollectionState