From 6be6f80ece3d0a756aa5ec4ff50041b1b0068488 Mon Sep 17 00:00:00 2001 From: Greg Cooper Date: Sat, 25 Nov 2023 12:03:25 -0700 Subject: [PATCH] Allow jdialog to be a parent rather than just jframe --- .../baseComponents/AbstractButtonDialog.java | 9 ++++++++ .../ui/baseComponents/AbstractDialog.java | 23 +++++++++++++++++++ .../AbstractValidationButtonDialog.java | 10 ++++++++ 3 files changed, 42 insertions(+) diff --git a/megamek/src/megamek/client/ui/baseComponents/AbstractButtonDialog.java b/megamek/src/megamek/client/ui/baseComponents/AbstractButtonDialog.java index 6320292bf2a..0970e62ee78 100644 --- a/megamek/src/megamek/client/ui/baseComponents/AbstractButtonDialog.java +++ b/megamek/src/megamek/client/ui/baseComponents/AbstractButtonDialog.java @@ -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 diff --git a/megamek/src/megamek/client/ui/baseComponents/AbstractDialog.java b/megamek/src/megamek/client/ui/baseComponents/AbstractDialog.java index a68b94b0820..35024cfb382 100644 --- a/megamek/src/megamek/client/ui/baseComponents/AbstractDialog.java +++ b/megamek/src/megamek/client/ui/baseComponents/AbstractDialog.java @@ -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 diff --git a/megamek/src/megamek/client/ui/baseComponents/AbstractValidationButtonDialog.java b/megamek/src/megamek/client/ui/baseComponents/AbstractValidationButtonDialog.java index 66cbf07597e..c1393c910f7 100644 --- a/megamek/src/megamek/client/ui/baseComponents/AbstractValidationButtonDialog.java +++ b/megamek/src/megamek/client/ui/baseComponents/AbstractValidationButtonDialog.java @@ -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