diff --git a/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java b/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java index a23487ae8ba..e481c35060e 100644 --- a/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java +++ b/src/org/openstreetmap/josm/gui/ConditionalOptionPaneUtil.java @@ -4,6 +4,7 @@ import static org.openstreetmap.josm.tools.I18n.tr; import java.awt.Component; +import java.awt.Dialog; import java.awt.GridBagLayout; import java.util.HashMap; import java.util.HashSet; @@ -14,6 +15,8 @@ import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JRadioButton; +import javax.swing.event.AncestorEvent; +import javax.swing.event.AncestorListener; import org.openstreetmap.josm.gui.widgets.JMultilineLabel; import org.openstreetmap.josm.spi.preferences.Config; @@ -23,7 +26,7 @@ /** * ConditionalOptionPaneUtil provides static utility methods for displaying modal message dialogs * which can be enabled/disabled by the user. - * + *
* They wrap the methods provided by {@link JOptionPane}. Within JOSM you should use these
* methods rather than the bare methods from {@link JOptionPane} because the methods provided
* by ConditionalOptionPaneUtil ensure that a dialog window is always on top and isn't hidden by one of the
@@ -92,13 +95,13 @@ public static void endBulkOperation(final String prefKey) {
* Displays an confirmation dialog with some option buttons given by optionType
.
* It is always on top even if there are other open windows like detached dialogs,
* relation editors, history browsers and the like.
- *
+ *
* Set optionType
to {@link JOptionPane#YES_NO_OPTION} for a dialog with a YES and
* a NO button.
-
+ *
* Set optionType
to {@link JOptionPane#YES_NO_CANCEL_OPTION} for a dialog with a YES,
* a NO and a CANCEL button
- *
+ *
* Returns one of the constants JOptionPane.YES_OPTION, JOptionPane.NO_OPTION,
* JOptionPane.CANCEL_OPTION or JOptionPane.CLOSED_OPTION depending on the action chosen by
* the user.
@@ -132,13 +135,13 @@ public static int showOptionDialog(String preferenceKey, Component parent, Objec
* Displays a confirmation dialog with some option buttons given by optionType
.
* It is always on top even if there are other open windows like detached dialogs,
* relation editors, history browsers and the like.
- *
+ *
* Set optionType
to {@link JOptionPane#YES_NO_OPTION} for a dialog with a YES and
* a NO button.
-
+ *
* Set optionType
to {@link JOptionPane#YES_NO_CANCEL_OPTION} for a dialog with a YES,
* a NO and a CANCEL button
- *
+ *
* Replies true, if the selected option is equal to trueOption
, otherwise false.
* Replies true, if the dialog is not displayed because the respective preference option
* preferenceKey
is set to false and the user has previously chosen
@@ -180,7 +183,7 @@ private static boolean isYesOrNo(int returnCode) {
* Displays an message in modal dialog with an OK button. Makes sure the dialog
* is always on top even if there are other open windows like detached dialogs,
* relation editors, history browsers and the like.
- *
+ *
* If there is a preference with key preferenceKey
and value false
* the dialog is not show.
*
@@ -283,6 +286,35 @@ public static class MessagePanel extends JPanel {
add(cbShowImmediateDialog, GBC.eol());
}
add(cbStandard, GBC.eol());
+
+ this.addAncestorListener(new AncestorListener() {
+ boolean wasAlwaysOnTop;
+ @Override
+ public void ancestorAdded(AncestorEvent event) {
+ if (event.getAncestor() instanceof Dialog) {
+ Dialog dialog = (Dialog) event.getAncestor();
+ wasAlwaysOnTop = dialog.isAlwaysOnTop();
+ if (dialog.isVisible() && dialog.isModal()) {
+ dialog.setAlwaysOnTop(true);
+ }
+ }
+ }
+
+ @Override
+ public void ancestorRemoved(AncestorEvent event) {
+ if (event.getAncestor() instanceof Dialog) {
+ Dialog dialog = (Dialog) event.getAncestor();
+ if (dialog.isVisible() && dialog.isModal()) {
+ dialog.setAlwaysOnTop(wasAlwaysOnTop);
+ }
+ }
+ }
+
+ @Override
+ public void ancestorMoved(AncestorEvent event) {
+ // Do nothing
+ }
+ });
}
NotShowAgain getNotShowAgain() {
diff --git a/src/org/openstreetmap/josm/gui/ExtendedDialog.java b/src/org/openstreetmap/josm/gui/ExtendedDialog.java
index bfb689f87c6..eb10cdba473 100644
--- a/src/org/openstreetmap/josm/gui/ExtendedDialog.java
+++ b/src/org/openstreetmap/josm/gui/ExtendedDialog.java
@@ -459,6 +459,9 @@ public void setVisible(boolean visible) {
rememberWindowGeometry(new WindowGeometry(this));
}
}
+ if (visible && isModal()) {
+ this.setAlwaysOnTop(true);
+ }
super.setVisible(visible);
if (!visible && disposeOnClose) {
diff --git a/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java b/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
index cc29b0aabed..92ca48c1016 100644
--- a/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
+++ b/src/org/openstreetmap/josm/gui/HelpAwareOptionPane.java
@@ -218,11 +218,11 @@ public void actionPerformed(ActionEvent e) {
* the dialog includes a "Help" button and launches the help browser if the user presses F1. If the
* user clicks on the "Help" button the option dialog remains open and JOSM launches the help
* browser.
- *
+ *
* helpTopic
is the trailing part of a JOSM online help URL, i.e. the part after the leading
- * https://josm.openstreetmap.de/wiki/Help
. It should start with a leading '/' and it
+ * {@code https://josm.openstreetmap.de/wiki/Help}. It should start with a leading '/' and it
* may include an anchor after a '#'.
- *
+ *
* Examples *
* It can be used, when you need to show a message dialog from a worker thread, * e.g. from {@code PleaseWaitRunnable}. *