FileDocCategorySizeDatePackage
DefaultColorSelectionModel.javaAPI DocJava SE 5 API4156Fri Aug 26 14:58:00 BST 2005javax.swing.colorchooser

DefaultColorSelectionModel

public class DefaultColorSelectionModel extends Object implements Serializable, ColorSelectionModel
A generic implementation of ColorSelectionModel.
version
1.15 12/19/03
author
Steve Wilson
see
java.awt.Color

Fields Summary
protected transient 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
private Color
selectedColor
Constructors Summary
public DefaultColorSelectionModel()
Creates a DefaultColorSelectionModel with the current color set to Color.white. This is the default constructor.


                         
      
        selectedColor = Color.white;
    
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.

param
color the new Color

        selectedColor = color;
    
Methods Summary
public voidaddChangeListener(javax.swing.event.ChangeListener l)
Adds a ChangeListener to the model.

param
l the ChangeListener to be added

	listenerList.add(ChangeListener.class, l);
    
protected voidfireStateChanged()
Runs each ChangeListener's stateChanged method.

see
EventListenerList

        Object[] listeners = listenerList.getListenerList();
        for (int i = listeners.length - 2; i >= 0; i -=2 ) {
            if (listeners[i] == ChangeListener.class) {
                if (changeEvent == null) {
                    changeEvent = new ChangeEvent(this);
                }
                ((ChangeListener)listeners[i+1]).stateChanged(changeEvent);
            }
        }
    
public javax.swing.event.ChangeListener[]getChangeListeners()
Returns an array of all the ChangeListeners added to this DefaultColorSelectionModel with addChangeListener.

return
all of the ChangeListeners added, or an empty array if no listeners have been added
since
1.4

        return (ChangeListener[])listenerList.getListeners(
                ChangeListener.class);
    
public java.awt.ColorgetSelectedColor()
Returns the selected Color which should be non-null.

return
the selected Color

        return selectedColor;
    
public voidremoveChangeListener(javax.swing.event.ChangeListener l)
Removes a ChangeListener from the model.

param
l the ChangeListener to be removed

	listenerList.remove(ChangeListener.class, l);
    
public voidsetSelectedColor(java.awt.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.

param
color the new Color

        if (color != null && !selectedColor.equals(color)) {
            selectedColor = color;
            fireStateChanged();
        }