();
/**
* Specifies the title of the Dialog.
* This field can be null.
*
* @serial
* @see #getTitle()
* @see #setTitle(String)
*/
String title;
private transient ModalEventFilter modalFilter;
private transient volatile SecondaryLoop secondaryLoop;
/*
* Indicates that this dialog is being hidden. This flag is set to true at
* the beginning of hide() and to false at the end of hide().
*
* @see #hide()
* @see #hideAndDisposePreHandler()
* @see #hideAndDisposeHandler()
* @see #shouldBlock()
*/
transient volatile boolean isInHide = false;
/*
* Indicates that this dialog is being disposed. This flag is set to true at
* the beginning of doDispose() and to false at the end of doDispose().
*
* @see #hide()
* @see #hideAndDisposePreHandler()
* @see #hideAndDisposeHandler()
* @see #doDispose()
*/
transient volatile boolean isInDispose = false;
private static final String base = "dialog";
private static int nameCounter = 0;
/*
* JDK 1.1 serialVersionUID
*/
private static final long serialVersionUID = 5920926903803293709L;
/**
* Constructs an initially invisible, modeless Dialog with
* the specified owner Frame and an empty title.
*
* @param owner the owner of the dialog or null if
* this dialog has no owner
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see Component#setSize
* @see Component#setVisible
*/
public Dialog(Frame owner) {
this(owner, "", false);
}
/**
* Constructs an initially invisible Dialog with the specified
* owner Frame and modality and an empty title.
*
* @param owner the owner of the dialog or null if
* this dialog has no owner
* @param modal specifies whether dialog blocks user input to other top-level
* windows when shown. If false, the dialog is MODELESS;
* if true, the modality type property is set to
* DEFAULT_MODALITY_TYPE
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
*/
public Dialog(Frame owner, boolean modal) {
this(owner, "", modal);
}
/**
* Constructs an initially invisible, modeless Dialog with
* the specified owner Frame and title.
*
* @param owner the owner of the dialog or null if
* this dialog has no owner
* @param title the title of the dialog or null if this dialog
* has no title
* @exception IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @see Component#setSize
* @see Component#setVisible
*/
public Dialog(Frame owner, String title) {
this(owner, title, false);
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Frame, title and modality.
*
* @param owner the owner of the dialog or null if
* this dialog has no owner
* @param title the title of the dialog or null if this dialog
* has no title
* @param modal specifies whether dialog blocks user input to other top-level
* windows when shown. If false, the dialog is MODELESS;
* if true, the modality type property is set to
* DEFAULT_MODALITY_TYPE
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see Component#setSize
* @see Component#setVisible
*/
public Dialog(Frame owner, String title, boolean modal) {
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
}
/**
* Constructs an initially invisible Dialog with the specified owner
* Frame, title, modality, and GraphicsConfiguration.
* @param owner the owner of the dialog or null if this dialog
* has no owner
* @param title the title of the dialog or null if this dialog
* has no title
* @param modal specifies whether dialog blocks user input to other top-level
* windows when shown. If false, the dialog is MODELESS;
* if true, the modality type property is set to
* DEFAULT_MODALITY_TYPE
* @param gc the GraphicsConfiguration of the target screen device;
* if null, the default system GraphicsConfiguration
* is assumed
* @exception java.lang.IllegalArgumentException if gc
* is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see Component#setSize
* @see Component#setVisible
* @since 1.4
*/
public Dialog(Frame owner, String title, boolean modal,
GraphicsConfiguration gc) {
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
}
/**
* Constructs an initially invisible, modeless Dialog with
* the specified owner Dialog and an empty title.
*
* @param owner the owner of the dialog or null if this
* dialog has no owner
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.2
*/
public Dialog(Dialog owner) {
this(owner, "", false);
}
/**
* Constructs an initially invisible, modeless Dialog
* with the specified owner Dialog and title.
*
* @param owner the owner of the dialog or null if this
* has no owner
* @param title the title of the dialog or null if this dialog
* has no title
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.GraphicsEnvironment#isHeadless
* @since 1.2
*/
public Dialog(Dialog owner, String title) {
this(owner, title, false);
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Dialog, title, and modality.
*
* @param owner the owner of the dialog or null if this
* dialog has no owner
* @param title the title of the dialog or null if this
* dialog has no title
* @param modal specifies whether dialog blocks user input to other top-level
* windows when shown. If false, the dialog is MODELESS;
* if true, the modality type property is set to
* DEFAULT_MODALITY_TYPE
* @exception IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
*
* @since 1.2
*/
public Dialog(Dialog owner, String title, boolean modal) {
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Dialog, title, modality and
* GraphicsConfiguration.
*
* @param owner the owner of the dialog or null if this
* dialog has no owner
* @param title the title of the dialog or null if this
* dialog has no title
* @param modal specifies whether dialog blocks user input to other top-level
* windows when shown. If false, the dialog is MODELESS;
* if true, the modality type property is set to
* DEFAULT_MODALITY_TYPE
* @param gc the GraphicsConfiguration of the target screen device;
* if null, the default system GraphicsConfiguration
* is assumed
* @exception java.lang.IllegalArgumentException if gc
* is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see Component#setSize
* @see Component#setVisible
*
* @since 1.4
*/
public Dialog(Dialog owner, String title, boolean modal,
GraphicsConfiguration gc) {
this(owner, title, modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS, gc);
}
/**
* Constructs an initially invisible, modeless Dialog with the
* specified owner Window and an empty title.
*
* @param owner the owner of the dialog. The owner must be an instance of
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
* of their descendents or null
*
* @exception java.lang.IllegalArgumentException if the owner
* is not an instance of {@link java.awt.Dialog Dialog} or {@link
* java.awt.Frame Frame}
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.GraphicsEnvironment#isHeadless
*
* @since 1.6
*/
public Dialog(Window owner) {
this(owner, "", ModalityType.MODELESS);
}
/**
* Constructs an initially invisible, modeless Dialog with
* the specified owner Window and title.
*
* @param owner the owner of the dialog. The owner must be an instance of
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
* of their descendents or null
* @param title the title of the dialog or null if this dialog
* has no title
*
* @exception java.lang.IllegalArgumentException if the owner
* is not an instance of {@link java.awt.Dialog Dialog} or {@link
* java.awt.Frame Frame}
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
*
* @see java.awt.GraphicsEnvironment#isHeadless
*
* @since 1.6
*/
public Dialog(Window owner, String title) {
this(owner, title, ModalityType.MODELESS);
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Window and modality and an empty title.
*
* @param owner the owner of the dialog. The owner must be an instance of
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
* of their descendents or null
* @param modalityType specifies whether dialog blocks input to other
* windows when shown. null value and unsupported modality
* types are equivalent to MODELESS
*
* @exception java.lang.IllegalArgumentException if the owner
* is not an instance of {@link java.awt.Dialog Dialog} or {@link
* java.awt.Frame Frame}
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
* @exception SecurityException if the calling thread does not have permission
* to create modal dialogs with the given modalityType
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.awt.Toolkit#isModalityTypeSupported
*
* @since 1.6
*/
public Dialog(Window owner, ModalityType modalityType) {
this(owner, "", modalityType);
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Window, title and modality.
*
* @param owner the owner of the dialog. The owner must be an instance of
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
* of their descendents or null
* @param title the title of the dialog or null if this dialog
* has no title
* @param modalityType specifies whether dialog blocks input to other
* windows when shown. null value and unsupported modality
* types are equivalent to MODELESS
*
* @exception java.lang.IllegalArgumentException if the owner
* is not an instance of {@link java.awt.Dialog Dialog} or {@link
* java.awt.Frame Frame}
* @exception java.lang.IllegalArgumentException if the owner's
* GraphicsConfiguration is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
* @exception SecurityException if the calling thread does not have permission
* to create modal dialogs with the given modalityType
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.awt.Toolkit#isModalityTypeSupported
*
* @since 1.6
*/
public Dialog(Window owner, String title, ModalityType modalityType) {
super(owner);
if ((owner != null) &&
!(owner instanceof Frame) &&
!(owner instanceof Dialog))
{
throw new IllegalArgumentException("Wrong parent window");
}
this.title = title;
setModalityType(modalityType);
SunToolkit.checkAndSetPolicy(this);
initialized = true;
}
/**
* Constructs an initially invisible Dialog with the
* specified owner Window, title, modality and
* GraphicsConfiguration.
*
* @param owner the owner of the dialog. The owner must be an instance of
* {@link java.awt.Dialog Dialog}, {@link java.awt.Frame Frame}, any
* of their descendents or null
* @param title the title of the dialog or null if this dialog
* has no title
* @param modalityType specifies whether dialog blocks input to other
* windows when shown. null value and unsupported modality
* types are equivalent to MODELESS
* @param gc the GraphicsConfiguration of the target screen device;
* if null, the default system GraphicsConfiguration
* is assumed
*
* @exception java.lang.IllegalArgumentException if the owner
* is not an instance of {@link java.awt.Dialog Dialog} or {@link
* java.awt.Frame Frame}
* @exception java.lang.IllegalArgumentException if gc
* is not from a screen device
* @exception HeadlessException when
* GraphicsEnvironment.isHeadless() returns true
* @exception SecurityException if the calling thread does not have permission
* to create modal dialogs with the given modalityType
*
* @see java.awt.Dialog.ModalityType
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#setModalityType
* @see java.awt.GraphicsEnvironment#isHeadless
* @see java.awt.Toolkit#isModalityTypeSupported
*
* @since 1.6
*/
public Dialog(Window owner, String title, ModalityType modalityType,
GraphicsConfiguration gc) {
super(owner, gc);
if ((owner != null) &&
!(owner instanceof Frame) &&
!(owner instanceof Dialog))
{
throw new IllegalArgumentException("wrong owner window");
}
this.title = title;
setModalityType(modalityType);
SunToolkit.checkAndSetPolicy(this);
initialized = true;
}
/**
* Construct a name for this component. Called by getName() when the
* name is null.
*/
String constructComponentName() {
synchronized (Dialog.class) {
return base + nameCounter++;
}
}
/**
* 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.
* @see Component#isDisplayable
* @see #removeNotify
*/
public void addNotify() {
synchronized (getTreeLock()) {
if (parent != null && parent.getPeer() == null) {
parent.addNotify();
}
if (peer == null) {
peer = getToolkit().createDialog(this);
}
super.addNotify();
}
}
/**
* Indicates whether the dialog is modal.
*
* This method is obsolete and is kept for backwards compatibility only.
* Use {@link #getModalityType getModalityType()} instead.
*
* @return true if this dialog window is modal;
* false otherwise
*
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#setModal
* @see java.awt.Dialog#getModalityType
* @see java.awt.Dialog#setModalityType
*/
public boolean isModal() {
return isModal_NoClientCode();
}
final boolean isModal_NoClientCode() {
return modalityType != ModalityType.MODELESS;
}
/**
* Specifies whether this dialog should be modal.
*
* This method is obsolete and is kept for backwards compatibility only.
* Use {@link #setModalityType setModalityType()} instead.
*
* Note: changing modality of the visible dialog may have no effect
* until it is hidden and then shown again.
*
* @param modal specifies whether dialog blocks input to other windows
* when shown; calling to setModal(true) is equivalent to
* setModalityType(Dialog.DEFAULT_MODALITY_TYPE), and
* calling to setModal(false) is equvivalent to
* setModalityType(Dialog.ModalityType.MODELESS)
*
* @see java.awt.Dialog#DEFAULT_MODALITY_TYPE
* @see java.awt.Dialog.ModalityType#MODELESS
* @see java.awt.Dialog#isModal
* @see java.awt.Dialog#getModalityType
* @see java.awt.Dialog#setModalityType
*
* @since 1.1
*/
public void setModal(boolean modal) {
this.modal = modal;
setModalityType(modal ? DEFAULT_MODALITY_TYPE : ModalityType.MODELESS);
}
/**
* Returns the modality type of this dialog.
*
* @return modality type of this dialog
*
* @see java.awt.Dialog#setModalityType
*
* @since 1.6
*/
public ModalityType getModalityType() {
return modalityType;
}
/**
* Sets the modality type for this dialog. See {@link
* java.awt.Dialog.ModalityType ModalityType} for possible modality types.
*
* If the given modality type is not supported, MODELESS
* is used. You may want to call getModalityType() after calling
* this method to ensure that the modality type has been set.
*
* Note: changing modality of the visible dialog may have no effect
* until it is hidden and then shown again.
*
* @param type specifies whether dialog blocks input to other
* windows when shown. null value and unsupported modality
* types are equivalent to MODELESS
* @exception SecurityException if the calling thread does not have permission
* to create modal dialogs with the given modalityType
*
* @see java.awt.Dialog#getModalityType
* @see java.awt.Toolkit#isModalityTypeSupported
*
* @since 1.6
*/
public void setModalityType(ModalityType type) {
if (type == null) {
type = Dialog.ModalityType.MODELESS;
}
if (!Toolkit.getDefaultToolkit().isModalityTypeSupported(type)) {
type = Dialog.ModalityType.MODELESS;
}
if (modalityType == type) {
return;
}
checkModalityPermission(type);
modalityType = type;
modal = (modalityType != ModalityType.MODELESS);
}
/**
* Gets the title of the dialog. The title is displayed in the
* dialog's border.
* @return the title of this dialog window. The title may be
* null.
* @see java.awt.Dialog#setTitle
*/
public String getTitle() {
return title;
}
/**
* Sets the title of the Dialog.
* @param title the title displayed in the dialog's border;
* a null value results in an empty title
* @see #getTitle
*/
public void setTitle(String title) {
String oldTitle = this.title;
synchronized(this) {
this.title = title;
DialogPeer peer = (DialogPeer)this.peer;
if (peer != null) {
peer.setTitle(title);
}
}
firePropertyChange("title", oldTitle, title);
}
/**
* @return true if we actually showed, false if we just called toFront()
*/
private boolean conditionalShow(Component toFocus, AtomicLong time) {
boolean retval;
closeSplashScreen();
synchronized (getTreeLock()) {
if (peer == null) {
addNotify();
}
validateUnconditionally();
if (visible) {
toFront();
retval = false;
} else {
visible = retval = true;
// check if this dialog should be modal blocked BEFORE calling peer.show(),
// otherwise, a pair of FOCUS_GAINED and FOCUS_LOST may be mistakenly
// generated for the dialog
if (!isModal()) {
checkShouldBeBlocked(this);
} else {
modalDialogs.add(this);
modalShow();
}
if (toFocus != null && time != null && isFocusable() &&
isEnabled() && !isModalBlocked()) {
// keep the KeyEvents from being dispatched
// until the focus has been transfered
time.set(Toolkit.getEventQueue().getMostRecentKeyEventTime());
KeyboardFocusManager.getCurrentKeyboardFocusManager().
enqueueKeyEvents(time.get(), toFocus);
}
// This call is required as the show() method of the Dialog class
// does not invoke the super.show(). So wried... :(
mixOnShowing();
peer.setVisible(true); // now guaranteed never to block
if (isModalBlocked()) {
modalBlocker.toFront();
}
setLocationByPlatform(false);
for (int i = 0; i < ownedWindowList.size(); i++) {
Window child = ownedWindowList.elementAt(i).get();
if ((child != null) && child.showWithParent) {
child.show();
child.showWithParent = false;
} // endif
} // endfor
Window.updateChildFocusableWindowState(this);
createHierarchyEvents(HierarchyEvent.HIERARCHY_CHANGED,
this, parent,
HierarchyEvent.SHOWING_CHANGED,
Toolkit.enabledOnToolkit(AWTEvent.HIERARCHY_EVENT_MASK));
if (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;
}
/**
* Shows or hides this {@code Dialog} depending on the value of parameter
* {@code b}.
* @param b if {@code true}, makes the {@code Dialog} visible,
* otherwise hides the {@code Dialog}.
* If the dialog and/or its owner
* are not yet displayable, both are made displayable. The
* dialog will be validated prior to being made visible.
* If {@code false}, hides the {@code Dialog} and then causes {@code setVisible(true)}
* to return if it is currently blocked.
*
* Notes for modal dialogs.
*
* - {@code setVisible(true)}: If the dialog is not already
* visible, this call will not return until the dialog is
* hidden by calling {@code setVisible(false)} or
* {@code dispose}.
*
- {@code setVisible(false)}: Hides the dialog and then
* returns on {@code setVisible(true)} if it is currently blocked.
*
- It is OK to call this method from the event dispatching
* thread because the toolkit ensures that other events are
* not blocked while this method is blocked.
*
* @see java.awt.Window#setVisible
* @see java.awt.Window#dispose
* @see java.awt.Component#isDisplayable
* @see java.awt.Component#validate
* @see java.awt.Dialog#isModal
*/
public void setVisible(boolean b) {
super.setVisible(b);
}
/**
* Makes the {@code Dialog} visible. If the dialog and/or its owner
* are not yet displayable, both are made displayable. The
* dialog will be validated prior to being made visible.
* If the dialog is already visible, this will bring the dialog
* to the front.
*
* If the dialog is modal and is not already visible, this call
* will not return until the dialog is hidden by calling hide or
* dispose. It is permissible to show modal dialogs from the event
* dispatching thread because the toolkit will ensure that another
* event pump runs while the one which invoked this method is blocked.
* @see Component#hide
* @see Component#isDisplayable
* @see Component#validate
* @see #isModal
* @see Window#setVisible(boolean)
* @deprecated As of JDK version 1.5, replaced by
* {@link #setVisible(boolean) setVisible(boolean)}.
*/
@Deprecated
public void show() {
if (!initialized) {
throw new IllegalStateException("The dialog component " +
"has not been initialized properly");
}
beforeFirstShow = false;
if (!isModal()) {
conditionalShow(null, null);
} else {
AppContext showAppContext = AppContext.getAppContext();
AtomicLong time = new AtomicLong();
Component predictedFocusOwner = null;
try {
predictedFocusOwner = getMostRecentFocusOwner();
if (conditionalShow(predictedFocusOwner, time)) {
modalFilter = ModalEventFilter.createFilterForDialog(this);
final Conditional cond = new Conditional() {
@Override
public boolean evaluate() {
return windowClosingException == null;
}
};
// if this dialog is toolkit-modal, the filter should be added
// to all EDTs (for all AppContexts)
if (modalityType == ModalityType.TOOLKIT_MODAL) {
Iterator it = AppContext.getAppContexts().iterator();
while (it.hasNext()) {
AppContext appContext = it.next();
if (appContext == showAppContext) {
continue;
}
EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
// it may occur that EDT for appContext hasn't been started yet, so
// we post an empty invocation event to trigger EDT initialization
Runnable createEDT = new Runnable() {
public void run() {};
};
eventQueue.postEvent(new InvocationEvent(this, createEDT));
EventDispatchThread edt = eventQueue.getDispatchThread();
edt.addEventFilter(modalFilter);
}
}
modalityPushed();
try {
final EventQueue eventQueue = AccessController.doPrivileged(
new PrivilegedAction() {
public EventQueue run() {
return Toolkit.getDefaultToolkit().getSystemEventQueue();
}
});
secondaryLoop = eventQueue.createSecondaryLoop(cond, modalFilter, 0);
if (!secondaryLoop.enter()) {
secondaryLoop = null;
}
} finally {
modalityPopped();
}
// if this dialog is toolkit-modal, its filter must be removed
// from all EDTs (for all AppContexts)
if (modalityType == ModalityType.TOOLKIT_MODAL) {
Iterator it = AppContext.getAppContexts().iterator();
while (it.hasNext()) {
AppContext appContext = it.next();
if (appContext == showAppContext) {
continue;
}
EventQueue eventQueue = (EventQueue)appContext.get(AppContext.EVENT_QUEUE_KEY);
EventDispatchThread edt = eventQueue.getDispatchThread();
edt.removeEventFilter(modalFilter);
}
}
if (windowClosingException != null) {
windowClosingException.fillInStackTrace();
throw windowClosingException;
}
}
} finally {
if (predictedFocusOwner != null) {
// Restore normal key event dispatching
KeyboardFocusManager.getCurrentKeyboardFocusManager().
dequeueKeyEvents(time.get(), predictedFocusOwner);
}
}
}
}
final void modalityPushed() {
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
SunToolkit stk = (SunToolkit)tk;
stk.notifyModalityPushed(this);
}
}
final void modalityPopped() {
Toolkit tk = Toolkit.getDefaultToolkit();
if (tk instanceof SunToolkit) {
SunToolkit stk = (SunToolkit)tk;
stk.notifyModalityPopped(this);
}
}
void interruptBlocking() {
if (isModal()) {
disposeImpl();
} else if (windowClosingException != null) {
windowClosingException.fillInStackTrace();
windowClosingException.printStackTrace();
windowClosingException = null;
}
}
private void hideAndDisposePreHandler() {
isInHide = true;
synchronized (getTreeLock()) {
if (secondaryLoop != null) {
modalHide();
// dialog can be shown and then disposed before its
// modal filter is created
if (modalFilter != null) {
modalFilter.disable();
}
modalDialogs.remove(this);
}
}
}
private void hideAndDisposeHandler() {
if (secondaryLoop != null) {
secondaryLoop.exit();
secondaryLoop = null;
}
isInHide = false;
}
/**
* Hides the Dialog and then causes {@code show} to return if it is currently
* blocked.
* @see Window#show
* @see Window#dispose
* @see Window#setVisible(boolean)
* @deprecated As of JDK version 1.5, replaced by
* {@link #setVisible(boolean) setVisible(boolean)}.
*/
@Deprecated
public void hide() {
hideAndDisposePreHandler();
super.hide();
// fix for 5048370: if hide() is called from super.doDispose(), then
// hideAndDisposeHandler() should not be called here as it will be called
// at the end of doDispose()
if (!isInDispose) {
hideAndDisposeHandler();
}
}
/**
* Disposes the Dialog and then causes show() to return if it is currently
* blocked.
*/
void doDispose() {
// fix for 5048370: set isInDispose flag to true to prevent calling
// to hideAndDisposeHandler() from hide()
isInDispose = true;
super.doDispose();
hideAndDisposeHandler();
isInDispose = false;
}
/**
* {@inheritDoc}
*
* If this dialog is modal and blocks some windows, then all of them are
* also sent to the back to keep them below the blocking dialog.
*
* @see java.awt.Window#toBack
*/
public void toBack() {
super.toBack();
if (visible) {
synchronized (getTreeLock()) {
for (Window w : blockedWindows) {
w.toBack_NoClientCode();
}
}
}
}
/**
* Indicates whether this dialog is resizable by the user.
* By default, all dialogs are initially resizable.
* @return true if the user can resize the dialog;
* false otherwise.
* @see java.awt.Dialog#setResizable
*/
public boolean isResizable() {
return resizable;
}
/**
* Sets whether this dialog is resizable by the user.
* @param resizable true if the user can
* resize this dialog; false otherwise.
* @see java.awt.Dialog#isResizable
*/
public void setResizable(boolean resizable) {
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) {
invalidateIfValid();
}
}
/**
* Disables or enables decorations for this dialog.
*
* This method can only be called while the dialog is not displayable. To
* make this dialog decorated, it must be opaque and have the default shape,
* otherwise the {@code IllegalComponentStateException} will be thrown.
* Refer to {@link Window#setShape}, {@link Window#setOpacity} and {@link
* Window#setBackground} for details
*
* @param undecorated {@code true} if no dialog decorations are to be
* enabled; {@code false} if dialog decorations are to be enabled
*
* @throws IllegalComponentStateException if the dialog is displayable
* @throws IllegalComponentStateException if {@code undecorated} is
* {@code false}, and this dialog does not have the default shape
* @throws IllegalComponentStateException if {@code undecorated} is
* {@code false}, and this dialog opacity is less than {@code 1.0f}
* @throws IllegalComponentStateException if {@code undecorated} is
* {@code false}, and the alpha value of this dialog background
* color is less than {@code 1.0f}
*
* @see #isUndecorated
* @see Component#isDisplayable
* @see Window#getShape
* @see Window#getOpacity
* @see Window#getBackground
*
* @since 1.4
*/
public void setUndecorated(boolean undecorated) {
/* Make sure we don't run in the middle of peer creation.*/
synchronized (getTreeLock()) {
if (isDisplayable()) {
throw new IllegalComponentStateException("The dialog is displayable.");
}
if (!undecorated) {
if (getOpacity() < 1.0f) {
throw new IllegalComponentStateException("The dialog is not opaque");
}
if (getShape() != null) {
throw new IllegalComponentStateException("The dialog does not have a default shape");
}
Color bg = getBackground();
if ((bg != null) && (bg.getAlpha() < 255)) {
throw new IllegalComponentStateException("The dialog background color is not opaque");
}
}
this.undecorated = undecorated;
}
}
/**
* Indicates whether this dialog is undecorated.
* By default, all dialogs are initially decorated.
* @return true if dialog is undecorated;
* false otherwise.
* @see java.awt.Dialog#setUndecorated
* @since 1.4
*/
public boolean isUndecorated() {
return undecorated;
}
/**
* {@inheritDoc}
*/
@Override
public void setOpacity(float opacity) {
synchronized (getTreeLock()) {
if ((opacity < 1.0f) && !isUndecorated()) {
throw new IllegalComponentStateException("The dialog is decorated");
}
super.setOpacity(opacity);
}
}
/**
* {@inheritDoc}
*/
@Override
public void setShape(Shape shape) {
synchronized (getTreeLock()) {
if ((shape != null) && !isUndecorated()) {
throw new IllegalComponentStateException("The dialog is decorated");
}
super.setShape(shape);
}
}
/**
* {@inheritDoc}
*/
@Override
public void setBackground(Color bgColor) {
synchronized (getTreeLock()) {
if ((bgColor != null) && (bgColor.getAlpha() < 255) && !isUndecorated()) {
throw new IllegalComponentStateException("The dialog is decorated");
}
super.setBackground(bgColor);
}
}
/**
* 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.
*
* @return the parameter string of this dialog window.
*/
protected String paramString() {
String str = super.paramString() + "," + modalityType;
if (title != null) {
str += ",title=" + title;
}
return str;
}
/**
* Initialize JNI field and method IDs
*/
private static native void initIDs();
/*
* --- Modality support ---
*
*/
/*
* This method is called only for modal dialogs.
*
* Goes through the list of all visible top-level windows and
* divide them into three distinct groups: blockers of this dialog,
* blocked by this dialog and all others. Then blocks this dialog
* by first met dialog from the first group (if any) and blocks all
* the windows from the second group.
*/
void modalShow() {
// find all the dialogs that block this one
IdentityArrayList