/[classpath]/classpath/javax/swing/DefaultSingleSelectionModel.java
ViewVC logotype

Diff of /classpath/javax/swing/DefaultSingleSelectionModel.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.4.2.2 by gnu_andrew, Sun Jan 16 02:14:49 2005 UTC revision 1.4.2.3 by gnu_andrew, Sun Jan 16 15:15:13 2005 UTC
# Line 47  import javax.swing.event.EventListenerLi Line 47  import javax.swing.event.EventListenerLi
47    
48  /**  /**
49   * DefaultSingleSelectionModel   * DefaultSingleSelectionModel
50   * @author      Andrew Selkirk   *
51   * @version     1.0   * @author Andrew Selkirk
52   */   */
53  public class DefaultSingleSelectionModel  public class DefaultSingleSelectionModel
54    implements SingleSelectionModel, Serializable    implements SingleSelectionModel, Serializable
55  {  {
56    static final long serialVersionUID = 3676229404753786004L;    private static final long serialVersionUID = 3676229404753786004L;
57    
58    /**    /**
59     * changeEvent     * changeEvent
60     */     */
61    protected transient ChangeEvent changeEvent = new ChangeEvent (this);    protected transient ChangeEvent changeEvent = new ChangeEvent(this);
62    
63    /**    /**
64     * listenerList     * listenerList
65     */     */
66    protected EventListenerList listenerList= new EventListenerList ();    protected EventListenerList listenerList = new EventListenerList();
67    
68    /**    /**
69     * index     * index
# Line 73  public class DefaultSingleSelectionModel Line 73  public class DefaultSingleSelectionModel
73    /**    /**
74     * Constructor DefaultSingleSelectionModel     * Constructor DefaultSingleSelectionModel
75     */     */
76    public DefaultSingleSelectionModel ()    public DefaultSingleSelectionModel()
77    {    {
78        // Do nothing.
79    }    }
80    
81    /**    /**
82     * getSelectedIndex     * getSelectedIndex
83     * @return int     * @return int
84     */     */
85    public int getSelectedIndex ()    public int getSelectedIndex()
86    {    {
87      return index;      return index;
88    }    }
# Line 90  public class DefaultSingleSelectionModel Line 91  public class DefaultSingleSelectionModel
91     * setSelectedIndex     * setSelectedIndex
92     * @param index TODO     * @param index TODO
93     */     */
94    public void setSelectedIndex (int index)    public void setSelectedIndex(int index)
95    {    {
     // Set Data  
96      this.index = index;      this.index = index;
97        fireStateChanged();
     // Notify Listeners  
     fireStateChanged ();  
98    }    }
99    
100    /**    /**
101     * clearSelection     * clearSelection
102     */     */
103    public void clearSelection ()    public void clearSelection()
104    {    {
     // Set Data  
105      index = -1;      index = -1;
106        fireStateChanged();
     // Notify Listeners  
     fireStateChanged ();  
107    }    }
108    
109    /**    /**
110     * isSelected     * isSelected
111     * @return boolean     * @return boolean
112     */     */
113    public boolean isSelected ()    public boolean isSelected()
114    {    {
115      return (index != -1);      return index != -1;
116    }    }
117    
118    /**    /**
# Line 125  public class DefaultSingleSelectionModel Line 120  public class DefaultSingleSelectionModel
120     *     *
121     * @param listener the listener to add     * @param listener the listener to add
122     */     */
123    public void addChangeListener (ChangeListener listener)    public void addChangeListener(ChangeListener listener)
124    {    {
125      listenerList.add (ChangeListener.class, listener);      listenerList.add(ChangeListener.class, listener);
126    }    }
127    
128    /**    /**
# Line 135  public class DefaultSingleSelectionModel Line 130  public class DefaultSingleSelectionModel
130     *     *
131     * @param listener the listener to remove     * @param listener the listener to remove
132     */     */
133    public void removeChangeListener (ChangeListener listener)    public void removeChangeListener(ChangeListener listener)
134    {    {
135      listenerList.remove (ChangeListener.class, listener);      listenerList.remove(ChangeListener.class, listener);
136    }    }
137    
138    /**    /**
139     * fireStateChanged     * fireStateChanged
140     */     */
141    protected void fireStateChanged ()    protected void fireStateChanged()
142    {    {
143      // Variables      ChangeListener[] listeners = getChangeListeners();
144      ChangeListener listener;  
145      ChangeListener[] listeners;      for (int i = 0; i < listeners.length; i++)
146      int index;        listeners[i].stateChanged(changeEvent);
   
     // Get Listeners  
     listeners = getChangeListeners ();  
   
     // Process Listeners  
     for (index = 0; index < listeners.length; index++)  
       {  
         listener = listeners [index];  
         listener.stateChanged (changeEvent);  
       }  
147    }    }
148    
149    /**    /**
# Line 170  public class DefaultSingleSelectionModel Line 155  public class DefaultSingleSelectionModel
155     *     *
156     * @since 1.3     * @since 1.3
157     */     */
158    public EventListener[] getListeners (Class listenerClass)    public EventListener[] getListeners(Class listenerClass)
159    {    {
160      return listenerList.getListeners (listenerClass);      return listenerList.getListeners(listenerClass);
161    }    }
162    
163    /**    /**
# Line 180  public class DefaultSingleSelectionModel Line 165  public class DefaultSingleSelectionModel
165     *     *
166     * @since 1.4     * @since 1.4
167     */     */
168    public ChangeListener[] getChangeListeners ()    public ChangeListener[] getChangeListeners()
169    {    {
170      return (ChangeListener[]) getListeners (ChangeListener.class);      return (ChangeListener[]) getListeners(ChangeListener.class);
171    }    }
172  }  }

Legend:
Removed from v.1.4.2.2  
changed lines
  Added in v.1.4.2.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26