1. /*
  2. * @(#)Dialog.java 1.99 04/05/18
  3. *
  4. * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.peer.DialogPeer;
  9. import java.awt.event.*;
  10. import java.io.ObjectOutputStream;
  11. import java.io.ObjectInputStream;
  12. import java.io.IOException;
  13. import javax.accessibility.*;
  14. import sun.awt.AppContext;
  15. import sun.awt.SunToolkit;
  16. import sun.awt.PeerEvent;
  17. /**
  18. * A Dialog is a top-level window with a title and a border
  19. * that is typically used to take some form of input from the user.
  20. *
  21. * The size of the dialog includes any area designated for the
  22. * border. The dimensions of the border area can be obtained
  23. * using the <code>getInsets</code> method, however, since
  24. * these dimensions are platform-dependent, a valid insets
  25. * value cannot be obtained until the dialog is made displayable
  26. * by either calling <code>pack</code> or <code>show</code>.
  27. * Since the border area is included in the overall size of the
  28. * dialog, the border effectively obscures a portion of the dialog,
  29. * constraining the area available for rendering and/or displaying
  30. * subcomponents to the rectangle which has an upper-left corner
  31. * location of <code>(insets.left, insets.top)</code>, and has a size of
  32. * <code>width - (insets.left + insets.right)</code> by
  33. * <code>height - (insets.top + insets.bottom)</code>.
  34. * <p>
  35. * The default layout for a dialog is <code>BorderLayout</code>.
  36. * <p>
  37. * A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
  38. * with <code>setUndecorated</code>. This can only be done while the dialog
  39. * is not {@link Component#isDisplayable() displayable}.
  40. * <p>
  41. * A dialog must have either a frame or another dialog defined as its
  42. * owner when it's constructed. When the owner window of a visible dialog
  43. * is minimized, the dialog will automatically be hidden
  44. * from the user. When the owner window is subsequently restored,
  45. * the dialog is made visible to the user again.
  46. * <p>
  47. * In a multi-screen environment, you can create a <code>Dialog</code>
  48. * on a different screen device than its owner. See {@link java.awt.Frame} for
  49. * more information.
  50. * <p>
  51. * A dialog can be either modeless (the default) or modal. A modal
  52. * dialog is one which blocks input to all other toplevel windows
  53. * in the application, except for any windows created with the dialog
  54. * as their owner.
  55. * <p>
  56. * Dialogs are capable of generating the following
  57. * <code>WindowEvents</code>:
  58. * <code>WindowOpened</code>, <code>WindowClosing</code>,
  59. * <code>WindowClosed</code>, <code>WindowActivated</code>,
  60. * <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>,
  61. * <code>WindowLostFocus</code>.
  62. *
  63. * @see WindowEvent
  64. * @see Window#addWindowListener
  65. *
  66. * @version 1.99, 05/18/04
  67. * @author Sami Shaio
  68. * @author Arthur van Hoff
  69. * @since JDK1.0
  70. */
  71. public class Dialog extends Window {
  72. static {
  73. /* ensure that the necessary native libraries are loaded */
  74. Toolkit.loadLibraries();
  75. if (!GraphicsEnvironment.isHeadless()) {
  76. initIDs();
  77. }
  78. }
  79. /**
  80. * A dialog's resizable property. Will be true
  81. * if the Dialog is to be resizable, otherwise
  82. * it will be false.
  83. *
  84. * @serial
  85. * @see #setResizable(boolean)
  86. */
  87. boolean resizable = true;
  88. /**
  89. * This field indicates whether the dialog is undecorated.
  90. * This property can only be changed while the dialog is not displayable.
  91. * <code>undecorated</code> will be true if the dialog is
  92. * undecorated, otherwise it will be false.
  93. *
  94. * @serial
  95. * @see #setUndecorated(boolean)
  96. * @see #isUndecorated()
  97. * @see Component#isDisplayable()
  98. * @since 1.4
  99. */
  100. boolean undecorated = false;
  101. /**
  102. * Will be true if the Dialog is modal,
  103. * otherwise the dialog will be modeless.
  104. * A modal Dialog grabs all the input to
  105. * the owner frame from the user.
  106. *
  107. * @serial
  108. * @see #isModal()
  109. * @see #setModal(boolean)
  110. */
  111. boolean modal;
  112. /**
  113. * Specifies the title of the Dialog.
  114. * This field can be null.
  115. *
  116. * @serial
  117. * @see #getTitle()
  118. * @see #setTitle(String)
  119. */
  120. String title;
  121. private transient boolean keepBlocking = false;
  122. private static final String base = "dialog";
  123. private static int nameCounter = 0;
  124. /*
  125. * JDK 1.1 serialVersionUID
  126. */
  127. private static final long serialVersionUID = 5920926903803293709L;
  128. /**
  129. * Constructs an initially invisible, non-modal <code>Dialog</code> with
  130. * an empty title and the specified owner frame.
  131. *
  132. * @param owner the owner of the dialog
  133. * @exception IllegalArgumentException if the <code>owner</code>'s
  134. * <code>GraphicsConfiguration</code> is not from a screen device
  135. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  136. * is <code>null</code> this exception is always thrown
  137. * when <code>GraphicsEnvironment.isHeadless</code>
  138. * returns <code>true</code>
  139. * @see java.awt.GraphicsEnvironment#isHeadless
  140. * @see Component#setSize
  141. * @see Component#setVisible
  142. */
  143. public Dialog(Frame owner) {
  144. this(owner, "", false);
  145. }
  146. /**
  147. * Constructs an initially invisible <code>Dialog</code> with an empty title,
  148. * the specified owner frame and modality.
  149. *
  150. * @param owner the owner of the dialog
  151. * @param modal if <code>true</code>, dialog blocks input to other
  152. * app windows when shown
  153. * @exception IllegalArgumentException if the <code>owner</code>'s
  154. * <code>GraphicsConfiguration</code> is not from a screen device
  155. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  156. * is <code>null</code> this exception is always thrown
  157. * when <code>GraphicsEnvironment.isHeadless</code>
  158. * returns <code>true</code>
  159. * @see java.awt.GraphicsEnvironment#isHeadless
  160. */
  161. public Dialog(Frame owner, boolean modal) {
  162. this(owner, "", modal);
  163. }
  164. /**
  165. * Constructs an initially invisible, non-modal <code>Dialog</code> with
  166. * the specified owner frame and title.
  167. *
  168. * @param owner the owner of the dialog
  169. * @param title the title of the dialog; a <code>null</code> value
  170. * will be accepted without causing a
  171. * <code>NullPointerException</code> to be thrown
  172. * @exception IllegalArgumentException if the <code>owner</code>'s
  173. * <code>GraphicsConfiguration</code> is not from a screen device
  174. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  175. * is <code>null</code> this exception is always thrown
  176. * when <code>GraphicsEnvironment.isHeadless</code>
  177. * returns <code>true</code>
  178. * @see java.awt.GraphicsEnvironment#isHeadless
  179. * @see Component#setSize
  180. * @see Component#setVisible
  181. */
  182. public Dialog(Frame owner, String title) {
  183. this(owner, title, false);
  184. }
  185. /**
  186. * Constructs an initially invisible <code>Dialog</code> with the
  187. * specified owner frame, title, and modality.
  188. *
  189. * @param owner the owner of the dialog
  190. * @param title the title of the dialog; a <code>null</code> value
  191. * will be accepted without causing a
  192. * <code>NullPointerException</code> to be thrown
  193. * @param modal if true, dialog blocks input to other app windows when shown
  194. * @exception IllegalArgumentException if the <code>owner</code>'s
  195. * <code>GraphicsConfiguration</code> is not from a screen device
  196. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  197. * is <code>null</code>. This exception is always thrown
  198. * when <code>GraphicsEnvironment.isHeadless</code>
  199. * returns <code>true</code>
  200. * @see java.awt.GraphicsEnvironment#isHeadless
  201. * @see Component#setSize
  202. * @see Component#setVisible
  203. */
  204. public Dialog(Frame owner, String title, boolean modal) {
  205. super(owner);
  206. this.title = title;
  207. this.modal = modal;
  208. SunToolkit.checkAndSetPolicy(this, false);
  209. }
  210. /**
  211. * Constructs an initially invisible Dialog with the
  212. * specified owner frame, title, modality, and
  213. * <code>GraphicsConfiguration</code>.
  214. * @param owner the owner of the dialog
  215. * @param title the title of the dialog. A <code>null</code> value
  216. * will be accepted without causing a NullPointerException
  217. * to be thrown.
  218. * @param modal if true, dialog blocks input to other app windows when shown
  219. * @param gc the <code>GraphicsConfiguration</code>
  220. * of the target screen device. If <code>gc</code> is
  221. * <code>null</code>, the same
  222. * <code>GraphicsConfiguration</code> as the owning Frame is used.
  223. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  224. * is <code>null</code>. This exception is always thrown
  225. * when GraphicsEnvironment.isHeadless() returns true
  226. * @see java.awt.GraphicsEnvironment#isHeadless
  227. * @see Component#setSize
  228. * @see Component#setVisible
  229. * @since 1.4
  230. */
  231. public Dialog(Frame owner, String title, boolean modal,
  232. GraphicsConfiguration gc) {
  233. super(owner, gc);
  234. this.title = title;
  235. this.modal = modal;
  236. SunToolkit.checkAndSetPolicy(this, false);
  237. }
  238. /**
  239. * Constructs an initially invisible, non-modal Dialog with
  240. * an empty title and the specified owner dialog.
  241. * @param owner the owner of the dialog
  242. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  243. * is <code>null</code>. This exception is always thrown
  244. * when GraphicsEnvironment.isHeadless() returns true
  245. * @see java.awt.GraphicsEnvironment#isHeadless
  246. * @since 1.2
  247. */
  248. public Dialog(Dialog owner) {
  249. this(owner, "", false);
  250. }
  251. /**
  252. * Constructs an initially invisible, non-modal Dialog
  253. * with the specified owner dialog and title.
  254. * @param owner the owner of the dialog
  255. * @param title the title of the dialog. A <code>null</code> value
  256. * will be accepted without causing a NullPointerException
  257. * to be thrown.
  258. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  259. * is <code>null</code>. This exception is always thrown
  260. * when GraphicsEnvironment.isHeadless() returns true
  261. * @see java.awt.GraphicsEnvironment#isHeadless
  262. * @since 1.2
  263. */
  264. public Dialog(Dialog owner, String title) {
  265. this(owner, title, false);
  266. }
  267. /**
  268. * Constructs an initially invisible <code>Dialog</code> with the
  269. * specified owner dialog, title, and modality.
  270. *
  271. * @param owner the owner of the dialog
  272. * @exception IllegalArgumentException if the <code>owner</code>'s
  273. * <code>GraphicsConfiguration</code> is not from a screen device
  274. * @param title the title of the dialog; a <code>null</code> value
  275. * will be accepted without causing a
  276. * <code>NullPointerException</code> to be thrown
  277. * @param modal if true, dialog blocks input to other app windows when shown
  278. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  279. * is <code>null</code> this exception is always thrown
  280. * when <code>GraphicsEnvironment.isHeadless</code>
  281. * returns <code>true</code>
  282. * @see java.awt.GraphicsEnvironment#isHeadless
  283. * @since 1.2
  284. */
  285. public Dialog(Dialog owner, String title, boolean modal) {
  286. super(owner);
  287. this.title = title;
  288. this.modal = modal;
  289. SunToolkit.checkAndSetPolicy(this, false);
  290. }
  291. /**
  292. * Constructs an initially invisible <code>Dialog</code> with the
  293. * specified owner dialog, title, modality, and
  294. * <code>GraphicsConfiguration</code>.
  295. *
  296. * @param owner the owner of the dialog
  297. * @param title the title of the dialog; a <code>null</code> value
  298. * will be accepted without causing a
  299. * <code>NullPointerException</code> to be thrown
  300. * @param modal if true, dialog blocks input to other app windows when shown
  301. * @param gc the <code>GraphicsConfiguration</code>
  302. * of the target screen device; if <code>gc</code> is
  303. * <code>null</code>, the same
  304. * <code>GraphicsConfiguration</code> as the owning Dialog is used
  305. * @exception IllegalArgumentException if the <code>owner</code>'s
  306. * <code>GraphicsConfiguration</code> is not from a screen device
  307. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  308. * is <code>null</code> this exception is always thrown
  309. * when <code>GraphicsEnvironment.isHeadless</code>
  310. * returns <code>true</code>
  311. * @see java.awt.GraphicsEnvironment#isHeadless
  312. * @see Component#setSize
  313. * @see Component#setVisible
  314. * @since 1.4
  315. */
  316. public Dialog(Dialog owner, String title, boolean modal,
  317. GraphicsConfiguration gc) {
  318. super(owner, gc);
  319. this.title = title;
  320. this.modal = modal;
  321. SunToolkit.checkAndSetPolicy(this, false);
  322. }
  323. /**
  324. * Construct a name for this component. Called by getName() when the
  325. * name is null.
  326. */
  327. String constructComponentName() {
  328. synchronized (getClass()) {
  329. return base + nameCounter++;
  330. }
  331. }
  332. /**
  333. * Makes this Dialog displayable by connecting it to
  334. * a native screen resource. Making a dialog displayable will
  335. * cause any of its children to be made displayable.
  336. * This method is called internally by the toolkit and should
  337. * not be called directly by programs.
  338. * @see Component#isDisplayable
  339. * @see #removeNotify
  340. */
  341. public void addNotify() {
  342. synchronized (getTreeLock()) {
  343. if (parent != null && parent.getPeer() == null) {
  344. parent.addNotify();
  345. }
  346. if (peer == null) {
  347. peer = getToolkit().createDialog(this);
  348. }
  349. super.addNotify();
  350. }
  351. }
  352. /**
  353. * Indicates whether the dialog is modal.
  354. * When a modal Dialog is made visible, user input will be
  355. * blocked to the other windows in the application, except for
  356. * any windows created with this dialog as their owner.
  357. *
  358. * @return <code>true</code> if this dialog window is modal;
  359. * <code>false</code> otherwise.
  360. * @see java.awt.Dialog#setModal
  361. */
  362. public boolean isModal() {
  363. return modal;
  364. }
  365. /**
  366. * Specifies whether this dialog should be modal.
  367. * @see java.awt.Dialog#isModal
  368. * @since JDK1.1
  369. */
  370. public void setModal(boolean b) {
  371. this.modal = b;
  372. }
  373. /**
  374. * Gets the title of the dialog. The title is displayed in the
  375. * dialog's border.
  376. * @return the title of this dialog window. The title may be
  377. * <code>null</code>.
  378. * @see java.awt.Dialog#setTitle
  379. */
  380. public String getTitle() {
  381. return title;
  382. }
  383. /**
  384. * Sets the title of the Dialog.
  385. * @param title the title displayed in the dialog's border;
  386. * a null value results in an empty title
  387. * @see #getTitle
  388. */
  389. public void setTitle(String title) {
  390. String oldTitle = this.title;
  391. synchronized(this) {
  392. this.title = title;
  393. DialogPeer peer = (DialogPeer)this.peer;
  394. if (peer != null) {
  395. peer.setTitle(title);
  396. }
  397. }
  398. firePropertyChange("title", oldTitle, title);
  399. }
  400. /**
  401. * @return true if we actually showed, false if we just called toFront()
  402. */
  403. private boolean conditionalShow() {
  404. boolean retval;
  405. synchronized (getTreeLock()) {
  406. if (peer == null) {
  407. addNotify();
  408. }
  409. validate();
  410. if (visible) {
  411. toFront();
  412. retval = false;
  413. } else {
  414. visible = retval = true;
  415. peer.show(); // now guaranteed never to block
  416. createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
  417. this, parent,
  418. HierarchyEvent.SHOWING_CHANGED,
  419. Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
  420. }
  421. if (retval && (componentListener != null ||
  422. (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
  423. Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))) {
  424. ComponentEvent e =
  425. new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
  426. Toolkit.getEventQueue().postEvent(e);
  427. }
  428. }
  429. if (retval && (state & OPENED) == 0) {
  430. postWindowEvent(WindowEvent.WINDOW_OPENED);
  431. state |= OPENED;
  432. }
  433. return retval;
  434. }
  435. /**
  436. * Stores the app context on which event dispatch thread the dialog
  437. * is being shown. Initialized in show(), used in hideAndDisposeHandler()
  438. */
  439. transient private AppContext showAppContext;
  440. /**
  441. * @deprecated As of JDK version 1.5, replaced by
  442. * {@link Component#setVisible(boolean) Component.setVisible(boolean)}.
  443. */
  444. @Deprecated
  445. public void show() {
  446. beforeFirstShow = false;
  447. if (!isModal()) {
  448. conditionalShow();
  449. } else {
  450. // Set this variable before calling conditionalShow(). That
  451. // way, if the Dialog is hidden right after being shown, we
  452. // won't mistakenly block this thread.
  453. keepBlocking = true;
  454. // Store the app context on which this dialog is being shown.
  455. // Event dispatch thread of this app context will be sleeping until
  456. // we wake it by any event from hideAndDisposeHandler().
  457. showAppContext = AppContext.getAppContext();
  458. // keep the KeyEvents from being dispatched
  459. // until the focus has been transfered
  460. long time = Toolkit.getEventQueue().getMostRecentEventTimeEx();
  461. Component predictedFocusOwner = getMostRecentFocusOwner();
  462. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  463. enqueueKeyEvents(time, predictedFocusOwner);
  464. try {
  465. if (conditionalShow()) {
  466. // We have two mechanisms for blocking: 1. If we're on the
  467. // EventDispatchThread, start a new event pump. 2. If we're
  468. // on any other thread, call wait() on the treelock.
  469. Runnable pumpEventsForHierarchy = new Runnable() {
  470. public void run() {
  471. EventDispatchThread dispatchThread =
  472. (EventDispatchThread)Thread.currentThread();
  473. dispatchThread.pumpEventsForHierarchy(new Conditional() {
  474. public boolean evaluate() {
  475. return keepBlocking && windowClosingException == null;
  476. }
  477. }, Dialog.this);
  478. }
  479. };
  480. if (EventQueue.isDispatchThread()) {
  481. /*
  482. * dispose SequencedEvent we are dispatching on current
  483. * AppContext, to prevent us from hang.
  484. *
  485. * BugId 4531693 (son@sparc.spb.su)
  486. */
  487. SequencedEvent currentSequencedEvent = KeyboardFocusManager.
  488. getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
  489. if (currentSequencedEvent != null) {
  490. currentSequencedEvent.dispose();
  491. }
  492. pumpEventsForHierarchy.run();
  493. } else {
  494. synchronized (getTreeLock()) {
  495. Toolkit.getEventQueue().
  496. postEvent(new PeerEvent(this,
  497. pumpEventsForHierarchy,
  498. PeerEvent.PRIORITY_EVENT));
  499. while (keepBlocking && windowClosingException == null) {
  500. try {
  501. getTreeLock().wait();
  502. } catch (InterruptedException e) {
  503. break;
  504. }
  505. }
  506. }
  507. }
  508. if (windowClosingException != null) {
  509. windowClosingException.fillInStackTrace();
  510. throw windowClosingException;
  511. }
  512. }
  513. } finally {
  514. // Restore normal key event dispatching
  515. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  516. dequeueKeyEvents(time, predictedFocusOwner);
  517. }
  518. }
  519. }
  520. void interruptBlocking() {
  521. if (modal) {
  522. disposeImpl();
  523. } else if (windowClosingException != null) {
  524. windowClosingException.fillInStackTrace();
  525. windowClosingException.printStackTrace();
  526. windowClosingException = null;
  527. }
  528. }
  529. final static class WakingRunnable implements Runnable {
  530. public void run() {
  531. }
  532. }
  533. private void hideAndDisposeHandler() {
  534. if (keepBlocking) {
  535. synchronized (getTreeLock()) {
  536. keepBlocking = false;
  537. if (showAppContext != null) {
  538. // Wake up event dispatch thread on which the dialog was
  539. // initially shown
  540. SunToolkit.postEvent(showAppContext,
  541. new PeerEvent(this,
  542. new WakingRunnable(),
  543. PeerEvent.PRIORITY_EVENT));
  544. showAppContext = null;
  545. }
  546. EventQueue.invokeLater(new WakingRunnable());
  547. getTreeLock().notifyAll();
  548. }
  549. }
  550. }
  551. /**
  552. * @deprecated As of JDK version 1.5, replaced by
  553. * {@link Component#setVisible(boolean) Component.setVisible(boolean)}.
  554. */
  555. @Deprecated
  556. public void hide() {
  557. super.hide();
  558. hideAndDisposeHandler();
  559. }
  560. /**
  561. * Disposes the Dialog and then causes show() to return if it is currently
  562. * blocked.
  563. */
  564. void doDispose() {
  565. super.doDispose();
  566. hideAndDisposeHandler();
  567. }
  568. /**
  569. * Indicates whether this dialog is resizable by the user.
  570. * @return <code>true</code> if the user can resize the dialog;
  571. * <code>false</code> otherwise.
  572. * @see java.awt.Dialog#setResizable
  573. */
  574. public boolean isResizable() {
  575. return resizable;
  576. }
  577. /**
  578. * Sets whether this dialog is resizable by the user.
  579. * @param resizable <code>true</code> if the user can
  580. * resize this dialog; <code>false</code> otherwise.
  581. * @see java.awt.Dialog#isResizable
  582. */
  583. public void setResizable(boolean resizable) {
  584. boolean testvalid = false;
  585. synchronized (this) {
  586. this.resizable = resizable;
  587. DialogPeer peer = (DialogPeer)this.peer;
  588. if (peer != null) {
  589. peer.setResizable(resizable);
  590. testvalid = true;
  591. }
  592. }
  593. // On some platforms, changing the resizable state affects
  594. // the insets of the Dialog. If we could, we'd call invalidate()
  595. // from the peer, but we need to guarantee that we're not holding
  596. // the Dialog lock when we call invalidate().
  597. if (testvalid && valid) {
  598. invalidate();
  599. }
  600. }
  601. /**
  602. * Disables or enables decorations for this dialog.
  603. * This method can only be called while the dialog is not displayable.
  604. * @param undecorated <code>true</code> if no dialog decorations are
  605. * to be enabled;
  606. * <code>false</code> if dialog decorations are to be enabled.
  607. * @throws <code>IllegalComponentStateException</code> if the dialog
  608. * is displayable.
  609. * @see #isUndecorated
  610. * @see Component#isDisplayable
  611. * @since 1.4
  612. */
  613. public void setUndecorated(boolean undecorated) {
  614. /* Make sure we don't run in the middle of peer creation.*/
  615. synchronized (getTreeLock()) {
  616. if (isDisplayable()) {
  617. throw new IllegalComponentStateException("The dialog is displayable.");
  618. }
  619. this.undecorated = undecorated;
  620. }
  621. }
  622. /**
  623. * Indicates whether this dialog is undecorated.
  624. * By default, all dialogs are initially decorated.
  625. * @return <code>true</code> if dialog is undecorated;
  626. * <code>false</code> otherwise.
  627. * @see java.awt.Dialog#setUndecorated
  628. * @since 1.4
  629. */
  630. public boolean isUndecorated() {
  631. return undecorated;
  632. }
  633. /**
  634. * Returns a string representing the state of this dialog. This
  635. * method is intended to be used only for debugging purposes, and the
  636. * content and format of the returned string may vary between
  637. * implementations. The returned string may be empty but may not be
  638. * <code>null</code>.
  639. *
  640. * @return the parameter string of this dialog window.
  641. */
  642. protected String paramString() {
  643. String str = super.paramString() + (modal ? ",modal" : ",modeless");
  644. if (title != null) {
  645. str += ",title=" + title;
  646. }
  647. return str;
  648. }
  649. /**
  650. * Initialize JNI field and method IDs
  651. */
  652. private static native void initIDs();
  653. /*
  654. * --- Accessibility Support ---
  655. *
  656. */
  657. /**
  658. * Gets the AccessibleContext associated with this Dialog.
  659. * For dialogs, the AccessibleContext takes the form of an
  660. * AccessibleAWTDialog.
  661. * A new AccessibleAWTDialog instance is created if necessary.
  662. *
  663. * @return an AccessibleAWTDialog that serves as the
  664. * AccessibleContext of this Dialog
  665. */
  666. public AccessibleContext getAccessibleContext() {
  667. if (accessibleContext == null) {
  668. accessibleContext = new AccessibleAWTDialog();
  669. }
  670. return accessibleContext;
  671. }
  672. /**
  673. * This class implements accessibility support for the
  674. * <code>Dialog</code> class. It provides an implementation of the
  675. * Java Accessibility API appropriate to dialog user-interface elements.
  676. */
  677. protected class AccessibleAWTDialog extends AccessibleAWTWindow
  678. {
  679. /*
  680. * JDK 1.3 serialVersionUID
  681. */
  682. private static final long serialVersionUID = 4837230331833941201L;
  683. /**
  684. * Get the role of this object.
  685. *
  686. * @return an instance of AccessibleRole describing the role of the
  687. * object
  688. * @see AccessibleRole
  689. */
  690. public AccessibleRole getAccessibleRole() {
  691. return AccessibleRole.DIALOG;
  692. }
  693. /**
  694. * Get the state of this object.
  695. *
  696. * @return an instance of AccessibleStateSet containing the current
  697. * state set of the object
  698. * @see AccessibleState
  699. */
  700. public AccessibleStateSet getAccessibleStateSet() {
  701. AccessibleStateSet states = super.getAccessibleStateSet();
  702. if (getFocusOwner() != null) {
  703. states.add(AccessibleState.ACTIVE);
  704. }
  705. if (isModal()) {
  706. states.add(AccessibleState.MODAL);
  707. }
  708. if (isResizable()) {
  709. states.add(AccessibleState.RESIZABLE);
  710. }
  711. return states;
  712. }
  713. } // inner class AccessibleAWTDialog
  714. }