-
Notifications
You must be signed in to change notification settings - Fork 914
Improve Dialog Placement #5280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Dialog Placement #5280
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1591,6 +1591,18 @@ private void initBounds() { | |
| */ | ||
| private Window findFocusedWindow() { | ||
| Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow(); | ||
| if( w == null ) { | ||
| // PR#5280 | ||
| LOG.fine( () -> "No focused window, find mainWindow" ); | ||
|
Comment on lines
1593
to
+1596
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If there is no focused window, then try the mainWindow before doing the backup which centers on the JDK's default screen. |
||
| for( Frame f01 : Frame.getFrames() ) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nitpick: call
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@sdedic I'd like to do that; can you give me some guidance? Need to find a non-API file in
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah ;) my bad, I overlooked the module boundary. No suggestion that 'feels' right then. An option would be to add a API/SPI method on e.g. DialogDisplayer. Related to existing 'nearby' code: this method uses
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've wondered about that myself; are the two equivalent? I'm copying your comment to #4887 which are notes for a follow on PR addressing some stuff in |
||
| if( "NbMainWindow".equals(f01.getName())) { //NOI18N | ||
| if(f01.getWidth() != 0 || f01.getHeight() != 0) { | ||
| w = f01; | ||
| } | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| while( null != w && !w.isShowing() ) { | ||
| w = w.getOwner(); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1157,11 +1157,9 @@ private static GraphicsConfiguration getCurrentGraphicsConfiguration() { | |
| 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 @@ private static Rectangle findCenterBounds(GraphicsConfiguration gconf, Dimension | |
| ); | ||
| } | ||
|
|
||
| /** | ||
| * 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 | ||
eirikbakke marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| 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 static Component findDialogParent() { | |
| parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow(); | ||
| } | ||
| if (parent == null) { | ||
| Frame[] f = Frame.getFrames(); | ||
| parent = f.length == 0 ? null : f[f.length - 1]; | ||
| // PR#5280 | ||
| parent = findMainWindow(); | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a change suggested by @matthiasblaesing in #4739 (comment). The change was deferred pending concrete examples. There is an example detailed in the opening comment for this PR.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @errael I would possibly fall back to the original behaviour if the search for the main window returns null. Ideally it wouldn't use the name to find the right window, but that might be the easiest way to achieve. I have no idea how many people (if any!) use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
The original behavior is severely flawed. Take a look in the comment that opened this PR, under notes on Utilities.findDialogParent. And from the javadoc for Frame.getFrames()
Notice that this technique is already in use in this file. May have to do with dependencies. This PR encapsulates its use in a method so at least it's not buried.
If someone explicitly wants random dialog placement there are probably more interesting ways. I believe this case rarely comes up AFAIK, I've just been lucky. A null owner is probably more consistent (better?). If this is a strong concern for (Aside: I've wondered about use of non standard window system; are there any known examples in "production"? )
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @errael yes, I read the doc. Let's stick with what you have and see if any complaints come out of the woodwork! |
||
| } | ||
| return parent; | ||
| } | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is a cosmetic change. It's both more clear and allows easier comparison to what's going on in the
case