1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  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 package java.awt;
  26 
  27 import java.awt.peer.MenuComponentPeer;
  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 sun.awt.ComponentFactory;
  34 
  35 import javax.accessibility.*;
  36 
  37 import java.security.AccessControlContext;
  38 import java.security.AccessController;
  39 
  40 /**
  41  * The abstract class <code>MenuComponent</code> is the superclass
  42  * of all menu-related components. In this respect, the class
  43  * <code>MenuComponent</code> is analogous to the abstract superclass
  44  * <code>Component</code> for AWT components.
  45  * <p>
  46  * Menu components receive and process AWT events, just as components do,
  47  * through the method <code>processEvent</code>.
  48  *
  49  * @author      Arthur van Hoff
  50  * @since       1.0
  51  */
  52 public abstract class MenuComponent implements java.io.Serializable {
  53 
  54     static {
  55         /* ensure that the necessary native libraries are loaded */
  56         Toolkit.loadLibraries();
  57         if (!GraphicsEnvironment.isHeadless()) {
  58             initIDs();
  59         }
  60     }
  61 
  62     transient volatile MenuComponentPeer peer;
  63     transient MenuContainer parent;
  64 
  65     /**
  66      * The <code>AppContext</code> of the <code>MenuComponent</code>.
  67      * This is set in the constructor and never changes.
  68      */
  69     transient AppContext appContext;
  70 
  71     /**
  72      * The menu component's font. This value can be
  73      * <code>null</code> at which point a default will be used.
  74      * This defaults to <code>null</code>.
  75      *
  76      * @serial
  77      * @see #setFont(Font)
  78      * @see #getFont()
  79      */
  80     Font font;
  81 
  82     /**
  83      * The menu component's name, which defaults to <code>null</code>.
  84      * @serial
  85      * @see #getName()
  86      * @see #setName(String)
  87      */
  88     private String name;
  89 
  90     /**
  91      * A variable to indicate whether a name is explicitly set.
  92      * If <code>true</code> the name will be set explicitly.
  93      * This defaults to <code>false</code>.
  94      * @serial
  95      * @see #setName(String)
  96      */
  97     private boolean nameExplicitlySet = false;
  98 
  99     /**
 100      * Defaults to <code>false</code>.
 101      * @serial
 102      * @see #dispatchEvent(AWTEvent)
 103      */
 104     boolean newEventsOnly = false;
 105 
 106     /*
 107      * The menu's AccessControlContext.
 108      */
 109     private transient volatile AccessControlContext acc =
 110             AccessController.getContext();
 111 
 112     /*
 113      * Returns the acc this menu component was constructed with.
 114      */
 115     final AccessControlContext getAccessControlContext() {
 116         if (acc == null) {
 117             throw new SecurityException(
 118                     "MenuComponent is missing AccessControlContext");
 119         }
 120         return acc;
 121     }
 122 
 123     /*
 124      * Internal constants for serialization.
 125      */
 126     final static String actionListenerK = Component.actionListenerK;
 127     final static String itemListenerK = Component.itemListenerK;
 128 
 129     /*
 130      * JDK 1.1 serialVersionUID
 131      */
 132     private static final long serialVersionUID = -4536902356223894379L;
 133 
 134     static {
 135         AWTAccessor.setMenuComponentAccessor(
 136             new AWTAccessor.MenuComponentAccessor() {
 137                 @Override
 138                 public AppContext getAppContext(MenuComponent menuComp) {
 139                     return menuComp.appContext;
 140                 }
 141                 @Override
 142                 public void setAppContext(MenuComponent menuComp,
 143                                           AppContext appContext) {
 144                     menuComp.appContext = appContext;
 145                 }
 146                 @Override
 147                 @SuppressWarnings("unchecked")
 148                 public <T extends MenuComponentPeer> T getPeer(MenuComponent menuComp) {
 149                     return (T) menuComp.peer;
 150                 }
 151                 @Override
 152                 public MenuContainer getParent(MenuComponent menuComp) {
 153                     return menuComp.parent;
 154                 }
 155                 @Override
 156                 public void setParent(MenuComponent menuComp, MenuContainer menuContainer) {
 157                     menuComp.parent = menuContainer;
 158                 }
 159                 @Override
 160                 public Font getFont_NoClientCode(MenuComponent menuComp) {
 161                     return menuComp.getFont_NoClientCode();
 162                 }
 163             });
 164     }
 165 
 166     /**
 167      * Creates a <code>MenuComponent</code>.
 168      * @exception HeadlessException if
 169      *    <code>GraphicsEnvironment.isHeadless</code>
 170      *    returns <code>true</code>
 171      * @see java.awt.GraphicsEnvironment#isHeadless
 172      */
 173     public MenuComponent() throws HeadlessException {
 174         GraphicsEnvironment.checkHeadless();
 175         appContext = AppContext.getAppContext();
 176     }
 177 
 178     /**
 179      * Constructs a name for this <code>MenuComponent</code>.
 180      * Called by <code>getName</code> when the name is <code>null</code>.
 181      * @return a name for this <code>MenuComponent</code>
 182      */
 183     String constructComponentName() {
 184         return null; // For strict compliance with prior platform versions, a MenuComponent
 185                      // that doesn't set its name should return null from
 186                      // getName()
 187     }
 188 
 189     final ComponentFactory getComponentFactory() {
 190         final Toolkit toolkit = Toolkit.getDefaultToolkit();
 191         if (toolkit instanceof ComponentFactory) {
 192             return (ComponentFactory) toolkit;
 193         }
 194         throw new AWTError("Unsupported toolkit: " + toolkit);
 195     }
 196 
 197     /**
 198      * Gets the name of the menu component.
 199      * @return        the name of the menu component
 200      * @see           java.awt.MenuComponent#setName(java.lang.String)
 201      * @since         1.1
 202      */
 203     public String getName() {
 204         if (name == null && !nameExplicitlySet) {
 205             synchronized(this) {
 206                 if (name == null && !nameExplicitlySet)
 207                     name = constructComponentName();
 208             }
 209         }
 210         return name;
 211     }
 212 
 213     /**
 214      * Sets the name of the component to the specified string.
 215      * @param         name    the name of the menu component
 216      * @see           java.awt.MenuComponent#getName
 217      * @since         1.1
 218      */
 219     public void setName(String name) {
 220         synchronized(this) {
 221             this.name = name;
 222             nameExplicitlySet = true;
 223         }
 224     }
 225 
 226     /**
 227      * Returns the parent container for this menu component.
 228      * @return    the menu component containing this menu component,
 229      *                 or <code>null</code> if this menu component
 230      *                 is the outermost component, the menu bar itself
 231      */
 232     public MenuContainer getParent() {
 233         return getParent_NoClientCode();
 234     }
 235     // NOTE: This method may be called by privileged threads.
 236     //       This functionality is implemented in a package-private method
 237     //       to insure that it cannot be overridden by client subclasses.
 238     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
 239     final MenuContainer getParent_NoClientCode() {
 240         return parent;
 241     }
 242 
 243     /**
 244      * Gets the font used for this menu component.
 245      * @return   the font used in this menu component, if there is one;
 246      *                  <code>null</code> otherwise
 247      * @see     java.awt.MenuComponent#setFont
 248      */
 249     public Font getFont() {
 250         Font font = this.font;
 251         if (font != null) {
 252             return font;
 253         }
 254         MenuContainer parent = this.parent;
 255         if (parent != null) {
 256             return parent.getFont();
 257         }
 258         return null;
 259     }
 260 
 261     // NOTE: This method may be called by privileged threads.
 262     //       This functionality is implemented in a package-private method
 263     //       to insure that it cannot be overridden by client subclasses.
 264     //       DO NOT INVOKE CLIENT CODE ON THIS THREAD!
 265     final Font getFont_NoClientCode() {
 266         Font font = this.font;
 267         if (font != null) {
 268             return font;
 269         }
 270 
 271         // The MenuContainer interface does not have getFont_NoClientCode()
 272         // and it cannot, because it must be package-private. Because of
 273         // this, we must manually cast classes that implement
 274         // MenuContainer.
 275         Object parent = this.parent;
 276         if (parent != null) {
 277             if (parent instanceof Component) {
 278                 font = ((Component)parent).getFont_NoClientCode();
 279             } else if (parent instanceof MenuComponent) {
 280                 font = ((MenuComponent)parent).getFont_NoClientCode();
 281             }
 282         }
 283         return font;
 284     } // getFont_NoClientCode()
 285 
 286 
 287     /**
 288      * Sets the font to be used for this menu component to the specified
 289      * font. This font is also used by all subcomponents of this menu
 290      * component, unless those subcomponents specify a different font.
 291      * <p>
 292      * Some platforms may not support setting of all font attributes
 293      * of a menu component; in such cases, calling <code>setFont</code>
 294      * will have no effect on the unsupported font attributes of this
 295      * menu component.  Unless subcomponents of this menu component
 296      * specify a different font, this font will be used by those
 297      * subcomponents if supported by the underlying platform.
 298      *
 299      * @param     f   the font to be set
 300      * @see       #getFont
 301      * @see       Font#getAttributes
 302      * @see       java.awt.font.TextAttribute
 303      */
 304     public void setFont(Font f) {
 305         font = f;
 306         //Fixed 6312943: NullPointerException in method MenuComponent.setFont(Font)
 307         MenuComponentPeer peer = this.peer;
 308         if (peer != null) {
 309             peer.setFont(f);
 310         }
 311     }
 312 
 313     /**
 314      * Removes the menu component's peer.  The peer allows us to modify the
 315      * appearance of the menu component without changing the functionality of
 316      * the menu component.
 317      */
 318     public void removeNotify() {
 319         synchronized (getTreeLock()) {
 320             MenuComponentPeer p = this.peer;
 321             if (p != null) {
 322                 Toolkit.getEventQueue().removeSourceEvents(this, true);
 323                 this.peer = null;
 324                 p.dispose();
 325             }
 326         }
 327     }
 328 
 329     /**
 330      * Posts the specified event to the menu.
 331      * This method is part of the Java&nbsp;1.0 event system
 332      * and it is maintained only for backwards compatibility.
 333      * Its use is discouraged, and it may not be supported
 334      * in the future.
 335      * @param evt the event which is to take place
 336      * @deprecated As of JDK version 1.1, replaced by {@link
 337      * #dispatchEvent(AWTEvent) dispatchEvent}.
 338      */
 339     @Deprecated
 340     public boolean postEvent(Event evt) {
 341         MenuContainer parent = this.parent;
 342         if (parent != null) {
 343             parent.postEvent(evt);
 344         }
 345         return false;
 346     }
 347 
 348     /**
 349      * Delivers an event to this component or one of its sub components.
 350      * @param e the event
 351      */
 352     public final void dispatchEvent(AWTEvent e) {
 353         dispatchEventImpl(e);
 354     }
 355 
 356     void dispatchEventImpl(AWTEvent e) {
 357         EventQueue.setCurrentEventAndMostRecentTime(e);
 358 
 359         Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
 360 
 361         if (newEventsOnly ||
 362             (parent != null && parent instanceof MenuComponent &&
 363              ((MenuComponent)parent).newEventsOnly)) {
 364             if (eventEnabled(e)) {
 365                 processEvent(e);
 366             } else if (e instanceof ActionEvent && parent != null) {
 367                 e.setSource(parent);
 368                 ((MenuComponent)parent).dispatchEvent(e);
 369             }
 370 
 371         } else { // backward compatibility
 372             Event olde = e.convertToOld();
 373             if (olde != null) {
 374                 postEvent(olde);
 375             }
 376         }
 377     }
 378 
 379     // REMIND: remove when filtering is done at lower level
 380     boolean eventEnabled(AWTEvent e) {
 381         return false;
 382     }
 383     /**
 384      * Processes events occurring on this menu component.
 385      * <p>Note that if the event parameter is <code>null</code>
 386      * the behavior is unspecified and may result in an
 387      * exception.
 388      *
 389      * @param e the event
 390      * @since 1.1
 391      */
 392     protected void processEvent(AWTEvent e) {
 393     }
 394 
 395     /**
 396      * Returns a string representing the state of this
 397      * <code>MenuComponent</code>. This method is intended to be used
 398      * only for debugging purposes, and the content and format of the
 399      * returned string may vary between implementations. The returned
 400      * string may be empty but may not be <code>null</code>.
 401      *
 402      * @return     the parameter string of this menu component
 403      */
 404     protected String paramString() {
 405         String thisName = getName();
 406         return (thisName != null? thisName : "");
 407     }
 408 
 409     /**
 410      * Returns a representation of this menu component as a string.
 411      * @return  a string representation of this menu component
 412      */
 413     public String toString() {
 414         return getClass().getName() + "[" + paramString() + "]";
 415     }
 416 
 417     /**
 418      * Gets this component's locking object (the object that owns the thread
 419      * synchronization monitor) for AWT component-tree and layout
 420      * operations.
 421      * @return this component's locking object
 422      */
 423     protected final Object getTreeLock() {
 424         return Component.LOCK;
 425     }
 426 
 427     /**
 428      * Reads the menu component from an object input stream.
 429      *
 430      * @param s the <code>ObjectInputStream</code> to read
 431      * @exception HeadlessException if
 432      *   <code>GraphicsEnvironment.isHeadless</code> returns
 433      *   <code>true</code>
 434      * @serial
 435      * @see java.awt.GraphicsEnvironment#isHeadless
 436      */
 437     private void readObject(ObjectInputStream s)
 438         throws ClassNotFoundException, IOException, HeadlessException
 439     {
 440         GraphicsEnvironment.checkHeadless();
 441 
 442         acc = AccessController.getContext();
 443 
 444         s.defaultReadObject();
 445 
 446         appContext = AppContext.getAppContext();
 447     }
 448 
 449     /**
 450      * Initialize JNI field and method IDs.
 451      */
 452     private static native void initIDs();
 453 
 454 
 455     /*
 456      * --- Accessibility Support ---
 457      *
 458      *  MenuComponent will contain all of the methods in interface Accessible,
 459      *  though it won't actually implement the interface - that will be up
 460      *  to the individual objects which extend MenuComponent.
 461      */
 462 
 463     AccessibleContext accessibleContext = null;
 464 
 465     /**
 466      * Gets the <code>AccessibleContext</code> associated with
 467      * this <code>MenuComponent</code>.
 468      *
 469      * The method implemented by this base class returns <code>null</code>.
 470      * Classes that extend <code>MenuComponent</code>
 471      * should implement this method to return the
 472      * <code>AccessibleContext</code> associated with the subclass.
 473      *
 474      * @return the <code>AccessibleContext</code> of this
 475      *     <code>MenuComponent</code>
 476      * @since 1.3
 477      */
 478     public AccessibleContext getAccessibleContext() {
 479         return accessibleContext;
 480     }
 481 
 482     /**
 483      * Inner class of <code>MenuComponent</code> used to provide
 484      * default support for accessibility.  This class is not meant
 485      * to be used directly by application developers, but is instead
 486      * meant only to be subclassed by menu component developers.
 487      * <p>
 488      * The class used to obtain the accessible role for this object.
 489      * @since 1.3
 490      */
 491     protected abstract class AccessibleAWTMenuComponent
 492         extends AccessibleContext
 493         implements java.io.Serializable, AccessibleComponent,
 494                    AccessibleSelection
 495     {
 496         /*
 497          * JDK 1.3 serialVersionUID
 498          */
 499         private static final long serialVersionUID = -4269533416223798698L;
 500 
 501         /**
 502          * Although the class is abstract, this should be called by
 503          * all sub-classes.
 504          */
 505         protected AccessibleAWTMenuComponent() {
 506         }
 507 
 508         // AccessibleContext methods
 509         //
 510 
 511         /**
 512          * Gets the <code>AccessibleSelection</code> associated with this
 513          * object which allows its <code>Accessible</code> children to be selected.
 514          *
 515          * @return <code>AccessibleSelection</code> if supported by object;
 516          *      else return <code>null</code>
 517          * @see AccessibleSelection
 518          */
 519         public AccessibleSelection getAccessibleSelection() {
 520             return this;
 521         }
 522 
 523         /**
 524          * Gets the accessible name of this object.  This should almost never
 525          * return <code>java.awt.MenuComponent.getName</code>, as that
 526          * generally isn't a localized name, and doesn't have meaning for the
 527          * user.  If the object is fundamentally a text object (e.g. a menu item), the
 528          * accessible name should be the text of the object (e.g. "save").
 529          * If the object has a tooltip, the tooltip text may also be an
 530          * appropriate String to return.
 531          *
 532          * @return the localized name of the object -- can be <code>null</code>
 533          *         if this object does not have a name
 534          * @see AccessibleContext#setAccessibleName
 535          */
 536         public String getAccessibleName() {
 537             return accessibleName;
 538         }
 539 
 540         /**
 541          * Gets the accessible description of this object.  This should be
 542          * a concise, localized description of what this object is - what
 543          * is its meaning to the user.  If the object has a tooltip, the
 544          * tooltip text may be an appropriate string to return, assuming
 545          * it contains a concise description of the object (instead of just
 546          * the name of the object - e.g. a "Save" icon on a toolbar that
 547          * had "save" as the tooltip text shouldn't return the tooltip
 548          * text as the description, but something like "Saves the current
 549          * text document" instead).
 550          *
 551          * @return the localized description of the object -- can be
 552          *     <code>null</code> if this object does not have a description
 553          * @see AccessibleContext#setAccessibleDescription
 554          */
 555         public String getAccessibleDescription() {
 556             return accessibleDescription;
 557         }
 558 
 559         /**
 560          * Gets the role of this object.
 561          *
 562          * @return an instance of <code>AccessibleRole</code>
 563          *     describing the role of the object
 564          * @see AccessibleRole
 565          */
 566         public AccessibleRole getAccessibleRole() {
 567             return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses
 568         }
 569 
 570         /**
 571          * Gets the state of this object.
 572          *
 573          * @return an instance of <code>AccessibleStateSet</code>
 574          *     containing the current state set of the object
 575          * @see AccessibleState
 576          */
 577         public AccessibleStateSet getAccessibleStateSet() {
 578             return MenuComponent.this.getAccessibleStateSet();
 579         }
 580 
 581         /**
 582          * Gets the <code>Accessible</code> parent of this object.
 583          * If the parent of this object implements <code>Accessible</code>,
 584          * this method should simply return <code>getParent</code>.
 585          *
 586          * @return the <code>Accessible</code> parent of this object -- can
 587          *    be <code>null</code> if this object does not have an
 588          *    <code>Accessible</code> parent
 589          */
 590         public Accessible getAccessibleParent() {
 591             if (accessibleParent != null) {
 592                 return accessibleParent;
 593             } else {
 594                 MenuContainer parent = MenuComponent.this.getParent();
 595                 if (parent instanceof Accessible) {
 596                     return (Accessible) parent;
 597                 }
 598             }
 599             return null;
 600         }
 601 
 602         /**
 603          * Gets the index of this object in its accessible parent.
 604          *
 605          * @return the index of this object in its parent; -1 if this
 606          *     object does not have an accessible parent
 607          * @see #getAccessibleParent
 608          */
 609         public int getAccessibleIndexInParent() {
 610             return MenuComponent.this.getAccessibleIndexInParent();
 611         }
 612 
 613         /**
 614          * Returns the number of accessible children in the object.  If all
 615          * of the children of this object implement <code>Accessible</code>,
 616          * then this method should return the number of children of this object.
 617          *
 618          * @return the number of accessible children in the object
 619          */
 620         public int getAccessibleChildrenCount() {
 621             return 0; // MenuComponents don't have children
 622         }
 623 
 624         /**
 625          * Returns the nth <code>Accessible</code> child of the object.
 626          *
 627          * @param i zero-based index of child
 628          * @return the nth Accessible child of the object
 629          */
 630         public Accessible getAccessibleChild(int i) {
 631             return null; // MenuComponents don't have children
 632         }
 633 
 634         /**
 635          * Returns the locale of this object.
 636          *
 637          * @return the locale of this object
 638          */
 639         public java.util.Locale getLocale() {
 640             MenuContainer parent = MenuComponent.this.getParent();
 641             if (parent instanceof Component)
 642                 return ((Component)parent).getLocale();
 643             else
 644                 return java.util.Locale.getDefault();
 645         }
 646 
 647         /**
 648          * Gets the <code>AccessibleComponent</code> associated with
 649          * this object if one exists.  Otherwise return <code>null</code>.
 650          *
 651          * @return the component
 652          */
 653         public AccessibleComponent getAccessibleComponent() {
 654             return this;
 655         }
 656 
 657 
 658         // AccessibleComponent methods
 659         //
 660         /**
 661          * Gets the background color of this object.
 662          *
 663          * @return the background color, if supported, of the object;
 664          *     otherwise, <code>null</code>
 665          */
 666         public Color getBackground() {
 667             return null; // Not supported for MenuComponents
 668         }
 669 
 670         /**
 671          * Sets the background color of this object.
 672          * (For transparency, see <code>isOpaque</code>.)
 673          *
 674          * @param c the new <code>Color</code> for the background
 675          * @see Component#isOpaque
 676          */
 677         public void setBackground(Color c) {
 678             // Not supported for MenuComponents
 679         }
 680 
 681         /**
 682          * Gets the foreground color of this object.
 683          *
 684          * @return the foreground color, if supported, of the object;
 685          *     otherwise, <code>null</code>
 686          */
 687         public Color getForeground() {
 688             return null; // Not supported for MenuComponents
 689         }
 690 
 691         /**
 692          * Sets the foreground color of this object.
 693          *
 694          * @param c the new <code>Color</code> for the foreground
 695          */
 696         public void setForeground(Color c) {
 697             // Not supported for MenuComponents
 698         }
 699 
 700         /**
 701          * Gets the <code>Cursor</code> of this object.
 702          *
 703          * @return the <code>Cursor</code>, if supported, of the object;
 704          *     otherwise, <code>null</code>
 705          */
 706         public Cursor getCursor() {
 707             return null; // Not supported for MenuComponents
 708         }
 709 
 710         /**
 711          * Sets the <code>Cursor</code> of this object.
 712          * <p>
 713          * The method may have no visual effect if the Java platform
 714          * implementation and/or the native system do not support
 715          * changing the mouse cursor shape.
 716          * @param cursor the new <code>Cursor</code> for the object
 717          */
 718         public void setCursor(Cursor cursor) {
 719             // Not supported for MenuComponents
 720         }
 721 
 722         /**
 723          * Gets the <code>Font</code> of this object.
 724          *
 725          * @return the <code>Font</code>,if supported, for the object;
 726          *     otherwise, <code>null</code>
 727          */
 728         public Font getFont() {
 729             return MenuComponent.this.getFont();
 730         }
 731 
 732         /**
 733          * Sets the <code>Font</code> of this object.
 734          *
 735          * @param f the new <code>Font</code> for the object
 736          */
 737         public void setFont(Font f) {
 738             MenuComponent.this.setFont(f);
 739         }
 740 
 741         /**
 742          * Gets the <code>FontMetrics</code> of this object.
 743          *
 744          * @param f the <code>Font</code>
 745          * @return the FontMetrics, if supported, the object;
 746          *              otherwise, <code>null</code>
 747          * @see #getFont
 748          */
 749         public FontMetrics getFontMetrics(Font f) {
 750             return null; // Not supported for MenuComponents
 751         }
 752 
 753         /**
 754          * Determines if the object is enabled.
 755          *
 756          * @return true if object is enabled; otherwise, false
 757          */
 758         public boolean isEnabled() {
 759             return true; // Not supported for MenuComponents
 760         }
 761 
 762         /**
 763          * Sets the enabled state of the object.
 764          *
 765          * @param b if true, enables this object; otherwise, disables it
 766          */
 767         public void setEnabled(boolean b) {
 768             // Not supported for MenuComponents
 769         }
 770 
 771         /**
 772          * Determines if the object is visible.  Note: this means that the
 773          * object intends to be visible; however, it may not in fact be
 774          * showing on the screen because one of the objects that this object
 775          * is contained by is not visible.  To determine if an object is
 776          * showing on the screen, use <code>isShowing</code>.
 777          *
 778          * @return true if object is visible; otherwise, false
 779          */
 780         public boolean isVisible() {
 781             return true; // Not supported for MenuComponents
 782         }
 783 
 784         /**
 785          * Sets the visible state of the object.
 786          *
 787          * @param b if true, shows this object; otherwise, hides it
 788          */
 789         public void setVisible(boolean b) {
 790             // Not supported for MenuComponents
 791         }
 792 
 793         /**
 794          * Determines if the object is showing.  This is determined by checking
 795          * the visibility of the object and ancestors of the object.  Note:
 796          * this will return true even if the object is obscured by another
 797          * (for example, it happens to be underneath a menu that was pulled
 798          * down).
 799          *
 800          * @return true if object is showing; otherwise, false
 801          */
 802         public boolean isShowing() {
 803             return true; // Not supported for MenuComponents
 804         }
 805 
 806         /**
 807          * Checks whether the specified point is within this object's bounds,
 808          * where the point's x and y coordinates are defined to be relative to
 809          * the coordinate system of the object.
 810          *
 811          * @param p the <code>Point</code> relative to the coordinate
 812          *     system of the object
 813          * @return true if object contains <code>Point</code>; otherwise false
 814          */
 815         public boolean contains(Point p) {
 816             return false; // Not supported for MenuComponents
 817         }
 818 
 819         /**
 820          * Returns the location of the object on the screen.
 821          *
 822          * @return location of object on screen -- can be <code>null</code>
 823          *     if this object is not on the screen
 824          */
 825         public Point getLocationOnScreen() {
 826             return null; // Not supported for MenuComponents
 827         }
 828 
 829         /**
 830          * Gets the location of the object relative to the parent in the form
 831          * of a point specifying the object's top-left corner in the screen's
 832          * coordinate space.
 833          *
 834          * @return an instance of <code>Point</code> representing the
 835          *    top-left corner of the object's bounds in the coordinate
 836          *    space of the screen; <code>null</code> if
 837          *    this object or its parent are not on the screen
 838          */
 839         public Point getLocation() {
 840             return null; // Not supported for MenuComponents
 841         }
 842 
 843         /**
 844          * Sets the location of the object relative to the parent.
 845          */
 846         public void setLocation(Point p) {
 847             // Not supported for MenuComponents
 848         }
 849 
 850         /**
 851          * Gets the bounds of this object in the form of a
 852          * <code>Rectangle</code> object.
 853          * The bounds specify this object's width, height, and location
 854          * relative to its parent.
 855          *
 856          * @return a rectangle indicating this component's bounds;
 857          *     <code>null</code> if this object is not on the screen
 858          */
 859         public Rectangle getBounds() {
 860             return null; // Not supported for MenuComponents
 861         }
 862 
 863         /**
 864          * Sets the bounds of this object in the form of a
 865          * <code>Rectangle</code> object.
 866          * The bounds specify this object's width, height, and location
 867          * relative to its parent.
 868          *
 869          * @param r a rectangle indicating this component's bounds
 870          */
 871         public void setBounds(Rectangle r) {
 872             // Not supported for MenuComponents
 873         }
 874 
 875         /**
 876          * Returns the size of this object in the form of a
 877          * <code>Dimension</code> object. The height field of
 878          * the <code>Dimension</code> object contains this object's
 879          * height, and the width field of the <code>Dimension</code>
 880          * object contains this object's width.
 881          *
 882          * @return a <code>Dimension</code> object that indicates the
 883          *         size of this component; <code>null</code>
 884          *         if this object is not on the screen
 885          */
 886         public Dimension getSize() {
 887             return null; // Not supported for MenuComponents
 888         }
 889 
 890         /**
 891          * Resizes this object.
 892          *
 893          * @param d - the <code>Dimension</code> specifying the
 894          *    new size of the object
 895          */
 896         public void setSize(Dimension d) {
 897             // Not supported for MenuComponents
 898         }
 899 
 900         /**
 901          * Returns the <code>Accessible</code> child, if one exists,
 902          * contained at the local coordinate <code>Point</code>.
 903          * If there is no <code>Accessible</code> child, <code>null</code>
 904          * is returned.
 905          *
 906          * @param p the point defining the top-left corner of the
 907          *    <code>Accessible</code>, given in the coordinate space
 908          *    of the object's parent
 909          * @return the <code>Accessible</code>, if it exists,
 910          *    at the specified location; else <code>null</code>
 911          */
 912         public Accessible getAccessibleAt(Point p) {
 913             return null; // MenuComponents don't have children
 914         }
 915 
 916         /**
 917          * Returns whether this object can accept focus or not.
 918          *
 919          * @return true if object can accept focus; otherwise false
 920          */
 921         public boolean isFocusTraversable() {
 922             return true; // Not supported for MenuComponents
 923         }
 924 
 925         /**
 926          * Requests focus for this object.
 927          */
 928         public void requestFocus() {
 929             // Not supported for MenuComponents
 930         }
 931 
 932         /**
 933          * Adds the specified focus listener to receive focus events from this
 934          * component.
 935          *
 936          * @param l the focus listener
 937          */
 938         public void addFocusListener(java.awt.event.FocusListener l) {
 939             // Not supported for MenuComponents
 940         }
 941 
 942         /**
 943          * Removes the specified focus listener so it no longer receives focus
 944          * events from this component.
 945          *
 946          * @param l the focus listener
 947          */
 948         public void removeFocusListener(java.awt.event.FocusListener l) {
 949             // Not supported for MenuComponents
 950         }
 951 
 952         // AccessibleSelection methods
 953         //
 954 
 955         /**
 956          * Returns the number of <code>Accessible</code> children currently selected.
 957          * If no children are selected, the return value will be 0.
 958          *
 959          * @return the number of items currently selected
 960          */
 961          public int getAccessibleSelectionCount() {
 962              return 0;  //  To be fully implemented in a future release
 963          }
 964 
 965         /**
 966          * Returns an <code>Accessible</code> representing the specified
 967          * selected child in the object.  If there isn't a selection, or there are
 968          * fewer children selected than the integer passed in, the return
 969          * value will be <code>null</code>.
 970          * <p>Note that the index represents the i-th selected child, which
 971          * is different from the i-th child.
 972          *
 973          * @param i the zero-based index of selected children
 974          * @return the i-th selected child
 975          * @see #getAccessibleSelectionCount
 976          */
 977          public Accessible getAccessibleSelection(int i) {
 978              return null;  //  To be fully implemented in a future release
 979          }
 980 
 981         /**
 982          * Determines if the current child of this object is selected.
 983          *
 984          * @return true if the current child of this object is selected;
 985          *    else false
 986          * @param i the zero-based index of the child in this
 987          *      <code>Accessible</code> object
 988          * @see AccessibleContext#getAccessibleChild
 989          */
 990          public boolean isAccessibleChildSelected(int i) {
 991              return false;  //  To be fully implemented in a future release
 992          }
 993 
 994         /**
 995          * Adds the specified <code>Accessible</code> child of the object
 996          * to the object's selection.  If the object supports multiple selections,
 997          * the specified child is added to any existing selection, otherwise
 998          * it replaces any existing selection in the object.  If the
 999          * specified child is already selected, this method has no effect.
1000          *
1001          * @param i the zero-based index of the child
1002          * @see AccessibleContext#getAccessibleChild
1003          */
1004          public void addAccessibleSelection(int i) {
1005                //  To be fully implemented in a future release
1006          }
1007 
1008         /**
1009          * Removes the specified child of the object from the object's
1010          * selection.  If the specified item isn't currently selected, this
1011          * method has no effect.
1012          *
1013          * @param i the zero-based index of the child
1014          * @see AccessibleContext#getAccessibleChild
1015          */
1016          public void removeAccessibleSelection(int i) {
1017                //  To be fully implemented in a future release
1018          }
1019 
1020         /**
1021          * Clears the selection in the object, so that no children in the
1022          * object are selected.
1023          */
1024          public void clearAccessibleSelection() {
1025                //  To be fully implemented in a future release
1026          }
1027 
1028         /**
1029          * Causes every child of the object to be selected
1030          * if the object supports multiple selections.
1031          */
1032          public void selectAllAccessibleSelection() {
1033                //  To be fully implemented in a future release
1034          }
1035 
1036     } // inner class AccessibleAWTComponent
1037 
1038     /**
1039      * Gets the index of this object in its accessible parent.
1040      *
1041      * @return -1 if this object does not have an accessible parent;
1042      *      otherwise, the index of the child in its accessible parent.
1043      */
1044     int getAccessibleIndexInParent() {
1045         MenuContainer localParent = parent;
1046         if (!(localParent instanceof MenuComponent)) {
1047             // MenuComponents only have accessible index when inside MenuComponents
1048             return -1;
1049         }
1050         MenuComponent localParentMenu = (MenuComponent)localParent;
1051         return localParentMenu.getAccessibleChildIndex(this);
1052     }
1053 
1054     /**
1055      * Gets the index of the child within this MenuComponent.
1056      *
1057      * @param child MenuComponent whose index we are interested in.
1058      * @return -1 if this object doesn't contain the child,
1059      *      otherwise, index of the child.
1060      */
1061     int getAccessibleChildIndex(MenuComponent child) {
1062         return -1; // Overridden in subclasses.
1063     }
1064 
1065     /**
1066      * Gets the state of this object.
1067      *
1068      * @return an instance of <code>AccessibleStateSet</code>
1069      *     containing the current state set of the object
1070      * @see AccessibleState
1071      */
1072     AccessibleStateSet getAccessibleStateSet() {
1073         AccessibleStateSet states = new AccessibleStateSet();
1074         return states;
1075     }
1076 
1077 }