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