JIDE 3.5.15

com.jidesoft.combobox
Class ColorChooserPanel

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.jidesoft.combobox.PopupPanel
                      extended by com.jidesoft.combobox.ColorChooserPanel
All Implemented Interfaces:
ItemListener, ImageObserver, ItemSelectable, MenuContainer, Serializable, EventListener, Accessible

public class ColorChooserPanel
extends PopupPanel
implements ItemListener

ColorChooserPanel is a panel that has many color buttons. User can click on one and select the color. It supports ItemListener. Whenever a color is selected, itemStateChanged will be fired.
We support several color sets. From the 15 basic colors, 40 basic colors and 215 web colors. In additional to color sets, we also support gray scale, from 16 gray scales, 102 gray scales and 256 gray scales.

See Also:
Serialized Form

Nested Class Summary
 class ColorChooserPanel.ColorButton
          This class is the color button used in the ColorChooserPanel.
static interface ColorChooserPanel.ColorChooserDialogProvider
          An interface to bring up a custom ColorChooserDialog to choose a color when when the "More" button is pressed on the ColorChooserPanel.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
 
Field Summary
protected  JPanel _colorPanel
          JPanel which holds all color buttons.
protected  AbstractButton _defaultColor
          Button for default color.
protected  AbstractButton _moreColor
          Button for more color.
static int PALETTE_COLOR_15
          15 color palette.
static int PALETTE_COLOR_216
          Standard web-safe 216 color palette.
static int PALETTE_COLOR_40
          40 color palette.
static int PALETTE_CUSTOMIZE
          By passing value as palette, you can call setPossibleColors() and setPossibleColorNames() to setup your own palette.
static int PALETTE_GRAY_102
          102 gray color palette.
static int PALETTE_GRAY_16
          16 gray color palette.
static int PALETTE_GRAY_256
          256 gray color palette.
static String PROPERTY_SELECTED_COLOR
           
 
Fields inherited from class com.jidesoft.combobox.PopupPanel
_previousSelectedObject, SELECTED_BY_MOUSE_ROLLOVER
 
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.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ColorChooserPanel()
          Creates a new ColorChooserPanel.
ColorChooserPanel(Color[] colors, String[] names, boolean allowMoreColors, boolean allowDefaultColor)
          Creates a new ColorChooserPanel with customized palette.
ColorChooserPanel(Color[] colors, String[] names, boolean allowMoreColors, boolean allowDefaultColor, Locale locale)
          Creates a new ColorChooserPanel with customized palette.
ColorChooserPanel(Color[] colors, String[] names, int rows, int columns, boolean allowMoreColors, boolean allowDefaultColor, Locale locale)
          Creates a new ColorChooserPanel with customized palette.
ColorChooserPanel(int palette)
          Creates a new ColorChooserPanel with specified palette.
ColorChooserPanel(int palette, boolean allowMoreColors, boolean allowDefaultColor)
          Creates a new ColorChooserPanel with the specified palette and button options.
ColorChooserPanel(int palette, boolean allowMoreColors, boolean allowDefaultColor, Locale locale)
          Creates a new ColorChooserPanel with the specified palette and button options.
 
Method Summary
protected  AbstractButton createButton(String resourceString)
           
protected  void firstCell()
           
 ColorChooserPanel.ColorButton[] getColorButtons()
          Get the color buttons in the color chooser panel.
 ColorChooserPanel.ColorChooserDialogProvider getColorChooserDialogProvider()
          Gets a provider that can show a ColorChooserDialog and select a color.
protected static Color[] getPaletteGrayScale120()
           
protected static Color[] getPaletteGrayScale16()
           
protected static Color[] getPaletteGrayScale256()
           
 Color[] getPossibleColors()
          Gets possible colors used by this color chooser panel.
 String[] getPossibleColorsName()
          Gets possible color names.
protected  String getResourceString(String key)
          Gets the localized string from resource bundle.
protected  String getResourceString(String key, Locale locale)
          Gets the localized string from resource bundle of specified locale.
 Color getSelectedColor()
          Gets the selected color.
protected  void initColors()
           
protected  void initComponent()
           
 void itemStateChanged(ItemEvent e)
           
protected  void lastCell()
           
protected  void nextCell()
           
protected  void nextRow()
           
protected  void prevCell()
           
protected  void prevRow()
           
protected  void registerKeyStrokes()
           
 void setColorChooserDialogProvider(ColorChooserPanel.ColorChooserDialogProvider colorChooserDialogProvider)
          Sets a ColorChooserDialogProvider.
 void setLocale(Locale locale)
           
 void setSelectedColor(Color selectedColor)
          Sets the selected color.
protected  Color showColorChooser(Component component, String title, Color initColor)
          This method is called when when the "More" button is pressed on the ColorChooserPanel.
static Color showColorChooserDialog(Component component, String title, Color initialColor)
          Shows a modal color-chooser dialog and blocks until the dialog is hidden.
 void updateUI()
           
 
Methods inherited from class com.jidesoft.combobox.PopupPanel
addItemListener, addItemListener, fireItemStateChanged, getActualPreferredSize, getDefaultFocusComponent, getItemListeners, getMouseListener, getMouseMotionListener, getPreferredSize, getPreviousSelectedObject, getResizableCorners, getSelectedObject, getSelectedObjects, getTitle, isResetButtonVisible, isResizable, isStretchToFit, needsButtons, removeAllListeners, removeItemListener, requestFocus, setDefaultFocusComponent, setNeedButtons, setPreferredSize, setResizable, setResizableCorners, setSelectedObject, setSelectedObject, setSelectedObject, setSelectedObject, setStretchToFit, setTitle
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, 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, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, 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, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, 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

PALETTE_COLOR_15

public static final int PALETTE_COLOR_15
15 color palette. The 15 colors are (255, 255, 0), (0, 255, 0), (0, 255, 255), (255, 0, 255), (0, 0, 255), (255, 0, 0), (0, 0, 128), (0, 128, 128), (0, 128, 0), (0, 128, 0), (128, 0, 0), (128, 128, 0), (128, 128, 128), (192, 192, 192), and (0, 0, 0).

See Also:
Constant Field Values

PALETTE_COLOR_40

public static final int PALETTE_COLOR_40
40 color palette. The 40 colors are (0, 0, 0), (153, 51, 0), (51, 51, 0), (0, 51, 0), (0, 51, 102), (0, 0, 128), (51, 51, 153), (51, 51, 51), (128, 0, 0), (255, 102, 0), (128, 128, 0), (0, 128, 0), (0, 128, 128), (0, 0, 255), (102, 102, 153), (128, 128, 128), (255, 0, 0), (255, 153, 0), (153, 204, 0), (51, 153, 102), (51, 204, 204), (51, 102, 255), (128, 0, 128), (153, 153, 153), (255, 0, 255), (255, 204, 0), (255, 255, 0), (0, 255, 0), (0, 255, 255), (0, 204, 255), (153, 51, 102), (192, 192, 192), (255, 153, 204), (255, 204, 153), (255, 255, 153), (204, 255, 204), (204, 255, 255), (153, 204, 255), (204, 153, 255), and (255, 255, 255).

See Also:
Constant Field Values

PALETTE_COLOR_216

public static final int PALETTE_COLOR_216
Standard web-safe 216 color palette.

See Also:
Constant Field Values

PALETTE_GRAY_16

public static final int PALETTE_GRAY_16
16 gray color palette.

See Also:
Constant Field Values

PALETTE_GRAY_102

public static final int PALETTE_GRAY_102
102 gray color palette.

See Also:
Constant Field Values

PALETTE_GRAY_256

public static final int PALETTE_GRAY_256
256 gray color palette.

See Also:
Constant Field Values

PALETTE_CUSTOMIZE

public static final int PALETTE_CUSTOMIZE
By passing value as palette, you can call setPossibleColors() and setPossibleColorNames() to setup your own palette.

See Also:
Constant Field Values

_defaultColor

protected AbstractButton _defaultColor
Button for default color.


_moreColor

protected AbstractButton _moreColor
Button for more color.


_colorPanel

protected JPanel _colorPanel
JPanel which holds all color buttons.


PROPERTY_SELECTED_COLOR

public static final String PROPERTY_SELECTED_COLOR
See Also:
Constant Field Values
Constructor Detail

ColorChooserPanel

public ColorChooserPanel()
Creates a new ColorChooserPanel.


ColorChooserPanel

public ColorChooserPanel(int palette)
Creates a new ColorChooserPanel with specified palette.

Parameters:
palette - the palette.

ColorChooserPanel

public ColorChooserPanel(int palette,
                         boolean allowMoreColors,
                         boolean allowDefaultColor)
Creates a new ColorChooserPanel with the specified palette and button options.

Parameters:
palette - color palette
allowMoreColors - if more color button is visible.
allowDefaultColor - if default color button is visible.

ColorChooserPanel

public ColorChooserPanel(int palette,
                         boolean allowMoreColors,
                         boolean allowDefaultColor,
                         Locale locale)
Creates a new ColorChooserPanel with the specified palette and button options.

Parameters:
palette - color palette
allowMoreColors - if more color button is visible.
allowDefaultColor - if default color button is visible.
locale - the Locale

ColorChooserPanel

public ColorChooserPanel(Color[] colors,
                         String[] names,
                         boolean allowMoreColors,
                         boolean allowDefaultColor)
Creates a new ColorChooserPanel with customized palette.

Parameters:
colors - possible colors
names - names of possible colors.
allowMoreColors - if more color button is visible.
allowDefaultColor - if default color button is visible.

ColorChooserPanel

public ColorChooserPanel(Color[] colors,
                         String[] names,
                         boolean allowMoreColors,
                         boolean allowDefaultColor,
                         Locale locale)
Creates a new ColorChooserPanel with customized palette.

Parameters:
colors - possible colors
names - names of possible colors.
allowMoreColors - if more color button is visible.
allowDefaultColor - if default color button is visible.
locale - the Locale

ColorChooserPanel

public ColorChooserPanel(Color[] colors,
                         String[] names,
                         int rows,
                         int columns,
                         boolean allowMoreColors,
                         boolean allowDefaultColor,
                         Locale locale)
Creates a new ColorChooserPanel with customized palette. You can also specify how the color buttons are laid out by passing in rows and columns. Please note, if either the rows or columns is 0, we will suggest a preferred row and column value based on the length of the colors array. Otherwise we will use the row value specified in the rows parameter. The value in the columns is ignored because the length of the colors and rows are enough to determine the layout of the color labels.

Please make sure the length of colors and names array should equal with each other and not equal with 0. And please make rows no larger than the length of colors. Otherwise, the method will throw illegal argument exceptions.

Parameters:
colors - the possible colors
names - the names of possible colors.
rows - the number of rows, 0 if you want to use the suggested row value based on the number of the possible colors
columns - the number of columns, 0 if you want to use the suggested column value based on the number of the possible colors
allowMoreColors - if more color button is visible.
allowDefaultColor - if default color button is visible.
locale - the Locale
Method Detail

updateUI

public void updateUI()
Overrides:
updateUI in class JPanel

initColors

protected void initColors()

getPaletteGrayScale16

protected static Color[] getPaletteGrayScale16()

getPaletteGrayScale120

protected static Color[] getPaletteGrayScale120()

getPaletteGrayScale256

protected static Color[] getPaletteGrayScale256()

getPossibleColors

public Color[] getPossibleColors()
Gets possible colors used by this color chooser panel.

Returns:
possible colors.

getPossibleColorsName

public String[] getPossibleColorsName()
Gets possible color names.

Returns:
possible color names

getSelectedColor

public Color getSelectedColor()
Gets the selected color.

Returns:
the selected color.

setSelectedColor

public void setSelectedColor(Color selectedColor)
Sets the selected color.

Parameters:
selectedColor - the selected color.

initComponent

protected void initComponent()

createButton

protected AbstractButton createButton(String resourceString)

showColorChooser

protected Color showColorChooser(Component component,
                                 String title,
                                 Color initColor)
This method is called when when the "More" button is pressed on the ColorChooserPanel. It will use ColorChooserDialogProvider to show a custom color chooser dialog to choose a customized color. If ColorChooserDialogProvider is null, we will use the default JColorChooser to choose a color.

Parameters:
component - the owner of the JColorChooser.
title - the title of the JColorChooser dialog.
initColor - the initial color.
Returns:
the color user picked.

getColorChooserDialogProvider

public ColorChooserPanel.ColorChooserDialogProvider getColorChooserDialogProvider()
Gets a provider that can show a ColorChooserDialog and select a color.

Returns:
a ColorChooserDialogProvider.

setColorChooserDialogProvider

public void setColorChooserDialogProvider(ColorChooserPanel.ColorChooserDialogProvider colorChooserDialogProvider)
Sets a ColorChooserDialogProvider. You can use this method to provide your own color chooser dialog when the "More" button is pressed on the ColorChooserPanel.

Parameters:
colorChooserDialogProvider - a new ColorChooserDialogProvider.

getColorButtons

public ColorChooserPanel.ColorButton[] getColorButtons()
Get the color buttons in the color chooser panel.

Returns:
the buttons.

showColorChooserDialog

public static Color showColorChooserDialog(Component component,
                                           String title,
                                           Color initialColor)
                                    throws HeadlessException
Shows a modal color-chooser dialog and blocks until the dialog is hidden. If the user presses the "OK" button, then this method hides/disposes the dialog and returns the selected color. If the user presses the "Cancel" button or closes the dialog without pressing "OK", then this method hides/disposes the dialog and returns null.

Parameters:
component - the parent Component for the dialog
title - the String containing the dialog's title
initialColor - the initial Color set when the color-chooser is shown
Returns:
the selected color or null if the user opted out
Throws:
HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless()

itemStateChanged

public void itemStateChanged(ItemEvent e)
Specified by:
itemStateChanged in interface ItemListener

prevCell

protected void prevCell()

nextCell

protected void nextCell()

prevRow

protected void prevRow()

nextRow

protected void nextRow()

firstCell

protected void firstCell()

lastCell

protected void lastCell()

registerKeyStrokes

protected void registerKeyStrokes()

setLocale

public void setLocale(Locale locale)
Overrides:
setLocale in class Component

getResourceString

protected String getResourceString(String key)
Gets the localized string from resource bundle. Subclass can override it to provide its own string. Available keys are defined in color.properties. We get color names directly from the resource bundle without using this method. So overriding it will not have any effect on color names.

Parameters:
key - the resource key
Returns:
the localized string.

getResourceString

protected String getResourceString(String key,
                                   Locale locale)
Gets the localized string from resource bundle of specified locale. Subclass can override it to provide its own string. Available keys are defined in color.properties.

Parameters:
key - the resource key
locale - the locale
Returns:
the localized string.

JIDE 3.5.15