com.sygem.swing.colorchooser
Class AdvancedColorChooser

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bycom.sygem.swing.colorchooser.AdvancedColorChooser
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class AdvancedColorChooser
extends javax.swing.JComponent
implements javax.accessibility.Accessible, java.io.Serializable

An improved Color Picker dialog/component.

Whilst the API interface is based on the original JColorChooser that comes with Swing, this color picker has a closer resemblence to the kind of color picker found in commercial painting programs.

Features include:

Title: AdvancedColorChooser
Description: A sophisticated Color Chooser dialog
Copyright: Copyright (c) 2004
Company: SyGem Software

Version:
1.0c
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
static java.lang.String SELECTION_MODEL_PROPERTY
          The selection model property name.
 
Fields inherited from class javax.swing.JComponent
TOOL_TIP_TEXT_KEY, 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
AdvancedColorChooser()
          Simple no-args constructor.
AdvancedColorChooser(java.awt.Color initialColor)
          Creates an AdvancedColorChooser component, with the color set to initialColor.
AdvancedColorChooser(javax.swing.colorchooser.ColorSelectionModel model)
          Creates an AdvancedColorChooser component, with the ColorSelectionModel set to model.
 
Method Summary
static void addSwatchData(SwatchData data)
          Registers a set of Swatch data that will appear in the Swatches window.
 void closeRecentColorsWindow()
          Closes the Recent Colors window, if it is open.
 void closeSwatchesWindow()
          Closes the Swatches window, if it is open.
static javax.swing.JDialog createDialog(java.awt.Component c, java.lang.String title, boolean modal, AdvancedColorChooser chooserPane, java.awt.event.ActionListener okListener, java.awt.event.ActionListener cancelListener)
          Creates and returns a new dialog containing the specified AdvancedColorChooser pane along with "OK", "Cancel", and "Reset" buttons.
 javax.accessibility.AccessibleContext getAccessibleContext()
          Gets the AccessibleContext associated with this AdvancedColorChooser.
 java.awt.Color getColor()
          Gets the current color value from the color chooser.
 CustomColorDataSource getDataSource()
          Returns the currently registered data source used for storing/retrieving custom color data.
 javax.swing.colorchooser.ColorSelectionModel getSelectionModel()
          Returns the data model that handles color selections.
static java.util.Enumeration getSwatchData()
          Returns an enumeration containing all of the currently registered SwatchData objects.
static java.awt.Window getWindow()
          Returns the Window used for holding the color chooser component.
 boolean isUseWebColors()
          Returns TRUE if the color chooser is limited to web-safe colors.
static void registerCustomColorDataSource(CustomColorDataSource source)
          Registers a data source for storing and retrieving custom color indformation.
static void removeSwatchData(java.lang.String title)
          Removes a set of Swatch data, based on the title of the Swatch set.
static void removeSwatchData(SwatchData data)
          Removes a set of Swatch data from the Swatches window.
 void setColor(java.awt.Color c)
          Sets the color of this color chooser to the specified color.
 void setColor(int c)
          Sets the current color of the color chooser to the specified color.
 void setColor(int r, int g, int b)
          Sets the current color of the color chooser to the specified RGB color.
 void setDataSource(CustomColorDataSource dataSource)
          Sets the data source used for storing/retrieving custom color data.
 void setSelectionModel(javax.swing.colorchooser.ColorSelectionModel newModel)
          Sets the model containing the selected color.
 void setUseWebColors(boolean useWebColors)
          Determines whether or not the color chooser is to be limited to web-safe colors.
 void setWindow(java.awt.Window window)
          Sets the Window used for displaying the color chooser component.
static java.awt.Color showDialog(java.awt.Component component, java.lang.String title, java.awt.Color initialColor)
          Shows a modal color-chooser dialog and blocks until the dialog is hidden.
 
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, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, 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, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintImmediately, paintImmediately, print, printAll, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, 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, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, createImage, createImage, createVolatileImage, createVolatileImage, dispatchEvent, enable, 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, 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
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

SELECTION_MODEL_PROPERTY

public static final java.lang.String SELECTION_MODEL_PROPERTY
The selection model property name.

See Also:
Constant Field Values
Constructor Detail

AdvancedColorChooser

public AdvancedColorChooser()
                     throws java.awt.HeadlessException
Simple no-args constructor. The default color will be set to Color.white

Throws:
java.awt.HeadlessException

AdvancedColorChooser

public AdvancedColorChooser(java.awt.Color initialColor)
                     throws java.awt.HeadlessException

Creates an AdvancedColorChooser component, with the color set to initialColor.

NOTE: Unless you call setWindow(), the Swatches and Recent Colors panels will be unavailable.

Parameters:
initialColor - The initial color for this color chooser
Throws:
java.awt.HeadlessException

AdvancedColorChooser

public AdvancedColorChooser(javax.swing.colorchooser.ColorSelectionModel model)
                     throws java.awt.HeadlessException

Creates an AdvancedColorChooser component, with the ColorSelectionModel set to model.

NOTE: Unless you call setWindow(), the Swatches and Recent Colors panels will be unavailable.

Parameters:
model - The ColorSelectionModel for this color chooser
Throws:
java.awt.HeadlessException
Method Detail

addSwatchData

public static void addSwatchData(SwatchData data)
Registers a set of Swatch data that will appear in the Swatches window. This method is static so you can call it before using showDialog.

Parameters:
data - The SwatchData to be added
See Also:
showDialog(java.awt.Component, java.lang.String, java.awt.Color)

closeRecentColorsWindow

public void closeRecentColorsWindow()
Closes the Recent Colors window, if it is open.


closeSwatchesWindow

public void closeSwatchesWindow()
Closes the Swatches window, if it is open.


createDialog

public static javax.swing.JDialog createDialog(java.awt.Component c,
                                               java.lang.String title,
                                               boolean modal,
                                               AdvancedColorChooser chooserPane,
                                               java.awt.event.ActionListener okListener,
                                               java.awt.event.ActionListener cancelListener)
                                        throws java.awt.HeadlessException
Creates and returns a new dialog containing the specified AdvancedColorChooser pane along with "OK", "Cancel", and "Reset" buttons. If the "OK" or "Cancel" buttons are pressed, the dialog is automatically hidden (but not disposed). If the "Reset" button is pressed, the color-chooser's color will be reset to the color which was set the last time show was invoked on the dialog and the dialog will remain showing.

Parameters:
c - the parent component for the dialog
title - the title for the dialog
modal - a boolean. When true, the remainder of the program is inactive until the dialog is closed.
chooserPane - the AdvancedColorChooser to be placed inside the dialog
okListener - the ActionListener invoked when "OK" is pressed
cancelListener - the ActionListener invoked when "Cancel" is pressed
Returns:
a new dialog containing the color-chooser pane
Throws:
java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless()

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Gets the AccessibleContext associated with this AdvancedColorChooser. For color choosers, the AccessibleContext takes the form of an AccessibleAdvancedColorChooser. A new AccessibleAdvancedColorChooser instance is created if necessary.

Specified by:
getAccessibleContext in interface javax.accessibility.Accessible
Returns:
an AccessibleAdvancedColorChooser that serves as the AccessibleContext of this AdvancedColorChooser

getColor

public java.awt.Color getColor()
Gets the current color value from the color chooser. By default, this delegates to the model.

Returns:
the current color value of the color chooser

getDataSource

public CustomColorDataSource getDataSource()
Returns the currently registered data source used for storing/retrieving custom color data.

Returns:
The current CustomColorDataSource (or null if none)

getSelectionModel

public javax.swing.colorchooser.ColorSelectionModel getSelectionModel()
Returns the data model that handles color selections.

Returns:
a ColorSelectionModel object

getSwatchData

public static java.util.Enumeration getSwatchData()
Returns an enumeration containing all of the currently registered SwatchData objects.

Returns:
All of the SwatchData objects

getWindow

public static java.awt.Window getWindow()
Returns the Window used for holding the color chooser component.

Returns:
The Window, or null if not set

isUseWebColors

public boolean isUseWebColors()
Returns TRUE if the color chooser is limited to web-safe colors.

Returns:
The value of the useWebColors property

registerCustomColorDataSource

public static void registerCustomColorDataSource(CustomColorDataSource source)

Registers a data source for storing and retrieving custom color indformation.

NOTE: This static method should be used instead of setDataSource is you are using the showDialog method.

Parameters:
source - CustomColorDataSource
See Also:
showDialog(java.awt.Component, java.lang.String, java.awt.Color)

removeSwatchData

public static void removeSwatchData(java.lang.String title)
Removes a set of Swatch data, based on the title of the Swatch set.

Parameters:
title - The name of the Swatch data to remove

removeSwatchData

public static void removeSwatchData(SwatchData data)
Removes a set of Swatch data from the Swatches window.

Parameters:
data - The SwatchData to be removed

setColor

public void setColor(java.awt.Color c)
Sets the color of this color chooser to the specified color. The ColorSelectionModel will fire a ChangeEvent

Parameters:
c - The new Color for this color chooser

setColor

public void setColor(int c)
Sets the current color of the color chooser to the specified color.

Parameters:
c - an integer value that sets the current color in the chooser where the low-order 8 bits specify the Blue value, the next 8 bits specify the Green value, and the 8 bits above that specify the Red value.

setColor

public void setColor(int r,
                     int g,
                     int b)
Sets the current color of the color chooser to the specified RGB color. Note that the values of red, green, and blue should be between the numbers 0 and 255, inclusive.

Parameters:
r - an int specifying the amount of Red
g - an int specifying the amount of Green
b - an int specifying the amount of Blue
Throws:
java.lang.IllegalArgumentException - if r,g,b values are out of range
See Also:
Color

setDataSource

public void setDataSource(CustomColorDataSource dataSource)
Sets the data source used for storing/retrieving custom color data.

Parameters:
dataSource - The CustomColorDataSource to use

setSelectionModel

public void setSelectionModel(javax.swing.colorchooser.ColorSelectionModel newModel)
Sets the model containing the selected color.

Parameters:
newModel - The new ColorSelectionModel object

setUseWebColors

public void setUseWebColors(boolean useWebColors)
Determines whether or not the color chooser is to be limited to web-safe colors. Only the web-safe colors will be displayed on the main hue/saturation display.

Parameters:
useWebColors - True if the color chooser should be limited to web-safe colors.

setWindow

public void setWindow(java.awt.Window window)
Sets the Window used for displaying the color chooser component. If this property has been set, the Swatch and Recent Colors windows will become available, and they will be positioned alongside the window.

Parameters:
window - The Window used for holding the color chooser

showDialog

public static java.awt.Color showDialog(java.awt.Component component,
                                        java.lang.String title,
                                        java.awt.Color initialColor)
                                 throws java.awt.HeadlessException
Shows a modal color-chooser dialog and blocks until the dialog is hidden. Just like the original JColorChooser method of the same name, 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:
java.awt.HeadlessException - if GraphicsEnvironment.isHeadless() returns true.
See Also:
GraphicsEnvironment.isHeadless()


Copyright © 2004 SyGem Software. All Rights Reserved.