javax.swing.colorchooser

Class DefaultColorSelectionModel

public class DefaultColorSelectionModel extends Object implements ColorSelectionModel, Serializable

This is the default implementation of the ColorSelectionModel interface that JColorChoosers use.
Field Summary
protected ChangeEventchangeEvent
The ChangeEvent fired to all ChangeListeners.
protected EventListenerListlistenerList
The list of listeners.
Constructor Summary
DefaultColorSelectionModel()
Creates a new color selection model with the default white color.
DefaultColorSelectionModel(Color color)
Creates a new color selection model with a given selected color.
Method Summary
voidaddChangeListener(ChangeListener listener)
Adds a listener to this model.
protected voidfireStateChanged()
Calls all the stateChanged() method of all added ChangeListener objects with changeEvent as argument.
ChangeListener[]getChangeListeners()
Returns all currently added ChangeListener objects.
ColorgetSelectedColor()
Returns the selected color.
voidremoveChangeListener(ChangeListener listener)
Removes a listener from this model.
voidsetSelectedColor(Color color)
This method sets the color.

Field Detail

changeEvent

protected transient ChangeEvent changeEvent
The ChangeEvent fired to all ChangeListeners.

listenerList

protected EventListenerList listenerList
The list of listeners.

Constructor Detail

DefaultColorSelectionModel

public DefaultColorSelectionModel()
Creates a new color selection model with the default white color.

DefaultColorSelectionModel

public DefaultColorSelectionModel(Color color)
Creates a new color selection model with a given selected color.

Parameters: color The initial color.

Throws: Error If the color is null.

Method Detail

addChangeListener

public void addChangeListener(ChangeListener listener)
Adds a listener to this model.

Parameters: listener The listener to add.

fireStateChanged

protected void fireStateChanged()
Calls all the stateChanged() method of all added ChangeListener objects with changeEvent as argument.

getChangeListeners

public ChangeListener[] getChangeListeners()
Returns all currently added ChangeListener objects.

Returns: Array of ChangeListener objects.

getSelectedColor

public Color getSelectedColor()
Returns the selected color.

Returns: The selected color.

removeChangeListener

public void removeChangeListener(ChangeListener listener)
Removes a listener from this model.

Parameters: listener The listener to remove.

setSelectedColor

public void setSelectedColor(Color color)
This method sets the color.

Parameters: color The color to set.

Throws: Error If the color is set.