You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@netbeans.apache.org by ma...@apache.org on 2023/02/06 20:15:13 UTC

[netbeans] branch master updated: When placing a dialog through NetBeans' API, if no focused component is found then use NbMainWindow. Change fallback for Utilities.findDialogParent to use NbMainWindow.

This is an automated email from the ASF dual-hosted git repository.

matthiasblaesing pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/netbeans.git


The following commit(s) were added to refs/heads/master by this push:
     new 9164e39505 When placing a dialog through NetBeans' API, if no focused component is found then use NbMainWindow. Change fallback for Utilities.findDialogParent to use NbMainWindow.
     new 23882eec46 Merge pull request #5280 from errael/ImproveDialogPlacement
9164e39505 is described below

commit 9164e3950559c361f69b4cf95317748a1bb363a5
Author: Ernie Rael <er...@raelity.com>
AuthorDate: Wed Jan 11 14:40:55 2023 -0800

    When placing a dialog through NetBeans' API,
    if no focused component is found then use NbMainWindow.
    Change fallback for Utilities.findDialogParent to use NbMainWindow.
---
 .../core/windows/services/DialogDisplayerImpl.java |  9 +++----
 .../core/windows/services/NbPresenter.java         | 12 +++++++++
 .../src/org/openide/util/Utilities.java            | 31 +++++++++++++++++-----
 3 files changed, 39 insertions(+), 13 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 63f5fdcadb..8cbcb8227e 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
@@ -225,7 +225,7 @@ public class DialogDisplayerImpl extends DialogDisplayer {
             // if a modal dialog is active use it as parent
             // otherwise use the main window
 
-            NbPresenter presenter = null;
+            NbPresenter presenter;
             if (descriptor instanceof DialogDescriptor) {
                 if (NbPresenter.currentModalDialog != null) {
                     if (NbPresenter.currentModalDialog.isLeaf ()) {
@@ -252,11 +252,8 @@ public class DialogDisplayerImpl extends DialogDisplayer {
                         presenter = new NbPresenter(descriptor, NbPresenter.currentModalDialog, true);
                     }
                 } else {
-                    Frame f = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() 
-                        instanceof Frame ? 
-                        (Frame) KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow() 
-                        : WindowManager.getDefault().getMainWindow();
-
+                    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager ().getActiveWindow ();
+                    Frame f = w instanceof Frame ? (Frame) w : WindowManager.getDefault().getMainWindow();
                     if (noParent) {
                         f = null;
                     }
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 1e1ea8a0b2..18fdc69006 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
@@ -1591,6 +1591,18 @@ implements PropertyChangeListener, WindowListener, Mutex.Action<Void>, Comparato
      */
     private Window findFocusedWindow() {
         Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
+        if( w == null ) {
+            // PR#5280
+            LOG.fine( () -> "No focused window, find mainWindow" );
+            for( Frame f01 : Frame.getFrames() ) {
+                if( "NbMainWindow".equals(f01.getName())) { //NOI18N
+                    if(f01.getWidth() != 0 || f01.getHeight() != 0) {
+                        w = f01;
+                    }
+                    break;
+                }
+            }
+        }
         while( null != w && !w.isShowing() ) {
             w = w.getOwner();
         }
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 ba5d85eb3e..4c632f5d7c 100644
--- a/platform/openide.util.ui/src/org/openide/util/Utilities.java
+++ b/platform/openide.util.ui/src/org/openide/util/Utilities.java
@@ -1157,11 +1157,9 @@ public final class Utilities {
                 return w.getGraphicsConfiguration();
             } else {
                 //#217737 - try to find the main window which could be placed in secondary screen
-                for( Frame f : Frame.getFrames() ) {
-                    if( "NbMainWindow".equals(f.getName())) { //NOI18N
-                        return f.getGraphicsConfiguration();
-                    }
-                }
+                Frame f = findMainWindow();
+                if(f != null)
+                    return f.getGraphicsConfiguration();
             }
         }
 
@@ -1325,6 +1323,25 @@ public final class Utilities {
         );
     }
 
+    /**
+     * Find the main NetBeans window; must have width or height.
+     * This is used locally to avoid dependency issues. 
+     * @return NetBeans' main window
+     */
+    private static Frame findMainWindow()
+    {
+        Frame f = null;
+        for( Frame f01 : Frame.getFrames() ) {
+            if( "NbMainWindow".equals(f01.getName())) { //NOI18N
+                if(f01.getWidth() != 0 || f01.getHeight() != 0) {
+                    f = f01;
+                }
+                break;
+            }
+        }
+        return f;
+    }
+
     /**
      * This is for use in situations where a standard swing API,
      * such as {@linkplain JOptionPane.show*} or {@linkplain JFileChooser.show*},
@@ -1345,8 +1362,8 @@ public final class Utilities {
             parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
         }
         if (parent == null) {
-            Frame[] f = Frame.getFrames();
-            parent = f.length == 0 ? null : f[f.length - 1];
+            // PR#5280
+            parent = findMainWindow();
         }
         return parent;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@netbeans.apache.org
For additional commands, e-mail: commits-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists