1. /*
  2. * @(#)MenuComponent.java 1.77 04/05/18
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.peer.MenuComponentPeer;
  9. import java.awt.event.ActionEvent;
  10. import java.io.IOException;
  11. import java.io.ObjectInputStream;
  12. import sun.awt.AppContext;
  13. import sun.awt.SunToolkit;
  14. import javax.accessibility.*;
  15. /**
  16. * The abstract class <code>MenuComponent</code> is the superclass
  17. * of all menu-related components. In this respect, the class
  18. * <code>MenuComponent</code> is analogous to the abstract superclass
  19. * <code>Component</code> for AWT components.
  20. * <p>
  21. * Menu components receive and process AWT events, just as components do,
  22. * through the method <code>processEvent</code>.
  23. *
  24. * @version 1.77, 05/18/04
  25. * @author Arthur van Hoff
  26. * @since JDK1.0
  27. */
  28. public abstract class MenuComponent implements java.io.Serializable {
  29. static {
  30. /* ensure that the necessary native libraries are loaded */
  31. Toolkit.loadLibraries();
  32. if (!GraphicsEnvironment.isHeadless()) {
  33. initIDs();
  34. }
  35. }
  36. transient MenuComponentPeer peer;
  37. transient MenuContainer parent;
  38. /**
  39. * The <code>AppContext</code> of the <code>MenuComponent</code>.
  40. * This is set in the constructor and never changes.
  41. */
  42. transient AppContext appContext;
  43. /**
  44. * The menu component's font. This value can be
  45. * <code>null</code> at which point a default will be used.
  46. * This defaults to <code>null</code>.
  47. *
  48. * @serial
  49. * @see #setFont(Font)
  50. * @see #getFont()
  51. */
  52. Font font;
  53. /**
  54. * The menu component's name, which defaults to <code>null</code>.
  55. * @serial
  56. * @see #getName()
  57. * @see #setName(String)
  58. */
  59. private String name;
  60. /**
  61. * A variable to indicate whether a name is explicitly set.
  62. * If <code>true</code> the name will be set explicitly.
  63. * This defaults to <code>false</code>.
  64. * @serial
  65. * @see #setName(String)
  66. */
  67. private boolean nameExplicitlySet = false;
  68. /**
  69. * Defaults to <code>false</code>.
  70. * @serial
  71. * @see #dispatchEvent(AWTEvent)
  72. */
  73. boolean newEventsOnly = false;
  74. /*
  75. * Internal constants for serialization.
  76. */
  77. final static String actionListenerK = Component.actionListenerK;
  78. final static String itemListenerK = Component.itemListenerK;
  79. /*
  80. * JDK 1.1 serialVersionUID
  81. */
  82. private static final long serialVersionUID = -4536902356223894379L;
  83. /**
  84. * This object is used as a key for internal hashtables.
  85. */
  86. transient private Object privateKey = new Object();
  87. /**
  88. * Creates a <code>MenuComponent</code>.
  89. * @exception HeadlessException if
  90. * <code>GraphicsEnvironment.isHeadless</code>
  91. * returns <code>true</code>
  92. * @see java.awt.GraphicsEnvironment#isHeadless
  93. */
  94. public MenuComponent() throws HeadlessException {
  95. GraphicsEnvironment.checkHeadless();
  96. appContext = AppContext.getAppContext();
  97. }
  98. /**
  99. * Constructs a name for this <code>MenuComponent</code>.
  100. * Called by <code>getName</code> when the name is <code>null</code>.
  101. * @return a name for this <code>MenuComponent</code>
  102. */
  103. String constructComponentName() {
  104. return null; // For strict compliance with prior platform versions, a MenuComponent
  105. // that doesn't set its name should return null from
  106. // getName()
  107. }
  108. /**
  109. * Gets the name of the menu component.
  110. * @return the name of the menu component
  111. * @see java.awt.MenuComponent#setName(java.lang.String)
  112. * @since JDK1.1
  113. */
  114. public String getName() {
  115. if (name == null && !nameExplicitlySet) {
  116. synchronized(this) {
  117. if (name == null && !nameExplicitlySet)
  118. name = constructComponentName();
  119. }
  120. }
  121. return name;
  122. }
  123. /**
  124. * Sets the name of the component to the specified string.
  125. * @param name the name of the menu component
  126. * @see java.awt.MenuComponent#getName
  127. * @since JDK1.1
  128. */
  129. public void setName(String name) {
  130. synchronized(this) {
  131. this.name = name;
  132. nameExplicitlySet = true;
  133. }
  134. }
  135. /**
  136. * Returns the parent container for this menu component.
  137. * @return the menu component containing this menu component,
  138. * or <code>null</code> if this menu component
  139. * is the outermost component, the menu bar itself
  140. */
  141. public MenuContainer getParent() {
  142. return getParent_NoClientCode();
  143. }
  144. // NOTE: This method may be called by privileged threads.
  145. // This functionality is implemented in a package-private method
  146. // to insure that it cannot be overridden by client subclasses.
  147. // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  148. final MenuContainer getParent_NoClientCode() {
  149. return parent;
  150. }
  151. /**
  152. * @deprecated As of JDK version 1.1,
  153. * programs should not directly manipulate peers.
  154. */
  155. @Deprecated
  156. public MenuComponentPeer getPeer() {
  157. return peer;
  158. }
  159. /**
  160. * Gets the font used for this menu component.
  161. * @return the font used in this menu component, if there is one;
  162. * <code>null</code> otherwise
  163. * @see java.awt.MenuComponent#setFont
  164. */
  165. public Font getFont() {
  166. Font font = this.font;
  167. if (font != null) {
  168. return font;
  169. }
  170. MenuContainer parent = this.parent;
  171. if (parent != null) {
  172. return parent.getFont();
  173. }
  174. return null;
  175. }
  176. // NOTE: This method may be called by privileged threads.
  177. // This functionality is implemented in a package-private method
  178. // to insure that it cannot be overridden by client subclasses.
  179. // DO NOT INVOKE CLIENT CODE ON THIS THREAD!
  180. final Font getFont_NoClientCode() {
  181. Font font = this.font;
  182. if (font != null) {
  183. return font;
  184. }
  185. // The MenuContainer interface does not have getFont_NoClientCode()
  186. // and it cannot, because it must be package-private. Because of
  187. // this, we must manually cast classes that implement
  188. // MenuContainer.
  189. Object parent = this.parent;
  190. if (parent != null) {
  191. if (parent instanceof Component) {
  192. font = ((Component)parent).getFont_NoClientCode();
  193. } else if (parent instanceof MenuComponent) {
  194. font = ((MenuComponent)parent).getFont_NoClientCode();
  195. }
  196. }
  197. return font;
  198. } // getFont_NoClientCode()
  199. /**
  200. * Sets the font to be used for this menu component to the specified
  201. * font. This font is also used by all subcomponents of this menu
  202. * component, unless those subcomponents specify a different font.
  203. * <p>
  204. * Some platforms may not support setting of all font attributes
  205. * of a menu component; in such cases, calling <code>setFont</code>
  206. * will have no effect on the unsupported font attributes of this
  207. * menu component. Unless subcomponents of this menu component
  208. * specify a different font, this font will be used by those
  209. * subcomponents if supported by the underlying platform.
  210. *
  211. * @param f the font to be set
  212. * @see #getFont
  213. * @see Font#getAttributes
  214. * @see java.awt.font.TextAttribute
  215. */
  216. public void setFont(Font f) {
  217. font = f;
  218. if (peer != null) {
  219. peer.setFont(f);
  220. }
  221. }
  222. /**
  223. * Removes the menu component's peer. The peer allows us to modify the
  224. * appearance of the menu component without changing the functionality of
  225. * the menu component.
  226. */
  227. public void removeNotify() {
  228. synchronized (getTreeLock()) {
  229. MenuComponentPeer p = (MenuComponentPeer)this.peer;
  230. if (p != null) {
  231. Toolkit.getEventQueue().removeSourceEvents(this, true);
  232. this.peer = null;
  233. p.dispose();
  234. }
  235. }
  236. }
  237. /**
  238. * Posts the specified event to the menu.
  239. * This method is part of the Java 1.0 event system
  240. * and it is maintained only for backwards compatibility.
  241. * Its use is discouraged, and it may not be supported
  242. * in the future.
  243. * @param evt the event which is to take place
  244. * @deprecated As of JDK version 1.1, replaced by {@link
  245. * #dispatchEvent(AWTEvent) dispatchEvent}.
  246. */
  247. @Deprecated
  248. public boolean postEvent(Event evt) {
  249. MenuContainer parent = this.parent;
  250. if (parent != null) {
  251. parent.postEvent(evt);
  252. }
  253. return false;
  254. }
  255. /*
  256. * Delivers an event to this component or one of its sub components.
  257. * @param e the event
  258. */
  259. public final void dispatchEvent(AWTEvent e) {
  260. dispatchEventImpl(e);
  261. }
  262. void dispatchEventImpl(AWTEvent e) {
  263. EventQueue.setCurrentEventAndMostRecentTime(e);
  264. Toolkit.getDefaultToolkit().notifyAWTEventListeners(e);
  265. if (newEventsOnly ||
  266. (parent != null && parent instanceof MenuComponent &&
  267. ((MenuComponent)parent).newEventsOnly)) {
  268. if (eventEnabled(e)) {
  269. processEvent(e);
  270. } else if (e instanceof ActionEvent && parent != null) {
  271. e.setSource(parent);
  272. ((MenuComponent)parent).dispatchEvent(e);
  273. }
  274. } else { // backward compatibility
  275. Event olde = e.convertToOld();
  276. if (olde != null) {
  277. postEvent(olde);
  278. }
  279. }
  280. }
  281. // REMIND: remove when filtering is done at lower level
  282. boolean eventEnabled(AWTEvent e) {
  283. return false;
  284. }
  285. /**
  286. * Processes events occurring on this menu component.
  287. * <p>Note that if the event parameter is <code>null</code>
  288. * the behavior is unspecified and may result in an
  289. * exception.
  290. *
  291. * @param e the event
  292. * @since JDK1.1
  293. */
  294. protected void processEvent(AWTEvent e) {
  295. }
  296. /**
  297. * Returns a string representing the state of this
  298. * <code>MenuComponent</code>. This method is intended to be used
  299. * only for debugging purposes, and the content and format of the
  300. * returned string may vary between implementations. The returned
  301. * string may be empty but may not be <code>null</code>.
  302. *
  303. * @return the parameter string of this menu component
  304. */
  305. protected String paramString() {
  306. String thisName = getName();
  307. return (thisName != null? thisName : "");
  308. }
  309. /**
  310. * Returns a representation of this menu component as a string.
  311. * @return a string representation of this menu component
  312. */
  313. public String toString() {
  314. return getClass().getName() + "[" + paramString() + "]";
  315. }
  316. /**
  317. * Gets this component's locking object (the object that owns the thread
  318. * sychronization monitor) for AWT component-tree and layout
  319. * operations.
  320. * @return this component's locking object
  321. */
  322. protected final Object getTreeLock() {
  323. return Component.LOCK;
  324. }
  325. /**
  326. * Reads the menu component from an object input stream.
  327. *
  328. * @param s the <code>ObjectInputStream</code> to read
  329. * @exception HeadlessException if
  330. * <code>GraphicsEnvironment.isHeadless</code> returns
  331. * <code>true</code>
  332. * @serial
  333. * @see java.awt.GraphicsEnvironment#isHeadless
  334. */
  335. private void readObject(ObjectInputStream s)
  336. throws ClassNotFoundException, IOException, HeadlessException
  337. {
  338. GraphicsEnvironment.checkHeadless();
  339. s.defaultReadObject();
  340. privateKey = new Object();
  341. appContext = AppContext.getAppContext();
  342. }
  343. /**
  344. * Initialize JNI field and method IDs.
  345. */
  346. private static native void initIDs();
  347. /*
  348. * --- Accessibility Support ---
  349. *
  350. * MenuComponent will contain all of the methods in interface Accessible,
  351. * though it won't actually implement the interface - that will be up
  352. * to the individual objects which extend MenuComponent.
  353. */
  354. AccessibleContext accessibleContext = null;
  355. /**
  356. * Gets the <code>AccessibleContext</code> associated with
  357. * this <code>MenuComponent</code>.
  358. *
  359. * The method implemented by this base class returns <code>null</code>.
  360. * Classes that extend <code>MenuComponent</code>
  361. * should implement this method to return the
  362. * <code>AccessibleContext</code> associated with the subclass.
  363. *
  364. * @return the <code>AccessibleContext</code> of this
  365. * <code>MenuComponent</code>
  366. */
  367. public AccessibleContext getAccessibleContext() {
  368. return accessibleContext;
  369. }
  370. /**
  371. * Inner class of <code>MenuComponent</code> used to provide
  372. * default support for accessibility. This class is not meant
  373. * to be used directly by application developers, but is instead
  374. * meant only to be subclassed by menu component developers.
  375. * <p>
  376. * The class used to obtain the accessible role for this object.
  377. */
  378. protected abstract class AccessibleAWTMenuComponent
  379. extends AccessibleContext
  380. implements java.io.Serializable, AccessibleComponent,
  381. AccessibleSelection
  382. {
  383. /*
  384. * JDK 1.3 serialVersionUID
  385. */
  386. private static final long serialVersionUID = -4269533416223798698L;
  387. /**
  388. * Although the class is abstract, this should be called by
  389. * all sub-classes.
  390. */
  391. protected AccessibleAWTMenuComponent() {
  392. }
  393. // AccessibleContext methods
  394. //
  395. /**
  396. * Gets the <code>AccessibleSelection</code> associated with this
  397. * object which allows its <code>Accessible</code> children to be selected.
  398. *
  399. * @return <code>AccessibleSelection</code> if supported by object;
  400. * else return <code>null</code>
  401. * @see AccessibleSelection
  402. */
  403. public AccessibleSelection getAccessibleSelection() {
  404. return this;
  405. }
  406. /**
  407. * Gets the accessible name of this object. This should almost never
  408. * return <code>java.awt.MenuComponent.getName</code>, as that
  409. * generally isn't a localized name, and doesn't have meaning for the
  410. * user. If the object is fundamentally a text object (e.g. a menu item), the
  411. * accessible name should be the text of the object (e.g. "save").
  412. * If the object has a tooltip, the tooltip text may also be an
  413. * appropriate String to return.
  414. *
  415. * @return the localized name of the object -- can be <code>null</code>
  416. * if this object does not have a name
  417. * @see AccessibleContext#setAccessibleName
  418. */
  419. public String getAccessibleName() {
  420. return accessibleName;
  421. }
  422. /**
  423. * Gets the accessible description of this object. This should be
  424. * a concise, localized description of what this object is - what
  425. * is its meaning to the user. If the object has a tooltip, the
  426. * tooltip text may be an appropriate string to return, assuming
  427. * it contains a concise description of the object (instead of just
  428. * the name of the object - e.g. a "Save" icon on a toolbar that
  429. * had "save" as the tooltip text shouldn't return the tooltip
  430. * text as the description, but something like "Saves the current
  431. * text document" instead).
  432. *
  433. * @return the localized description of the object -- can be
  434. * <code>null</code> if this object does not have a description
  435. * @see AccessibleContext#setAccessibleDescription
  436. */
  437. public String getAccessibleDescription() {
  438. return accessibleDescription;
  439. }
  440. /**
  441. * Gets the role of this object.
  442. *
  443. * @return an instance of <code>AccessibleRole</code>
  444. * describing the role of the object
  445. * @see AccessibleRole
  446. */
  447. public AccessibleRole getAccessibleRole() {
  448. return AccessibleRole.AWT_COMPONENT; // Non-specific -- overridden in subclasses
  449. }
  450. /**
  451. * Gets the state of this object.
  452. *
  453. * @return an instance of <code>AccessibleStateSet</code>
  454. * containing the current state set of the object
  455. * @see AccessibleState
  456. */
  457. public AccessibleStateSet getAccessibleStateSet() {
  458. return MenuComponent.this.getAccessibleStateSet();
  459. }
  460. /**
  461. * Gets the <code>Accessible</code> parent of this object.
  462. * If the parent of this object implements <code>Accessible</code>,
  463. * this method should simply return <code>getParent</code>.
  464. *
  465. * @return the <code>Accessible</code> parent of this object -- can
  466. * be <code>null</code> if this object does not have an
  467. * <code>Accessible</code> parent
  468. */
  469. public Accessible getAccessibleParent() {
  470. if (accessibleParent != null) {
  471. return accessibleParent;
  472. } else {
  473. MenuContainer parent = MenuComponent.this.getParent();
  474. if (parent instanceof Accessible) {
  475. return (Accessible) parent;
  476. }
  477. }
  478. return null;
  479. }
  480. /**
  481. * Gets the index of this object in its accessible parent.
  482. *
  483. * @return the index of this object in its parent; -1 if this
  484. * object does not have an accessible parent
  485. * @see #getAccessibleParent
  486. */
  487. public int getAccessibleIndexInParent() {
  488. return MenuComponent.this.getAccessibleIndexInParent();
  489. }
  490. /**
  491. * Returns the number of accessible children in the object. If all
  492. * of the children of this object implement <code>Accessible</code>,
  493. * then this method should return the number of children of this object.
  494. *
  495. * @return the number of accessible children in the object
  496. */
  497. public int getAccessibleChildrenCount() {
  498. return 0; // MenuComponents don't have children
  499. }
  500. /**
  501. * Returns the nth <code>Accessible</code> child of the object.
  502. *
  503. * @param i zero-based index of child
  504. * @return the nth Accessible child of the object
  505. */
  506. public Accessible getAccessibleChild(int i) {
  507. return null; // MenuComponents don't have children
  508. }
  509. /**
  510. * Returns the locale of this object.
  511. *
  512. * @return the locale of this object
  513. */
  514. public java.util.Locale getLocale() {
  515. MenuContainer parent = MenuComponent.this.getParent();
  516. if (parent instanceof Component)
  517. return ((Component)parent).getLocale();
  518. else
  519. return java.util.Locale.getDefault();
  520. }
  521. /**
  522. * Gets the <code>AccessibleComponent</code> associated with
  523. * this object if one exists. Otherwise return <code>null</code>.
  524. *
  525. * @return the component
  526. */
  527. public AccessibleComponent getAccessibleComponent() {
  528. return this;
  529. }
  530. // AccessibleComponent methods
  531. //
  532. /**
  533. * Gets the background color of this object.
  534. *
  535. * @return the background color, if supported, of the object;
  536. * otherwise, <code>null</code>
  537. */
  538. public Color getBackground() {
  539. return null; // Not supported for MenuComponents
  540. }
  541. /**
  542. * Sets the background color of this object.
  543. * (For transparency, see <code>isOpaque</code>.)
  544. *
  545. * @param c the new <code>Color</code> for the background
  546. * @see Component#isOpaque
  547. */
  548. public void setBackground(Color c) {
  549. // Not supported for MenuComponents
  550. }
  551. /**
  552. * Gets the foreground color of this object.
  553. *
  554. * @return the foreground color, if supported, of the object;
  555. * otherwise, <code>null</code>
  556. */
  557. public Color getForeground() {
  558. return null; // Not supported for MenuComponents
  559. }
  560. /**
  561. * Sets the foreground color of this object.
  562. *
  563. * @param c the new <code>Color</code> for the foreground
  564. */
  565. public void setForeground(Color c) {
  566. // Not supported for MenuComponents
  567. }
  568. /**
  569. * Gets the <code>Cursor</code> of this object.
  570. *
  571. * @return the <code>Curso</code>, if supported, of the object;
  572. * otherwise, <code>null</code>
  573. */
  574. public Cursor getCursor() {
  575. return null; // Not supported for MenuComponents
  576. }
  577. /**
  578. * Sets the <code>Cursor</code> of this object.
  579. *
  580. * @param cursor the new <code>Cursor</code> for the object
  581. */
  582. public void setCursor(Cursor cursor) {
  583. // Not supported for MenuComponents
  584. }
  585. /**
  586. * Gets the <code>Font</code> of this object.
  587. *
  588. * @return the <code>Font</code>,if supported, for the object;
  589. * otherwise, <code>null</code>
  590. */
  591. public Font getFont() {
  592. return MenuComponent.this.getFont();
  593. }
  594. /**
  595. * Sets the <code>Font</code> of this object.
  596. *
  597. * @param f the new <code>Font</code> for the object
  598. */
  599. public void setFont(Font f) {
  600. MenuComponent.this.setFont(f);
  601. }
  602. /**
  603. * Gets the <code>FontMetrics</code> of this object.
  604. *
  605. * @param f the <code>Font</code>
  606. * @return the FontMetrics, if supported, the object;
  607. * otherwise, <code>null</code>
  608. * @see #getFont
  609. */
  610. public FontMetrics getFontMetrics(Font f) {
  611. return null; // Not supported for MenuComponents
  612. }
  613. /**
  614. * Determines if the object is enabled.
  615. *
  616. * @return true if object is enabled; otherwise, false
  617. */
  618. public boolean isEnabled() {
  619. return true; // Not supported for MenuComponents
  620. }
  621. /**
  622. * Sets the enabled state of the object.
  623. *
  624. * @param b if true, enables this object; otherwise, disables it
  625. */
  626. public void setEnabled(boolean b) {
  627. // Not supported for MenuComponents
  628. }
  629. /**
  630. * Determines if the object is visible. Note: this means that the
  631. * object intends to be visible; however, it may not in fact be
  632. * showing on the screen because one of the objects that this object
  633. * is contained by is not visible. To determine if an object is
  634. * showing on the screen, use <code>isShowing</code>.
  635. *
  636. * @return true if object is visible; otherwise, false
  637. */
  638. public boolean isVisible() {
  639. return true; // Not supported for MenuComponents
  640. }
  641. /**
  642. * Sets the visible state of the object.
  643. *
  644. * @param b if true, shows this object; otherwise, hides it
  645. */
  646. public void setVisible(boolean b) {
  647. // Not supported for MenuComponents
  648. }
  649. /**
  650. * Determines if the object is showing. This is determined by checking
  651. * the visibility of the object and ancestors of the object. Note:
  652. * this will return true even if the object is obscured by another
  653. * (for example, it happens to be underneath a menu that was pulled
  654. * down).
  655. *
  656. * @return true if object is showing; otherwise, false
  657. */
  658. public boolean isShowing() {
  659. return true; // Not supported for MenuComponents
  660. }
  661. /**
  662. * Checks whether the specified point is within this object's bounds,
  663. * where the point's x and y coordinates are defined to be relative to
  664. * the coordinate system of the object.
  665. *
  666. * @param p the <code>Point</code> relative to the coordinate
  667. * system of the object
  668. * @return true if object contains <code>Point</code> otherwise false
  669. */
  670. public boolean contains(Point p) {
  671. return false; // Not supported for MenuComponents
  672. }
  673. /**
  674. * Returns the location of the object on the screen.
  675. *
  676. * @return location of object on screen -- can be <code>null</code>
  677. * if this object is not on the screen
  678. */
  679. public Point getLocationOnScreen() {
  680. return null; // Not supported for MenuComponents
  681. }
  682. /**
  683. * Gets the location of the object relative to the parent in the form
  684. * of a point specifying the object's top-left corner in the screen's
  685. * coordinate space.
  686. *
  687. * @return an instance of <code>Point</code> representing the
  688. * top-left corner of the object's bounds in the coordinate
  689. * space of the screen; <code>null</code> if
  690. * this object or its parent are not on the screen
  691. */
  692. public Point getLocation() {
  693. return null; // Not supported for MenuComponents
  694. }
  695. /**
  696. * Sets the location of the object relative to the parent.
  697. */
  698. public void setLocation(Point p) {
  699. // Not supported for MenuComponents
  700. }
  701. /**
  702. * Gets the bounds of this object in the form of a
  703. * <code>Rectangle</code> object.
  704. * The bounds specify this object's width, height, and location
  705. * relative to its parent.
  706. *
  707. * @return a rectangle indicating this component's bounds;
  708. * <code>null</code> if this object is not on the screen
  709. */
  710. public Rectangle getBounds() {
  711. return null; // Not supported for MenuComponents
  712. }
  713. /**
  714. * Sets the bounds of this object in the form of a
  715. * <code>Rectangle</code> object.
  716. * The bounds specify this object's width, height, and location
  717. * relative to its parent.
  718. *
  719. * @param r a rectangle indicating this component's bounds
  720. */
  721. public void setBounds(Rectangle r) {
  722. // Not supported for MenuComponents
  723. }
  724. /**
  725. * Returns the size of this object in the form of a
  726. * <code>Dimension</code> object. The height field of
  727. * the <code>Dimension</code> object contains this object's
  728. * height, and the width field of the <code>Dimension</code>
  729. * object contains this object's width.
  730. *
  731. * @return a <code>Dimension</code> object that indicates the
  732. * size of this component; <code>null</code>
  733. * if this object is not on the screen
  734. */
  735. public Dimension getSize() {
  736. return null; // Not supported for MenuComponents
  737. }
  738. /**
  739. * Resizes this object.
  740. *
  741. * @param d - the <code>Dimension</code> specifying the
  742. * new size of the object
  743. */
  744. public void setSize(Dimension d) {
  745. // Not supported for MenuComponents
  746. }
  747. /**
  748. * Returns the <code>Accessible</code> child, if one exists,
  749. * contained at the local coordinate <code>Point</code>.
  750. * If there is no <code>Accessible</code> child, <code>null</code>
  751. * is returned.
  752. *
  753. * @param p the point defining the top-left corner of the
  754. * <code>Accessible</code>, given in the coordinate space
  755. * of the object's parent
  756. * @return the <code>Accessible</code>, if it exists,
  757. * at the specified location; else <code>null</code>
  758. */
  759. public Accessible getAccessibleAt(Point p) {
  760. return null; // MenuComponents don't have children
  761. }
  762. /**
  763. * Returns whether this object can accept focus or not.
  764. *
  765. * @return true if object can accept focus; otherwise false
  766. */
  767. public boolean isFocusTraversable() {
  768. return true; // Not supported for MenuComponents
  769. }
  770. /**
  771. * Requests focus for this object.
  772. */
  773. public void requestFocus() {
  774. // Not supported for MenuComponents
  775. }
  776. /**
  777. * Adds the specified focus listener to receive focus events from this
  778. * component.
  779. *
  780. * @param l the focus listener
  781. */
  782. public void addFocusListener(java.awt.event.FocusListener l) {
  783. // Not supported for MenuComponents
  784. }
  785. /**
  786. * Removes the specified focus listener so it no longer receives focus
  787. * events from this component.
  788. *
  789. * @param l the focus listener
  790. */
  791. public void removeFocusListener(java.awt.event.FocusListener l) {
  792. // Not supported for MenuComponents
  793. }
  794. // AccessibleSelection methods
  795. //
  796. /**
  797. * Returns the number of <code>Accessible</code> children currently selected.
  798. * If no children are selected, the return value will be 0.
  799. *
  800. * @return the number of items currently selected
  801. */
  802. public int getAccessibleSelectionCount() {
  803. return 0; // To be fully implemented in a future release
  804. }
  805. /**
  806. * Returns an <code>Accessible</code> representing the specified
  807. * selected child in the object. If there isn't a selection, or there are
  808. * fewer children selected than the integer passed in, the return
  809. * value will be <code>null</code>.
  810. * <p>Note that the index represents the i-th selected child, which
  811. * is different from the i-th child.
  812. *
  813. * @param i the zero-based index of selected children
  814. * @return the i-th selected child
  815. * @see #getAccessibleSelectionCount
  816. */
  817. public Accessible getAccessibleSelection(int i) {
  818. return null; // To be fully implemented in a future release
  819. }
  820. /**
  821. * Determines if the current child of this object is selected.
  822. *
  823. * @return true if the current child of this object is selected;
  824. * else false
  825. * @param i the zero-based index of the child in this
  826. * <code>Accessible</code> object
  827. * @see AccessibleContext#getAccessibleChild
  828. */
  829. public boolean isAccessibleChildSelected(int i) {
  830. return false; // To be fully implemented in a future release
  831. }
  832. /**
  833. * Adds the specified <code>Accessible</code> child of the object
  834. * to the object's selection. If the object supports multiple selections,
  835. * the specified child is added to any existing selection, otherwise
  836. * it replaces any existing selection in the object. If the
  837. * specified child is already selected, this method has no effect.
  838. *
  839. * @param i the zero-based index of the child
  840. * @see AccessibleContext#getAccessibleChild
  841. */
  842. public void addAccessibleSelection(int i) {
  843. // To be fully implemented in a future release
  844. }
  845. /**
  846. * Removes the specified child of the object from the object's
  847. * selection. If the specified item isn't currently selected, this
  848. * method has no effect.
  849. *
  850. * @param i the zero-based index of the child
  851. * @see AccessibleContext#getAccessibleChild
  852. */
  853. public void removeAccessibleSelection(int i) {
  854. // To be fully implemented in a future release
  855. }
  856. /**
  857. * Clears the selection in the object, so that no children in the
  858. * object are selected.
  859. */
  860. public void clearAccessibleSelection() {
  861. // To be fully implemented in a future release
  862. }
  863. /**
  864. * Causes every child of the object to be selected
  865. * if the object supports multiple selections.
  866. */
  867. public void selectAllAccessibleSelection() {
  868. // To be fully implemented in a future release
  869. }
  870. } // inner class AccessibleAWTComponent
  871. /**
  872. * Gets the index of this object in its accessible parent.
  873. *
  874. * @return -1 if this object does not have an accessible parent;
  875. * otherwise, the index of the child in its accessible parent.
  876. */
  877. int getAccessibleIndexInParent() {
  878. MenuContainer localParent = parent;
  879. if (!(localParent instanceof MenuComponent)) {
  880. // MenuComponents only have accessible index when inside MenuComponents
  881. return -1;
  882. }
  883. MenuComponent localParentMenu = (MenuComponent)localParent;
  884. return localParentMenu.getAccessibleChildIndex(this);
  885. }
  886. /**
  887. * Gets the index of the child within this MenuComponent.
  888. *
  889. * @param child MenuComponent whose index we are interested in.
  890. * @return -1 if this object doesn't contain the child,
  891. * otherwise, index of the child.
  892. */
  893. int getAccessibleChildIndex(MenuComponent child) {
  894. return -1; // Overridden in subclasses.
  895. }
  896. /**
  897. * Gets the state of this object.
  898. *
  899. * @return an instance of <code>AccessibleStateSet</code>
  900. * containing the current state set of the object
  901. * @see AccessibleState
  902. */
  903. AccessibleStateSet getAccessibleStateSet() {
  904. AccessibleStateSet states = new AccessibleStateSet();
  905. return states;
  906. }
  907. }