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