public class

DefaultColorSelectionModel

extends Object
implements Serializable ColorSelectionModel
java.lang.Object
   ↳ javax.swing.colorchooser.DefaultColorSelectionModel

Class Overview

A generic implementation of ColorSelectionModel.

See Also

Summary

Fields
protected ChangeEvent changeEvent Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property.
protected EventListenerList listenerList
Public Constructors
DefaultColorSelectionModel()
Creates a DefaultColorSelectionModel with the current color set to Color.white.
DefaultColorSelectionModel(Color color)
Creates a DefaultColorSelectionModel with the current color set to color, which should be non-null.
Public Methods
void addChangeListener(ChangeListener l)
Adds a ChangeListener to the model.
ChangeListener[] getChangeListeners()
Returns an array of all the ChangeListeners added to this DefaultColorSelectionModel with addChangeListener.
Color getSelectedColor()
Returns the selected Color which should be non-null.
void removeChangeListener(ChangeListener l)
Removes a ChangeListener from the model.
void setSelectedColor(Color color)
Sets the selected color to color.
Protected Methods
void fireStateChanged()
Runs each ChangeListener's stateChanged method.
[Expand]
Inherited Methods
From class java.lang.Object
From interface javax.swing.colorchooser.ColorSelectionModel

Fields

protected ChangeEvent changeEvent

Only one ChangeEvent is needed per model instance since the event's only (read-only) state is the source property. The source of events generated here is always "this".

protected EventListenerList listenerList

Public Constructors

public DefaultColorSelectionModel ()

Creates a DefaultColorSelectionModel with the current color set to Color.white. This is the default constructor.

public DefaultColorSelectionModel (Color color)

Creates a DefaultColorSelectionModel with the current color set to color, which should be non-null. Note that setting the color to null is undefined and may have unpredictable results.

Parameters
color the new Color

Public Methods

public void addChangeListener (ChangeListener l)

Adds a ChangeListener to the model.

Parameters
l the ChangeListener to be added

public ChangeListener[] getChangeListeners ()

Returns an array of all the ChangeListeners added to this DefaultColorSelectionModel with addChangeListener.

Returns
  • all of the ChangeListeners added, or an empty array if no listeners have been added

public Color getSelectedColor ()

Returns the selected Color which should be non-null.

Returns
  • the selected Color

public void removeChangeListener (ChangeListener l)

Removes a ChangeListener from the model.

Parameters
l the ChangeListener to be removed

public void setSelectedColor (Color color)

Sets the selected color to color. Note that setting the color to null is undefined and may have unpredictable results. This method fires a state changed event if it sets the current color to a new non-null color; if the new color is the same as the current color, no event is fired.

Parameters
color the new Color

Protected Methods

protected void fireStateChanged ()

Runs each ChangeListener's stateChanged method.