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