Oracle JEWT API Reference
Release 4.2.24.0.0
B12199-01

oracle.bali.ewt.chooser.color
Class ColorPalettePane

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--oracle.bali.ewt.painter.PaintContextComponent
                          |
                          +--oracle.bali.ewt.LWComponent
                                |
                                +--oracle.bali.ewt.chooser.color.ColorPalettePane
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class ColorPalettePane
extends oracle.bali.ewt.LWComponent
implements javax.accessibility.Accessible

This class implements a simple ColorPalettePane.

This component contains a grid that displays Color objects. Users can pick a color by clicking on a cell in the grid or navigating with the keyboard.

The Colors displayed in the grid are defined in a TwoDModel that is set by setColorPalette().

Clients can get the selected color by calling getSelectedColor().

Clients can add a java.beans.PropertyChangeListener and listen for the PROPERTY_SELECTED_COLOR PropertyChangeEvent to find out when the user changes the selected color.

Custom Colors

The ColorPalettePane can also contain a second grid of colors know as custom colors. Clients can control the visibility of this palette by calling setCustomColorsVisible().

The custom colors are displayed below the main color palette.

Clients must also supply a model for the custom colors by calling setCustomColorPalette(). The ColorPalettePane does not try to match the horizontal size of the two color palettes. It is the responsibility of the client to make sure the two color palettes have the same number of columns.

Color Names

The ColorPalettePane also displays a label at the bottom of the component that contains the name of the currently selected color.

Clients need to supply a TwoDModel of color names by calling ColorPalettePane.setColorNames(). When the currently selected color changes the label will change to the name given in this data source. It is the responsibility of the client to make sure the color model and name model match up.

If the client has supplied a custom color palette they might also wish to supply a model that contains the custom color names by calling setCustomColorNames().

Editing

The ColorPalettePane also allows users to edit a color in the custom color palette. The main color palette is not editable by default. Clients must make the edit button visible by calling setEditVisible(). When the user edits a color in the custom palette the ColorPalettePane will fire a PROPERTY_COLOR_PALETTE PropertyChangeEvent.

A ColorChooserPane is used to edit the custom color.

Custom Components

Clients can also add custom components to the ColorPalettePane. These components will be placed to the right of the palette and above the edit button if it is visible. Clients can call addCustomComponent() to add a custom component.

Clients can add custom components to, for example, load a palette, save a palette, add rows to the custom palette, or remove rows from the custom palette.

See Also:
ColorChooserPane, Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static int BUTTON_CANCEL
          Constant indicating that the cancel button was pressed.
static int BUTTON_OK
          Constant indicating that the OK button was pressed.
static java.lang.String PROPERTY_COLOR_PALETTE
          The PropertyName to listen for when the user changes the custom Color palette.
static java.lang.String PROPERTY_SELECTED_COLOR
          The PropertyName to listen for when the user changes the selected color.
 
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
ColorPalettePane()
          Create the color palette pane with the default palette.
ColorPalettePane(TwoDModel colorPalette)
          Create the color palette pane with the given palette.
ColorPalettePane(TwoDModel colorPalette, java.awt.Color selectedColor, boolean editButtonVisible)
          Create the color palette pane with the given palette, the given selected color, the given visibility of the edit button, and no custom palette.
ColorPalettePane(TwoDModel colorPalette, java.awt.Color selectedColor, boolean editButtonVisible, TwoDModel customPalette)
          Create the color palette pane with the given palette, the given selected color, the given visibility of the edit button, and the given custom palette.
 
Method Summary
 void addCustomComponent(java.awt.Component component)
          Add a custom Component to the layout.
 void addNotify()
          Override to set the font of the color name label to bold
 void dispose()
          Free any memory associated with this ColorPalettePane.
 javax.accessibility.AccessibleContext getAccessibleContext()
          Get the AccessibleContext associated with this ColorPalettePane
 ColorChooserPane getColorChooserPane()
          Get the ColorChooserPane that will be used to edit a custom color.
 java.lang.String getColorName()
          Get the name of the currently selected color.
 TwoDModel getColorNames()
          Get the model that contains the color names for the main color palette.
 TwoDModel getColorPalette()
          Returns the model of colors that the ColorPalettePane shows.
 TwoDModel getCustomColorNames()
          Get the model that contains the color names for the custom color palette.
 TwoDModel getCustomColorPalette()
          Returns the model of custom colors that the ColorPalettePane shows.
 java.awt.Component getCustomComponent(int index)
          Get the custom Component at the given zero based index.
 int getCustomComponentCount()
          Get the number of custom Components that have been added to this pane.
 java.awt.Color getSelectedColor()
          Returns the color that is currently selected, or null if there is no selected color.
 boolean isColorNameVisible()
          Get if the color name label is visible.
 boolean isCustomColorSelected()
          Returns true if the currently selected color is in the custom palette.
 boolean isCustomColorsVisible()
          Get if the custom color grid is displayed or not.
 boolean isEditVisible()
          Get if the edit button is visible or not.
 void removeCustomComponent(java.awt.Component component)
          Remove a custom Component from the layout.
 void setColorName(java.lang.String name)
          Set the name of the currently selected color.
 void setColorNames(TwoDModel names)
          Set the model that contains the color names for the main color palette.
 void setColorNameVisible(boolean visible)
          Set if the color name label is visible.
 void setColorPalette(TwoDModel colors)
          Change the color palette that the ColorPalettePane uses.
 void setCustomColorNames(TwoDModel names)
          Set the model that contains the color names for the custom color palette.
 void setCustomColorPalette(TwoDModel colors)
          Change the custom color palette that the ColorPalettePane uses.
 void setCustomColorsVisible(boolean visible)
          Set if the custom color grid is displayed or not.
 void setEditVisible(boolean visible)
          Set if the edit button is visible or not.
 void setEnabled(boolean enabled)
          Override to pass onto children.
 void setLocale(java.util.Locale newLocale)
          Override to set strings when locale changes.
 void setSelectedColor(java.awt.Color c)
          Sets the selected color in the default grid.
 void setSelectedColor(java.awt.Color c, boolean colorInCustomPalette)
          Sets the selected color in the either the custom palette or the main palette of the color grid.
static int showDialog(java.awt.Component parent, ColorPalettePane pane)
          Show the given ColorPalettePane in a modal, non resizable, Dialog with the default title, centered over the given parent component.
static int showDialog(java.awt.Component parent, ColorPalettePane pane, java.lang.String dialogTitle, boolean resizable)
          Show the given ColorPalettePane in a modal Dialog with the given resizability, with the given title, centered over the given parent component.
 
Methods inherited from class oracle.bali.ewt.LWComponent
clipToParents, freezeRepaints, getActualAlignment, getActualReadingDirection, getAlignment, getBorderInsets, getDocumentSize, getFill, getPageBounds, getPrintPaintContext, isFocusTraversable, paintChildren, paintComponent, paintImmediateInterior, paintImmediateInterior, paintImmediately, paintOverChildren, printPage, processEvent, processEventImpl, repaint, repaintInterior, repaintInterior, setAlignment, setFill, unfreezeRepaints, updateUI
 
Methods inherited from class oracle.bali.ewt.painter.PaintContextComponent
getBorderContext, getPaintContext, getPaintData, getPaintState, getUIDefaults, setUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVerifyInputWhenFocusTarget, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, hide, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processFocusEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

PROPERTY_COLOR_PALETTE

public static final java.lang.String PROPERTY_COLOR_PALETTE
The PropertyName to listen for when the user changes the custom Color palette.

PROPERTY_SELECTED_COLOR

public static final java.lang.String PROPERTY_SELECTED_COLOR
The PropertyName to listen for when the user changes the selected color.

BUTTON_OK

public static final int BUTTON_OK
Constant indicating that the OK button was pressed.
See Also:
showDialog(java.awt.Component, oracle.bali.ewt.chooser.color.ColorPalettePane)

BUTTON_CANCEL

public static final int BUTTON_CANCEL
Constant indicating that the cancel button was pressed.
See Also:
showDialog(java.awt.Component, oracle.bali.ewt.chooser.color.ColorPalettePane)
Constructor Detail

ColorPalettePane

public ColorPalettePane()
Create the color palette pane with the default palette.

ColorPalettePane

public ColorPalettePane(TwoDModel colorPalette)
Create the color palette pane with the given palette.

ColorPalettePane

public ColorPalettePane(TwoDModel colorPalette,
                        java.awt.Color selectedColor,
                        boolean editButtonVisible)
Create the color palette pane with the given palette, the given selected color, the given visibility of the edit button, and no custom palette.

ColorPalettePane

public ColorPalettePane(TwoDModel colorPalette,
                        java.awt.Color selectedColor,
                        boolean editButtonVisible,
                        TwoDModel customPalette)
Create the color palette pane with the given palette, the given selected color, the given visibility of the edit button, and the given custom palette.
Method Detail

showDialog

public static int showDialog(java.awt.Component parent,
                             ColorPalettePane pane)
Show the given ColorPalettePane in a modal, non resizable, Dialog with the default title, centered over the given parent component.
Parameters:
parent - The parent component to center the dialog over.
pane - The ColorPalettePane to show in the dialog
Returns:
Either BUTTON_OK or BUTTON_CANCEL indicating if the user pressed ok or cancel.

showDialog

public static int showDialog(java.awt.Component parent,
                             ColorPalettePane pane,
                             java.lang.String dialogTitle,
                             boolean resizable)
Show the given ColorPalettePane in a modal Dialog with the given resizability, with the given title, centered over the given parent component.
Parameters:
parent - The parent component to center the dialog over.
pane - The ColorPalettePane to show in the dialog
dialogTitle - The title of the dialog
resizable - True if the dialog is resizable
Returns:
Either BUTTON_OK or BUTTON_CANCEL indicating if the user pressed ok or cancel.

setColorPalette

public void setColorPalette(TwoDModel colors)
Change the color palette that the ColorPalettePane uses. If colors is null the default color palette is used. The default palette is the Web Safe 216 color palette.
See Also:
getColorPalette()

getColorPalette

public TwoDModel getColorPalette()
Returns the model of colors that the ColorPalettePane shows.

See Also:
setColorPalette(oracle.bali.ewt.model.TwoDModel)

setCustomColorPalette

public void setCustomColorPalette(TwoDModel colors)
Change the custom color palette that the ColorPalettePane uses. If colors is null the custom color palette is not displayed. Clients can also change the visibility of the custom palette by calling setCustomColorsVisible().
See Also:
getCustomColorPalette(), setCustomColorsVisible(boolean)

getCustomColorPalette

public TwoDModel getCustomColorPalette()
Returns the model of custom colors that the ColorPalettePane shows.

See Also:
getCustomColorPalette()

setEditVisible

public void setEditVisible(boolean visible)
Set if the edit button is visible or not. This button allows users to edit a color in the custom color palette.

See Also:
isEditVisible()

isEditVisible

public boolean isEditVisible()
Get if the edit button is visible or not. This button allows users to edit a color in the custom color palette.

See Also:
setEditVisible(boolean)

setSelectedColor

public void setSelectedColor(java.awt.Color c)
Sets the selected color in the default grid.

This must be a color from the model of getColorPalette().

Throws:
java.lang.IllegalArgumentException - if the color is not found in the color palette.

getSelectedColor

public java.awt.Color getSelectedColor()
Returns the color that is currently selected, or null if there is no selected color. This color can be in either the main palette or the custom palette. Clients can call isCustomColorSelected() to differentiate.

isCustomColorSelected

public boolean isCustomColorSelected()
Returns true if the currently selected color is in the custom palette. Returns false if the currently selected color is selected in the main palette.

setSelectedColor

public void setSelectedColor(java.awt.Color c,
                             boolean colorInCustomPalette)
Sets the selected color in the either the custom palette or the main palette of the color grid.

If custom is false the the color must be in the getColorPalette() model. Otherwise the color must be in the getCustomColorPalette() model.

Throws:
java.lang.IllegalArgumentException - if the color is not found in either the color model

setColorNames

public void setColorNames(TwoDModel names)
Set the model that contains the color names for the main color palette. It is the clients responsibility to make sure the names correspond to the correct colors in the color palette.

See Also:
getColorNames(), setColorPalette(oracle.bali.ewt.model.TwoDModel)

getColorNames

public TwoDModel getColorNames()
Get the model that contains the color names for the main color palette.

See Also:
setColorNames(oracle.bali.ewt.model.TwoDModel)

setCustomColorNames

public void setCustomColorNames(TwoDModel names)
Set the model that contains the color names for the custom color palette. It is the clients responsibility to make sure the names correspond to the correct colors in the custom color palette.

See Also:
getCustomColorNames(), setCustomColorPalette(oracle.bali.ewt.model.TwoDModel)

getCustomColorNames

public TwoDModel getCustomColorNames()
Get the model that contains the color names for the custom color palette.

See Also:
setCustomColorNames(oracle.bali.ewt.model.TwoDModel)

setColorName

public void setColorName(java.lang.String name)
Set the name of the currently selected color. Clients must have supplied a model of names by using setColorNames(). If the selected color is in the custom color palette a model must be supplied via setCustomColorNames().

See Also:
getColorName(), isColorNameVisible(), setColorNames(oracle.bali.ewt.model.TwoDModel), setCustomColorNames(oracle.bali.ewt.model.TwoDModel)

getColorName

public java.lang.String getColorName()
Get the name of the currently selected color.
See Also:
setColorName(java.lang.String), isColorNameVisible()

setCustomColorsVisible

public void setCustomColorsVisible(boolean visible)
Set if the custom color grid is displayed or not.
See Also:
isCustomColorsVisible(), setCustomColorPalette(oracle.bali.ewt.model.TwoDModel)

isCustomColorsVisible

public boolean isCustomColorsVisible()
Get if the custom color grid is displayed or not.
See Also:
setCustomColorsVisible(boolean)

setColorNameVisible

public void setColorNameVisible(boolean visible)
Set if the color name label is visible.
See Also:
isColorNameVisible()

isColorNameVisible

public boolean isColorNameVisible()
Get if the color name label is visible.
See Also:
setColorNameVisible(boolean)

addCustomComponent

public void addCustomComponent(java.awt.Component component)
Add a custom Component to the layout. This Component will be placed on the right side of the pane.
See Also:
removeCustomComponent(java.awt.Component)

removeCustomComponent

public void removeCustomComponent(java.awt.Component component)
Remove a custom Component from the layout.
See Also:
addCustomComponent(java.awt.Component)

getCustomComponentCount

public int getCustomComponentCount()
Get the number of custom Components that have been added to this pane.
See Also:
addCustomComponent(java.awt.Component)

getCustomComponent

public java.awt.Component getCustomComponent(int index)
Get the custom Component at the given zero based index.
See Also:
addCustomComponent(java.awt.Component), getCustomComponentCount()

getColorChooserPane

public ColorChooserPane getColorChooserPane()
Get the ColorChooserPane that will be used to edit a custom color. Clients can customize which attributes of the ColorChooserPane are set by using the object returned from this method.

dispose

public void dispose()
Free any memory associated with this ColorPalettePane. Once dispose() is called the ColorPalettePane will become unusable.

setEnabled

public void setEnabled(boolean enabled)
Override to pass onto children.
Overrides:
setEnabled in class javax.swing.JComponent

addNotify

public void addNotify()
Override to set the font of the color name label to bold
Overrides:
addNotify in class javax.swing.JComponent

getAccessibleContext

public javax.accessibility.AccessibleContext getAccessibleContext()
Get the AccessibleContext associated with this ColorPalettePane
Specified by:
getAccessibleContext in interface javax.accessibility.Accessible
Overrides:
getAccessibleContext in class javax.swing.JComponent
Returns:
the AccessibleContext of this ColorPalettePane

setLocale

public void setLocale(java.util.Locale newLocale)
Override to set strings when locale changes.
Overrides:
setLocale in class java.awt.Component

Oracle JEWT 4.2.24

Copyright © [xxxx],2003, Oracle. All Rights Reserved.