1. /*
  2. * @(#)Box.java 1.31 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package javax.swing;
  8. import java.awt.*;
  9. import java.awt.event.*;
  10. import java.beans.PropertyChangeListener;
  11. import java.util.Locale;
  12. import java.io.Serializable;
  13. import javax.accessibility.*;
  14. /**
  15. * A lightweight container
  16. * that uses a BoxLayout object as its layout manager.
  17. * Box provides several class methods
  18. * that are useful for containers using BoxLayout --
  19. * even non-Box containers.
  20. *
  21. * <p>
  22. *
  23. * The Box class can create several kinds
  24. * of invisible components
  25. * that affect layout:
  26. * glue, struts, and rigid areas.
  27. * If all the components your Box contains
  28. * have a fixed size,
  29. * you might want to use a glue component
  30. * (returned by <code>createGlue</code>)
  31. * to control the components' positions.
  32. * If you need a fixed amount of space between two components,
  33. * try using a strut
  34. * (<code>createHorizontalStrut</code> or <code>createVerticalStrut</code>).
  35. * If you need an invisible component
  36. * that always takes up the same amount of space,
  37. * get it by invoking <code>createRigidArea</code>.
  38. * <p>
  39. * <strong>Warning:</strong>
  40. * Serialized objects of this class will not be compatible with
  41. * future Swing releases. The current serialization support is appropriate
  42. * for short term storage or RMI between applications running the same
  43. * version of Swing. A future release of Swing will provide support for
  44. * long term persistence.
  45. *
  46. * @see BoxLayout
  47. *
  48. * @author Timothy Prinzing
  49. * @version 1.31 11/29/01
  50. */
  51. public class Box extends Container implements Accessible {
  52. /**
  53. * Creates a <code>Box</code> that displays its components
  54. * along the the specified axis.
  55. *
  56. * @param axis can be either <code>BoxLayout.X_AXIS</code>
  57. * (to display components from left to right) or
  58. * <code>BoxLayout.Y_AXIS</code>
  59. * (to display them from top to bottom)
  60. * @see #createHorizontalBox
  61. * @see #createVerticalBox
  62. */
  63. public Box(int axis) {
  64. super();
  65. super.setLayout(new BoxLayout(this, axis));
  66. }
  67. /**
  68. * Creates a <code>Box</code> that displays its components
  69. * from left to right.
  70. *
  71. * @return the box
  72. */
  73. public static Box createHorizontalBox() {
  74. return new Box(BoxLayout.X_AXIS);
  75. }
  76. /**
  77. * Creates a <code>Box</code> that displays its components
  78. * from top to bottom.
  79. *
  80. * @return the box
  81. */
  82. public static Box createVerticalBox() {
  83. return new Box(BoxLayout.Y_AXIS);
  84. }
  85. /**
  86. * Creates an invisible component that's always the specified size.
  87. * <!-- WHEN WOULD YOU USE THIS AS OPPOSED TO A STRUT? -->
  88. *
  89. * @param d the dimensions of the invisible component
  90. * @return the component
  91. * @see #createGlue
  92. * @see #createHorizontalStrut
  93. * @see #createVerticalStrut
  94. */
  95. public static Component createRigidArea(Dimension d) {
  96. return new Filler(d, d, d);
  97. }
  98. /**
  99. * Creates an invisible, fixed-width component.
  100. * In a horizontal box,
  101. * you typically use this method
  102. * to force a certain amount of space between two components.
  103. * In a vertical box,
  104. * you might use this method
  105. * to force the box to be at least the specified width.
  106. * The invisible component has no height
  107. * unless excess space is available,
  108. * in which case it takes its share of available space,
  109. * just like any other component that has no maximum height.
  110. *
  111. * @param width the width of the invisible component, in pixels >= 0
  112. * @return the component
  113. * @see #createVerticalStrut
  114. * @see #createGlue
  115. * @see #createRigidArea
  116. */
  117. public static Component createHorizontalStrut(int width) {
  118. // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  119. // to date because BoxLayout alignment breaks.
  120. return new Filler(new Dimension(width,0), new Dimension(width,0),
  121. new Dimension(width, Short.MAX_VALUE));
  122. }
  123. /**
  124. * Creates an invisible, fixed-height component.
  125. * In a vertical box,
  126. * you typically use this method
  127. * to force a certain amount of space between two components.
  128. * In a horizontal box,
  129. * you might use this method
  130. * to force the box to be at least the specified height.
  131. * The invisible component has no width
  132. * unless excess space is available,
  133. * in which case it takes its share of available space,
  134. * just like any other component that has no maximum width.
  135. *
  136. * @param height the height of the invisible component, in pixels >= 0
  137. * @return the component
  138. * @see #createHorizontalStrut
  139. * @see #createGlue
  140. * @see #createRigidArea
  141. */
  142. public static Component createVerticalStrut(int height) {
  143. // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  144. // to date because BoxLayout alignment breaks.
  145. return new Filler(new Dimension(0,height), new Dimension(0,height),
  146. new Dimension(Short.MAX_VALUE, height));
  147. }
  148. /**
  149. * Creates an invisible "glue" component
  150. * that can be useful in a Box
  151. * whose visible components have a maximum width
  152. * (for a horizontal box)
  153. * or height (for a vertical box).
  154. * You can think of the glue component
  155. * as being a gooey substance
  156. * that expands as much as necessary
  157. * to fill the space between its neighboring components.
  158. *
  159. * <p>
  160. *
  161. * For example, suppose you have
  162. * a horizontal box that contains two fixed-size components.
  163. * If the box gets extra space,
  164. * the fixed-size components won't become larger,
  165. * so where does the extra space go?
  166. * Without glue,
  167. * the extra space goes to the right of the second component.
  168. * If you put glue between the fixed-size components,
  169. * then the extra space goes there.
  170. * If you put glue before the first fixed-size component,
  171. * the extra space goes there,
  172. * and the fixed-size components are shoved against the right
  173. * edge of the box.
  174. * If you put glue before the first fixed-size component
  175. * and after the second fixed-size component,
  176. * the fixed-size components are centered in the box.
  177. *
  178. * <p>
  179. *
  180. * To use glue,
  181. * call <code>Box.createGlue</code>
  182. * and add the returned component to a container.
  183. * The glue component has no minimum or preferred size,
  184. * so it takes no space unless excess space is available.
  185. * If excess space is available,
  186. * then the glue component takes its share of available
  187. * horizontal or vertical space,
  188. * just like any other component that has no maximum width or height.
  189. *
  190. * @return the component
  191. */
  192. public static Component createGlue() {
  193. // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  194. // to date because BoxLayout alignment breaks.
  195. return new Filler(new Dimension(0,0), new Dimension(0,0),
  196. new Dimension(Short.MAX_VALUE, Short.MAX_VALUE));
  197. }
  198. /**
  199. * Creates a horizontal glue component.
  200. *
  201. * @return the component
  202. */
  203. public static Component createHorizontalGlue() {
  204. // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  205. // to date because BoxLayout alignment breaks.
  206. return new Filler(new Dimension(0,0), new Dimension(0,0),
  207. new Dimension(Short.MAX_VALUE, 0));
  208. }
  209. /**
  210. * Creates a vertical glue component.
  211. *
  212. * @return the component
  213. */
  214. public static Component createVerticalGlue() {
  215. // PENDING(jeff) change to Integer.MAX_VALUE. This hasn't been done
  216. // to date because BoxLayout alignment breaks.
  217. return new Filler(new Dimension(0,0), new Dimension(0,0),
  218. new Dimension(0, Short.MAX_VALUE));
  219. }
  220. /**
  221. * Throws an AWTError, since a Box can use only a BoxLayout.
  222. *
  223. * @param l the layout manager to use
  224. */
  225. public void setLayout(LayoutManager l) {
  226. throw new AWTError("Illegal request");
  227. }
  228. /**
  229. * An implementation of a lightweight component that participates in
  230. * layout but has no view.
  231. * <p>
  232. * <strong>Warning:</strong>
  233. * Serialized objects of this class will not be compatible with
  234. * future Swing releases. The current serialization support is appropriate
  235. * for short term storage or RMI between applications running the same
  236. * version of Swing. A future release of Swing will provide support for
  237. * long term persistence.
  238. */
  239. public static class Filler extends Component implements Accessible {
  240. /**
  241. * Constructor to create shape with the given size ranges.
  242. *
  243. * @param min Minimum size
  244. * @param pref Preferred size
  245. * @param max Maximum size
  246. */
  247. public Filler(Dimension min, Dimension pref, Dimension max) {
  248. reqMin = min;
  249. reqPref = pref;
  250. reqMax = max;
  251. }
  252. /**
  253. * Change the size requests for this shape. An invalidate() is
  254. * propagated upward as a result so that layout will eventually
  255. * happen with using the new sizes.
  256. *
  257. * @param min Value to return for getMinimumSize
  258. * @param pref Value to return for getPreferredSize
  259. * @param max Value to return for getMaximumSize
  260. */
  261. public void changeShape(Dimension min, Dimension pref, Dimension max) {
  262. reqMin = min;
  263. reqPref = pref;
  264. reqMax = max;
  265. invalidate();
  266. }
  267. // ---- Component methods ------------------------------------------
  268. /**
  269. * Returns the minimum size of the component.
  270. *
  271. * @return the size
  272. */
  273. public Dimension getMinimumSize() {
  274. return reqMin;
  275. }
  276. /**
  277. * Returns the preferred size of the component.
  278. *
  279. * @return the size
  280. */
  281. public Dimension getPreferredSize() {
  282. return reqPref;
  283. }
  284. /**
  285. * Returns the maximum size of the component.
  286. *
  287. * @return the size
  288. */
  289. public Dimension getMaximumSize() {
  290. return reqMax;
  291. }
  292. // ---- member variables ---------------------------------------
  293. private Dimension reqMin;
  294. private Dimension reqPref;
  295. private Dimension reqMax;
  296. /////////////////
  297. // Accessibility support for Box$Filler
  298. ////////////////
  299. /**
  300. * The currently set AccessibleContext object.
  301. */
  302. protected AccessibleContext accessibleContext = null;
  303. /**
  304. * Gets the AccessibleContext associated with this Component.
  305. * Creates a new context if necessary.
  306. *
  307. * @return the AccessibleContext of this Component
  308. */
  309. public AccessibleContext getAccessibleContext() {
  310. if (accessibleContext == null) {
  311. accessibleContext = new AccessibleBoxFiller();
  312. }
  313. return accessibleContext;
  314. }
  315. protected class AccessibleBoxFiller extends AccessibleContext
  316. implements Serializable, AccessibleComponent {
  317. // AccessibleContext methods
  318. //
  319. /**
  320. * Gets the role of this object.
  321. *
  322. * @return an instance of AccessibleRole describing the role of
  323. * the object (AccessibleRole.FILLER)
  324. * @see AccessibleRole
  325. */
  326. public AccessibleRole getAccessibleRole() {
  327. return AccessibleRole.FILLER;
  328. }
  329. /**
  330. * Gets the state of this object.
  331. *
  332. * @return an instance of AccessibleStateSet containing the current
  333. * state set of the object
  334. * @see AccessibleState
  335. */
  336. public AccessibleStateSet getAccessibleStateSet() {
  337. return SwingUtilities.getAccessibleStateSet(Filler.this);
  338. }
  339. /**
  340. * Get the Accessible parent of this object. If the parent of this
  341. * object implements Accessible, this method should simply return
  342. * getParent().
  343. *
  344. * @return the Accessible parent of this object; null if this
  345. * object does not have an Accessible parent
  346. */
  347. public Accessible getAccessibleParent() {
  348. if (accessibleParent != null) {
  349. return accessibleParent;
  350. } else {
  351. Container parent = getParent();
  352. if (parent instanceof Accessible) {
  353. return (Accessible) parent;
  354. }
  355. }
  356. return null;
  357. }
  358. /**
  359. * Gets the index of this object in its accessible parent.
  360. *
  361. * @return the index of this object in its parent >= 0; -1 if this
  362. * object does not have an accessible parent.
  363. * @see #getAccessibleParent
  364. */
  365. public int getAccessibleIndexInParent() {
  366. return SwingUtilities.getAccessibleIndexInParent(Filler.this);
  367. }
  368. /**
  369. * Returns the number of accessible children in the object. If all
  370. * of the children of this object implement Accessible, then this
  371. * method should return the number of children of this object.
  372. *
  373. * @return the number of accessible children in the object >= 0
  374. */
  375. public int getAccessibleChildrenCount() {
  376. return SwingUtilities.getAccessibleChildrenCount(Filler.this);
  377. }
  378. /**
  379. * Returns the nth Accessible child of the object.
  380. *
  381. * @param i zero-based index of child
  382. * @return the nth Accessible child of the object, null if none
  383. */
  384. public Accessible getAccessibleChild(int i) {
  385. return SwingUtilities.getAccessibleChild(Filler.this,i);
  386. }
  387. /**
  388. * Returns the locale of this object.
  389. *
  390. * @return the locale of this object
  391. */
  392. public Locale getLocale() {
  393. return Filler.this.getLocale();
  394. }
  395. /**
  396. * Gets the AccessibleComponent associated with this object if one
  397. * exists. Otherwise return null.
  398. *
  399. * @return the component
  400. */
  401. public AccessibleComponent getAccessibleComponent() {
  402. return this;
  403. }
  404. // AccessibleComponent methods
  405. //
  406. /**
  407. * Gets the background color of this object.
  408. *
  409. * @return the background color, if supported, of the object;
  410. * otherwise, null
  411. */
  412. public Color getBackground() {
  413. return Filler.this.getBackground();
  414. }
  415. // NOTE: IN THE NEXT MAJOR RELEASE, isOpaque WILL MIGRATE
  416. // TO java.awt.Component -- ADJUST @SEE LINK BELOW.
  417. /**
  418. * Sets the background color of this object.
  419. * (For transparency, see <code>isOpaque</code>.)
  420. *
  421. * @param c the new Color for the background, null if none
  422. * @s JComponent#isOpaque
  423. */
  424. public void setBackground(Color c) {
  425. Filler.this.setBackground(c);
  426. }
  427. /**
  428. * Gets the foreground color of this object.
  429. *
  430. * @return the foreground color, if supported, of the object;
  431. * otherwise, null
  432. */
  433. public Color getForeground() {
  434. return Filler.this.getForeground();
  435. }
  436. /**
  437. * Sets the foreground color of this object.
  438. *
  439. * @param c the new Color for the foreground, null if none
  440. */
  441. public void setForeground(Color c) {
  442. Filler.this.setForeground(c);
  443. }
  444. /**
  445. * Gets the Cursor of this object.
  446. *
  447. * @return the Cursor, if supported, of the object; otherwise, null
  448. */
  449. public Cursor getCursor() {
  450. return Filler.this.getCursor();
  451. }
  452. /**
  453. * Set the Cursor of this object.
  454. *
  455. * @param cursor the new Cursor for the object, null if none
  456. */
  457. public void setCursor(Cursor cursor) {
  458. Filler.this.setCursor(cursor);
  459. }
  460. /**
  461. * Gets the Font of this object.
  462. *
  463. * @return the Font,if supported, for the object; otherwise, null
  464. */
  465. public Font getFont() {
  466. return Filler.this.getFont();
  467. }
  468. /**
  469. * Sets the Font of this object.
  470. *
  471. * @param f the new Font for the object, null if none
  472. */
  473. public void setFont(Font f) {
  474. Filler.this.setFont(f);
  475. }
  476. /**
  477. * Gets the FontMetrics of this object.
  478. *
  479. * @param f the Font, null if none
  480. * @return the FontMetrics, if supported, the object;
  481. * otherwise, null
  482. * @see #getFont
  483. */
  484. public FontMetrics getFontMetrics(Font f) {
  485. return Filler.this.getFontMetrics(f);
  486. }
  487. /**
  488. * Determines if the object is enabled.
  489. *
  490. * @return true if object is enabled; otherwise, false
  491. */
  492. public boolean isEnabled() {
  493. return Filler.this.isEnabled();
  494. }
  495. /**
  496. * Sets the enabled state of the object.
  497. *
  498. * @param b if true, enables this object; otherwise, disables it
  499. */
  500. public void setEnabled(boolean b) {
  501. boolean old = Filler.this.isEnabled();
  502. Filler.this.setEnabled(b);
  503. if (b != old) {
  504. if (accessibleContext != null) {
  505. if (b) {
  506. accessibleContext.firePropertyChange(
  507. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  508. null, AccessibleState.ENABLED);
  509. } else {
  510. accessibleContext.firePropertyChange(
  511. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  512. AccessibleState.ENABLED, null);
  513. }
  514. }
  515. }
  516. }
  517. /**
  518. * Determines if the object is visible. Note: this means that the
  519. * object intends to be visible; however, it may not in fact be
  520. * showing on the screen because one of the objects that this object
  521. * is contained by is not visible. To determine if an object is
  522. * showing on the screen, use isShowing().
  523. *
  524. * @return true if object is visible; otherwise, false
  525. */
  526. public boolean isVisible() {
  527. return Filler.this.isVisible();
  528. }
  529. /**
  530. * Sets the visible state of the object.
  531. *
  532. * @param b if true, shows this object; otherwise, hides it
  533. */
  534. public void setVisible(boolean b) {
  535. boolean old = Filler.this.isVisible();
  536. Filler.this.setVisible(b);
  537. if (b != old) {
  538. if (accessibleContext != null) {
  539. if (b) {
  540. accessibleContext.firePropertyChange(
  541. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  542. null, AccessibleState.VISIBLE);
  543. } else {
  544. accessibleContext.firePropertyChange(
  545. AccessibleContext.ACCESSIBLE_STATE_PROPERTY,
  546. AccessibleState.VISIBLE, null);
  547. }
  548. }
  549. }
  550. }
  551. /**
  552. * Determines if the object is showing. This is determined by
  553. * checking the visibility of the object and ancestors of the
  554. * object. Note: this will return true even if the object is
  555. * obscured by another (for example, it happens to be
  556. * underneath a menu that was pulled down).
  557. *
  558. * @return true if object is showing; otherwise, false
  559. */
  560. public boolean isShowing() {
  561. return Filler.this.isShowing();
  562. }
  563. /**
  564. * Checks whether the specified point is within this object's
  565. * bounds, where the point's x and y coordinates are defined to
  566. * be relative to the coordinate system of the object.
  567. *
  568. * @param p the Point relative to the coordinate system of
  569. * the object
  570. * @return true if object contains Point; otherwise false
  571. */
  572. public boolean contains(Point p) {
  573. return Filler.this.contains(p);
  574. }
  575. /**
  576. * Returns the location of the object on the screen.
  577. *
  578. * @return location of object on screen; can be null if this object
  579. * is not on the screen
  580. */
  581. public Point getLocationOnScreen() {
  582. if (Filler.this.isShowing()) {
  583. return Filler.this.getLocationOnScreen();
  584. } else {
  585. return null;
  586. }
  587. }
  588. /**
  589. * Gets the location of the object relative to the parent in the
  590. * form of a point specifying the object's top-left corner in
  591. * the screen's coordinate space.
  592. *
  593. * @return An instance of Point representing the top-left corner of
  594. * the objects's bounds in the coordinate space of the screen;
  595. * null if this object or its parent are not on the screen
  596. */
  597. public Point getLocation() {
  598. return Filler.this.getLocation();
  599. }
  600. /**
  601. * Sets the location of the object relative to the parent.
  602. *
  603. * @param p the location to be set
  604. */
  605. public void setLocation(Point p) {
  606. Filler.this.setLocation(p);
  607. }
  608. /**
  609. * Gets the bounds of this object in the form of a Rectangle
  610. * object. The bounds specify this object's width, height,
  611. * and location relative to its parent.
  612. *
  613. * @return A rectangle indicating this component's bounds; null if
  614. * this object is not on the screen.
  615. */
  616. public Rectangle getBounds() {
  617. return Filler.this.getBounds();
  618. }
  619. /**
  620. * Sets the bounds of this object in the form of a Rectangle
  621. * object. The bounds specify this object's width, height,
  622. * and location relative to its parent.
  623. *
  624. * @param r a rectangle indicating this component's bounds
  625. */
  626. public void setBounds(Rectangle r) {
  627. Filler.this.setBounds(r);
  628. }
  629. /**
  630. * Returns the size of this object in the form of a Dimension
  631. * object. The height field of the Dimension object contains
  632. * this objects's height, and the width field of the Dimension
  633. * object contains this object's width.
  634. *
  635. * @return A Dimension object that indicates the size of this
  636. * component; null if this object is not on the screen
  637. */
  638. public Dimension getSize() {
  639. return Filler.this.getSize();
  640. }
  641. /**
  642. * Resizes this object.
  643. *
  644. * @param d - The dimension specifying the new size of the object.
  645. */
  646. public void setSize(Dimension d) {
  647. Filler.this.setSize(d);
  648. }
  649. /**
  650. * Returns the Accessible child, if one exists, contained at the
  651. * local coordinate Point.
  652. *
  653. * @param p The point defining the top-left corner of the
  654. * Accessible, given in the coordinate space of the object's
  655. * parent.
  656. * @return the Accessible, if it exists, at the specified location;
  657. * else null
  658. */
  659. public Accessible getAccessibleAt(Point p) {
  660. return SwingUtilities.getAccessibleAt(Filler.this,p);
  661. }
  662. /**
  663. * Returns whether this object can accept focus or not.
  664. *
  665. * @return true if object can accept focus; otherwise false
  666. */
  667. public boolean isFocusTraversable() {
  668. return Filler.this.isFocusTraversable();
  669. }
  670. /**
  671. * Requests focus for this object.
  672. */
  673. public void requestFocus() {
  674. Filler.this.requestFocus();
  675. }
  676. /**
  677. * Adds the specified listener to receive focus events from this
  678. * component.
  679. *
  680. * @param l the focus listener
  681. */
  682. public void addFocusListener(FocusListener l) {
  683. Filler.this.addFocusListener(l);
  684. }
  685. /**
  686. * Removes the specified listener so it no longer receives focus
  687. * events from this component.
  688. *
  689. * @param l the focus listener
  690. */
  691. public void removeFocusListener(FocusListener l) {
  692. Filler.this.removeFocusListener(l);
  693. }
  694. }
  695. }
  696. /////////////////
  697. // Accessibility support for Box
  698. ////////////////
  699. /**
  700. * The currently set AccessibleContext object.
  701. */
  702. protected AccessibleContext accessibleContext = null;
  703. /**
  704. * Get the AccessibleContext associated with this JComponent.
  705. * Creates a new context if necessary.
  706. *
  707. * @return the AccessibleContext of this JComponent
  708. */
  709. public AccessibleContext getAccessibleContext() {
  710. if (accessibleContext == null) {
  711. accessibleContext = new AccessibleBox();
  712. }
  713. return accessibleContext;
  714. }
  715. protected class AccessibleBox extends AccessibleContext
  716. implements Serializable, AccessibleComponent {
  717. // AccessibleContext methods
  718. //
  719. /**
  720. * Gets the role of this object.
  721. *
  722. * @return an instance of AccessibleRole describing the role of the
  723. * object (AccessibleRole.FILLER)
  724. * @see AccessibleRole
  725. */
  726. public AccessibleRole getAccessibleRole() {
  727. return AccessibleRole.FILLER;
  728. }
  729. /**
  730. * Gets the state of this object.
  731. *
  732. * @return an instance of AccessibleStateSet containing the current
  733. * state set of the object
  734. * @see AccessibleState
  735. */
  736. public AccessibleStateSet getAccessibleStateSet() {
  737. return SwingUtilities.getAccessibleStateSet(Box.this);
  738. }
  739. /**
  740. * Gets the Accessible parent of this object. If the parent of this
  741. * object implements Accessible, this method should simply return
  742. * getParent().
  743. *
  744. * @return the Accessible parent of this object -- can be null if this
  745. * object does not have an Accessible parent
  746. */
  747. public Accessible getAccessibleParent() {
  748. Container parent = getParent();
  749. if (parent instanceof Accessible) {
  750. return (Accessible) parent;
  751. } else {
  752. return null;
  753. }
  754. }
  755. /**
  756. * Gets the index of this object in its accessible parent.
  757. *
  758. * @return the index of this object in its parent >= 0; -1 if this
  759. * object does not have an accessible parent.
  760. * @see #getAccessibleParent
  761. */
  762. public int getAccessibleIndexInParent() {
  763. return SwingUtilities.getAccessibleIndexInParent(Box.this);
  764. }
  765. /**
  766. * Returns the number of accessible children in the object. If all
  767. * of the children of this object implement Accessible, then this
  768. * method should return the number of children of this object.
  769. *
  770. * @return the number of accessible children in the object >= 0.
  771. */
  772. public int getAccessibleChildrenCount() {
  773. return SwingUtilities.getAccessibleChildrenCount(Box.this);
  774. }
  775. /**
  776. * Return the nth Accessible child of the object.
  777. *
  778. * @param i zero-based index of child
  779. * @return the nth Accessible child of the object, or null
  780. */
  781. public Accessible getAccessibleChild(int i) {
  782. return SwingUtilities.getAccessibleChild(Box.this,i);
  783. }
  784. /**
  785. * Returns the locale of this object.
  786. *
  787. * @return the locale of this object
  788. */
  789. public Locale getLocale() {
  790. return Box.this.getLocale();
  791. }
  792. /**
  793. * Gets the AccessibleComponent associated with this object if one
  794. * exists. Otherwise return null.
  795. *
  796. * @return the component
  797. */
  798. public AccessibleComponent getAccessibleComponent() {
  799. return this;
  800. }
  801. // AccessibleComponent methods
  802. //
  803. /**
  804. * Gets the background color of this object.
  805. *
  806. * @return the background color, if supported, of the object;
  807. * otherwise, null
  808. */
  809. public Color getBackground() {
  810. return Box.this.getBackground();
  811. }
  812. /**
  813. * Sets the background color of this object.
  814. *
  815. * @param c the new Color for the background, null if none
  816. */
  817. public void setBackground(Color c) {
  818. Box.this.setBackground(c);
  819. }
  820. /**
  821. * Gets the foreground color of this object.
  822. *
  823. * @return the foreground color, if supported, of the object;
  824. * otherwise, null
  825. */
  826. public Color getForeground() {
  827. return Box.this.getForeground();
  828. }
  829. /**
  830. * Sets the foreground color of this object.
  831. *
  832. * @param c the new Color for the foreground, null if none
  833. */
  834. public void setForeground(Color c) {
  835. Box.this.setForeground(c);
  836. }
  837. /**
  838. * Gets the Cursor of this object.
  839. *
  840. * @return the Cursor, if supported, of the object; otherwise, null
  841. */
  842. public Cursor getCursor() {
  843. return Box.this.getCursor();
  844. }
  845. /**
  846. * Sets the Cursor of this object.
  847. *
  848. * @param cursor the new Cursor for the object, null if none
  849. */
  850. public void setCursor(Cursor cursor) {
  851. Box.this.setCursor(cursor);
  852. }
  853. /**
  854. * Gets the Font of this object.
  855. *
  856. * @return the Font,if supported, for the object; otherwise, null
  857. */
  858. public Font getFont() {
  859. return Box.this.getFont();
  860. }
  861. /**
  862. * Sets the Font of this object.
  863. *
  864. * @param f the new Font for the object, null if none
  865. */
  866. public void setFont(Font f) {
  867. Box.this.setFont(f);
  868. }
  869. /**
  870. * Gets the FontMetrics of this object.
  871. *
  872. * @param f the Font
  873. * @return the FontMetrics, if supported, the object; otherwise, null
  874. * @see #getFont
  875. */
  876. public FontMetrics getFontMetrics(Font f) {
  877. return Box.this.getFontMetrics(f);
  878. }
  879. /**
  880. * Determines if the object is enabled.
  881. *
  882. * @return true if object is enabled; otherwise, false
  883. */
  884. public boolean isEnabled() {
  885. return Box.this.isEnabled();
  886. }
  887. /**
  888. * Sets the enabled state of the object.
  889. *
  890. * @param b if true, enables this object; otherwise, disables it
  891. */
  892. public void setEnabled(boolean b) {
  893. Box.this.setEnabled(b);
  894. }
  895. /**
  896. * Determines if the object is visible. Note: this means that the
  897. * object intends to be visible; however, it may not in fact be
  898. * showing on the screen because one of the objects that this object
  899. * is contained by is not visible. To determine if an object is
  900. * showing on the screen, use isShowing().
  901. *
  902. * @return true if object is visible; otherwise, false
  903. */
  904. public boolean isVisible() {
  905. return Box.this.isVisible();
  906. }
  907. /**
  908. * Sets the visible state of the object.
  909. *
  910. * @param b if true, shows this object; otherwise, hides it
  911. */
  912. public void setVisible(boolean b) {
  913. Box.this.setVisible(b);
  914. }
  915. /**
  916. * Determines if the object is showing. This is determined by checking
  917. * the visibility of the object and ancestors of the object. Note:
  918. * this will return true even if the object is obscured by another
  919. * (for example, it happens to be underneath a menu that was pulled
  920. * down).
  921. *
  922. * @return true if object is showing; otherwise, false
  923. */
  924. public boolean isShowing() {
  925. return Box.this.isShowing();
  926. }
  927. /**
  928. * Checks whether the specified point is within this object's bounds,
  929. * where the point's x and y coordinates are defined to be relative to
  930. * the coordinate system of the object.
  931. *
  932. * @param p the Point relative to the coordinate system of the object
  933. * @return true if object contains Point; otherwise false
  934. */
  935. public boolean contains(Point p) {
  936. return Box.this.contains(p);
  937. }
  938. /**
  939. * Returns the location of the object on the screen.
  940. *
  941. * @return location of object on screen -- can be null if this object
  942. * is not on the screen
  943. */
  944. public Point getLocationOnScreen() {
  945. return Box.this.getLocationOnScreen();
  946. }
  947. /**
  948. * Gets the location of the object relative to the parent in the form
  949. * of a point specifying the object's top-left corner in the screen's
  950. * coordinate space.
  951. *
  952. * @return An instance of Point representing the top-left corner of
  953. * the objects's bounds in the coordinate space of the screen; null if
  954. * this object or its parent are not on the screen
  955. */
  956. public Point getLocation() {
  957. return Box.this.getLocation();
  958. }
  959. /**
  960. * Sets the location of the object relative to the parent.
  961. *
  962. * @param p the location to be set
  963. */
  964. public void setLocation(Point p) {
  965. Box.this.setLocation(p);
  966. }
  967. /**
  968. * Gets the bounds of this object in the form of a Rectangle object.
  969. * The bounds specify this object's width, height, and location
  970. * relative to its parent.
  971. *
  972. * @return A rectangle indicating this component's bounds; null if
  973. * this object is not on the screen.
  974. */
  975. public Rectangle getBounds() {
  976. return Box.this.getBounds();
  977. }
  978. /**
  979. * Sets the bounds of this object in the form of a Rectangle object.
  980. * The bounds specify this object's width, height, and location
  981. * relative to its parent.
  982. *
  983. * @param r a rectangle indicating this component's bounds
  984. */
  985. public void setBounds(Rectangle r) {
  986. Box.this.setBounds(r);
  987. }
  988. /**
  989. * Returns the size of this object in the form of a Dimension object.
  990. * The height field of the Dimension object contains this objects's
  991. * height, and the width field of the Dimension object contains this
  992. * object's width.
  993. *
  994. * @return A Dimension object that indicates the size of this
  995. * component; null if this object is not on the screen
  996. */
  997. public Dimension getSize() {
  998. return Box.this.getSize();
  999. }
  1000. /**
  1001. * Resizes this object.
  1002. *
  1003. * @param d - The dimension specifying the new size of the object.
  1004. */
  1005. public void setSize(Dimension d) {
  1006. Box.this.setSize(d);
  1007. }
  1008. /**
  1009. * Returns the Accessible child, if one exists, contained at the local
  1010. * coordinate Point.
  1011. *
  1012. * @param p The point defining the top-left corner of the Accessible,
  1013. * given in the coordinate space of the object's parent.
  1014. * @return the Accessible, if it exists, at the specified location;
  1015. * else null
  1016. */
  1017. public Accessible getAccessibleAt(Point p) {
  1018. return SwingUtilities.getAccessibleAt(Box.this,p);
  1019. }
  1020. /**
  1021. * Determines whether this object can accept focus or not.
  1022. *
  1023. * @return true if object can accept focus; otherwise false
  1024. */
  1025. public boolean isFocusTraversable() {
  1026. return Box.this.isFocusTraversable();
  1027. }
  1028. /**
  1029. * Requests focus for this object.
  1030. */
  1031. public void requestFocus() {
  1032. Box.this.requestFocus();
  1033. }
  1034. /**
  1035. * Adds the specified focus listener to receive focus events from this
  1036. * component.
  1037. *
  1038. * @param l the focus listener
  1039. */
  1040. public void addFocusListener(FocusListener l) {
  1041. Box.this.addFocusListener(l);
  1042. }
  1043. /**
  1044. * Removes the specified focus listener so it no longer receives focus
  1045. * events from this component.
  1046. *
  1047. * @param l the focus listener
  1048. */
  1049. public void removeFocusListener(FocusListener l) {
  1050. Box.this.removeFocusListener(l);
  1051. }
  1052. } // inner class AccessibleBox
  1053. }