< prev index next >

src/java.desktop/share/classes/javax/swing/MenuSelectionManager.java

Print this page




  74         }
  75     }
  76 
  77     /**
  78      * Only one ChangeEvent is needed per button model instance since the
  79      * event's only state is the source property.  The source of events
  80      * generated is always "this".
  81      */
  82     protected transient ChangeEvent changeEvent = null;
  83     /** The collection of registered listeners */
  84     protected EventListenerList listenerList = new EventListenerList();
  85 
  86     /**
  87      * Changes the selection in the menu hierarchy.  The elements
  88      * in the array are sorted in order from the root menu
  89      * element to the currently selected menu element.
  90      * <p>
  91      * Note that this method is public but is used by the look and
  92      * feel engine and should not be called by client applications.
  93      *
  94      * @param path  an array of <code>MenuElement</code> objects specifying
  95      *        the selected path
  96      */
  97     public void setSelectedPath(MenuElement[] path) {
  98         int i,c;
  99         int currentSelectionCount = selection.size();
 100         int firstDifference = 0;
 101 
 102         if(path == null) {
 103             path = new MenuElement[0];
 104         }
 105 
 106         if (DEBUG) {
 107             System.out.print("Previous:  "); printMenuElementArray(getSelectedPath());
 108             System.out.print("New:  "); printMenuElementArray(path);
 109         }
 110 
 111         for(i=0,c=path.length;i<c;i++) {
 112             if (i < currentSelectionCount && selection.elementAt(i) == path[i])
 113                 firstDifference++;
 114             else


 156 
 157     /**
 158      * Adds a ChangeListener to the button.
 159      *
 160      * @param l the listener to add
 161      */
 162     public void addChangeListener(ChangeListener l) {
 163         listenerList.add(ChangeListener.class, l);
 164     }
 165 
 166     /**
 167      * Removes a ChangeListener from the button.
 168      *
 169      * @param l the listener to remove
 170      */
 171     public void removeChangeListener(ChangeListener l) {
 172         listenerList.remove(ChangeListener.class, l);
 173     }
 174 
 175     /**
 176      * Returns an array of all the <code>ChangeListener</code>s added
 177      * to this MenuSelectionManager with addChangeListener().
 178      *
 179      * @return all of the <code>ChangeListener</code>s added or an empty
 180      *         array if no listeners have been added
 181      * @since 1.4
 182      */
 183     public ChangeListener[] getChangeListeners() {
 184         return listenerList.getListeners(ChangeListener.class);
 185     }
 186 
 187     /**
 188      * Notifies all listeners that have registered interest for
 189      * notification on this event type.  The event instance
 190      * is created lazily.
 191      *
 192      * @see EventListenerList
 193      */
 194     protected void fireStateChanged() {
 195         // Guaranteed to return a non-null array
 196         Object[] listeners = listenerList.getListenerList();
 197         // Process the listeners last to first, notifying
 198         // those that are interested in this event
 199         for (int i = listeners.length-2; i>=0; i-=2) {




  74         }
  75     }
  76 
  77     /**
  78      * Only one ChangeEvent is needed per button model instance since the
  79      * event's only state is the source property.  The source of events
  80      * generated is always "this".
  81      */
  82     protected transient ChangeEvent changeEvent = null;
  83     /** The collection of registered listeners */
  84     protected EventListenerList listenerList = new EventListenerList();
  85 
  86     /**
  87      * Changes the selection in the menu hierarchy.  The elements
  88      * in the array are sorted in order from the root menu
  89      * element to the currently selected menu element.
  90      * <p>
  91      * Note that this method is public but is used by the look and
  92      * feel engine and should not be called by client applications.
  93      *
  94      * @param path  an array of {@code MenuElement} objects specifying
  95      *        the selected path
  96      */
  97     public void setSelectedPath(MenuElement[] path) {
  98         int i,c;
  99         int currentSelectionCount = selection.size();
 100         int firstDifference = 0;
 101 
 102         if(path == null) {
 103             path = new MenuElement[0];
 104         }
 105 
 106         if (DEBUG) {
 107             System.out.print("Previous:  "); printMenuElementArray(getSelectedPath());
 108             System.out.print("New:  "); printMenuElementArray(path);
 109         }
 110 
 111         for(i=0,c=path.length;i<c;i++) {
 112             if (i < currentSelectionCount && selection.elementAt(i) == path[i])
 113                 firstDifference++;
 114             else


 156 
 157     /**
 158      * Adds a ChangeListener to the button.
 159      *
 160      * @param l the listener to add
 161      */
 162     public void addChangeListener(ChangeListener l) {
 163         listenerList.add(ChangeListener.class, l);
 164     }
 165 
 166     /**
 167      * Removes a ChangeListener from the button.
 168      *
 169      * @param l the listener to remove
 170      */
 171     public void removeChangeListener(ChangeListener l) {
 172         listenerList.remove(ChangeListener.class, l);
 173     }
 174 
 175     /**
 176      * Returns an array of all the {@code ChangeListener}s added
 177      * to this MenuSelectionManager with addChangeListener().
 178      *
 179      * @return all of the {@code ChangeListener}s added or an empty
 180      *         array if no listeners have been added
 181      * @since 1.4
 182      */
 183     public ChangeListener[] getChangeListeners() {
 184         return listenerList.getListeners(ChangeListener.class);
 185     }
 186 
 187     /**
 188      * Notifies all listeners that have registered interest for
 189      * notification on this event type.  The event instance
 190      * is created lazily.
 191      *
 192      * @see EventListenerList
 193      */
 194     protected void fireStateChanged() {
 195         // Guaranteed to return a non-null array
 196         Object[] listeners = listenerList.getListenerList();
 197         // Process the listeners last to first, notifying
 198         // those that are interested in this event
 199         for (int i = listeners.length-2; i>=0; i-=2) {


< prev index next >