< prev index next >

src/share/classes/javax/swing/JMenuItem.java

Print this page
rev 1527 : 6727662: Code improvement and warnings removing from swing packages
Summary: Removed unnecessary castings and other warnings
Reviewed-by: malenkov


 258      * @see JComponent#getUIClassID
 259      * @see UIDefaults#getUI
 260      */
 261     public String getUIClassID() {
 262         return uiClassID;
 263     }
 264 
 265 
 266     /**
 267      * Identifies the menu item as "armed". If the mouse button is
 268      * released while it is over this item, the menu's action event
 269      * will fire. If the mouse button is released elsewhere, the
 270      * event will not fire and the menu item will be disarmed.
 271      *
 272      * @param b true to arm the menu item so it can be selected
 273      * @beaninfo
 274      *    description: Mouse release will fire an action event
 275      *         hidden: true
 276      */
 277     public void setArmed(boolean b) {
 278         ButtonModel model = (ButtonModel) getModel();
 279 
 280         boolean oldValue = model.isArmed();
 281         if(model.isArmed() != b) {
 282             model.setArmed(b);
 283         }
 284     }
 285 
 286     /**
 287      * Returns whether the menu item is "armed".
 288      *
 289      * @return true if the menu item is armed, and it can be selected
 290      * @see #setArmed
 291      */
 292     public boolean isArmed() {
 293         ButtonModel model = (ButtonModel) getModel();
 294         return model.isArmed();
 295     }
 296 
 297     /**
 298      * Enables or disables the menu item.
 299      *
 300      * @param b  true to enable the item
 301      * @beaninfo
 302      *    description: Does the component react to user interaction
 303      *          bound: true
 304      *      preferred: true
 305      */
 306     public void setEnabled(boolean b) {
 307         // Make sure we aren't armed!
 308         if (!b && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
 309             setArmed(false);
 310         }
 311         super.setEnabled(b);
 312     }
 313 


 704     }
 705 
 706     /**
 707      * Removes a <code>MenuDragMouseListener</code> from the menu item.
 708      *
 709      * @param l the <code>MenuDragMouseListener</code> to be removed
 710      */
 711     public void removeMenuDragMouseListener(MenuDragMouseListener l) {
 712         listenerList.remove(MenuDragMouseListener.class, l);
 713     }
 714 
 715     /**
 716      * Returns an array of all the <code>MenuDragMouseListener</code>s added
 717      * to this JMenuItem with addMenuDragMouseListener().
 718      *
 719      * @return all of the <code>MenuDragMouseListener</code>s added or an empty
 720      *         array if no listeners have been added
 721      * @since 1.4
 722      */
 723     public MenuDragMouseListener[] getMenuDragMouseListeners() {
 724         return (MenuDragMouseListener[])listenerList.getListeners(
 725                 MenuDragMouseListener.class);
 726     }
 727 
 728     /**
 729      * Adds a <code>MenuKeyListener</code> to the menu item.
 730      *
 731      * @param l the <code>MenuKeyListener</code> to be added
 732      */
 733     public void addMenuKeyListener(MenuKeyListener l) {
 734         listenerList.add(MenuKeyListener.class, l);
 735     }
 736 
 737     /**
 738      * Removes a <code>MenuKeyListener</code> from the menu item.
 739      *
 740      * @param l the <code>MenuKeyListener</code> to be removed
 741      */
 742     public void removeMenuKeyListener(MenuKeyListener l) {
 743         listenerList.remove(MenuKeyListener.class, l);
 744     }
 745 
 746     /**
 747      * Returns an array of all the <code>MenuKeyListener</code>s added
 748      * to this JMenuItem with addMenuKeyListener().
 749      *
 750      * @return all of the <code>MenuKeyListener</code>s added or an empty
 751      *         array if no listeners have been added
 752      * @since 1.4
 753      */
 754     public MenuKeyListener[] getMenuKeyListeners() {
 755         return (MenuKeyListener[])listenerList.getListeners(
 756                 MenuKeyListener.class);
 757     }
 758 
 759     /**
 760      * See JComponent.readObject() for information about serialization
 761      * in Swing.
 762      */
 763     private void readObject(ObjectInputStream s)
 764         throws IOException, ClassNotFoundException
 765     {
 766         s.defaultReadObject();
 767         if (getUIClassID().equals(uiClassID)) {
 768             updateUI();
 769         }
 770     }
 771 
 772     private void writeObject(ObjectOutputStream s) throws IOException {
 773         s.defaultWriteObject();
 774         if (getUIClassID().equals(uiClassID)) {
 775             byte count = JComponent.getWriteObjCounter(this);
 776             JComponent.setWriteObjCounter(this, --count);




 258      * @see JComponent#getUIClassID
 259      * @see UIDefaults#getUI
 260      */
 261     public String getUIClassID() {
 262         return uiClassID;
 263     }
 264 
 265 
 266     /**
 267      * Identifies the menu item as "armed". If the mouse button is
 268      * released while it is over this item, the menu's action event
 269      * will fire. If the mouse button is released elsewhere, the
 270      * event will not fire and the menu item will be disarmed.
 271      *
 272      * @param b true to arm the menu item so it can be selected
 273      * @beaninfo
 274      *    description: Mouse release will fire an action event
 275      *         hidden: true
 276      */
 277     public void setArmed(boolean b) {
 278         ButtonModel model = getModel();
 279 
 280         boolean oldValue = model.isArmed();
 281         if(model.isArmed() != b) {
 282             model.setArmed(b);
 283         }
 284     }
 285 
 286     /**
 287      * Returns whether the menu item is "armed".
 288      *
 289      * @return true if the menu item is armed, and it can be selected
 290      * @see #setArmed
 291      */
 292     public boolean isArmed() {
 293         ButtonModel model = getModel();
 294         return model.isArmed();
 295     }
 296 
 297     /**
 298      * Enables or disables the menu item.
 299      *
 300      * @param b  true to enable the item
 301      * @beaninfo
 302      *    description: Does the component react to user interaction
 303      *          bound: true
 304      *      preferred: true
 305      */
 306     public void setEnabled(boolean b) {
 307         // Make sure we aren't armed!
 308         if (!b && !UIManager.getBoolean("MenuItem.disabledAreNavigable")) {
 309             setArmed(false);
 310         }
 311         super.setEnabled(b);
 312     }
 313 


 704     }
 705 
 706     /**
 707      * Removes a <code>MenuDragMouseListener</code> from the menu item.
 708      *
 709      * @param l the <code>MenuDragMouseListener</code> to be removed
 710      */
 711     public void removeMenuDragMouseListener(MenuDragMouseListener l) {
 712         listenerList.remove(MenuDragMouseListener.class, l);
 713     }
 714 
 715     /**
 716      * Returns an array of all the <code>MenuDragMouseListener</code>s added
 717      * to this JMenuItem with addMenuDragMouseListener().
 718      *
 719      * @return all of the <code>MenuDragMouseListener</code>s added or an empty
 720      *         array if no listeners have been added
 721      * @since 1.4
 722      */
 723     public MenuDragMouseListener[] getMenuDragMouseListeners() {
 724         return listenerList.getListeners(MenuDragMouseListener.class);

 725     }
 726 
 727     /**
 728      * Adds a <code>MenuKeyListener</code> to the menu item.
 729      *
 730      * @param l the <code>MenuKeyListener</code> to be added
 731      */
 732     public void addMenuKeyListener(MenuKeyListener l) {
 733         listenerList.add(MenuKeyListener.class, l);
 734     }
 735 
 736     /**
 737      * Removes a <code>MenuKeyListener</code> from the menu item.
 738      *
 739      * @param l the <code>MenuKeyListener</code> to be removed
 740      */
 741     public void removeMenuKeyListener(MenuKeyListener l) {
 742         listenerList.remove(MenuKeyListener.class, l);
 743     }
 744 
 745     /**
 746      * Returns an array of all the <code>MenuKeyListener</code>s added
 747      * to this JMenuItem with addMenuKeyListener().
 748      *
 749      * @return all of the <code>MenuKeyListener</code>s added or an empty
 750      *         array if no listeners have been added
 751      * @since 1.4
 752      */
 753     public MenuKeyListener[] getMenuKeyListeners() {
 754         return listenerList.getListeners(MenuKeyListener.class);

 755     }
 756 
 757     /**
 758      * See JComponent.readObject() for information about serialization
 759      * in Swing.
 760      */
 761     private void readObject(ObjectInputStream s)
 762         throws IOException, ClassNotFoundException
 763     {
 764         s.defaultReadObject();
 765         if (getUIClassID().equals(uiClassID)) {
 766             updateUI();
 767         }
 768     }
 769 
 770     private void writeObject(ObjectOutputStream s) throws IOException {
 771         s.defaultWriteObject();
 772         if (getUIClassID().equals(uiClassID)) {
 773             byte count = JComponent.getWriteObjCounter(this);
 774             JComponent.setWriteObjCounter(this, --count);


< prev index next >