Dialogpublic class Dialog extends Window A Dialog is a top-level window with a title and a border
that is typically used to take some form of input from the user.
The size of the dialog includes any area designated for the
border. The dimensions of the border area can be obtained
using the getInsets method, however, since
these dimensions are platform-dependent, a valid insets
value cannot be obtained until the dialog is made displayable
by either calling pack or show .
Since the border area is included in the overall size of the
dialog, the border effectively obscures a portion of the dialog,
constraining the area available for rendering and/or displaying
subcomponents to the rectangle which has an upper-left corner
location of (insets.left, insets.top) , and has a size of
width - (insets.left + insets.right) by
height - (insets.top + insets.bottom) .
The default layout for a dialog is BorderLayout .
A dialog may have its native decorations (i.e. Frame & Titlebar) turned off
with setUndecorated . This can only be done while the dialog
is not {@link Component#isDisplayable() displayable}.
A dialog must have either a frame or another dialog defined as its
owner when it's constructed. When the owner window of a visible dialog
is minimized, the dialog will automatically be hidden
from the user. When the owner window is subsequently restored,
the dialog is made visible to the user again.
In a multi-screen environment, you can create a Dialog
on a different screen device than its owner. See {@link java.awt.Frame} for
more information.
A dialog can be either modeless (the default) or modal. A modal
dialog is one which blocks input to all other toplevel windows
in the application, except for any windows created with the dialog
as their owner.
Dialogs are capable of generating the following
WindowEvents :
WindowOpened , WindowClosing ,
WindowClosed , WindowActivated ,
WindowDeactivated , WindowGainedFocus ,
WindowLostFocus . |
Fields Summary |
---|
boolean | resizableA dialog's resizable property. Will be true
if the Dialog is to be resizable, otherwise
it will be false. | boolean | undecoratedThis field indicates whether the dialog is undecorated.
This property can only be changed while the dialog is not displayable.
undecorated will be true if the dialog is
undecorated, otherwise it will be false. | boolean | modalWill be true if the Dialog is modal,
otherwise the dialog will be modeless.
A modal Dialog grabs all the input to
the owner frame from the user. | String | titleSpecifies the title of the Dialog.
This field can be null. | private transient boolean | keepBlocking | private static final String | base | private static int | nameCounter | private static final long | serialVersionUID | private transient AppContext | showAppContextStores the app context on which event dispatch thread the dialog
is being shown. Initialized in show(), used in hideAndDisposeHandler() |
Constructors Summary |
---|
public Dialog(Frame owner)Constructs an initially invisible, non-modal Dialog with
an empty title and the specified owner frame.
this(owner, "", false);
| public Dialog(Frame owner, boolean modal)Constructs an initially invisible Dialog with an empty title,
the specified owner frame and modality.
this(owner, "", modal);
| public Dialog(Frame owner, String title)Constructs an initially invisible, non-modal Dialog with
the specified owner frame and title.
this(owner, title, false);
| public Dialog(Frame owner, String title, boolean modal)Constructs an initially invisible Dialog with the
specified owner frame, title, and modality.
super(owner);
this.title = title;
this.modal = modal;
SunToolkit.checkAndSetPolicy(this, false);
| public Dialog(Frame owner, String title, boolean modal, GraphicsConfiguration gc)Constructs an initially invisible Dialog with the
specified owner frame, title, modality, and
GraphicsConfiguration .
super(owner, gc);
this.title = title;
this.modal = modal;
SunToolkit.checkAndSetPolicy(this, false);
| public Dialog(Dialog owner)Constructs an initially invisible, non-modal Dialog with
an empty title and the specified owner dialog.
this(owner, "", false);
| public Dialog(Dialog owner, String title)Constructs an initially invisible, non-modal Dialog
with the specified owner dialog and title.
this(owner, title, false);
| public Dialog(Dialog owner, String title, boolean modal)Constructs an initially invisible Dialog with the
specified owner dialog, title, and modality.
super(owner);
this.title = title;
this.modal = modal;
SunToolkit.checkAndSetPolicy(this, false);
| public Dialog(Dialog owner, String title, boolean modal, GraphicsConfiguration gc)Constructs an initially invisible Dialog with the
specified owner dialog, title, modality, and
GraphicsConfiguration .
super(owner, gc);
this.title = title;
this.modal = modal;
SunToolkit.checkAndSetPolicy(this, false);
|
Methods Summary |
---|
public void | addNotify()Makes this Dialog displayable by connecting it to
a native screen resource. Making a dialog displayable will
cause any of its children to be made displayable.
This method is called internally by the toolkit and should
not be called directly by programs.
synchronized (getTreeLock()) {
if (parent != null && parent.getPeer() == null) {
parent.addNotify();
}
if (peer == null) {
peer = getToolkit().createDialog(this);
}
super.addNotify();
}
| private boolean | conditionalShow()
boolean retval;
synchronized (getTreeLock()) {
if (peer == null) {
addNotify();
}
validate();
if (visible) {
toFront();
retval = false;
} else {
visible = retval = true;
peer.show(); // now guaranteed never to block
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
this, parent,
HierarchyEvent.SHOWING_CHANGED,
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
}
if (retval && (componentListener != null ||
(eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0 ||
Toolkit.enabledOnToolkit(AWTEvent.COMPONENT_EVENT_MASK))) {
ComponentEvent e =
new ComponentEvent(this, ComponentEvent.COMPONENT_SHOWN);
Toolkit.getEventQueue().postEvent(e);
}
}
if (retval && (state & OPENED) == 0) {
postWindowEvent(WindowEvent.WINDOW_OPENED);
state |= OPENED;
}
return retval;
| java.lang.String | constructComponentName()Construct a name for this component. Called by getName() when the
name is null.
synchronized (getClass()) {
return base + nameCounter++;
}
| void | doDispose()Disposes the Dialog and then causes show() to return if it is currently
blocked.
super.doDispose();
hideAndDisposeHandler();
| public javax.accessibility.AccessibleContext | getAccessibleContext()Gets the AccessibleContext associated with this Dialog.
For dialogs, the AccessibleContext takes the form of an
AccessibleAWTDialog.
A new AccessibleAWTDialog instance is created if necessary.
if (accessibleContext == null) {
accessibleContext = new AccessibleAWTDialog();
}
return accessibleContext;
| public java.lang.String | getTitle()Gets the title of the dialog. The title is displayed in the
dialog's border.
return title;
| public void | hide()
super.hide();
hideAndDisposeHandler();
| private void | hideAndDisposeHandler()
if (keepBlocking) {
synchronized (getTreeLock()) {
keepBlocking = false;
if (showAppContext != null) {
// Wake up event dispatch thread on which the dialog was
// initially shown
SunToolkit.postEvent(showAppContext,
new PeerEvent(this,
new WakingRunnable(),
PeerEvent.PRIORITY_EVENT));
showAppContext = null;
}
EventQueue.invokeLater(new WakingRunnable());
getTreeLock().notifyAll();
}
}
| private static native void | initIDs()Initialize JNI field and method IDs
| void | interruptBlocking()
if (modal) {
disposeImpl();
} else if (windowClosingException != null) {
windowClosingException.fillInStackTrace();
windowClosingException.printStackTrace();
windowClosingException = null;
}
| public boolean | isModal()Indicates whether the dialog is modal.
When a modal Dialog is made visible, user input will be
blocked to the other windows in the application, except for
any windows created with this dialog as their owner.
return modal;
| public boolean | isResizable()Indicates whether this dialog is resizable by the user.
return resizable;
| public boolean | isUndecorated()Indicates whether this dialog is undecorated.
By default, all dialogs are initially decorated.
return undecorated;
| protected java.lang.String | paramString()Returns a string representing the state of this dialog. This
method is intended to be used only for debugging purposes, and the
content and format of the returned string may vary between
implementations. The returned string may be empty but may not be
null .
String str = super.paramString() + (modal ? ",modal" : ",modeless");
if (title != null) {
str += ",title=" + title;
}
return str;
| public void | setModal(boolean b)Specifies whether this dialog should be modal.
this.modal = b;
| public void | setResizable(boolean resizable)Sets whether this dialog is resizable by the user.
boolean testvalid = false;
synchronized (this) {
this.resizable = resizable;
DialogPeer peer = (DialogPeer)this.peer;
if (peer != null) {
peer.setResizable(resizable);
testvalid = true;
}
}
// On some platforms, changing the resizable state affects
// the insets of the Dialog. If we could, we'd call invalidate()
// from the peer, but we need to guarantee that we're not holding
// the Dialog lock when we call invalidate().
if (testvalid && valid) {
invalidate();
}
| public void | setTitle(java.lang.String title)Sets the title of the Dialog.
String oldTitle = this.title;
synchronized(this) {
this.title = title;
DialogPeer peer = (DialogPeer)this.peer;
if (peer != null) {
peer.setTitle(title);
}
}
firePropertyChange("title", oldTitle, title);
| public void | setUndecorated(boolean undecorated)Disables or enables decorations for this dialog.
This method can only be called while the dialog is not displayable.
/* Make sure we don't run in the middle of peer creation.*/
synchronized (getTreeLock()) {
if (isDisplayable()) {
throw new IllegalComponentStateException("The dialog is displayable.");
}
this.undecorated = undecorated;
}
| public void | show()
beforeFirstShow = false;
if (!isModal()) {
conditionalShow();
} else {
// Set this variable before calling conditionalShow(). That
// way, if the Dialog is hidden right after being shown, we
// won't mistakenly block this thread.
keepBlocking = true;
// Store the app context on which this dialog is being shown.
// Event dispatch thread of this app context will be sleeping until
// we wake it by any event from hideAndDisposeHandler().
showAppContext = AppContext.getAppContext();
// keep the KeyEvents from being dispatched
// until the focus has been transfered
long time = Toolkit.getEventQueue().getMostRecentEventTimeEx();
Component predictedFocusOwner = getMostRecentFocusOwner();
KeyboardFocusManager.getCurrentKeyboardFocusManager().
enqueueKeyEvents(time, predictedFocusOwner);
try {
if (conditionalShow()) {
// We have two mechanisms for blocking: 1. If we're on the
// EventDispatchThread, start a new event pump. 2. If we're
// on any other thread, call wait() on the treelock.
Runnable pumpEventsForHierarchy = new Runnable() {
public void run() {
EventDispatchThread dispatchThread =
(EventDispatchThread)Thread.currentThread();
dispatchThread.pumpEventsForHierarchy(new Conditional() {
public boolean evaluate() {
return keepBlocking && windowClosingException == null;
}
}, Dialog.this);
}
};
if (EventQueue.isDispatchThread()) {
/*
* dispose SequencedEvent we are dispatching on current
* AppContext, to prevent us from hang.
*
* BugId 4531693 (son@sparc.spb.su)
*/
SequencedEvent currentSequencedEvent = KeyboardFocusManager.
getCurrentKeyboardFocusManager().getCurrentSequencedEvent();
if (currentSequencedEvent != null) {
currentSequencedEvent.dispose();
}
pumpEventsForHierarchy.run();
} else {
synchronized (getTreeLock()) {
Toolkit.getEventQueue().
postEvent(new PeerEvent(this,
pumpEventsForHierarchy,
PeerEvent.PRIORITY_EVENT));
while (keepBlocking && windowClosingException == null) {
try {
getTreeLock().wait();
} catch (InterruptedException e) {
break;
}
}
}
}
if (windowClosingException != null) {
windowClosingException.fillInStackTrace();
throw windowClosingException;
}
}
} finally {
// Restore normal key event dispatching
KeyboardFocusManager.getCurrentKeyboardFocusManager().
dequeueKeyEvents(time, predictedFocusOwner);
}
}
|
|