1 /*
   2  * Copyright (c) 1995, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 package java.awt;
  26 
  27 import java.awt.peer.MenuComponentPeer;
  28 import java.awt.event.ActionEvent;
  29 import java.io.IOException;
  30 import java.io.ObjectInputStream;
  31 import sun.awt.AppContext;
  32 import sun.awt.AWTAccessor;


  33 import 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 volatile 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                 @SuppressWarnings("unchecked")
 146                 public <T extends MenuComponentPeer> T getPeer(MenuComponent menuComp) {
 147                     return (T) menuComp.peer;
 148                 }
 149                 @Override
 150                 public MenuContainer getParent(MenuComponent menuComp) {
 151                     return menuComp.parent;
 152                 }
 153                 @Override
 154                 public void setParent(MenuComponent menuComp, MenuContainer menuContainer) {
 155                     menuComp.parent = menuContainer;
 156                 }
 157                 @Override
 158                 public Font getFont_NoClientCode(MenuComponent menuComp) {
 159                     return menuComp.getFont_NoClientCode();
 160                 }
 161             });
 162     }
 163 
 164     /**
 165      * Creates a <code>MenuComponent</code>.
 166      * @exception HeadlessException if
 167      *    <code>GraphicsEnvironment.isHeadless</code>
 168      *    returns <code>true</code>
 169      * @see java.awt.GraphicsEnvironment#isHeadless
 170      */
 171     public MenuComponent() throws HeadlessException {
 172         GraphicsEnvironment.checkHeadless();
 173         appContext = AppContext.getAppContext();
 174     }
 175 
 176     /**
 177      * Constructs a name for this <code>MenuComponent</code>.
 178      * Called by <code>getName</code> when the name is <code>null</code>.
 179      * @return a name for this <code>MenuComponent</code>
 180      */
 181     String constructComponentName() {
 182         return null; // For strict compliance with prior platform versions, a MenuComponent
 183                      // that doesn't set its name should return null from
 184                      // getName()
 185     }
 186 








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