1. /*
  2. * @(#)Dialog.java 1.90 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt;
  8. import java.awt.peer.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.90, 01/23/03
  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. setFocusTraversalPolicy(KeyboardFocusManager.
  209. getCurrentKeyboardFocusManager().
  210. getDefaultFocusTraversalPolicy()
  211. );
  212. }
  213. /**
  214. * Constructs an initially invisible Dialog with the
  215. * specified owner frame, title, modality, and
  216. * <code>GraphicsConfiguration</code>.
  217. * @param owner the owner of the dialog
  218. * @param title the title of the dialog. A <code>null</code> value
  219. * will be accepted without causing a NullPointerException
  220. * to be thrown.
  221. * @param modal if true, dialog blocks input to other app windows when shown
  222. * @param gc the <code>GraphicsConfiguration</code>
  223. * of the target screen device. If <code>gc</code> is
  224. * <code>null</code>, the same
  225. * <code>GraphicsConfiguration</code> as the owning Frame is used.
  226. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  227. * is <code>null</code>. This exception is always thrown
  228. * when GraphicsEnvironment.isHeadless() returns true
  229. * @see java.awt.GraphicsEnvironment#isHeadless
  230. * @see Component#setSize
  231. * @see Component#setVisible
  232. * @since 1.4
  233. */
  234. public Dialog(Frame owner, String title, boolean modal,
  235. GraphicsConfiguration gc) {
  236. super(owner, gc);
  237. this.title = title;
  238. this.modal = modal;
  239. setFocusTraversalPolicy(KeyboardFocusManager.
  240. getCurrentKeyboardFocusManager().
  241. getDefaultFocusTraversalPolicy()
  242. );
  243. }
  244. /**
  245. * Constructs an initially invisible, non-modal Dialog with
  246. * an empty title and the specified owner dialog.
  247. * @param owner the owner of the dialog
  248. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  249. * is <code>null</code>. This exception is always thrown
  250. * when GraphicsEnvironment.isHeadless() returns true
  251. * @see java.awt.GraphicsEnvironment#isHeadless
  252. * @since 1.2
  253. */
  254. public Dialog(Dialog owner) {
  255. this(owner, "", false);
  256. }
  257. /**
  258. * Constructs an initially invisible, non-modal Dialog
  259. * with the specified owner dialog and title.
  260. * @param owner the owner of the dialog
  261. * @param title the title of the dialog. A <code>null</code> value
  262. * will be accepted without causing a NullPointerException
  263. * to be thrown.
  264. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  265. * is <code>null</code>. This exception is always thrown
  266. * when GraphicsEnvironment.isHeadless() returns true
  267. * @see java.awt.GraphicsEnvironment#isHeadless
  268. * @since 1.2
  269. */
  270. public Dialog(Dialog owner, String title) {
  271. this(owner, title, false);
  272. }
  273. /**
  274. * Constructs an initially invisible <code>Dialog</code> with the
  275. * specified owner dialog, title, and modality.
  276. *
  277. * @param owner the owner of the dialog
  278. * @exception IllegalArgumentException if the <code>owner</code>'s
  279. * <code>GraphicsConfiguration</code> is not from a screen device
  280. * @param title the title of the dialog; a <code>null</code> value
  281. * will be accepted without causing a
  282. * <code>NullPointerException</code> to be thrown
  283. * @param modal if true, dialog blocks input to other app windows when shown
  284. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  285. * is <code>null</code> this exception is always thrown
  286. * when <code>GraphicsEnvironment.isHeadless</code>
  287. * returns <code>true</code>
  288. * @see java.awt.GraphicsEnvironment#isHeadless
  289. * @since 1.2
  290. */
  291. public Dialog(Dialog owner, String title, boolean modal) {
  292. super(owner);
  293. this.title = title;
  294. this.modal = modal;
  295. setFocusTraversalPolicy(KeyboardFocusManager.
  296. getCurrentKeyboardFocusManager().
  297. getDefaultFocusTraversalPolicy()
  298. );
  299. }
  300. /**
  301. * Constructs an initially invisible <code>Dialog</code> with the
  302. * specified owner dialog, title, modality, and
  303. * <code>GraphicsConfiguration</code>.
  304. *
  305. * @param owner the owner of the dialog
  306. * @param title the title of the dialog; a <code>null</code> value
  307. * will be accepted without causing a
  308. * <code>NullPointerException</code> to be thrown
  309. * @param modal if true, dialog blocks input to other app windows when shown
  310. * @param gc the <code>GraphicsConfiguration</code>
  311. * of the target screen device; if <code>gc</code> is
  312. * <code>null</code>, the same
  313. * <code>GraphicsConfiguration</code> as the owning Dialog is used
  314. * @exception IllegalArgumentException if the <code>owner</code>'s
  315. * <code>GraphicsConfiguration</code> is not from a screen device
  316. * @exception java.lang.IllegalArgumentException if <code>owner</code>
  317. * is <code>null</code> this exception is always thrown
  318. * when <code>GraphicsEnvironment.isHeadless</code>
  319. * returns <code>true</code>
  320. * @see java.awt.GraphicsEnvironment#isHeadless
  321. * @see Component#setSize
  322. * @see Component#setVisible
  323. * @since 1.4
  324. */
  325. public Dialog(Dialog owner, String title, boolean modal,
  326. GraphicsConfiguration gc) {
  327. super(owner, gc);
  328. this.title = title;
  329. this.modal = modal;
  330. setFocusTraversalPolicy(KeyboardFocusManager.
  331. getCurrentKeyboardFocusManager().
  332. getDefaultFocusTraversalPolicy()
  333. );
  334. }
  335. /**
  336. * Construct a name for this component. Called by getName() when the
  337. * name is null.
  338. */
  339. String constructComponentName() {
  340. synchronized (getClass()) {
  341. return base + nameCounter++;
  342. }
  343. }
  344. /**
  345. * Makes this Dialog displayable by connecting it to
  346. * a native screen resource. Making a dialog displayable will
  347. * cause any of its children to be made displayable.
  348. * This method is called internally by the toolkit and should
  349. * not be called directly by programs.
  350. * @see Component#isDisplayable
  351. * @see #removeNotify
  352. */
  353. public void addNotify() {
  354. synchronized (getTreeLock()) {
  355. if (parent != null && parent.getPeer() == null) {
  356. parent.addNotify();
  357. }
  358. if (peer == null) {
  359. peer = getToolkit().createDialog(this);
  360. }
  361. super.addNotify();
  362. }
  363. }
  364. /**
  365. * Indicates whether the dialog is modal.
  366. * When a modal Dialog is made visible, user input will be
  367. * blocked to the other windows in the application, except for
  368. * any windows created with this dialog as their owner.
  369. *
  370. * @return <code>true</code> if this dialog window is modal;
  371. * <code>false</code> otherwise.
  372. * @see java.awt.Dialog#setModal
  373. */
  374. public boolean isModal() {
  375. return modal;
  376. }
  377. /**
  378. * Specifies whether this dialog should be modal.
  379. * @see java.awt.Dialog#isModal
  380. * @since JDK1.1
  381. */
  382. public void setModal(boolean b) {
  383. this.modal = b;
  384. }
  385. /**
  386. * Gets the title of the dialog. The title is displayed in the
  387. * dialog's border.
  388. * @return the title of this dialog window. The title may be
  389. * <code>null</code>.
  390. * @see java.awt.Dialog#setTitle
  391. */
  392. public String getTitle() {
  393. return title;
  394. }
  395. /**
  396. * Sets the title of the Dialog.
  397. * @param title the title displayed in the dialog's border;
  398. * a null value results in an empty title
  399. * @see #getTitle
  400. */
  401. public void setTitle(String title) {
  402. String oldTitle = this.title;
  403. synchronized(this) {
  404. this.title = title;
  405. DialogPeer peer = (DialogPeer)this.peer;
  406. if (peer != null) {
  407. peer.setTitle(title);
  408. }
  409. }
  410. firePropertyChange("title", oldTitle, title);
  411. }
  412. /**
  413. * @return true if we actually showed, false if we just called toFront()
  414. */
  415. private boolean conditionalShow() {
  416. boolean retval;
  417. synchronized (getTreeLock()) {
  418. if (peer == null) {
  419. addNotify();
  420. }
  421. validate();
  422. if (visible) {
  423. toFront();
  424. retval = false;
  425. } else {
  426. visible = retval = true;
  427. peer.show(); // now guaranteed never to block
  428. createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
  429. this, parent,
  430. HierarchyEvent.SHOWING_CHANGED,
  431. Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
  432. }
  433. if (retval && (componentListener != null ||
  434. (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
  435. Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))) {
  436. ComponentEvent e =
  437. new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
  438. Toolkit.getEventQueue().postEvent(e);
  439. }
  440. }
  441. if (retval && (state & OPENED) == 0) {
  442. postWindowEvent(WindowEvent.WINDOW_OPENED);
  443. state |= OPENED;
  444. }
  445. return retval;
  446. }
  447. /**
  448. * Stores the app context on which event dispatch thread the dialog
  449. * is being shown. Initialized in show(), used in hideAndDisposeHandler()
  450. */
  451. transient private AppContext showAppContext;
  452. /**
  453. * Makes the Dialog visible. If the dialog and/or its owner
  454. * are not yet displayable, both are made displayable. The
  455. * dialog will be validated prior to being made visible.
  456. * If the dialog is already visible, this will bring the dialog
  457. * to the front.
  458. * <p>
  459. * If the dialog is modal and is not already visible, this call will
  460. * not return until the dialog is hidden by calling <code>hide</code> or
  461. * <code>dispose</code>. It is permissible to show modal dialogs from
  462. * the event dispatching thread because the toolkit will ensure that
  463. * another event pump runs while the one which invoked this method
  464. * is blocked.
  465. * @see Component#hide
  466. * @see Component#isDisplayable
  467. * @see Component#validate
  468. * @see java.awt.Dialog#isModal
  469. */
  470. public void show() {
  471. beforeFirstShow = false;
  472. if (!isModal()) {
  473. conditionalShow();
  474. } else {
  475. // Set this variable before calling conditionalShow(). That
  476. // way, if the Dialog is hidden right after being shown, we
  477. // won't mistakenly block this thread.
  478. keepBlocking = true;
  479. // Store the app context on which this dialog is being shown.
  480. // Event dispatch thread of this app context will be sleeping until
  481. // we wake it by any event from hideAndDisposeHandler().
  482. showAppContext = AppContext.getAppContext();
  483. if (conditionalShow()) {
  484. // We have two mechanisms for blocking: 1. If we're on the
  485. // EventDispatchThread, start a new event pump. 2. If we're
  486. // on any other thread, call wait() on the treelock.
  487. // keep the KeyEvents from being dispatched
  488. // until the focus has been transfered
  489. long time = Toolkit.getEventQueue().getMostRecentEventTime();
  490. Component predictedFocusOwner = getMostRecentFocusOwner();
  491. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  492. enqueueKeyEvents(time, predictedFocusOwner);
  493. Runnable pumpEventsForHierarchy = new Runnable() {
  494. public void run() {
  495. EventDispatchThread dispatchThread =
  496. (EventDispatchThread)Thread.currentThread();
  497. dispatchThread.pumpEventsForHierarchy(new Conditional() {
  498. public boolean evaluate() {
  499. return keepBlocking && windowClosingException == null;
  500. }
  501. }, Dialog.this);
  502. }
  503. };
  504. if (EventQueue.isDispatchThread()) {
  505. /*
  506. * dispose SequencedEvent we are dispatching on current
  507. * AppContext, to prevent us from hang.
  508. *
  509. * BugId 4531693 (son@sparc.spb.su)
  510. */
  511. SequencedEvent currentSequencedEvent = KeyboardFocusManager.
  512. getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
  513. if (currentSequencedEvent != null) {
  514. currentSequencedEvent.dispose();
  515. }
  516. pumpEventsForHierarchy.run();
  517. } else {
  518. synchronized (getTreeLock()) {
  519. Toolkit.getEventQueue().
  520. postEvent(new PeerEvent(this,
  521. pumpEventsForHierarchy,
  522. PeerEvent.PRIORITY_EVENT));
  523. while (keepBlocking && windowClosingException == null) {
  524. try {
  525. getTreeLock().wait();
  526. } catch (InterruptedException e) {
  527. break;
  528. }
  529. }
  530. }
  531. }
  532. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  533. dequeueKeyEvents(time, predictedFocusOwner);
  534. if (windowClosingException != null) {
  535. windowClosingException.fillInStackTrace();
  536. throw windowClosingException;
  537. }
  538. }
  539. }
  540. }
  541. void interruptBlocking() {
  542. if (modal) {
  543. disposeImpl();
  544. } else if (windowClosingException != null) {
  545. windowClosingException.fillInStackTrace();
  546. windowClosingException.printStackTrace();
  547. windowClosingException = null;
  548. }
  549. }
  550. final static class WakingRunnable implements Runnable {
  551. public void run() {
  552. }
  553. }
  554. private void hideAndDisposeHandler() {
  555. if (keepBlocking) {
  556. synchronized (getTreeLock()) {
  557. keepBlocking = false;
  558. if (showAppContext != null) {
  559. // Wake up event dispatch thread on which the dialog was
  560. // initially shown
  561. SunToolkit.postEvent(showAppContext,
  562. new PeerEvent(this,
  563. new WakingRunnable(),
  564. PeerEvent.PRIORITY_EVENT));
  565. showAppContext = null;
  566. }
  567. EventQueue.invokeLater(new WakingRunnable());
  568. getTreeLock().notifyAll();
  569. }
  570. }
  571. }
  572. /**
  573. * Hides the Dialog and then causes show() to return if it is currently
  574. * blocked.
  575. */
  576. public void hide() {
  577. super.hide();
  578. hideAndDisposeHandler();
  579. }
  580. /**
  581. * Disposes the Dialog and then causes show() to return if it is currently
  582. * blocked.
  583. */
  584. public void dispose() {
  585. disposeImpl();
  586. }
  587. private void disposeImpl() {
  588. super.dispose();
  589. hideAndDisposeHandler();
  590. }
  591. /**
  592. * Indicates whether this dialog is resizable by the user.
  593. * @return <code>true</code> if the user can resize the dialog;
  594. * <code>false</code> otherwise.
  595. * @see java.awt.Dialog#setResizable
  596. */
  597. public boolean isResizable() {
  598. return resizable;
  599. }
  600. /**
  601. * Sets whether this dialog is resizable by the user.
  602. * @param resizable <code>true</code> if the user can
  603. * resize this dialog; <code>false</code> otherwise.
  604. * @see java.awt.Dialog#isResizable
  605. */
  606. public void setResizable(boolean resizable) {
  607. boolean testvalid = false;
  608. synchronized (this) {
  609. this.resizable = resizable;
  610. DialogPeer peer = (DialogPeer)this.peer;
  611. if (peer != null) {
  612. peer.setResizable(resizable);
  613. testvalid = true;
  614. }
  615. }
  616. // On some platforms, changing the resizable state affects
  617. // the insets of the Dialog. If we could, we'd call invalidate()
  618. // from the peer, but we need to guarantee that we're not holding
  619. // the Dialog lock when we call invalidate().
  620. if (testvalid && valid) {
  621. invalidate();
  622. }
  623. }
  624. /**
  625. * Disables or enables decorations for this dialog.
  626. * This method can only be called while the dialog is not displayable.
  627. * @param undecorated <code>true</code> if no dialog decorations are
  628. * to be enabled;
  629. * <code>false</code> if dialog decorations are to be enabled.
  630. * @throws <code>IllegalComponentStateException</code> if the dialog
  631. * is displayable.
  632. * @see #isUndecorated
  633. * @see Component#isDisplayable
  634. * @since 1.4
  635. */
  636. public void setUndecorated(boolean undecorated) {
  637. /* Make sure we don't run in the middle of peer creation.*/
  638. synchronized (getTreeLock()) {
  639. if (isDisplayable()) {
  640. throw new IllegalComponentStateException("The dialog is displayable.");
  641. }
  642. this.undecorated = undecorated;
  643. }
  644. }
  645. /**
  646. * Indicates whether this dialog is undecorated.
  647. * By default, all dialogs are initially decorated.
  648. * @return <code>true</code> if dialog is undecorated;
  649. * <code>false</code> otherwise.
  650. * @see java.awt.Dialog#setUndecorated
  651. * @since 1.4
  652. */
  653. public boolean isUndecorated() {
  654. return undecorated;
  655. }
  656. /**
  657. * Returns a string representing the state of this dialog. This
  658. * method is intended to be used only for debugging purposes, and the
  659. * content and format of the returned string may vary between
  660. * implementations. The returned string may be empty but may not be
  661. * <code>null</code>.
  662. *
  663. * @return the parameter string of this dialog window.
  664. */
  665. protected String paramString() {
  666. String str = super.paramString() + (modal ? ",modal" : ",modeless");
  667. if (title != null) {
  668. str += ",title=" + title;
  669. }
  670. return str;
  671. }
  672. /**
  673. * Initialize JNI field and method IDs
  674. */
  675. private static native void initIDs();
  676. /*
  677. * --- Accessibility Support ---
  678. *
  679. */
  680. /**
  681. * Gets the AccessibleContext associated with this Dialog.
  682. * For dialogs, the AccessibleContext takes the form of an
  683. * AccessibleAWTDialog.
  684. * A new AccessibleAWTDialog instance is created if necessary.
  685. *
  686. * @return an AccessibleAWTDialog that serves as the
  687. * AccessibleContext of this Dialog
  688. */
  689. public AccessibleContext getAccessibleContext() {
  690. if (accessibleContext == null) {
  691. accessibleContext = new AccessibleAWTDialog();
  692. }
  693. return accessibleContext;
  694. }
  695. /**
  696. * This class implements accessibility support for the
  697. * <code>Dialog</code> class. It provides an implementation of the
  698. * Java Accessibility API appropriate to dialog user-interface elements.
  699. */
  700. protected class AccessibleAWTDialog extends AccessibleAWTWindow {
  701. /**
  702. * Get the role of this object.
  703. *
  704. * @return an instance of AccessibleRole describing the role of the
  705. * object
  706. * @see AccessibleRole
  707. */
  708. public AccessibleRole getAccessibleRole() {
  709. return AccessibleRole.DIALOG;
  710. }
  711. /**
  712. * Get the state of this object.
  713. *
  714. * @return an instance of AccessibleStateSet containing the current
  715. * state set of the object
  716. * @see AccessibleState
  717. */
  718. public AccessibleStateSet getAccessibleStateSet() {
  719. AccessibleStateSet states = super.getAccessibleStateSet();
  720. if (getFocusOwner() != null) {
  721. states.add(AccessibleState.ACTIVE);
  722. }
  723. if (isModal()) {
  724. states.add(AccessibleState.MODAL);
  725. }
  726. if (isResizable()) {
  727. states.add(AccessibleState.RESIZABLE);
  728. }
  729. return states;
  730. }
  731. } // inner class AccessibleAWTDialog
  732. }