KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > java > awt > Dialog


1 /*
2  * @(#)Dialog.java 1.103 07/03/23
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
9 import java.awt.peer.DialogPeer;
10 import java.awt.event.*;
11 import java.io.ObjectOutputStream JavaDoc;
12 import java.io.ObjectInputStream JavaDoc;
13 import java.io.IOException JavaDoc;
14 import javax.accessibility.*;
15 import sun.awt.AppContext;
16 import sun.awt.SunToolkit;
17 import sun.awt.PeerEvent;
18 import java.security.AccessController JavaDoc;
19 import java.security.PrivilegedAction JavaDoc;
20 import java.util.concurrent.atomic.AtomicLong JavaDoc;
21
22 /**
23  * A Dialog is a top-level window with a title and a border
24  * that is typically used to take some form of input from the user.
25  *
26  * The size of the dialog includes any area designated for the
27  * border. The dimensions of the border area can be obtained
28  * using the <code>getInsets</code> method, however, since
29  * these dimensions are platform-dependent, a valid insets
30  * value cannot be obtained until the dialog is made displayable
31  * by either calling <code>pack</code> or <code>show</code>.
32  * Since the border area is included in the overall size of the
33  * dialog, the border effectively obscures a portion of the dialog,
34  * constraining the area available for rendering and/or displaying
35  * subcomponents to the rectangle which has an upper-left corner
36  * location of <code>(insets.left, insets.top)</code>, and has a size of
37  * <code>width - (insets.left + insets.right)</code> by
38  * <code>height - (insets.top + insets.bottom)</code>.
39  * <p>
40  * The default layout for a dialog is <code>BorderLayout</code>.
41  * <p>
42  * A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
43  * with <code>setUndecorated</code>. This can only be done while the dialog
44  * is not {@link Component#isDisplayable() displayable}.
45  * <p>
46  * A dialog must have either a frame or another dialog defined as its
47  * owner when it's constructed. When the owner window of a visible dialog
48  * is minimized, the dialog will automatically be hidden
49  * from the user. When the owner window is subsequently restored,
50  * the dialog is made visible to the user again.
51  * <p>
52  * In a multi-screen environment, you can create a <code>Dialog</code>
53  * on a different screen device than its owner. See {@link java.awt.Frame} for
54  * more information.
55  * <p>
56  * A dialog can be either modeless (the default) or modal. A modal
57  * dialog is one which blocks input to all other toplevel windows
58  * in the application, except for any windows created with the dialog
59  * as their owner.
60  * <p>
61  * Dialogs are capable of generating the following
62  * <code>WindowEvents</code>:
63  * <code>WindowOpened</code>, <code>WindowClosing</code>,
64  * <code>WindowClosed</code>, <code>WindowActivated</code>,
65  * <code>WindowDeactivated</code>, <code>WindowGainedFocus</code>,
66  * <code>WindowLostFocus</code>.
67  *
68  * @see WindowEvent
69  * @see Window#addWindowListener
70  *
71  * @version 1.103, 03/23/07
72  * @author Sami Shaio
73  * @author Arthur van Hoff
74  * @since JDK1.0
75  */

76 public class Dialog extends Window JavaDoc {
77
78     static {
79         /* ensure that the necessary native libraries are loaded */
80     Toolkit.loadLibraries();
81         if (!GraphicsEnvironment.isHeadless()) {
82             initIDs();
83         }
84     }
85
86     /**
87      * A dialog's resizable property. Will be true
88      * if the Dialog is to be resizable, otherwise
89      * it will be false.
90      *
91      * @serial
92      * @see #setResizable(boolean)
93      */

94     boolean resizable = true;
95
96
97     /**
98      * This field indicates whether the dialog is undecorated.
99      * This property can only be changed while the dialog is not displayable.
100      * <code>undecorated</code> will be true if the dialog is
101      * undecorated, otherwise it will be false.
102      *
103      * @serial
104      * @see #setUndecorated(boolean)
105      * @see #isUndecorated()
106      * @see Component#isDisplayable()
107      * @since 1.4
108      */

109     boolean undecorated = false;
110
111     /**
112      * Will be true if the Dialog is modal,
113      * otherwise the dialog will be modeless.
114      * A modal Dialog grabs all the input to
115      * the owner frame from the user.
116      *
117      * @serial
118      * @see #isModal()
119      * @see #setModal(boolean)
120      */

121     boolean modal;
122
123     /**
124      * Specifies the title of the Dialog.
125      * This field can be null.
126      *
127      * @serial
128      * @see #getTitle()
129      * @see #setTitle(String)
130      */

131     String JavaDoc title;
132
133     private transient boolean keepBlocking = false;
134
135     private static final String JavaDoc base = "dialog";
136     private static int nameCounter = 0;
137
138     /*
139      * JDK 1.1 serialVersionUID
140      */

141     private static final long serialVersionUID = 5920926903803293709L;
142
143     /**
144      * Constructs an initially invisible, non-modal <code>Dialog</code> with
145      * an empty title and the specified owner frame.
146      *
147      * @param owner the owner of the dialog
148      * @exception IllegalArgumentException if the <code>owner</code>'s
149      * <code>GraphicsConfiguration</code> is not from a screen device
150      * @exception java.lang.IllegalArgumentException if <code>owner</code>
151      * is <code>null</code>; this exception is always thrown
152      * when <code>GraphicsEnvironment.isHeadless</code>
153      * returns <code>true</code>
154      * @see java.awt.GraphicsEnvironment#isHeadless
155      * @see Component#setSize
156      * @see Component#setVisible
157      */

158     public Dialog(Frame JavaDoc owner) {
159     this(owner, "", false);
160     }
161
162     /**
163      * Constructs an initially invisible <code>Dialog</code> with an empty title,
164      * the specified owner frame and modality.
165      *
166      * @param owner the owner of the dialog
167      * @param modal if <code>true</code>, dialog blocks input to other
168      * app windows when shown
169      * @exception IllegalArgumentException if the <code>owner</code>'s
170      * <code>GraphicsConfiguration</code> is not from a screen device
171      * @exception java.lang.IllegalArgumentException if <code>owner</code>
172      * is <code>null</code>; this exception is always thrown
173      * when <code>GraphicsEnvironment.isHeadless</code>
174      * returns <code>true</code>
175      * @see java.awt.GraphicsEnvironment#isHeadless
176      */

177     public Dialog(Frame JavaDoc owner, boolean modal) {
178     this(owner, "", modal);
179     }
180
181     /**
182      * Constructs an initially invisible, non-modal <code>Dialog</code> with
183      * the specified owner frame and title.
184      *
185      * @param owner the owner of the dialog
186      * @param title the title of the dialog; a <code>null</code> value
187      * will be accepted without causing a
188      * <code>NullPointerException</code> to be thrown
189      * @exception IllegalArgumentException if the <code>owner</code>'s
190      * <code>GraphicsConfiguration</code> is not from a screen device
191      * @exception java.lang.IllegalArgumentException if <code>owner</code>
192      * is <code>null</code>; this exception is always thrown
193      * when <code>GraphicsEnvironment.isHeadless</code>
194      * returns <code>true</code>
195      * @see java.awt.GraphicsEnvironment#isHeadless
196      * @see Component#setSize
197      * @see Component#setVisible
198      */

199     public Dialog(Frame JavaDoc owner, String JavaDoc title) {
200     this(owner, title, false);
201     }
202
203     /**
204      * Constructs an initially invisible <code>Dialog</code> with the
205      * specified owner frame, title, and modality.
206      *
207      * @param owner the owner of the dialog
208      * @param title the title of the dialog; a <code>null</code> value
209      * will be accepted without causing a
210      * <code>NullPointerException</code> to be thrown
211      * @param modal if true, dialog blocks input to other app windows when shown
212      * @exception IllegalArgumentException if the <code>owner</code>'s
213      * <code>GraphicsConfiguration</code> is not from a screen device
214      * @exception java.lang.IllegalArgumentException if <code>owner</code>
215      * is <code>null</code>. This exception is always thrown
216      * when <code>GraphicsEnvironment.isHeadless</code>
217      * returns <code>true</code>
218      * @see java.awt.GraphicsEnvironment#isHeadless
219      * @see Component#setSize
220      * @see Component#setVisible
221      */

222     public Dialog(Frame JavaDoc owner, String JavaDoc title, boolean modal) {
223     super(owner);
224
225     this.title = title;
226     this.modal = modal;
227         SunToolkit.checkAndSetPolicy(this, false);
228     }
229
230     /**
231      * Constructs an initially invisible Dialog with the
232      * specified owner frame, title, modality, and
233      * <code>GraphicsConfiguration</code>.
234      * @param owner the owner of the dialog
235      * @param title the title of the dialog. A <code>null</code> value
236      * will be accepted without causing a NullPointerException
237      * to be thrown.
238      * @param modal if true, dialog blocks input to other app windows when shown
239      * @param gc the <code>GraphicsConfiguration</code>
240      * of the target screen device. If <code>gc</code> is
241      * <code>null</code>, the same
242      * <code>GraphicsConfiguration</code> as the owning Frame is used.
243      * @exception java.lang.IllegalArgumentException if <code>owner</code>
244      * is <code>null</code>. This exception is always thrown
245      * when GraphicsEnvironment.isHeadless() returns true
246      * @see java.awt.GraphicsEnvironment#isHeadless
247      * @see Component#setSize
248      * @see Component#setVisible
249      * @since 1.4
250      */

251     public Dialog(Frame JavaDoc owner, String JavaDoc title, boolean modal,
252                   GraphicsConfiguration JavaDoc gc) {
253         super(owner, gc);
254
255         this.title = title;
256         this.modal = modal;
257         SunToolkit.checkAndSetPolicy(this, false);
258     }
259
260     /**
261      * Constructs an initially invisible, non-modal Dialog with
262      * an empty title and the specified owner dialog.
263      * @param owner the owner of the dialog
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 JavaDoc owner) {
271     this(owner, "", false);
272     }
273
274     /**
275      * Constructs an initially invisible, non-modal Dialog
276      * with the specified owner dialog and title.
277      * @param owner the owner of the dialog
278      * @param title the title of the dialog. A <code>null</code> value
279      * will be accepted without causing a NullPointerException
280      * to be thrown.
281      * @exception java.lang.IllegalArgumentException if <code>owner</code>
282      * is <code>null</code>. This exception is always thrown
283      * when GraphicsEnvironment.isHeadless() returns true
284      * @see java.awt.GraphicsEnvironment#isHeadless
285      * @since 1.2
286      */

287     public Dialog(Dialog JavaDoc owner, String JavaDoc title) {
288     this(owner, title, false);
289     }
290
291     /**
292      * Constructs an initially invisible <code>Dialog</code> with the
293      * specified owner dialog, title, and modality.
294      *
295      * @param owner the owner of the dialog
296      * @exception IllegalArgumentException if the <code>owner</code>'s
297      * <code>GraphicsConfiguration</code> is not from a screen device
298      * @param title the title of the dialog; a <code>null</code> value
299      * will be accepted without causing a
300      * <code>NullPointerException</code> to be thrown
301      * @param modal if true, dialog blocks input to other app windows when shown
302      * @exception java.lang.IllegalArgumentException if <code>owner</code>
303      * is <code>null</code>; this exception is always thrown
304      * when <code>GraphicsEnvironment.isHeadless</code>
305      * returns <code>true</code>
306      * @see java.awt.GraphicsEnvironment#isHeadless
307      * @since 1.2
308      */

309     public Dialog(Dialog JavaDoc owner, String JavaDoc title, boolean modal) {
310     super(owner);
311
312     this.title = title;
313     this.modal = modal;
314         SunToolkit.checkAndSetPolicy(this, false);
315     }
316
317     /**
318      * Constructs an initially invisible <code>Dialog</code> with the
319      * specified owner dialog, title, modality, and
320      * <code>GraphicsConfiguration</code>.
321      *
322      * @param owner the owner of the dialog
323      * @param title the title of the dialog; a <code>null</code> value
324      * will be accepted without causing a
325      * <code>NullPointerException</code> to be thrown
326      * @param modal if true, dialog blocks input to other app windows when shown
327      * @param gc the <code>GraphicsConfiguration</code>
328      * of the target screen device; if <code>gc</code> is
329      * <code>null</code>, the same
330      * <code>GraphicsConfiguration</code> as the owning Dialog is used
331      * @exception IllegalArgumentException if the <code>owner</code>'s
332      * <code>GraphicsConfiguration</code> is not from a screen device
333      * @exception java.lang.IllegalArgumentException if <code>owner</code>
334      * is <code>null</code>; this exception is always thrown
335      * when <code>GraphicsEnvironment.isHeadless</code>
336      * returns <code>true</code>
337      * @see java.awt.GraphicsEnvironment#isHeadless
338      * @see Component#setSize
339      * @see Component#setVisible
340      * @since 1.4
341      */

342     public Dialog(Dialog JavaDoc owner, String JavaDoc title, boolean modal,
343                   GraphicsConfiguration JavaDoc gc) {
344     super(owner, gc);
345      
346     this.title = title;
347     this.modal = modal;
348         SunToolkit.checkAndSetPolicy(this, false);
349     }
350
351     /**
352      * Construct a name for this component. Called by getName() when the
353      * name is null.
354      */

355     String JavaDoc constructComponentName() {
356         synchronized (getClass()) {
357         return base + nameCounter++;
358     }
359     }
360
361     /**
362      * Makes this Dialog displayable by connecting it to
363      * a native screen resource. Making a dialog displayable will
364      * cause any of its children to be made displayable.
365      * This method is called internally by the toolkit and should
366      * not be called directly by programs.
367      * @see Component#isDisplayable
368      * @see #removeNotify
369      */

370     public void addNotify() {
371     synchronized (getTreeLock()) {
372         if (parent != null && parent.getPeer() == null) {
373                 parent.addNotify();
374         }
375
376         if (peer == null) {
377             peer = getToolkit().createDialog(this);
378         }
379         super.addNotify();
380     }
381     }
382
383     /**
384      * Indicates whether the dialog is modal.
385      * When a modal Dialog is made visible, user input will be
386      * blocked to the other windows in the application, except for
387      * any windows created with this dialog as their owner.
388      *
389      * @return <code>true</code> if this dialog window is modal;
390      * <code>false</code> otherwise.
391      * @see java.awt.Dialog#setModal
392      */

393     public boolean isModal() {
394     return modal;
395     }
396
397     /**
398      * Specifies whether this dialog should be modal.
399      * @see java.awt.Dialog#isModal
400      * @since JDK1.1
401      */

402     public void setModal(boolean b) {
403     this.modal = b;
404     }
405
406     /**
407      * Gets the title of the dialog. The title is displayed in the
408      * dialog's border.
409      * @return the title of this dialog window. The title may be
410      * <code>null</code>.
411      * @see java.awt.Dialog#setTitle
412      */

413     public String JavaDoc getTitle() {
414     return title;
415     }
416
417     /**
418      * Sets the title of the Dialog.
419      * @param title the title displayed in the dialog's border;
420      * a null value results in an empty title
421      * @see #getTitle
422      */

423     public void setTitle(String JavaDoc title) {
424         String JavaDoc oldTitle = this.title;
425
426         synchronized(this) {
427             this.title = title;
428             DialogPeer peer = (DialogPeer)this.peer;
429             if (peer != null) {
430                 peer.setTitle(title);
431             }
432         }
433         firePropertyChange("title", oldTitle, title);
434     }
435
436     /**
437      * @return true if we actually showed, false if we just called toFront()
438      */

439     private boolean conditionalShow(Component JavaDoc toFocus, AtomicLong JavaDoc time) {
440         boolean retval;
441
442         synchronized (getTreeLock()) {
443             if (peer == null) {
444                 addNotify();
445             }
446             validate();
447             if (visible) {
448                 toFront();
449                 retval = false;
450             } else {
451                 visible = retval = true;
452                 if (toFocus != null && time != null && isFocusable() && isEnabled())
453                 {
454                     // keep the KeyEvents from being dispatched
455
// until the focus has been transfered
456
time.set(Toolkit.getEventQueue().getMostRecentEventTimeEx());
457                     KeyboardFocusManager.getCurrentKeyboardFocusManager().
458                         enqueueKeyEvents(time.get(), toFocus);
459                 }
460
461                 peer.show(); // now guaranteed never to block
462

463                 for (int i = 0; i < ownedWindowList.size(); i++) {
464                     Window JavaDoc child = ownedWindowList.elementAt(i).get();
465                     if ((child != null) && child.showWithParent) {
466                         child.show();
467                         child.showWithParent = false;
468                     } // endif
469
} // endfor
470
Window.updateChildFocusableWindowState(this);
471
472         createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
473                       this, parent,
474                       HierarchyEvent.SHOWING_CHANGED,
475                                       Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
476             }
477         if (retval && (componentListener != null ||
478                (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
479                            Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))) {
480             ComponentEvent e =
481             new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
482         Toolkit.getEventQueue().postEvent(e);
483         }
484         }
485
486         if (retval && (state & OPENED) == 0) {
487             postWindowEvent(WindowEvent.WINDOW_OPENED);
488             state |= OPENED;
489         }
490
491         return retval;
492     }
493
494     /**
495     * Stores the app context on which event dispatch thread the dialog
496     * is being shown. Initialized in show(), used in hideAndDisposeHandler()
497     */

498     transient private AppContext showAppContext;
499
500    /**
501      * @deprecated As of JDK version 1.5, replaced by
502      * {@link Component#setVisible(boolean) Component.setVisible(boolean)}.
503      */

504     @Deprecated JavaDoc
505     public void show() {
506         beforeFirstShow = false;
507         if (!isModal()) {
508             conditionalShow(null, null);
509         } else {
510             // Set this variable before calling conditionalShow(). That
511
// way, if the Dialog is hidden right after being shown, we
512
// won't mistakenly block this thread.
513
keepBlocking = true;
514
515             // Store the app context on which this dialog is being shown.
516
// Event dispatch thread of this app context will be sleeping until
517
// we wake it by any event from hideAndDisposeHandler().
518
showAppContext = AppContext.getAppContext();
519
520             // keep the KeyEvents from being dispatched
521
// until the focus has been transfered
522
AtomicLong JavaDoc time = new AtomicLong JavaDoc();
523             Component JavaDoc predictedFocusOwner = getMostRecentFocusOwner();
524
525             try {
526                 if (conditionalShow(predictedFocusOwner, time)) {
527                     // We have two mechanisms for blocking: 1. If we're on the
528
// EventDispatchThread, start a new event pump. 2. If we're
529
// on any other thread, call wait() on the treelock.
530

531                     final Runnable JavaDoc pumpEventsForHierarchy = new Runnable JavaDoc() {
532                             public void run() {
533                                 EventDispatchThread JavaDoc dispatchThread =
534                                     (EventDispatchThread JavaDoc)Thread.currentThread();
535                                 dispatchThread.pumpEventsForHierarchy(new Conditional JavaDoc() {
536                                         public boolean evaluate() {
537                                             return keepBlocking && windowClosingException == null;
538                                         }
539                                     }, Dialog.this);
540                             }
541                         };
542
543                     modalityPushed();
544                     try {
545                     if (EventQueue.isDispatchThread()) {
546                         /*
547                          * dispose SequencedEvent we are dispatching on current
548                          * AppContext, to prevent us from hang.
549                      *
550                      * BugId 4531693 (son@sparc.spb.su)
551                      */

552                         SequencedEvent JavaDoc currentSequencedEvent = KeyboardFocusManager.
553                             getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
554                         if (currentSequencedEvent != null) {
555                             currentSequencedEvent.dispose();
556                         }
557
558                         /*
559                          * Event processing is done inside doPrivileged block so that
560                          * it wouldn't matter even if user code is on the stack
561                          * Fix for BugId 6300270
562                          */

563                         AccessController.doPrivileged(new PrivilegedAction JavaDoc() {
564                                 public Object JavaDoc run() {
565                                    pumpEventsForHierarchy.run();
566                                    return null;
567                                 }
568                         });
569
570                     } else {
571                         synchronized (getTreeLock()) {
572                             Toolkit.getEventQueue().
573                                 postEvent(new PeerEvent(this,
574                                                         pumpEventsForHierarchy,
575                                                         PeerEvent.PRIORITY_EVENT));
576                             while (keepBlocking && windowClosingException == null) {
577                                 try {
578                                     getTreeLock().wait();
579                                 } catch (InterruptedException JavaDoc e) {
580                                     break;
581                                 }
582                             }
583                         }
584                     }
585                     } finally {
586                         modalityPopped();
587                     }
588                     if (windowClosingException != null) {
589                         windowClosingException.fillInStackTrace();
590                         throw windowClosingException;
591                     }
592                 }
593             } finally {
594                 // Restore normal key event dispatching
595
KeyboardFocusManager.getCurrentKeyboardFocusManager().
596                     dequeueKeyEvents(time.get(), predictedFocusOwner);
597             }
598         }
599     }
600
601     final void modalityPushed() {
602         Toolkit JavaDoc tk = Toolkit.getDefaultToolkit();
603         if (tk instanceof SunToolkit) {
604             SunToolkit stk = (SunToolkit)tk;
605             stk.notifyModalityPushed(this);
606         }
607     }
608
609     final void modalityPopped() {
610         Toolkit JavaDoc tk = Toolkit.getDefaultToolkit();
611         if (tk instanceof SunToolkit) {
612             SunToolkit stk = (SunToolkit)tk;
613             stk.notifyModalityPopped(this);
614         }
615     }
616
617     void interruptBlocking() {
618         if (modal) {
619             disposeImpl();
620         } else if (windowClosingException != null) {
621             windowClosingException.fillInStackTrace();
622             windowClosingException.printStackTrace();
623             windowClosingException = null;
624         }
625     }
626     final static class WakingRunnable implements Runnable JavaDoc {
627         public void run() {
628         }
629     }
630     private void hideAndDisposeHandler() {
631         if (keepBlocking) {
632             synchronized (getTreeLock()) {
633                 keepBlocking = false;
634
635                 if (showAppContext != null) {
636                     // Wake up event dispatch thread on which the dialog was
637
// initially shown
638
SunToolkit.postEvent(showAppContext,
639                                          new PeerEvent(this,
640                                                        new WakingRunnable(),
641                                                        PeerEvent.PRIORITY_EVENT));
642                     showAppContext = null;
643                 }
644                 EventQueue.invokeLater(new WakingRunnable());
645                 getTreeLock().notifyAll();
646             }
647         }
648     }
649
650     /**
651      * @deprecated As of JDK version 1.5, replaced by
652      * {@link Component#setVisible(boolean) Component.setVisible(boolean)}.
653      */

654     @Deprecated JavaDoc
655     public void hide() {
656         super.hide();
657         hideAndDisposeHandler();
658     }
659
660     /**
661      * Disposes the Dialog and then causes show() to return if it is currently
662      * blocked.
663      */

664     void doDispose() {
665         super.doDispose();
666         hideAndDisposeHandler();
667     }
668
669     /**
670      * Indicates whether this dialog is resizable by the user.
671      * @return <code>true</code> if the user can resize the dialog;
672      * <code>false</code> otherwise.
673      * @see java.awt.Dialog#setResizable
674      */

675     public boolean isResizable() {
676     return resizable;
677     }
678
679     /**
680      * Sets whether this dialog is resizable by the user.
681      * @param resizable <code>true</code> if the user can
682      * resize this dialog; <code>false</code> otherwise.
683      * @see java.awt.Dialog#isResizable
684      */

685     public void setResizable(boolean resizable) {
686         boolean testvalid = false;
687
688         synchronized (this) {
689             this.resizable = resizable;
690             DialogPeer peer = (DialogPeer)this.peer;
691             if (peer != null) {
692                 peer.setResizable(resizable);
693                 testvalid = true;
694             }
695         }
696
697         // On some platforms, changing the resizable state affects
698
// the insets of the Dialog. If we could, we'd call invalidate()
699
// from the peer, but we need to guarantee that we're not holding
700
// the Dialog lock when we call invalidate().
701
if (testvalid && valid) {
702             invalidate();
703         }
704     }
705
706
707     /**
708      * Disables or enables decorations for this dialog.
709      * This method can only be called while the dialog is not displayable.
710      * @param undecorated <code>true</code> if no dialog decorations are
711      * to be enabled;
712      * <code>false</code> if dialog decorations are to be enabled.
713      * @throws <code>IllegalComponentStateException</code> if the dialog
714      * is displayable.
715      * @see #isUndecorated
716      * @see Component#isDisplayable
717      * @since 1.4
718      */

719     public void setUndecorated(boolean undecorated) {
720         /* Make sure we don't run in the middle of peer creation.*/
721         synchronized (getTreeLock()) {
722             if (isDisplayable()) {
723                 throw new IllegalComponentStateException JavaDoc("The dialog is displayable.");
724             }
725             this.undecorated = undecorated;
726         }
727     }
728
729     /**
730      * Indicates whether this dialog is undecorated.
731      * By default, all dialogs are initially decorated.
732      * @return <code>true</code> if dialog is undecorated;
733      * <code>false</code> otherwise.
734      * @see java.awt.Dialog#setUndecorated
735      * @since 1.4
736      */

737     public boolean isUndecorated() {
738     return undecorated;
739     }
740
741     /**
742      * Returns a string representing the state of this dialog. This
743      * method is intended to be used only for debugging purposes, and the
744      * content and format of the returned string may vary between
745      * implementations. The returned string may be empty but may not be
746      * <code>null</code>.
747      *
748      * @return the parameter string of this dialog window.
749      */

750     protected String JavaDoc paramString() {
751     String JavaDoc str = super.paramString() + (modal ? ",modal" : ",modeless");
752     if (title != null) {
753         str += ",title=" + title;
754     }
755     return str;
756     }
757
758     /**
759      * Initialize JNI field and method IDs
760      */

761     private static native void initIDs();
762
763     /*
764      * --- Accessibility Support ---
765      *
766      */

767
768     /**
769      * Gets the AccessibleContext associated with this Dialog.
770      * For dialogs, the AccessibleContext takes the form of an
771      * AccessibleAWTDialog.
772      * A new AccessibleAWTDialog instance is created if necessary.
773      *
774      * @return an AccessibleAWTDialog that serves as the
775      * AccessibleContext of this Dialog
776      */

777     public AccessibleContext getAccessibleContext() {
778         if (accessibleContext == null) {
779             accessibleContext = new AccessibleAWTDialog();
780         }
781         return accessibleContext;
782     }
783
784     /**
785      * This class implements accessibility support for the
786      * <code>Dialog</code> class. It provides an implementation of the
787      * Java Accessibility API appropriate to dialog user-interface elements.
788      */

789     protected class AccessibleAWTDialog extends AccessibleAWTWindow
790     {
791         /*
792          * JDK 1.3 serialVersionUID
793          */

794         private static final long serialVersionUID = 4837230331833941201L;
795
796         /**
797          * Get the role of this object.
798          *
799          * @return an instance of AccessibleRole describing the role of the
800          * object
801          * @see AccessibleRole
802          */

803         public AccessibleRole getAccessibleRole() {
804             return AccessibleRole.DIALOG;
805         }
806
807         /**
808          * Get the state of this object.
809          *
810          * @return an instance of AccessibleStateSet containing the current
811          * state set of the object
812          * @see AccessibleState
813          */

814         public AccessibleStateSet getAccessibleStateSet() {
815             AccessibleStateSet states = super.getAccessibleStateSet();
816             if (getFocusOwner() != null) {
817                 states.add(AccessibleState.ACTIVE);
818             }
819         if (isModal()) {
820                 states.add(AccessibleState.MODAL);
821         }
822         if (isResizable()) {
823                 states.add(AccessibleState.RESIZABLE);
824         }
825             return states;
826         }
827
828     } // inner class AccessibleAWTDialog
829
}
830
Popular Tags