17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.util.*; 29 import javax.swing.event.*; 30 import java.io.Serializable; 31 32 33 /** 34 * This class provides the ChangeListener part of the 35 * SpinnerModel interface that should be suitable for most concrete SpinnerModel 36 * implementations. Subclasses must provide an implementation of the 37 * <code>setValue</code>, <code>getValue</code>, <code>getNextValue</code> and 38 * <code>getPreviousValue</code> methods. 39 * 40 * @see JSpinner 41 * @see SpinnerModel 42 * @see SpinnerListModel 43 * @see SpinnerNumberModel 44 * @see SpinnerDateModel 45 * 46 * @author Hans Muller 47 * @since 1.4 48 */ 49 @SuppressWarnings("serial") // Field contents are not serializable across versions 50 public abstract class AbstractSpinnerModel implements SpinnerModel, Serializable 51 { 52 53 /** 54 * Only one ChangeEvent is needed per model instance since the 55 * event's only (read-only) state is the source property. The source 56 * of events generated here is always "this". 57 */ 58 private transient ChangeEvent changeEvent = null; 74 * @see SpinnerModel#addChangeListener 75 */ 76 public void addChangeListener(ChangeListener l) { 77 listenerList.add(ChangeListener.class, l); 78 } 79 80 81 /** 82 * Removes a ChangeListener from the model's listener list. 83 * 84 * @param l the ChangeListener to remove 85 * @see #addChangeListener 86 * @see SpinnerModel#removeChangeListener 87 */ 88 public void removeChangeListener(ChangeListener l) { 89 listenerList.remove(ChangeListener.class, l); 90 } 91 92 93 /** 94 * Returns an array of all the <code>ChangeListener</code>s added 95 * to this AbstractSpinnerModel with addChangeListener(). 96 * 97 * @return all of the <code>ChangeListener</code>s added or an empty 98 * array if no listeners have been added 99 * @since 1.4 100 */ 101 public ChangeListener[] getChangeListeners() { 102 return listenerList.getListeners(ChangeListener.class); 103 } 104 105 106 /** 107 * Run each ChangeListeners stateChanged() method. 108 * 109 * @see #setValue 110 * @see EventListenerList 111 */ 112 protected void fireStateChanged() 113 { 114 Object[] listeners = listenerList.getListenerList(); 115 for (int i = listeners.length - 2; i >= 0; i -=2 ) { 116 if (listeners[i] == ChangeListener.class) { 117 if (changeEvent == null) { | 17 * You should have received a copy of the GNU General Public License version 18 * 2 along with this work; if not, write to the Free Software Foundation, 19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 20 * 21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * questions. 24 */ 25 26 package javax.swing; 27 28 import java.util.*; 29 import javax.swing.event.*; 30 import java.io.Serializable; 31 32 33 /** 34 * This class provides the ChangeListener part of the 35 * SpinnerModel interface that should be suitable for most concrete SpinnerModel 36 * implementations. Subclasses must provide an implementation of the 37 * {@code setValue}, {@code getValue}, {@code getNextValue} and 38 * {@code getPreviousValue} methods. 39 * 40 * @see JSpinner 41 * @see SpinnerModel 42 * @see SpinnerListModel 43 * @see SpinnerNumberModel 44 * @see SpinnerDateModel 45 * 46 * @author Hans Muller 47 * @since 1.4 48 */ 49 @SuppressWarnings("serial") // Field contents are not serializable across versions 50 public abstract class AbstractSpinnerModel implements SpinnerModel, Serializable 51 { 52 53 /** 54 * Only one ChangeEvent is needed per model instance since the 55 * event's only (read-only) state is the source property. The source 56 * of events generated here is always "this". 57 */ 58 private transient ChangeEvent changeEvent = null; 74 * @see SpinnerModel#addChangeListener 75 */ 76 public void addChangeListener(ChangeListener l) { 77 listenerList.add(ChangeListener.class, l); 78 } 79 80 81 /** 82 * Removes a ChangeListener from the model's listener list. 83 * 84 * @param l the ChangeListener to remove 85 * @see #addChangeListener 86 * @see SpinnerModel#removeChangeListener 87 */ 88 public void removeChangeListener(ChangeListener l) { 89 listenerList.remove(ChangeListener.class, l); 90 } 91 92 93 /** 94 * Returns an array of all the {@code ChangeListener}s added 95 * to this AbstractSpinnerModel with addChangeListener(). 96 * 97 * @return all of the {@code ChangeListener}s added or an empty 98 * array if no listeners have been added 99 * @since 1.4 100 */ 101 public ChangeListener[] getChangeListeners() { 102 return listenerList.getListeners(ChangeListener.class); 103 } 104 105 106 /** 107 * Run each ChangeListeners stateChanged() method. 108 * 109 * @see #setValue 110 * @see EventListenerList 111 */ 112 protected void fireStateChanged() 113 { 114 Object[] listeners = listenerList.getListenerList(); 115 for (int i = listeners.length - 2; i >= 0; i -=2 ) { 116 if (listeners[i] == ChangeListener.class) { 117 if (changeEvent == null) { |