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