Skip to content

Commit

Permalink
Merge pull request #4923 from gcoopercos/fixJDialogOwner
Browse files Browse the repository at this point in the history
Allow jdialog to be a parent rather than just jframe
  • Loading branch information
neoancient authored Nov 28, 2023
2 parents 38d98e2 + 6be6f80 commit a42c675
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,15 @@ protected AbstractButtonDialog(final JFrame frame, final boolean modal, final Re
super(frame, modal, resources, name, title);
setResult(DialogResult.CANCELLED); // Default result is cancelled
}

/**
* This constructor is provided for uses cases where this dialog needs another dialog as a parent.
*/
protected AbstractButtonDialog(final JDialog dialog, final JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(dialog, frame, modal, resources, name, title);
setResult(DialogResult.CANCELLED); // Default result is cancelled
}
//endregion Constructors

//region Getters/Setters
Expand Down
23 changes: 23 additions & 0 deletions megamek/src/megamek/client/ui/baseComponents/AbstractDialog.java
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,29 @@ protected AbstractDialog(final JFrame frame, final boolean modal, final Resource
setFrame(frame);
this.resources = resources;
}

/**
* This allows Swing to create the dialog with another dialog as the parent. Which dialog swing renders on top
* is somewhat undefined, depending on the window manager. This can cause problems in the case of modal dialogs
* that show up behind other dialogs and you cannot get to them.
*
* @param dialog Owning dialog, for dialogs on dialogs
* @param frame Owning frame
* @param modal if this dialog is modal
* @param resources the resource bundle for this dialog
* @param name the dialog's name
* @param title the dialog's title resource key. This is required for accessibility reasons, and
* the method will error out if it isn't valid.
*/
protected AbstractDialog(final JDialog dialog, JFrame frame, final boolean modal, final ResourceBundle resources,
final String name, final String title) {
super(dialog, modal);
setTitle(resources.getString(title));
setName(name);
setFrame(frame);
this.resources = resources;
}

//endregion Constructors

//region Getters/Setters
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,16 @@ protected AbstractValidationButtonDialog(final JFrame frame, final boolean modal
super(frame, modal, resources, name, title);
setState(ValidationState.PENDING);
}

/**
* Allows a dialog to be passed in as the owner
*/
protected AbstractValidationButtonDialog(final JDialog owner, final JFrame frame, final boolean modal,
final ResourceBundle resources, final String name,
final String title) {
super(owner, frame, modal, resources, name, title);
setState(ValidationState.PENDING);
}
//endregion Constructors

//region Getters/Setters
Expand Down

0 comments on commit a42c675

Please sign in to comment.