This is an automated email from the ASF dual-hosted git repository. neilcsmith pushed a commit to branch revert-6216-rk-dialog-parent in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit b42b19b8a54ffcc26e74f1114cb0b0bbcb5e4a97 Author: Neil C Smith <neilcsmith....@googlemail.com> AuthorDate: Thu Aug 3 09:59:54 2023 +0100 Revert "Use the currently active dialog as the presenter parent" --- .../core/windows/services/DialogDisplayerImpl.java | 113 +++++++++++++-------- .../netbeans/core/windows/services/NbDialog.java | 10 +- .../core/windows/services/NbPresenter.java | 48 +++++---- .../core/windows/services/NodeOperationImpl.java | 8 +- .../windows/services/DialogDisplayerImplTest.java | 31 +----- .../core/windows/services/NbDialogTest.java | 53 ---------- .../core/windows/services/NbPresenterTest.java | 25 +---- .../core/windows/services/NotifyLaterTest.java | 2 +- platform/openide.util.ui/apichanges.xml | 16 --- .../src/org/openide/util/Utilities.java | 57 ++--------- 10 files changed, 122 insertions(+), 241 deletions(-) diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java b/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java index eb9df92d42..85cbb635ba 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/DialogDisplayerImpl.java @@ -42,7 +42,6 @@ import javax.swing.JRootPane; import javax.swing.SwingUtilities; import org.netbeans.core.windows.view.ui.DefaultSeparateContainer; import org.openide.util.Lookup; -import org.openide.util.Utilities; import org.openide.util.lookup.ServiceProvider; /** @@ -96,53 +95,53 @@ public class DialogDisplayerImpl extends DialogDisplayer { } return Mutex.EVENT.readAccess (new Mutex.Action<Dialog> () { public Dialog run () { - Window w = preferredParent; - if (w != null) { - // Verify the preferred parent - Component p = Utilities.findDialogParent(w); - if (p != w) { - w = null; + // if a modal dialog active use it as parent + // otherwise use the main window + if (NbPresenter.currentModalDialog != null) { + NbDialog dlg; + if (NbPresenter.currentModalDialog.isLeaf ()) { + dlg = new NbDialog(d, WindowManager.getDefault ().getMainWindow ()); + } else { + dlg = new NbDialog(d, NbPresenter.currentModalDialog); } + customizeDlg(dlg); + return dlg; } - if (w == null) { - w = findDialogParent(); - if (!(w instanceof NbPresenter) || !w.isVisible()) { - // undocked window is not instanceof NbPresenter although it's NetBeans's native window - // all docked windows implements ModeUIBase interface - if (! (w instanceof DefaultSeparateContainer.ModeUIBase)) { - Container cont = SwingUtilities.getAncestorOfClass(Window.class, w); - if (cont instanceof DefaultSeparateContainer.ModeUIBase) { - w = (Window) cont; - } else { - // don't set non-ide window as parent - w = WindowManager.getDefault ().getMainWindow (); + else { + Window w = preferredParent; + if( null == w ) { + w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow (); + if (!(w instanceof NbPresenter) || !w.isVisible()) { + // undocked window is not instanceof NbPresenter although it's NetBeans's native window + // all docked windows implements ModeUIBase interface + if (! (w instanceof DefaultSeparateContainer.ModeUIBase)) { + Container cont = SwingUtilities.getAncestorOfClass(Window.class, w); + if (cont instanceof DefaultSeparateContainer.ModeUIBase) { + w = (Window) cont; + } else { + // don't set non-ide window as parent + w = WindowManager.getDefault ().getMainWindow (); + } } + } else if (w instanceof NbPresenter && ((NbPresenter) w).isLeaf ()) { + w = WindowManager.getDefault ().getMainWindow (); } } + NbDialog dlg; + if (w instanceof Dialog) { + dlg = new NbDialog(d, (Dialog) w); + } else { + Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault ().getMainWindow (); + dlg = new NbDialog(d, f); + } + customizeDlg(dlg); + dlg.requestFocusInWindow (); + return dlg; } - NbDialog dlg = new NbDialog(d, w); - customizeDlg(dlg); - dlg.requestFocusInWindow (); - return dlg; } }); } - private Window findDialogParent() { - Component parentComponent = Utilities.findDialogParent(null); - if (parentComponent instanceof Window) { - return (Window) parentComponent; - } - Window parent = null; - if (parentComponent != null) { - parent = SwingUtilities.windowForComponent(parentComponent); - } - if (parent == null || parent instanceof NbPresenter && ((NbPresenter) parent).isLeaf ()) { - return WindowManager.getDefault().getMainWindow(); - } - return parent; - } - /** Notifies user by a dialog. * @param descriptor description that contains needed informations * @return the option that has been choosen in the notification. @@ -223,13 +222,43 @@ public class DialogDisplayerImpl extends DialogDisplayer { while ((win != null) && (!(win instanceof Window))) win = win.getParent (); if (win != null) focusOwner = ((Window)win).getFocusOwner (); - NbPresenter presenter; - Window parent = noParent ? null : findDialogParent(); + // if a modal dialog is active use it as parent + // otherwise use the main window + NbPresenter presenter; if (descriptor instanceof DialogDescriptor) { - presenter = new NbDialog((DialogDescriptor) descriptor, parent); + if (NbPresenter.currentModalDialog != null) { + if (NbPresenter.currentModalDialog.isLeaf ()) { + presenter = new NbDialog((DialogDescriptor) descriptor, WindowManager.getDefault ().getMainWindow ()); + } else { + presenter = new NbDialog((DialogDescriptor) descriptor, NbPresenter.currentModalDialog); + } + } else { + Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow (); + if (w instanceof NbPresenter && ((NbPresenter) w).isLeaf ()) { + w = WindowManager.getDefault ().getMainWindow (); + } + Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow(); + if (noParent) { + f = null; + } + presenter = new NbDialog((DialogDescriptor) descriptor, f); + } } else { - presenter = new NbPresenter(descriptor, parent, Dialog.DEFAULT_MODALITY_TYPE); + if (NbPresenter.currentModalDialog != null) { + if (NbPresenter.currentModalDialog.isLeaf()) { + presenter = new NbPresenter(descriptor, WindowManager.getDefault().getMainWindow(), true); + } else { + presenter = new NbPresenter(descriptor, NbPresenter.currentModalDialog, true); + } + } else { + Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow (); + Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow(); + if (noParent) { + f = null; + } + presenter = new NbPresenter(descriptor, f, true); + } } synchronized (this) { diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java b/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java index 8b884d7eb5..b4c0eb45b2 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/NbDialog.java @@ -50,15 +50,7 @@ final class NbDialog extends NbPresenter { super (d, owner, d.isModal ()); } - /** Creates a new Dialog from specified DialogDescriptor - * @param d The DialogDescriptor to create the dialog from - * @param owner Owner of this dialog. - */ - public NbDialog(DialogDescriptor d, Window owner) { - super(d, owner, d.isModal() ? Dialog.DEFAULT_MODALITY_TYPE : ModalityType.MODELESS); - } - - /** Getter for help. + /** Geter for help. */ @Override protected HelpCtx getHelpCtx () { diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java b/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java index aeb1eb7393..2c599104d2 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/NbPresenter.java @@ -26,6 +26,7 @@ import java.awt.Container; import java.awt.DefaultKeyboardFocusManager; import java.awt.Dialog; import java.awt.Dimension; +import java.awt.EventQueue; import java.awt.FlowLayout; import java.awt.Frame; import java.awt.GraphicsDevice; @@ -88,6 +89,7 @@ import org.openide.NotificationLineSupport; import org.openide.NotifyDescriptor; import org.openide.WizardDescriptor; import org.openide.awt.Mnemonics; +import org.openide.util.ChangeSupport; import org.openide.util.HelpCtx; import org.openide.util.ImageUtilities; import org.openide.util.Mutex; @@ -104,6 +106,9 @@ import org.openide.util.Utilities; class NbPresenter extends JDialog implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparator<Object> { + /** variable holding current modal dialog in the system */ + public static NbPresenter currentModalDialog; + private static final ChangeSupport cs = new ChangeSupport(NbPresenter.class); private static Boolean isJava17 = null; protected NotifyDescriptor descriptor; @@ -184,21 +189,6 @@ implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparato initialize(d); } - /** - * Creates a new Dialog from the specified NotifyDescriptor and owner. - * - * @param d the non-null descriptor from which to initialize the dialog - * @param owner the owner of the dialog, must be a {@code Dialog} or - * {@code Frame} instance or {@code null} (not recommended) - * @param modality specifies whether dialog blocks input to other windows - * when shown. {@code null} value and unsupported modality types are - * equivalent to {@code MODELESS} - */ - public NbPresenter(NotifyDescriptor d, Window owner, ModalityType modality) { - super(owner, d.getTitle(), modality); - initialize(d); - } - boolean isLeaf () { return leaf; } @@ -1102,7 +1092,6 @@ implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparato } } - @Override public Void run() { doShow(); return null; @@ -1119,21 +1108,30 @@ implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparato gd.setFullScreenWindow( null ); } } + NbPresenter prev = null; try { MenuSelectionManager.defaultManager().clearSelectedPath(); } catch( NullPointerException npE ) { //#216184 LOG.log( Level.FINE, null, npE ); } + if (isModal()) { + prev = currentModalDialog; + currentModalDialog = this; + fireChangeEvent(); + } superShow(); - if( null != fullScreenWindow ) { + if( null != fullScreenWindow ) getGraphicsConfiguration().getDevice().setFullScreenWindow( fullScreenWindow ); + + if (currentModalDialog != prev) { + currentModalDialog = prev; + fireChangeEvent(); } } - @Override public void propertyChange(final java.beans.PropertyChangeEvent evt) { if( !SwingUtilities.isEventDispatchThread() ) { SwingUtilities.invokeLater(new Runnable() { @@ -1276,13 +1274,19 @@ implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparato public void windowActivated(final java.awt.event.WindowEvent p1) { } - @Deprecated + // Used by JavaHelp: public static void addChangeListener(ChangeListener l) { - // Does nothing + cs.addChangeListener(l); } - @Deprecated public static void removeChangeListener(ChangeListener l) { - // Does nothing + cs.removeChangeListener(l); + } + private static void fireChangeEvent() { + EventQueue.invokeLater(new Runnable() { + public void run() { + cs.fireChange(); + } + }); } private final class EscapeAction extends AbstractAction { diff --git a/platform/core.windows/src/org/netbeans/core/windows/services/NodeOperationImpl.java b/platform/core.windows/src/org/netbeans/core/windows/services/NodeOperationImpl.java index d98c310039..d488b94c02 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/services/NodeOperationImpl.java +++ b/platform/core.windows/src/org/netbeans/core/windows/services/NodeOperationImpl.java @@ -51,7 +51,6 @@ import org.openide.util.HelpCtx; import org.openide.util.Mutex; import org.openide.util.NbBundle; import org.openide.util.UserCancelException; -import org.openide.util.Utilities; import org.openide.util.WeakSet; import org.openide.util.lookup.ServiceProvider; import org.openide.windows.Mode; @@ -351,7 +350,12 @@ public final class NodeOperationImpl extends NodeOperation { // Mutex.EVENT.readAccess (new Runnable () { // PENDING javax.swing.SwingUtilities.invokeLater(new Runnable() { public void run () { - boolean modal = Utilities.isModalDialogOpen(); + boolean modal; + if(NbPresenter.currentModalDialog == null) { + modal = false; + } else { + modal = true; + } Dialog dlg = org.openide.DialogDisplayer.getDefault().createDialog(new DialogDescriptor ( sheet, diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java index e0fd757ad0..9be4e6103c 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/DialogDisplayerImplTest.java @@ -23,7 +23,6 @@ import java.awt.Component; import java.awt.Dialog; import java.awt.EventQueue; import java.awt.Frame; -import java.awt.KeyboardFocusManager; import java.awt.Window; import java.util.concurrent.CancellationException; import java.util.concurrent.CompletableFuture; @@ -82,13 +81,10 @@ public class DialogDisplayerImplTest extends NbTestCase { @Override protected void tearDown() throws Exception { - while (true) { - Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - if (w == null) { - break; - } - w.setVisible(false); - w.dispose(); + if (NbPresenter.currentModalDialog != null) { + NbPresenter.currentModalDialog.setVisible(false); + NbPresenter.currentModalDialog.dispose(); + NbPresenter.currentModalDialog = null; } super.tearDown(); } @@ -351,23 +347,6 @@ public class DialogDisplayerImplTest extends NbTestCase { assertEquals(frame, dlg.getOwner()); } - @RandomlyFails - public void testNestedDialogParent() throws Exception { - Frame f = null; - Dialog owner = new Dialog(f, true); - postInAwtAndWaitOutsideAwt(() -> owner.setVisible(true)); - assertShowing("Owner is invisible", true, owner); - - child = new JButton(); - final NotifyDescriptor nd = new NotifyDescriptor.Message(child); - postInAwtAndWaitOutsideAwt(() -> DialogDisplayer.getDefault().notify(nd)); - - assertShowing("Child is invisible", true, child); - Window w = SwingUtilities.windowForComponent(child); - assertSame("Window parent is not owner", owner, w.getParent()); - postInAwtAndWaitOutsideAwt(() -> owner.setVisible(false)); - } - static void postInAwtAndWaitOutsideAwt (final Runnable run) throws Exception { // pendig to better implementation SwingUtilities.invokeLater (run); @@ -465,7 +444,7 @@ public class DialogDisplayerImplTest extends NbTestCase { thenApply((x) -> x); // wait for the dialog to be displayed - assertTrue(panel.displayed.await(10, TimeUnit.SECONDS)); + panel.displayed.await(10, TimeUnit.SECONDS); cf.cancel(true); diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java deleted file mode 100644 index 50f26c8448..0000000000 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbDialogTest.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.netbeans.core.windows.services; - -import java.awt.Dialog; -import java.awt.GraphicsEnvironment; -import java.awt.Window; -import javax.swing.JLabel; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.netbeans.junit.NbTestCase; -import org.openide.DialogDescriptor; - -public class NbDialogTest extends NbTestCase { - public static Test suite() { - return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(NbDialogTest.class); - } - - public NbDialogTest(String testName) { - super(testName); - } - - @Override - protected boolean runInEQ() { - return true; - } - - public void testModalityIsDefaultWhenModal() { - NbDialog d = new NbDialog(new DialogDescriptor(null, null, true, null), (Window) null); - assertEquals(Dialog.DEFAULT_MODALITY_TYPE, d.getModalityType()); - } - - public void testModalityIsModelessWhenNotModal() { - NbDialog d = new NbDialog(new DialogDescriptor(null, null, false, null), (Window) null); - assertEquals(Dialog.ModalityType.MODELESS, d.getModalityType()); - } -} diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java index 4b020f8c1e..73b88ea3ff 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NbPresenterTest.java @@ -20,7 +20,6 @@ package org.netbeans.core.windows.services; import java.awt.Dialog; -import java.awt.Frame; import java.awt.GraphicsEnvironment; import java.awt.Window; import java.util.Arrays; @@ -32,6 +31,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.openide.DialogDescriptor; import org.netbeans.junit.NbTestCase; +import org.netbeans.junit.RandomlyFails; import org.openide.NotifyDescriptor; import org.openide.util.HelpCtx; @@ -40,8 +40,6 @@ import org.openide.util.HelpCtx; * @author Jiri Rechtacek */ public class NbPresenterTest extends NbTestCase { - private static final String TITLE = "My dialog"; - private static final DialogDescriptor DESCRIPTOR = new DialogDescriptor(new JLabel ("Something interesting"), TITLE); public static Test suite() { return GraphicsEnvironment.isHeadless() ? new TestSuite() : new TestSuite(NbPresenterTest.class); @@ -51,27 +49,10 @@ public class NbPresenterTest extends NbTestCase { super (testName); } - @Override protected boolean runInEQ () { return true; } - public void testOwnerIsWindow() { - Window owner = new Frame(); - NbPresenter p = new NbPresenter(DESCRIPTOR, owner, Dialog.ModalityType.APPLICATION_MODAL); - assertSame(owner, p.getOwner()); - } - - public void testTitleIsFromDescriptor() { - NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL); - assertEquals(TITLE, p.getTitle()); - } - - public void testModalityIsSet() { - NbPresenter p = new NbPresenter(DESCRIPTOR, null, Dialog.ModalityType.APPLICATION_MODAL); - assertEquals(Dialog.ModalityType.APPLICATION_MODAL, p.getModalityType()); - } - public void testDialogsOptionsOnDefaultSystem () { System.setProperty ("xtest.looks_as_mac", "false"); doTestDialogsOptions (); @@ -89,7 +70,7 @@ public class NbPresenterTest extends NbTestCase { JButton rescue = new JButton ("Rescue"); JButton cancel = new JButton ("Cancel"); JButton [] options = new JButton [] {erase, rescue, cancel}; - DialogDescriptor dd = new DialogDescriptor (new JLabel ("Something interesting"), TITLE, modal, + DialogDescriptor dd = new DialogDescriptor (new JLabel ("Something interesting"), "My dialog", modal, // options options, rescue, @@ -142,7 +123,7 @@ public class NbPresenterTest extends NbTestCase { JButton rescue = new JButton ("Rescue"); JButton cancel = new JButton ("Cancel"); JButton [] options = new JButton [] {erase, rescue, cancel}; - DialogDescriptor dd = new DialogDescriptor (new JLabel ("Something interesting"), TITLE, false, + DialogDescriptor dd = new DialogDescriptor (new JLabel ("Something interesting"), "My dialog", false, // options options, rescue, diff --git a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java index dfaafebd51..30871cf802 100644 --- a/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java +++ b/platform/core.windows/test/unit/src/org/netbeans/core/windows/services/NotifyLaterTest.java @@ -116,7 +116,7 @@ public class NotifyLaterTest extends NbTestCase { assertNotNull("There is parent window", root); assertTrue("It is a dialog", root instanceof JDialog); JDialog d = (JDialog)root; - assertNull("d should have no owner", d.getParent()); + assertEquals("The owner of d is the same as owner of dialog without owner", new JDialog().getParent(), d.getParent()); SwingUtilities.invokeAndWait(new Runnable () { public void run() { diff --git a/platform/openide.util.ui/apichanges.xml b/platform/openide.util.ui/apichanges.xml index 4889fdc34f..d2290d01a4 100644 --- a/platform/openide.util.ui/apichanges.xml +++ b/platform/openide.util.ui/apichanges.xml @@ -27,22 +27,6 @@ <apidef name="actions">Actions API</apidef> </apidefs> <changes> - <change id="findDialogParent2"> - <api name="util"/> - <summary>static method Utilities.findDialogParent overloaded and isModalDialogOpen added</summary> - <version major="9" minor="30"/> - <date day="26" month="5" year="2023"/> - <author login="rkeen-siemens"/> - <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="yes"/> - <description> - <p> - Updated <code>findDialogParent</code> to ensure that if a modal dialog is open the returned component is in that dialog - and added an overload that allows providing a fallback component. - Added <code>isModalDialogOpen</code> to determine if there is a modal dialog open. - </p> - </description> - <class package="org.openide.util" name="Utilities"/> - </change> <change id="actionsForPathLookup"> <api name="util"/> <summary>Added variant Utilities.actionsForPath with Lookup that produces context-aware actions</summary> diff --git a/platform/openide.util.ui/src/org/openide/util/Utilities.java b/platform/openide.util.ui/src/org/openide/util/Utilities.java index 5234de2f49..3cd2172894 100644 --- a/platform/openide.util.ui/src/org/openide/util/Utilities.java +++ b/platform/openide.util.ui/src/org/openide/util/Utilities.java @@ -66,12 +66,10 @@ import java.util.Locale; import java.util.Map; import java.util.Map.Entry; import java.util.NoSuchElementException; -import java.util.Optional; import java.util.Set; import java.util.StringTokenizer; import java.util.Vector; import java.util.WeakHashMap; -import java.util.function.Supplier; import java.util.logging.Level; import java.util.logging.Logger; import javax.swing.Action; @@ -1345,68 +1343,31 @@ public final class Utilities { } /** - * Finds an appropriate component to use for a dialog's parent. This is for - * use in situations where a standard swing API, such as - * {@linkplain javax.swing.JOptionPane}.show* or - * {@linkplain javax.swing.JFileChooser}.show*, is used to display a dialog. - * {@code null} should never be used as a dialog's parent because it + * This is for use in situations where a standard swing API, + * such as {@linkplain javax.swing.JOptionPane}.show* or {@linkplain javax.swing.JFileChooser}.show*, + * is used to display a dialog. {@code null} should never be used + * as a dialog's parent because it * frequently does the wrong thing in a multi-screen setup. * <p> * The use of the NetBeans API * <a href="@org-openide-dialogs@/org/openide/DialogDisplayer.html#getDefault--">DialogDisplayer.getDefault*</a> - * is encouraged to display a dialog. - * - * @return A suitable parent component for swing dialogs + * is encouraged to display a dialog, but stuff happens. + * @return A suitable parent component for swing dialog displayers. * @since 9.26 */ // PR4739 public static Component findDialogParent() { - return findDialogParent(null); - } - - /** - * Finds an appropriate component to use for a dialog's parent. Similar to - * {@link #findDialogParent()} with the ability to specify a suggested - * parent component. The suggested parent will be returned if it is - * non-null, and either there is no active modal dialog or it is contained - * within that dialog. - * - * @param suggestedParent the component to return if non-null and valid - * @return the suggested parent if suitable, otherwise another suitable - * parent component for swing dialogs - * @since 9.30 - */ - public static Component findDialogParent(Component suggestedParent) { - Component parent = suggestedParent; - if (parent == null) { - parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); - } - Window active = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); + Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner(); if (parent == null) { - parent = active; - } else if (active instanceof Dialog && ((Dialog) active).isModal()) { - Window suggested = parent instanceof Window ? (Window) parent : SwingUtilities.windowForComponent(parent); - if (suggested != active) { - return active; - } + parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); } if (parent == null) { + // PR#5280 parent = findMainWindow(); } return parent; } - /** - * Check whether a modal dialog is open. - * - * @return true if a modal dialog is open, false otherwise - * @since 9.30 - */ - public static boolean isModalDialogOpen() { - Window active = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); - return active instanceof Dialog && ((Dialog) active).isModal(); - } - /** @return size of the screen. The size is modified for Windows OS * - some points are subtracted to reflect a presence of the taskbar * --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists