1 7 8 package javax.swing.colorchooser; 9 10 import javax.swing.*; 11 import javax.swing.event.*; 12 import java.awt.Color ; 13 import java.io.Serializable ; 14 15 23 public class DefaultColorSelectionModel implements ColorSelectionModel , Serializable { 24 25 30 protected transient ChangeEvent changeEvent = null; 31 32 protected EventListenerList listenerList = new EventListenerList(); 33 34 private Color selectedColor; 35 36 41 public DefaultColorSelectionModel() { 42 selectedColor = Color.white; 43 } 44 45 54 public DefaultColorSelectionModel(Color color) { 55 selectedColor = color; 56 } 57 58 64 public Color getSelectedColor() { 65 return selectedColor; 66 } 67 68 79 public void setSelectedColor(Color color) { 80 if (color != null && !selectedColor.equals(color)) { 81 selectedColor = color; 82 fireStateChanged(); 83 } 84 } 85 86 87 92 public void addChangeListener(ChangeListener l) { 93 listenerList.add(ChangeListener.class, l); 94 } 95 96 100 public void removeChangeListener(ChangeListener l) { 101 listenerList.remove(ChangeListener.class, l); 102 } 103 104 113 public ChangeListener[] getChangeListeners() { 114 return (ChangeListener[])listenerList.getListeners( 115 ChangeListener.class); 116 } 117 118 125 protected void fireStateChanged() 126 { 127 Object [] listeners = listenerList.getListenerList(); 128 for (int i = listeners.length - 2; i >= 0; i -=2 ) { 129 if (listeners[i] == ChangeListener.class) { 130 if (changeEvent == null) { 131 changeEvent = new ChangeEvent(this); 132 } 133 ((ChangeListener)listeners[i+1]).stateChanged(changeEvent); 134 } 135 } 136 } 137 138 } 139 | Popular Tags |