1. /*
  2. * @(#)JDialog.java 1.44 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.util.Vector;
  13. import java.io.Serializable;
  14. import javax.accessibility.*;
  15. import java.applet.Applet;
  16. /**
  17. * The main class for creating a dialog window. You can use this class
  18. * to create a custom dialog, or invoke the many static methods
  19. * in JOptionPane to create a variety of standard dialogs.
  20. *
  21. * The JDialog component contains a JRootPane as it's only
  22. * child.
  23. * The <code>contentPane</code> should be the parent of any children of
  24. * the JDialog. From the older <code>java.awt.Window</code> object you
  25. * would normally do something like this:
  26. * <PRE>
  27. * dialog.add(child);
  28. * </PRE>
  29. * Using JDialog the proper semantic is:
  30. * <PRE>
  31. * dialog.getContentPane().add(child);
  32. * </PRE>
  33. * The same priniciple holds true for setting layout managers, removing
  34. * components, listing children, etc. All these methods should normally
  35. * be sent to the <code>contentPane</code> instead of to the JDialog.
  36. * The <code>contentPane</code> is always non-null. Attempting to set it
  37. * to null generates an exception. The default <code>contentPane</code>
  38. * has a BorderLayout manager set on it.
  39. * <p>
  40. * Please see the JRootPane documentation for a complete
  41. * description of the <code>contentPane</code>, <code>glassPane</code>,
  42. * and <code>layeredPane</code> components.
  43. * <p>
  44. * NOTE: For 1.1, Modal dialogs are currently constrained to only allow
  45. * lightweight popup menus (JPopupMenu, JComboBox, JMenuBar) because
  46. * of window ownership limitations in AWT1.1. This creates the further
  47. * limitation of not being able to mix Swing popup components with
  48. * AWT heavyweight components in a modal dialog since the heavyweight
  49. * components would always overlap the lightweights, potentially
  50. * obscuring the popup menu.
  51. * (A heavyweight component uses a native-platform component (peer)
  52. * component for its implementation -- AWT components are heavyweight
  53. * components.)
  54. * <p>
  55. * For the keyboard keys used by this component in the standard Look and
  56. * Feel (L&F) renditions, see the
  57. * <a href="doc-files/Key-Index.html#JDialog">JDialog</a> key assignments.
  58. * <p>
  59. * <strong>Warning:</strong>
  60. * Serialized objects of this class will not be compatible with
  61. * future Swing releases. The current serialization support is appropriate
  62. * for short term storage or RMI between applications running the same
  63. * version of Swing. A future release of Swing will provide support for
  64. * long term persistence.
  65. *
  66. * @see JOptionPane
  67. * @see JRootPane
  68. *
  69. * @beaninfo
  70. * attribute: isContainer true
  71. * attribute: containerDelegate getContentPane
  72. * description: A toplevel window for creating dialog boxes.
  73. *
  74. * @version 1.44 11/29/01
  75. * @author David Kloba
  76. * @author James Gosling
  77. * @author Scott Violet
  78. */
  79. public class JDialog extends Dialog implements WindowConstants, Accessible, RootPaneContainer
  80. {
  81. private int defaultCloseOperation = HIDE_ON_CLOSE;
  82. /**
  83. * @see #getRootPane
  84. * @see #setRootPane
  85. */
  86. protected JRootPane rootPane;
  87. /**
  88. * @see #isRootPaneCheckingEnabled
  89. * @see #setRootPaneCheckingEnabled
  90. */
  91. protected boolean rootPaneCheckingEnabled = false;
  92. /**
  93. * Creates a non-modal dialog without a title and without
  94. * a specified Frame owner. A shared, hidden frame will be
  95. * set as the owner of the Dialog.
  96. */
  97. public JDialog() {
  98. this((Frame)null, false);
  99. }
  100. /**
  101. * Creates a non-modal dialog without a title with the
  102. * specifed Frame as its owner.
  103. *
  104. * @param owner the Frame from which the dialog is displayed
  105. */
  106. public JDialog(Frame owner) {
  107. this(owner, false);
  108. }
  109. /**
  110. * Creates a modal or non-modal dialog without a title and
  111. * with the specified owner frame.
  112. *
  113. * @param owner the Frame from which the dialog is displayed
  114. * @param modal true for a modal dialog, false for one that allows
  115. * others windows to be active at the same time
  116. */
  117. public JDialog(Frame owner, boolean modal) {
  118. this(owner, null, modal);
  119. }
  120. /**
  121. * Creates a non-modal dialog with the specified title and
  122. * with the specified owner frame.
  123. *
  124. * @param owner the Frame from which the dialog is displayed
  125. * @param title the String to display in the dialog's title bar
  126. */
  127. public JDialog(Frame owner, String title) {
  128. this(owner, title, false);
  129. }
  130. /**
  131. * Creates a modal or non-modal dialog with the specified title
  132. * and the specified owner frame.
  133. * <p>
  134. * NOTE: Any popup components (JComboBox, JPopupMenu, JMenuBar)
  135. * created within a modal dialog will be forced to be lightweight.
  136. *
  137. * @param owner the frame from which the dialog is displayed
  138. * @param title the String to display in the dialog's title bar
  139. * @param modal true for a modal dialog, false for one that allows
  140. * others windows to be active at the same time
  141. */
  142. public JDialog(Frame owner, String title, boolean modal) {
  143. super(owner == null? SwingUtilities.getSharedOwnerFrame() : owner,
  144. title, modal);
  145. dialogInit();
  146. }
  147. /**
  148. * Creates a non-modal dialog without a title with the
  149. * specifed Dialog as its owner.
  150. *
  151. * @param owner the Dialog from which the dialog is displayed
  152. */
  153. public JDialog(Dialog owner) {
  154. this(owner, false);
  155. }
  156. /**
  157. * Creates a modal or non-modal dialog without a title and
  158. * with the specified owner dialog.
  159. * <p>
  160. *
  161. * @param owner the Dialog from which the dialog is displayed
  162. * @param modal true for a modal dialog, false for one that allows
  163. * others windows to be active at the same time
  164. */
  165. public JDialog(Dialog owner, boolean modal) {
  166. this(owner, null, modal);
  167. }
  168. /**
  169. * Creates a non-modal dialog with the specified title and
  170. * with the specified owner dialog.
  171. *
  172. * @param owner the Dialog from which the dialog is displayed
  173. * @param title the String to display in the dialog's title bar
  174. */
  175. public JDialog(Dialog owner, String title) {
  176. this(owner, title, false);
  177. }
  178. /**
  179. * Creates a modal or non-modal dialog with the specified title
  180. * and the specified owner frame.
  181. *
  182. * @param owner the dialog from which the dialog is displayed
  183. * @param title the String to display in the dialog's title bar
  184. * @param modal true for a modal dialog, false for one that allows
  185. * others windows to be active at the same time
  186. */
  187. public JDialog(Dialog owner, String title, boolean modal) {
  188. super(owner, title, modal);
  189. dialogInit();
  190. }
  191. /** Called by the constructors to init the JDialog properly. */
  192. protected void dialogInit() {
  193. enableEvents(AWTEvent.KEY_EVENT_MASK | AWTEvent.WINDOW_EVENT_MASK);
  194. setRootPane(createRootPane());
  195. setRootPaneCheckingEnabled(true);
  196. }
  197. /** Called by the constructor methods to create the default rootPane. */
  198. protected JRootPane createRootPane() {
  199. return new JRootPane();
  200. }
  201. /**
  202. * Processes key events occurring on this component and, if appropriate,
  203. * passes them on to components in the dialog which have registered
  204. * interest in them.
  205. *
  206. * @param e the key event
  207. * @see java.awt.Component#processKeyEvent
  208. */
  209. protected void processKeyEvent(KeyEvent e) {
  210. super.processKeyEvent(e);
  211. if(!e.isConsumed()) {
  212. JComponent.processKeyBindingsForAllComponents(e,this,e.getID() == KeyEvent.KEY_PRESSED);
  213. }
  214. }
  215. /**
  216. * Handles window events depending on the state of the
  217. * <code>defaultCloseOperation</code> property.
  218. *
  219. * @see #setDefaultCloseOperation
  220. */
  221. protected void processWindowEvent(WindowEvent e) {
  222. super.processWindowEvent(e);
  223. if (e.getID() == WindowEvent.WINDOW_CLOSING) {
  224. switch(defaultCloseOperation) {
  225. case HIDE_ON_CLOSE:
  226. setVisible(false);
  227. break;
  228. case DISPOSE_ON_CLOSE:
  229. setVisible(false);
  230. dispose();
  231. break;
  232. case 3:
  233. System.exit(0);
  234. break;
  235. case DO_NOTHING_ON_CLOSE:
  236. default:
  237. break;
  238. }
  239. }
  240. }
  241. /**
  242. * Sets the operation which will happen by default when
  243. * the user initiates a "close" on this dialog.
  244. * The possible choices are:
  245. * <ul>
  246. * <li>DO_NOTHING_ON_CLOSE - do not do anything - require the
  247. * program to handle the operation in the windowClosing
  248. * method of a registered WindowListener object.
  249. * <li>HIDE_ON_CLOSE - automatically hide the dialog after
  250. * invoking any registered WindowListener objects
  251. * <li>DISPOSE_ON_CLOSE - automatically hide and dispose the
  252. * dialog after invoking any registered WindowListener objects
  253. * <li>EXIT_ON_CLOSE - Exit the application by way of System.exit.
  254. * Only use this in applications.
  255. * </ul>
  256. * <p>
  257. * The value is set to HIDE_ON_CLOSE by default.
  258. * @see #addWindowListener
  259. * @see #getDefaultCloseOperation
  260. *
  261. * @beaninfo
  262. * preferred: true
  263. * description: The dialog's default close operation.
  264. */
  265. public void setDefaultCloseOperation(int operation) {
  266. this.defaultCloseOperation = operation;
  267. }
  268. /**
  269. * Returns the operation which occurs when the user
  270. * initiates a "close" on this dialog.
  271. *
  272. * @return an int indicating the window-close operation
  273. * @see #setDefaultCloseOperation
  274. */
  275. public int getDefaultCloseOperation() {
  276. return defaultCloseOperation;
  277. }
  278. /**
  279. * Just calls <code>paint(g)</code>. This method was overridden to
  280. * prevent an unneccessary call to clear the background.
  281. */
  282. public void update(Graphics g) {
  283. paint(g);
  284. }
  285. /**
  286. * Sets the menubar for this dialog.
  287. * @param menubar the menubar being placed in the dialog
  288. *
  289. * @see #getJMenuBar
  290. *
  291. * @beaninfo
  292. * hidden: true
  293. * description: The menubar for accessing pulldown menus from this dialog.
  294. */
  295. public void setJMenuBar(JMenuBar menu) {
  296. getRootPane().setMenuBar(menu);
  297. }
  298. /**
  299. * Returns the menubar set on this dialog.
  300. *
  301. * @see #setJMenuBar
  302. */
  303. public JMenuBar getJMenuBar() {
  304. return getRootPane().getMenuBar();
  305. }
  306. /**
  307. * @return true if add and setLayout should be checked
  308. * @see #addImpl
  309. * @see #setLayout
  310. * @see #setRootPaneCheckingEnabled
  311. */
  312. protected boolean isRootPaneCheckingEnabled() {
  313. return rootPaneCheckingEnabled;
  314. }
  315. /**
  316. * If true then calls to add() and setLayout() will cause an exception
  317. * to be thrown.
  318. *
  319. * @see #addImpl
  320. * @see #setLayout
  321. * @see #isRootPaneCheckingEnabled
  322. * @beaninfo
  323. * hidden: true
  324. * description: Whether the add and setLayout methods throw exceptions when invoked.
  325. */
  326. protected void setRootPaneCheckingEnabled(boolean enabled) {
  327. rootPaneCheckingEnabled = enabled;
  328. }
  329. /**
  330. * Create an runtime exception with a message like:
  331. * <pre>
  332. * "Do not use JDialog.add() use JDialog.getContentPane().add() instead"
  333. * </pre>
  334. */
  335. private Error createRootPaneException(String op) {
  336. String type = getClass().getName();
  337. return new Error(
  338. "Do not use " + type + "." + op + "() use "
  339. + type + ".getContentPane()." + op + "() instead");
  340. }
  341. /**
  342. * By default, children may not be added directly to a this component,
  343. * they must be added to its contentPane instead. For example:
  344. * <pre>
  345. * thisComponent.getContentPane().add(child)
  346. * </pre>
  347. * An attempt to add to directly to this component will cause an
  348. * runtime exception to be thrown. Subclasses can disable this
  349. * behavior.
  350. *
  351. * @see #setRootPaneCheckingEnabled
  352. * @exception Error if called with rootPaneChecking true
  353. */
  354. protected void addImpl(Component comp, Object constraints, int index)
  355. {
  356. if(isRootPaneCheckingEnabled()) {
  357. throw createRootPaneException("add");
  358. }
  359. else {
  360. super.addImpl(comp, constraints, index);
  361. }
  362. }
  363. /**
  364. * Removes the specified component from this container.
  365. * @param comp the component to be removed
  366. * @see #add
  367. */
  368. public void remove(Component comp) {
  369. if (comp == rootPane) {
  370. super.remove(comp);
  371. } else {
  372. // Client mistake, but we need to handle it to avoid a
  373. // common object leak in client applications.
  374. getContentPane().remove(comp);
  375. }
  376. }
  377. /**
  378. * By default the layout of this component may not be set,
  379. * the layout of its contentPane should be set instead.
  380. * For example:
  381. * <pre>
  382. * thisComponent.getContentPane().setLayout(new BorderLayout())
  383. * </pre>
  384. * An attempt to set the layout of this component will cause an
  385. * runtime exception to be thrown. Subclasses can disable this
  386. * behavior.
  387. *
  388. * @see #setRootPaneCheckingEnabled
  389. * @exception Error if called with rootPaneChecking true
  390. */
  391. public void setLayout(LayoutManager manager) {
  392. if(isRootPaneCheckingEnabled()) {
  393. throw createRootPaneException("setLayout");
  394. }
  395. else {
  396. super.setLayout(manager);
  397. }
  398. }
  399. /**
  400. * Returns the rootPane object for this dialog.
  401. *
  402. * @see #setRootPane
  403. * @see RootPaneContainer#getRootPane
  404. */
  405. public JRootPane getRootPane() {
  406. return rootPane;
  407. }
  408. /**
  409. * Sets the rootPane property. This method is called by the constructor.
  410. * @param root the rootPane object for this dialog
  411. *
  412. * @see #getRootPane
  413. *
  414. * @beaninfo
  415. * hidden: true
  416. * description: the RootPane object for this dialog.
  417. */
  418. protected void setRootPane(JRootPane root) {
  419. if(rootPane != null) {
  420. remove(rootPane);
  421. }
  422. rootPane = root;
  423. if(rootPane != null) {
  424. boolean checkingEnabled = isRootPaneCheckingEnabled();
  425. try {
  426. setRootPaneCheckingEnabled(false);
  427. add(rootPane, BorderLayout.CENTER);
  428. }
  429. finally {
  430. setRootPaneCheckingEnabled(checkingEnabled);
  431. }
  432. }
  433. }
  434. /**
  435. * Returns the contentPane object for this dialog.
  436. *
  437. * @see #setContentPane
  438. * @see RootPaneContainer#getContentPane
  439. */
  440. public Container getContentPane() {
  441. return getRootPane().getContentPane();
  442. }
  443. /**
  444. * Sets the contentPane property. This method is called by the constructor.
  445. * @param contentPane the contentPane object for this dialog
  446. *
  447. * @exception java.awt.IllegalComponentStateException (a runtime
  448. * exception) if the content pane parameter is null
  449. * @see #getContentPane
  450. * @see RootPaneContainer#setContentPane
  451. *
  452. * @beaninfo
  453. * hidden: true
  454. * description: The client area of the dialog where child
  455. * components are normally inserted.
  456. */
  457. public void setContentPane(Container contentPane) {
  458. getRootPane().setContentPane(contentPane);
  459. }
  460. /**
  461. * Returns the layeredPane object for this dialog.
  462. *
  463. * @see #setLayeredPane
  464. * @see RootPaneContainer#getLayeredPane
  465. */
  466. public JLayeredPane getLayeredPane() {
  467. return getRootPane().getLayeredPane();
  468. }
  469. /**
  470. * Sets the layeredPane property. This method is called by the constructor.
  471. * @param layeredPane the layeredPane object for this dialog
  472. *
  473. * @exception java.awt.IllegalComponentStateException (a runtime
  474. * exception) if the layered pane parameter is null
  475. * @see #getLayeredPane
  476. * @see RootPaneContainer#setLayeredPane
  477. *
  478. * @beaninfo
  479. * hidden: true
  480. * description: The pane which holds the various dialog layers.
  481. */
  482. public void setLayeredPane(JLayeredPane layeredPane) {
  483. getRootPane().setLayeredPane(layeredPane);
  484. }
  485. /**
  486. * Returns the glassPane object for this dialog.
  487. *
  488. * @see #setGlassPane
  489. * @see RootPaneContainer#getGlassPane
  490. */
  491. public Component getGlassPane() {
  492. return getRootPane().getGlassPane();
  493. }
  494. /**
  495. * Sets the glassPane property.
  496. * This method is called by the constructor.
  497. * @param glassPane the glassPane object for this dialog
  498. * @see #getGlassPane
  499. * @see RootPaneContainer#setGlassPane
  500. *
  501. * @beaninfo
  502. * hidden: true
  503. * description: A transparent pane used for menu rendering.
  504. */
  505. public void setGlassPane(Component glassPane) {
  506. getRootPane().setGlassPane(glassPane);
  507. }
  508. /**
  509. * Sets the location of the dialog relative to the specified
  510. * component. If the component is not currently showing, the
  511. * dialog is centered on the screen.
  512. *
  513. * @param c the component in relation to which the dialog's location
  514. * is determined
  515. */
  516. public void setLocationRelativeTo(Component c) {
  517. Container root=null;
  518. if (c != null) {
  519. if (c instanceof Window || c instanceof Applet) {
  520. root = (Container)c;
  521. } else {
  522. Container parent;
  523. for(parent = c.getParent() ; parent != null ; parent = parent.getParent()) {
  524. if (parent instanceof Window || parent instanceof Applet) {
  525. root = parent;
  526. break;
  527. }
  528. }
  529. }
  530. }
  531. if((c != null && !c.isShowing()) || root == null ||
  532. !root.isShowing()) {
  533. Dimension paneSize = getSize();
  534. Dimension screenSize = getToolkit().getScreenSize();
  535. setLocation((screenSize.width - paneSize.width) / 2,
  536. (screenSize.height - paneSize.height) / 2);
  537. } else {
  538. Dimension invokerSize = c.getSize();
  539. Point invokerScreenLocation;
  540. // If this method is called directly after a call to
  541. // setLocation() on the "root", getLocationOnScreen()
  542. // may return stale results (Bug#4181562), so we walk
  543. // up the tree to calculate the position instead
  544. // (unless "root" is an applet, where we cannot walk
  545. // all the way up to a toplevel window)
  546. //
  547. if (root instanceof Applet) {
  548. invokerScreenLocation = c.getLocationOnScreen();
  549. } else {
  550. invokerScreenLocation = new Point(0,0);
  551. Component tc = c;
  552. while (tc != null) {
  553. Point tcl = tc.getLocation();
  554. invokerScreenLocation.x += tcl.x;
  555. invokerScreenLocation.y += tcl.y;
  556. if (tc == root) {
  557. break;
  558. }
  559. tc = tc.getParent();
  560. }
  561. }
  562. Rectangle dialogBounds = getBounds();
  563. int dx = invokerScreenLocation.x+((invokerSize.width-dialogBounds.width)>>1);
  564. int dy = invokerScreenLocation.y+((invokerSize.height - dialogBounds.height)>>1);
  565. Dimension ss = getToolkit().getScreenSize();
  566. if (dy+dialogBounds.height>ss.height) {
  567. dy = ss.height-dialogBounds.height;
  568. dx = invokerScreenLocation.x<(ss.width>>1) ? invokerScreenLocation.x+invokerSize.width :
  569. invokerScreenLocation.x-dialogBounds.width;
  570. }
  571. if (dx+dialogBounds.width>ss.width) dx = ss.width-dialogBounds.width;
  572. if (dx<0) dx = 0;
  573. if (dy<0) dy = 0;
  574. setLocation(dx, dy);
  575. }
  576. }
  577. /**
  578. * Returns a string representation of this JDialog. This method
  579. * is intended to be used only for debugging purposes, and the
  580. * content and format of the returned string may vary between
  581. * implementations. The returned string may be empty but may not
  582. * be <code>null</code>.
  583. *
  584. * @return a string representation of this JDialog.
  585. */
  586. protected String paramString() {
  587. String defaultCloseOperationString;
  588. if (defaultCloseOperation == HIDE_ON_CLOSE) {
  589. defaultCloseOperationString = "HIDE_ON_CLOSE";
  590. } else if (defaultCloseOperation == DISPOSE_ON_CLOSE) {
  591. defaultCloseOperationString = "DISPOSE_ON_CLOSE";
  592. } else if (defaultCloseOperation == DO_NOTHING_ON_CLOSE) {
  593. defaultCloseOperationString = "DO_NOTHING_ON_CLOSE";
  594. } else if (defaultCloseOperation == 3) {
  595. defaultCloseOperationString = "EXIT_ON_CLOSE";
  596. } else defaultCloseOperationString = "";
  597. String rootPaneString = (rootPane != null ?
  598. rootPane.toString() : "");
  599. String rootPaneCheckingEnabledString = (rootPaneCheckingEnabled ?
  600. "true" : "false");
  601. return super.paramString() +
  602. ",defaultCloseOperation=" + defaultCloseOperationString +
  603. ",rootPane=" + rootPaneString +
  604. ",rootPaneCheckingEnabled=" + rootPaneCheckingEnabledString;
  605. }
  606. /////////////////
  607. // Accessibility support
  608. ////////////////
  609. protected AccessibleContext accessibleContext = null;
  610. /**
  611. * Get the AccessibleContext associated with this JDialog
  612. *
  613. * @return the AccessibleContext of this JDialog
  614. */
  615. public AccessibleContext getAccessibleContext() {
  616. if (accessibleContext == null) {
  617. accessibleContext = new AccessibleJDialog();
  618. }
  619. return accessibleContext;
  620. }
  621. /**
  622. * The class used to obtain the AccessibleRole for this object.
  623. */
  624. protected class AccessibleJDialog extends AccessibleContext
  625. implements Serializable, AccessibleComponent {
  626. // AccessibleContext methods
  627. //
  628. /**
  629. * Get the accessible name of this object.
  630. *
  631. * @return the localized name of the object -- can be null if this
  632. * object does not have a name
  633. */
  634. public String getAccessibleName() {
  635. if (accessibleName != null) {
  636. return accessibleName;
  637. } else {
  638. if (getTitle() == null) {
  639. return super.getAccessibleName();
  640. } else {
  641. return getTitle();
  642. }
  643. }
  644. }
  645. /**
  646. * Get the role of this object.
  647. *
  648. * @return an instance of AccessibleRole describing the role of the
  649. * object
  650. * @see AccessibleRole
  651. */
  652. public AccessibleRole getAccessibleRole() {
  653. return AccessibleRole.DIALOG;
  654. }
  655. /**
  656. * Get the state of this object.
  657. *
  658. * @return an instance of AccessibleStateSet containing the current
  659. * state set of the object
  660. * @see AccessibleState
  661. */
  662. public AccessibleStateSet getAccessibleStateSet() {
  663. AccessibleStateSet states = SwingUtilities.getAccessibleStateSet(JDialog.this);
  664. if (isResizable()) {
  665. states.add(AccessibleState.RESIZABLE);
  666. }
  667. if (getFocusOwner() != null) {
  668. states.add(AccessibleState.ACTIVE);
  669. }
  670. if (isModal()) {
  671. states.add(AccessibleState.MODAL);
  672. }
  673. return states;
  674. }
  675. /**
  676. * Get the Accessible parent of this object. If the parent of this
  677. * object implements Accessible, this method should simply return
  678. * getParent().
  679. *
  680. * @return the Accessible parent of this object -- can be null if this
  681. * object does not have an Accessible parent
  682. */
  683. public Accessible getAccessibleParent() {
  684. if (accessibleParent != null) {
  685. return accessibleParent;
  686. } else {
  687. Container parent = getParent();
  688. if (parent instanceof Accessible) {
  689. return (Accessible) parent;
  690. }
  691. }
  692. return null;
  693. }
  694. /**
  695. * Get the index of this object in its accessible parent.
  696. *
  697. * @return the index of this object in its parent; -1 if this
  698. * object does not have an accessible parent.
  699. * @see #getAccessibleParent
  700. */
  701. public int getAccessibleIndexInParent() {
  702. return SwingUtilities.getAccessibleIndexInParent(JDialog.this);
  703. }
  704. /**
  705. * Returns the number of accessible children in the object. If all
  706. * of the children of this object implement Accessible, than this
  707. * method should return the number of children of this object.
  708. *
  709. * @return the number of accessible children in the object.
  710. */
  711. public int getAccessibleChildrenCount() {
  712. return SwingUtilities.getAccessibleChildrenCount(JDialog.this);
  713. }
  714. /**
  715. * Return the nth Accessible child of the object.
  716. *
  717. * @param i zero-based index of child
  718. * @return the nth Accessible child of the object
  719. */
  720. public Accessible getAccessibleChild(int i) {
  721. return SwingUtilities.getAccessibleChild(JDialog.this,i);
  722. }
  723. /**
  724. * Return the locale of this object.
  725. *
  726. * @return the locale of this object
  727. */
  728. public Locale getLocale() {
  729. return JDialog.this.getLocale();
  730. }
  731. /**
  732. * Get the AccessibleComponent associated with this object if one
  733. * exists. Otherwise return null.
  734. */
  735. public AccessibleComponent getAccessibleComponent() {
  736. return this;
  737. }
  738. // AccessibleComponent methods
  739. //
  740. /**
  741. * Get the background color of this object.
  742. *
  743. * @return the background color, if supported, of the object;
  744. * otherwise, null
  745. */
  746. public Color getBackground() {
  747. return JDialog.this.getBackground();
  748. }
  749. /**
  750. * Set the background color of this object.
  751. *
  752. * @param c the new Color for the background
  753. */
  754. public void setBackground(Color c) {
  755. JDialog.this.setBackground(c);
  756. }
  757. /**
  758. * Get the foreground color of this object.
  759. *
  760. * @return the foreground color, if supported, of the object;
  761. * otherwise, null
  762. */
  763. public Color getForeground() {
  764. return JDialog.this.getForeground();
  765. }
  766. /**
  767. * Set the foreground color of this object.
  768. *
  769. * @param c the new Color for the foreground
  770. */
  771. public void setForeground(Color c) {
  772. JDialog.this.setForeground(c);
  773. }
  774. /**
  775. * Get the Cursor of this object.
  776. *
  777. * @return the Cursor, if supported, of the object; otherwise, null
  778. */
  779. public Cursor getCursor() {
  780. return JDialog.this.getCursor();
  781. }
  782. /**
  783. * Set the Cursor of this object.
  784. *
  785. * @param c the new Cursor for the object
  786. */
  787. public void setCursor(Cursor cursor) {
  788. JDialog.this.setCursor(cursor);
  789. }
  790. /**
  791. * Get the Font of this object.
  792. *
  793. * @return the Font,if supported, for the object; otherwise, null
  794. */
  795. public Font getFont() {
  796. return JDialog.this.getFont();
  797. }
  798. /**
  799. * Set the Font of this object.
  800. *
  801. * @param f the new Font for the object
  802. */
  803. public void setFont(Font f) {
  804. JDialog.this.setFont(f);
  805. }
  806. /**
  807. * Get the FontMetrics of this object.
  808. *
  809. * @param f the Font
  810. * @return the FontMetrics, if supported, the object; otherwise, null
  811. * @see #getFont
  812. */
  813. public FontMetrics getFontMetrics(Font f) {
  814. return JDialog.this.getFontMetrics(f);
  815. }
  816. /**
  817. * Determine if the object is enabled.
  818. *
  819. * @return true if object is enabled; otherwise, false
  820. */
  821. public boolean isEnabled() {
  822. return JDialog.this.isEnabled();
  823. }
  824. /**
  825. * Set the enabled state of the object.
  826. *
  827. * @param b if true, enables this object; otherwise, disables it
  828. */
  829. public void setEnabled(boolean b) {
  830. JDialog.this.setEnabled(b);
  831. }
  832. /**
  833. * Determine if the object is visible. Note: this means that the
  834. * object intends to be visible; however, it may not in fact be
  835. * showing on the screen because one of the objects that this object
  836. * is contained by is not visible. To determine if an object is
  837. * showing on the screen, use isShowing().
  838. *
  839. * @return true if object is visible; otherwise, false
  840. */
  841. public boolean isVisible() {
  842. return JDialog.this.isVisible();
  843. }
  844. /**
  845. * Set the visible state of the object.
  846. *
  847. * @param b if true, shows this object; otherwise, hides it
  848. */
  849. public void setVisible(boolean b) {
  850. JDialog.this.setVisible(b);
  851. }
  852. /**
  853. * Determine if the object is showing. This is determined by checking
  854. * the visibility of the object and ancestors of the object. Note:
  855. * this will return true even if the object is obscured by another
  856. * (for example, it happens to be underneath a menu that was pulled
  857. * down).
  858. *
  859. * @return true if object is showing; otherwise, false
  860. */
  861. public boolean isShowing() {
  862. return JDialog.this.isShowing();
  863. }
  864. /**
  865. * Checks whether the specified point is within this object's bounds,
  866. * where the point's x and y coordinates are defined to be relative to
  867. * the coordinate system of the object.
  868. *
  869. * @param p the Point relative to the coordinate system of the object
  870. * @return true if object contains Point; otherwise false
  871. */
  872. public boolean contains(Point p) {
  873. return JDialog.this.contains(p);
  874. }
  875. /**
  876. * Returns the location of the object on the screen.
  877. *
  878. * @return location of object on screen -- can be null if this object
  879. * is not on the screen
  880. */
  881. public Point getLocationOnScreen() {
  882. return JDialog.this.getLocationOnScreen();
  883. }
  884. /**
  885. * Gets the location of the object relative to the parent in the form
  886. * of a point specifying the object's top-left corner in the screen's
  887. * coordinate space.
  888. *
  889. * @return An instance of Point representing the top-left corner of
  890. * the objects's bounds in the coordinate space of the screen; null if
  891. * this object or its parent are not on the screen
  892. */
  893. public Point getLocation() {
  894. return JDialog.this.getLocation();
  895. }
  896. /**
  897. * Sets the location of the object relative to the parent.
  898. */
  899. public void setLocation(Point p) {
  900. JDialog.this.setLocation(p);
  901. }
  902. /**
  903. * Gets the bounds of this object in the form of a Rectangle object.
  904. * The bounds specify this object's width, height, and location
  905. * relative to its parent.
  906. *
  907. * @return A rectangle indicating this component's bounds; null if
  908. * this object is not on the screen.
  909. */
  910. public Rectangle getBounds() {
  911. return JDialog.this.getBounds();
  912. }
  913. /**
  914. * Sets the bounds of this object in the form of a Rectangle object.
  915. * The bounds specify this object's width, height, and location
  916. * relative to its parent.
  917. *
  918. * @param A rectangle indicating this component's bounds
  919. */
  920. public void setBounds(Rectangle r) {
  921. JDialog.this.setBounds(r);
  922. }
  923. /**
  924. * Returns the size of this object in the form of a Dimension object.
  925. * The height field of the Dimension object contains this objects's
  926. * height, and the width field of the Dimension object contains this
  927. * object's width.
  928. *
  929. * @return A Dimension object that indicates the size of this
  930. * component; null if this object is not on the screen
  931. */
  932. public Dimension getSize() {
  933. return JDialog.this.getSize();
  934. }
  935. /**
  936. * Resizes this object so that it has width width and height.
  937. *
  938. * @param d - The dimension specifying the new size of the object.
  939. */
  940. public void setSize(Dimension d) {
  941. JDialog.this.setSize(d);
  942. }
  943. /**
  944. * Returns the Accessible child, if one exists, contained at the local
  945. * coordinate Point.
  946. *
  947. * @param p The point defining the top-left corner of the Accessible,
  948. * given in the coordinate space of the object's parent.
  949. * @return the Accessible, if it exists, at the specified location;
  950. * else null
  951. */
  952. public Accessible getAccessibleAt(Point p) {
  953. return SwingUtilities.getAccessibleAt(JDialog.this,p);
  954. }
  955. /**
  956. * Returns whether this object can accept focus or not.
  957. *
  958. * @return true if object can accept focus; otherwise false
  959. */
  960. public boolean isFocusTraversable() {
  961. return JDialog.this.isFocusTraversable();
  962. }
  963. /**
  964. * Requests focus for this object.
  965. */
  966. public void requestFocus() {
  967. JDialog.this.requestFocus();
  968. }
  969. /**
  970. * Adds the specified focus listener to receive focus events from this
  971. * component.
  972. *
  973. * @param l the focus listener
  974. */
  975. public void addFocusListener(FocusListener l) {
  976. JDialog.this.addFocusListener(l);
  977. }
  978. /**
  979. * Removes the specified focus listener so it no longer receives focus
  980. * events from this component.
  981. *
  982. * @param l the focus listener
  983. */
  984. public void removeFocusListener(FocusListener l) {
  985. JDialog.this.removeFocusListener(l);
  986. }
  987. } // inner class AccessibleJDialog
  988. }