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