下面列出了java.awt.Dialog#isShowing ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private List<AssertionError> checkForModalDialogs() {
List<AssertionError> errors = new ArrayList<>();
// We close all modal dialogs left over, because they block the AWT thread and could trigger a deadlock in the next test.
Dialog modalDialog;
while ((modalDialog = getActiveModalDialog()) != null) {
errors.add(new AssertionError(
String.format(
"Modal dialog %s: %s with title '%s'",
modalDialog.isShowing() ? "showing" : "not showing",
modalDialog.getClass().getName(),
modalDialog.getTitle())));
if (!modalDialog.isShowing()) break; // this assumes when the active dialog is not showing, none are showing
robot().close(modalDialog);
}
return errors;
}
private void makeVisible(Dialog d) throws InterruptedException {
d.setVisible(true);
while (!d.isShowing()) {
LOG.log(Level.INFO, "Waiting for is showing: {0}", d);
Thread.sleep (1000);
}
}
public @Override void actionPerformed(ActionEvent e) {
Dialog dialog = dialogWRef.get ();
if (dialog == null || ! dialog.isShowing ()) {
final CatalogPanel cp = new CatalogPanel ();
JButton closeButton = new JButton ();
Mnemonics.setLocalizedText (closeButton,NbBundle.getMessage (CatalogAction.class, "BTN_CatalogPanel_CloseButton")); // NOI18N
JButton openInEditor = new JButton ();
openInEditor.setEnabled (false);
OpenInEditorListener l = new OpenInEditorListener (cp, openInEditor);
openInEditor.addActionListener (l);
cp.getExplorerManager ().addPropertyChangeListener (l);
Mnemonics.setLocalizedText (openInEditor,NbBundle.getMessage (CatalogAction.class, "BTN_CatalogPanel_OpenInEditorButton")); // NOI18N
DialogDescriptor dd = new DialogDescriptor (cp,NbBundle.getMessage (CatalogAction.class, "LBL_CatalogPanel_Title"), // NOI18N
false, // modal
new Object [] { openInEditor, closeButton },
closeButton,
DialogDescriptor.DEFAULT_ALIGN,
null,
null);
dd.setClosingOptions (null);
// set helpctx to null again, DialogDescriptor replaces null with HelpCtx.DEFAULT_HELP
dd.setHelpCtx (null);
dialog = DialogDisplayer.getDefault ().createDialog (dd);
dialog.setVisible (true);
dialogWRef = new WeakReference<Dialog> (dialog);
} else {
dialog.toFront ();
}
}
/** @return Whether or not the application is currently in a modal state. */
public static boolean inModalState() {
for (Window window : Window.getWindows()) {
if (window instanceof Dialog) {
Dialog dialog = (Dialog) window;
if (dialog.isShowing()) {
ModalityType type = dialog.getModalityType();
if (type == ModalityType.APPLICATION_MODAL || type == ModalityType.TOOLKIT_MODAL) {
return true;
}
}
}
}
return false;
}