src/share/classes/java/awt/MenuComponent.java

Print this page
rev 10048 : 8044740: Convert all JDK versions used in @since tag to 1.n[.n] in jdk repo
Reviewed-by:


  28 import java.awt.event.ActionEvent;
  29 import java.io.IOException;
  30 import java.io.ObjectInputStream;
  31 import sun.awt.AppContext;
  32 import sun.awt.AWTAccessor;
  33 import javax.accessibility.*;
  34 
  35 import java.security.AccessControlContext;
  36 import java.security.AccessController;
  37 
  38 /**
  39  * The abstract class <code>MenuComponent</code> is the superclass
  40  * of all menu-related components. In this respect, the class
  41  * <code>MenuComponent</code> is analogous to the abstract superclass
  42  * <code>Component</code> for AWT components.
  43  * <p>
  44  * Menu components receive and process AWT events, just as components do,
  45  * through the method <code>processEvent</code>.
  46  *
  47  * @author      Arthur van Hoff
  48  * @since       JDK1.0
  49  */
  50 public abstract class MenuComponent implements java.io.Serializable {
  51 
  52     static {
  53         /* ensure that the necessary native libraries are loaded */
  54         Toolkit.loadLibraries();
  55         if (!GraphicsEnvironment.isHeadless()) {
  56             initIDs();
  57         }
  58     }
  59 
  60     transient MenuComponentPeer peer;
  61     transient MenuContainer parent;
  62 
  63     /**
  64      * The <code>AppContext</code> of the <code>MenuComponent</code>.
  65      * This is set in the constructor and never changes.
  66      */
  67     transient AppContext appContext;
  68 


 158     public MenuComponent() throws HeadlessException {
 159         GraphicsEnvironment.checkHeadless();
 160         appContext = AppContext.getAppContext();
 161     }
 162 
 163     /**
 164      * Constructs a name for this <code>MenuComponent</code>.
 165      * Called by <code>getName</code> when the name is <code>null</code>.
 166      * @return a name for this <code>MenuComponent</code>
 167      */
 168     String constructComponentName() {
 169         return null; // For strict compliance with prior platform versions, a MenuComponent
 170                      // that doesn't set its name should return null from
 171                      // getName()
 172     }
 173 
 174     /**
 175      * Gets the name of the menu component.
 176      * @return        the name of the menu component
 177      * @see           java.awt.MenuComponent#setName(java.lang.String)
 178      * @since         JDK1.1
 179      */
 180     public String getName() {
 181         if (name == null && !nameExplicitlySet) {
 182             synchronized(this) {
 183                 if (name == null && !nameExplicitlySet)
 184                     name = constructComponentName();
 185             }
 186         }
 187         return name;
 188     }
 189 
 190     /**
 191      * Sets the name of the component to the specified string.
 192      * @param         name    the name of the menu component
 193      * @see           java.awt.MenuComponent#getName
 194      * @since         JDK1.1
 195      */
 196     public void setName(String name) {
 197         synchronized(this) {
 198             this.name = name;
 199             nameExplicitlySet = true;
 200         }
 201     }
 202 
 203     /**
 204      * Returns the parent container for this menu component.
 205      * @return    the menu component containing this menu component,
 206      *                 or <code>null</code> if this menu component
 207      *                 is the outermost component, the menu bar itself
 208      */
 209     public MenuContainer getParent() {
 210         return getParent_NoClientCode();
 211     }
 212     // NOTE: This method may be called by privileged threads.
 213     //       This functionality is implemented in a package-private method
 214     //       to insure that it cannot be overridden by client subclasses.


 356 
 357         } else { // backward compatibility
 358             Event olde = e.convertToOld();
 359             if (olde != null) {
 360                 postEvent(olde);
 361             }
 362         }
 363     }
 364 
 365     // REMIND: remove when filtering is done at lower level
 366     boolean eventEnabled(AWTEvent e) {
 367         return false;
 368     }
 369     /**
 370      * Processes events occurring on this menu component.
 371      * <p>Note that if the event parameter is <code>null</code>
 372      * the behavior is unspecified and may result in an
 373      * exception.
 374      *
 375      * @param e the event
 376      * @since JDK1.1
 377      */
 378     protected void processEvent(AWTEvent e) {
 379     }
 380 
 381     /**
 382      * Returns a string representing the state of this
 383      * <code>MenuComponent</code>. This method is intended to be used
 384      * only for debugging purposes, and the content and format of the
 385      * returned string may vary between implementations. The returned
 386      * string may be empty but may not be <code>null</code>.
 387      *
 388      * @return     the parameter string of this menu component
 389      */
 390     protected String paramString() {
 391         String thisName = getName();
 392         return (thisName != null? thisName : "");
 393     }
 394 
 395     /**
 396      * Returns a representation of this menu component as a string.




  28 import java.awt.event.ActionEvent;
  29 import java.io.IOException;
  30 import java.io.ObjectInputStream;
  31 import sun.awt.AppContext;
  32 import sun.awt.AWTAccessor;
  33 import javax.accessibility.*;
  34 
  35 import java.security.AccessControlContext;
  36 import java.security.AccessController;
  37 
  38 /**
  39  * The abstract class <code>MenuComponent</code> is the superclass
  40  * of all menu-related components. In this respect, the class
  41  * <code>MenuComponent</code> is analogous to the abstract superclass
  42  * <code>Component</code> for AWT components.
  43  * <p>
  44  * Menu components receive and process AWT events, just as components do,
  45  * through the method <code>processEvent</code>.
  46  *
  47  * @author      Arthur van Hoff
  48  * @since       1.0
  49  */
  50 public abstract class MenuComponent implements java.io.Serializable {
  51 
  52     static {
  53         /* ensure that the necessary native libraries are loaded */
  54         Toolkit.loadLibraries();
  55         if (!GraphicsEnvironment.isHeadless()) {
  56             initIDs();
  57         }
  58     }
  59 
  60     transient MenuComponentPeer peer;
  61     transient MenuContainer parent;
  62 
  63     /**
  64      * The <code>AppContext</code> of the <code>MenuComponent</code>.
  65      * This is set in the constructor and never changes.
  66      */
  67     transient AppContext appContext;
  68 


 158     public MenuComponent() throws HeadlessException {
 159         GraphicsEnvironment.checkHeadless();
 160         appContext = AppContext.getAppContext();
 161     }
 162 
 163     /**
 164      * Constructs a name for this <code>MenuComponent</code>.
 165      * Called by <code>getName</code> when the name is <code>null</code>.
 166      * @return a name for this <code>MenuComponent</code>
 167      */
 168     String constructComponentName() {
 169         return null; // For strict compliance with prior platform versions, a MenuComponent
 170                      // that doesn't set its name should return null from
 171                      // getName()
 172     }
 173 
 174     /**
 175      * Gets the name of the menu component.
 176      * @return        the name of the menu component
 177      * @see           java.awt.MenuComponent#setName(java.lang.String)
 178      * @since         1.1
 179      */
 180     public String getName() {
 181         if (name == null && !nameExplicitlySet) {
 182             synchronized(this) {
 183                 if (name == null && !nameExplicitlySet)
 184                     name = constructComponentName();
 185             }
 186         }
 187         return name;
 188     }
 189 
 190     /**
 191      * Sets the name of the component to the specified string.
 192      * @param         name    the name of the menu component
 193      * @see           java.awt.MenuComponent#getName
 194      * @since         1.1
 195      */
 196     public void setName(String name) {
 197         synchronized(this) {
 198             this.name = name;
 199             nameExplicitlySet = true;
 200         }
 201     }
 202 
 203     /**
 204      * Returns the parent container for this menu component.
 205      * @return    the menu component containing this menu component,
 206      *                 or <code>null</code> if this menu component
 207      *                 is the outermost component, the menu bar itself
 208      */
 209     public MenuContainer getParent() {
 210         return getParent_NoClientCode();
 211     }
 212     // NOTE: This method may be called by privileged threads.
 213     //       This functionality is implemented in a package-private method
 214     //       to insure that it cannot be overridden by client subclasses.


 356 
 357         } else { // backward compatibility
 358             Event olde = e.convertToOld();
 359             if (olde != null) {
 360                 postEvent(olde);
 361             }
 362         }
 363     }
 364 
 365     // REMIND: remove when filtering is done at lower level
 366     boolean eventEnabled(AWTEvent e) {
 367         return false;
 368     }
 369     /**
 370      * Processes events occurring on this menu component.
 371      * <p>Note that if the event parameter is <code>null</code>
 372      * the behavior is unspecified and may result in an
 373      * exception.
 374      *
 375      * @param e the event
 376      * @since 1.1
 377      */
 378     protected void processEvent(AWTEvent e) {
 379     }
 380 
 381     /**
 382      * Returns a string representing the state of this
 383      * <code>MenuComponent</code>. This method is intended to be used
 384      * only for debugging purposes, and the content and format of the
 385      * returned string may vary between implementations. The returned
 386      * string may be empty but may not be <code>null</code>.
 387      *
 388      * @return     the parameter string of this menu component
 389      */
 390     protected String paramString() {
 391         String thisName = getName();
 392         return (thisName != null? thisName : "");
 393     }
 394 
 395     /**
 396      * Returns a representation of this menu component as a string.