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      * @return unconditionally returns false
 332      * @deprecated As of JDK version 1.1, replaced by {@link
 333      * #dispatchEvent(AWTEvent) dispatchEvent}.
 334      */
 335     @Deprecated
 336     public boolean postEvent(Event evt) {
 337         MenuContainer parent = this.parent;
 338         if (parent != null) {
 339             parent.postEvent(evt);
 340         }
 341         return false;
 342     }
 343 
 344     /**
 345      * Delivers an event to this component or one of its sub components.
 346      * @param e the event
 347      */
 348     public final void dispatchEvent(AWTEvent e) {
 349         dispatchEventImpl(e);
 350     }
 351 
 352     void dispatchEventImpl(AWTEvent e) {
 353         EventQueue.setCurrentEventAndMostRecentTime(e);
 354 
 355         Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
 356 
 357         if (newEventsOnly ||
 358             (parent != null && parent instanceof MenuComponent &&
 359              ((MenuComponent)parent).newEventsOnly)) {
 360             if (eventEnabled(e)) {
 361                 processEvent(e);
 362             } else if (e instanceof ActionEvent && parent != null) {
 363                 e.setSource(parent);
 364                 ((MenuComponent)parent).dispatchEvent(e);
 365             }
 366 
 367         } else { // backward compatibility
 368             Event olde = e.convertToOld();
 369             if (olde != null) {
 370                 postEvent(olde);
 371             }
 372         }
 373     }
 374 
 375     // REMIND: remove when filtering is done at lower level
 376     boolean eventEnabled(AWTEvent e) {
 377         return false;
 378     }
 379     /**
 380      * Processes events occurring on this menu component.
 381      * <p>Note that if the event parameter is <code>null</code>
 382      * the behavior is unspecified and may result in an
 383      * exception.
 384      *
 385      * @param e the event
 386      * @since 1.1
 387      */
 388     protected void processEvent(AWTEvent e) {
 389     }
 390 
 391     /**
 392      * Returns a string representing the state of this
 393      * <code>MenuComponent</code>. This method is intended to be used
 394      * only for debugging purposes, and the content and format of the
 395      * returned string may vary between implementations. The returned
 396      * string may be empty but may not be <code>null</code>.
 397      *
 398      * @return     the parameter string of this menu component
 399      */
 400     protected String paramString() {
 401         String thisName = getName();
 402         return (thisName != null? thisName : "");
 403     }
 404 
 405     /**
 406      * Returns a representation of this menu component as a string.
 407      * @return  a string representation of this menu component
 408      */
 409     public String toString() {
 410         return getClass().getName() + "[" + paramString() + "]";
 411     }
 412 
 413     /**
 414      * Gets this component's locking object (the object that owns the thread
 415      * synchronization monitor) for AWT component-tree and layout
 416      * operations.
 417      * @return this component's locking object
 418      */
 419     protected final Object getTreeLock() {
 420         return Component.LOCK;
 421     }
 422 
 423     /**
 424      * Reads the menu component from an object input stream.
 425      *
 426      * @param s the <code>ObjectInputStream</code> to read
 427      * @exception HeadlessException if
 428      *   <code>GraphicsEnvironment.isHeadless</code> returns
 429      *   <code>true</code>
 430      * @serial
 431      * @see java.awt.GraphicsEnvironment#isHeadless
 432      */
 433     private void readObject(ObjectInputStream s)
 434         throws ClassNotFoundException, IOException, HeadlessException
 435     {
 436         GraphicsEnvironment.checkHeadless();
 437 
 438         acc = AccessController.getContext();
 439 
 440         s.defaultReadObject();
 441 
 442         appContext = AppContext.getAppContext();
 443     }
 444 
 445     /**
 446      * Initialize JNI field and method IDs.
 447      */
 448     private static native void initIDs();
 449 
 450 
 451     /*
 452      * --- Accessibility Support ---
 453      *
 454      *  MenuComponent will contain all of the methods in interface Accessible,
 455      *  though it won't actually implement the interface - that will be up
 456      *  to the individual objects which extend MenuComponent.
 457      */
 458 
 459     AccessibleContext accessibleContext = null;
 460 
 461     /**
 462      * Gets the <code>AccessibleContext</code> associated with
 463      * this <code>MenuComponent</code>.
 464      *
 465      * The method implemented by this base class returns <code>null</code>.
 466      * Classes that extend <code>MenuComponent</code>
 467      * should implement this method to return the
 468      * <code>AccessibleContext</code> associated with the subclass.
 469      *
 470      * @return the <code>AccessibleContext</code> of this
 471      *     <code>MenuComponent</code>
 472      * @since 1.3
 473      */
 474     public AccessibleContext getAccessibleContext() {
 475         return accessibleContext;
 476     }
 477 
 478     /**
 479      * Inner class of <code>MenuComponent</code> used to provide
 480      * default support for accessibility.  This class is not meant
 481      * to be used directly by application developers, but is instead
 482      * meant only to be subclassed by menu component developers.
 483      * <p>
 484      * The class used to obtain the accessible role for this object.
 485      * @since 1.3
 486      */
 487     protected abstract class AccessibleAWTMenuComponent
 488         extends AccessibleContext
 489         implements java.io.Serializable, AccessibleComponent,
 490                    AccessibleSelection
 491     {
 492         /*
 493          * JDK 1.3 serialVersionUID
 494          */
 495         private static final long serialVersionUID = -4269533416223798698L;
 496 
 497         /**
 498          * Although the class is abstract, this should be called by
 499          * all sub-classes.
 500          */
 501         protected AccessibleAWTMenuComponent() {
 502         }
 503 
 504         // AccessibleContext methods
 505         //
 506 
 507         /**
 508          * Gets the <code>AccessibleSelection</code> associated with this
 509          * object which allows its <code>Accessible</code> children to be selected.
 510          *
 511          * @return <code>AccessibleSelection</code> if supported by object;
 512          *      else return <code>null</code>
 513          * @see AccessibleSelection
 514          */
 515         public AccessibleSelection getAccessibleSelection() {
 516             return this;
 517         }
 518 
 519         /**
 520          * Gets the accessible name of this object.  This should almost never
 521          * return <code>java.awt.MenuComponent.getName</code>, as that
 522          * generally isn't a localized name, and doesn't have meaning for the
 523          * user.  If the object is fundamentally a text object (e.g. a menu item), the
 524          * accessible name should be the text of the object (e.g. "save").
 525          * If the object has a tooltip, the tooltip text may also be an
 526          * appropriate String to return.
 527          *
 528          * @return the localized name of the object -- can be <code>null</code>
 529          *         if this object does not have a name
 530          * @see AccessibleContext#setAccessibleName
 531          */
 532         public String getAccessibleName() {
 533             return accessibleName;
 534         }
 535 
 536         /**
 537          * Gets the accessible description of this object.  This should be
 538          * a concise, localized description of what this object is - what
 539          * is its meaning to the user.  If the object has a tooltip, the
 540          * tooltip text may be an appropriate string to return, assuming
 541          * it contains a concise description of the object (instead of just
 542          * the name of the object - e.g. a "Save" icon on a toolbar that
 543          * had "save" as the tooltip text shouldn't return the tooltip
 544          * text as the description, but something like "Saves the current
 545          * text document" instead).
 546          *
 547          * @return the localized description of the object -- can be
 548          *     <code>null</code> if this object does not have a description
 549          * @see AccessibleContext#setAccessibleDescription
 550          */
 551         public String getAccessibleDescription() {
 552             return accessibleDescription;
 553         }
 554 
 555         /**
 556          * Gets the role of this object.
 557          *
 558          * @return an instance of <code>AccessibleRole</code>
 559          *     describing the role of the object
 560          * @see AccessibleRole
 561          */
 562         public AccessibleRole getAccessibleRole() {
 563             return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses
 564         }
 565 
 566         /**
 567          * Gets the state of this object.
 568          *
 569          * @return an instance of <code>AccessibleStateSet</code>
 570          *     containing the current state set of the object
 571          * @see AccessibleState
 572          */
 573         public AccessibleStateSet getAccessibleStateSet() {
 574             return MenuComponent.this.getAccessibleStateSet();
 575         }
 576 
 577         /**
 578          * Gets the <code>Accessible</code> parent of this object.
 579          * If the parent of this object implements <code>Accessible</code>,
 580          * this method should simply return <code>getParent</code>.
 581          *
 582          * @return the <code>Accessible</code> parent of this object -- can
 583          *    be <code>null</code> if this object does not have an
 584          *    <code>Accessible</code> parent
 585          */
 586         public Accessible getAccessibleParent() {
 587             if (accessibleParent != null) {
 588                 return accessibleParent;
 589             } else {
 590                 MenuContainer parent = MenuComponent.this.getParent();
 591                 if (parent instanceof Accessible) {
 592                     return (Accessible) parent;
 593                 }
 594             }
 595             return null;
 596         }
 597 
 598         /**
 599          * Gets the index of this object in its accessible parent.
 600          *
 601          * @return the index of this object in its parent; -1 if this
 602          *     object does not have an accessible parent
 603          * @see #getAccessibleParent
 604          */
 605         public int getAccessibleIndexInParent() {
 606             return MenuComponent.this.getAccessibleIndexInParent();
 607         }
 608 
 609         /**
 610          * Returns the number of accessible children in the object.  If all
 611          * of the children of this object implement <code>Accessible</code>,
 612          * then this method should return the number of children of this object.
 613          *
 614          * @return the number of accessible children in the object
 615          */
 616         public int getAccessibleChildrenCount() {
 617             return 0; // MenuComponents don't have children
 618         }
 619 
 620         /**
 621          * Returns the nth <code>Accessible</code> child of the object.
 622          *
 623          * @param i zero-based index of child
 624          * @return the nth Accessible child of the object
 625          */
 626         public Accessible getAccessibleChild(int i) {
 627             return null; // MenuComponents don't have children
 628         }
 629 
 630         /**
 631          * Returns the locale of this object.
 632          *
 633          * @return the locale of this object
 634          */
 635         public java.util.Locale getLocale() {
 636             MenuContainer parent = MenuComponent.this.getParent();
 637             if (parent instanceof Component)
 638                 return ((Component)parent).getLocale();
 639             else
 640                 return java.util.Locale.getDefault();
 641         }
 642 
 643         /**
 644          * Gets the <code>AccessibleComponent</code> associated with
 645          * this object if one exists.  Otherwise return <code>null</code>.
 646          *
 647          * @return the component
 648          */
 649         public AccessibleComponent getAccessibleComponent() {
 650             return this;
 651         }
 652 
 653 
 654         // AccessibleComponent methods
 655         //
 656         /**
 657          * Gets the background color of this object.
 658          *
 659          * @return the background color, if supported, of the object;
 660          *     otherwise, <code>null</code>
 661          */
 662         public Color getBackground() {
 663             return null; // Not supported for MenuComponents
 664         }
 665 
 666         /**
 667          * Sets the background color of this object.
 668          * (For transparency, see <code>isOpaque</code>.)
 669          *
 670          * @param c the new <code>Color</code> for the background
 671          * @see Component#isOpaque
 672          */
 673         public void setBackground(Color c) {
 674             // Not supported for MenuComponents
 675         }
 676 
 677         /**
 678          * Gets the foreground color of this object.
 679          *
 680          * @return the foreground color, if supported, of the object;
 681          *     otherwise, <code>null</code>
 682          */
 683         public Color getForeground() {
 684             return null; // Not supported for MenuComponents
 685         }
 686 
 687         /**
 688          * Sets the foreground color of this object.
 689          *
 690          * @param c the new <code>Color</code> for the foreground
 691          */
 692         public void setForeground(Color c) {
 693             // Not supported for MenuComponents
 694         }
 695 
 696         /**
 697          * Gets the <code>Cursor</code> of this object.
 698          *
 699          * @return the <code>Cursor</code>, if supported, of the object;
 700          *     otherwise, <code>null</code>
 701          */
 702         public Cursor getCursor() {
 703             return null; // Not supported for MenuComponents
 704         }
 705 
 706         /**
 707          * Sets the <code>Cursor</code> of this object.
 708          * <p>
 709          * The method may have no visual effect if the Java platform
 710          * implementation and/or the native system do not support
 711          * changing the mouse cursor shape.
 712          * @param cursor the new <code>Cursor</code> for the object
 713          */
 714         public void setCursor(Cursor cursor) {
 715             // Not supported for MenuComponents
 716         }
 717 
 718         /**
 719          * Gets the <code>Font</code> of this object.
 720          *
 721          * @return the <code>Font</code>,if supported, for the object;
 722          *     otherwise, <code>null</code>
 723          */
 724         public Font getFont() {
 725             return MenuComponent.this.getFont();
 726         }
 727 
 728         /**
 729          * Sets the <code>Font</code> of this object.
 730          *
 731          * @param f the new <code>Font</code> for the object
 732          */
 733         public void setFont(Font f) {
 734             MenuComponent.this.setFont(f);
 735         }
 736 
 737         /**
 738          * Gets the <code>FontMetrics</code> of this object.
 739          *
 740          * @param f the <code>Font</code>
 741          * @return the FontMetrics, if supported, the object;
 742          *              otherwise, <code>null</code>
 743          * @see #getFont
 744          */
 745         public FontMetrics getFontMetrics(Font f) {
 746             return null; // Not supported for MenuComponents
 747         }
 748 
 749         /**
 750          * Determines if the object is enabled.
 751          *
 752          * @return true if object is enabled; otherwise, false
 753          */
 754         public boolean isEnabled() {
 755             return true; // Not supported for MenuComponents
 756         }
 757 
 758         /**
 759          * Sets the enabled state of the object.
 760          *
 761          * @param b if true, enables this object; otherwise, disables it
 762          */
 763         public void setEnabled(boolean b) {
 764             // Not supported for MenuComponents
 765         }
 766 
 767         /**
 768          * Determines if the object is visible.  Note: this means that the
 769          * object intends to be visible; however, it may not in fact be
 770          * showing on the screen because one of the objects that this object
 771          * is contained by is not visible.  To determine if an object is
 772          * showing on the screen, use <code>isShowing</code>.
 773          *
 774          * @return true if object is visible; otherwise, false
 775          */
 776         public boolean isVisible() {
 777             return true; // Not supported for MenuComponents
 778         }
 779 
 780         /**
 781          * Sets the visible state of the object.
 782          *
 783          * @param b if true, shows this object; otherwise, hides it
 784          */
 785         public void setVisible(boolean b) {
 786             // Not supported for MenuComponents
 787         }
 788 
 789         /**
 790          * Determines if the object is showing.  This is determined by checking
 791          * the visibility of the object and ancestors of the object.  Note:
 792          * this will return true even if the object is obscured by another
 793          * (for example, it happens to be underneath a menu that was pulled
 794          * down).
 795          *
 796          * @return true if object is showing; otherwise, false
 797          */
 798         public boolean isShowing() {
 799             return true; // Not supported for MenuComponents
 800         }
 801 
 802         /**
 803          * Checks whether the specified point is within this object's bounds,
 804          * where the point's x and y coordinates are defined to be relative to
 805          * the coordinate system of the object.
 806          *
 807          * @param p the <code>Point</code> relative to the coordinate
 808          *     system of the object
 809          * @return true if object contains <code>Point</code>; otherwise false
 810          */
 811         public boolean contains(Point p) {
 812             return false; // Not supported for MenuComponents
 813         }
 814 
 815         /**
 816          * Returns the location of the object on the screen.
 817          *
 818          * @return location of object on screen -- can be <code>null</code>
 819          *     if this object is not on the screen
 820          */
 821         public Point getLocationOnScreen() {
 822             return null; // Not supported for MenuComponents
 823         }
 824 
 825         /**
 826          * Gets the location of the object relative to the parent in the form
 827          * of a point specifying the object's top-left corner in the screen's
 828          * coordinate space.
 829          *
 830          * @return an instance of <code>Point</code> representing the
 831          *    top-left corner of the object's bounds in the coordinate
 832          *    space of the screen; <code>null</code> if
 833          *    this object or its parent are not on the screen
 834          */
 835         public Point getLocation() {
 836             return null; // Not supported for MenuComponents
 837         }
 838 
 839         /**
 840          * Sets the location of the object relative to the parent.
 841          */
 842         public void setLocation(Point p) {
 843             // Not supported for MenuComponents
 844         }
 845 
 846         /**
 847          * Gets the bounds of this object in the form of a
 848          * <code>Rectangle</code> object.
 849          * The bounds specify this object's width, height, and location
 850          * relative to its parent.
 851          *
 852          * @return a rectangle indicating this component's bounds;
 853          *     <code>null</code> if this object is not on the screen
 854          */
 855         public Rectangle getBounds() {
 856             return null; // Not supported for MenuComponents
 857         }
 858 
 859         /**
 860          * Sets the bounds of this object in the form of a
 861          * <code>Rectangle</code> object.
 862          * The bounds specify this object's width, height, and location
 863          * relative to its parent.
 864          *
 865          * @param r a rectangle indicating this component's bounds
 866          */
 867         public void setBounds(Rectangle r) {
 868             // Not supported for MenuComponents
 869         }
 870 
 871         /**
 872          * Returns the size of this object in the form of a
 873          * <code>Dimension</code> object. The height field of
 874          * the <code>Dimension</code> object contains this object's
 875          * height, and the width field of the <code>Dimension</code>
 876          * object contains this object's width.
 877          *
 878          * @return a <code>Dimension</code> object that indicates the
 879          *         size of this component; <code>null</code>
 880          *         if this object is not on the screen
 881          */
 882         public Dimension getSize() {
 883             return null; // Not supported for MenuComponents
 884         }
 885 
 886         /**
 887          * Resizes this object.
 888          *
 889          * @param d - the <code>Dimension</code> specifying the
 890          *    new size of the object
 891          */
 892         public void setSize(Dimension d) {
 893             // Not supported for MenuComponents
 894         }
 895 
 896         /**
 897          * Returns the <code>Accessible</code> child, if one exists,
 898          * contained at the local coordinate <code>Point</code>.
 899          * If there is no <code>Accessible</code> child, <code>null</code>
 900          * is returned.
 901          *
 902          * @param p the point defining the top-left corner of the
 903          *    <code>Accessible</code>, given in the coordinate space
 904          *    of the object's parent
 905          * @return the <code>Accessible</code>, if it exists,
 906          *    at the specified location; else <code>null</code>
 907          */
 908         public Accessible getAccessibleAt(Point p) {
 909             return null; // MenuComponents don't have children
 910         }
 911 
 912         /**
 913          * Returns whether this object can accept focus or not.
 914          *
 915          * @return true if object can accept focus; otherwise false
 916          */
 917         public boolean isFocusTraversable() {
 918             return true; // Not supported for MenuComponents
 919         }
 920 
 921         /**
 922          * Requests focus for this object.
 923          */
 924         public void requestFocus() {
 925             // Not supported for MenuComponents
 926         }
 927 
 928         /**
 929          * Adds the specified focus listener to receive focus events from this
 930          * component.
 931          *
 932          * @param l the focus listener
 933          */
 934         public void addFocusListener(java.awt.event.FocusListener l) {
 935             // Not supported for MenuComponents
 936         }
 937 
 938         /**
 939          * Removes the specified focus listener so it no longer receives focus
 940          * events from this component.
 941          *
 942          * @param l the focus listener
 943          */
 944         public void removeFocusListener(java.awt.event.FocusListener l) {
 945             // Not supported for MenuComponents
 946         }
 947 
 948         // AccessibleSelection methods
 949         //
 950 
 951         /**
 952          * Returns the number of <code>Accessible</code> children currently selected.
 953          * If no children are selected, the return value will be 0.
 954          *
 955          * @return the number of items currently selected
 956          */
 957          public int getAccessibleSelectionCount() {
 958              return 0;  //  To be fully implemented in a future release
 959          }
 960 
 961         /**
 962          * Returns an <code>Accessible</code> representing the specified
 963          * selected child in the object.  If there isn't a selection, or there are
 964          * fewer children selected than the integer passed in, the return
 965          * value will be <code>null</code>.
 966          * <p>Note that the index represents the i-th selected child, which
 967          * is different from the i-th child.
 968          *
 969          * @param i the zero-based index of selected children
 970          * @return the i-th selected child
 971          * @see #getAccessibleSelectionCount
 972          */
 973          public Accessible getAccessibleSelection(int i) {
 974              return null;  //  To be fully implemented in a future release
 975          }
 976 
 977         /**
 978          * Determines if the current child of this object is selected.
 979          *
 980          * @return true if the current child of this object is selected;
 981          *    else false
 982          * @param i the zero-based index of the child in this
 983          *      <code>Accessible</code> object
 984          * @see AccessibleContext#getAccessibleChild
 985          */
 986          public boolean isAccessibleChildSelected(int i) {
 987              return false;  //  To be fully implemented in a future release
 988          }
 989 
 990         /**
 991          * Adds the specified <code>Accessible</code> child of the object
 992          * to the object's selection.  If the object supports multiple selections,
 993          * the specified child is added to any existing selection, otherwise
 994          * it replaces any existing selection in the object.  If the
 995          * specified child is already selected, this method has no effect.
 996          *
 997          * @param i the zero-based index of the child
 998          * @see AccessibleContext#getAccessibleChild
 999          */
1000          public void addAccessibleSelection(int i) {
1001                //  To be fully implemented in a future release
1002          }
1003 
1004         /**
1005          * Removes the specified child of the object from the object's
1006          * selection.  If the specified item isn't currently selected, this
1007          * method has no effect.
1008          *
1009          * @param i the zero-based index of the child
1010          * @see AccessibleContext#getAccessibleChild
1011          */
1012          public void removeAccessibleSelection(int i) {
1013                //  To be fully implemented in a future release
1014          }
1015 
1016         /**
1017          * Clears the selection in the object, so that no children in the
1018          * object are selected.
1019          */
1020          public void clearAccessibleSelection() {
1021                //  To be fully implemented in a future release
1022          }
1023 
1024         /**
1025          * Causes every child of the object to be selected
1026          * if the object supports multiple selections.
1027          */
1028          public void selectAllAccessibleSelection() {
1029                //  To be fully implemented in a future release
1030          }
1031 
1032     } // inner class AccessibleAWTComponent
1033 
1034     /**
1035      * Gets the index of this object in its accessible parent.
1036      *
1037      * @return -1 if this object does not have an accessible parent;
1038      *      otherwise, the index of the child in its accessible parent.
1039      */
1040     int getAccessibleIndexInParent() {
1041         MenuContainer localParent = parent;
1042         if (!(localParent instanceof MenuComponent)) {
1043             // MenuComponents only have accessible index when inside MenuComponents
1044             return -1;
1045         }
1046         MenuComponent localParentMenu = (MenuComponent)localParent;
1047         return localParentMenu.getAccessibleChildIndex(this);
1048     }
1049 
1050     /**
1051      * Gets the index of the child within this MenuComponent.
1052      *
1053      * @param child MenuComponent whose index we are interested in.
1054      * @return -1 if this object doesn't contain the child,
1055      *      otherwise, index of the child.
1056      */
1057     int getAccessibleChildIndex(MenuComponent child) {
1058         return -1; // Overridden in subclasses.
1059     }
1060 
1061     /**
1062      * Gets the state of this object.
1063      *
1064      * @return an instance of <code>AccessibleStateSet</code>
1065      *     containing the current state set of the object
1066      * @see AccessibleState
1067      */
1068     AccessibleStateSet getAccessibleStateSet() {
1069         AccessibleStateSet states = new AccessibleStateSet();
1070         return states;
1071     }
1072 
1073 }