Class ConditionalOptionPaneUtil
- java.lang.Object
-
- org.openstreetmap.josm.gui.ConditionalOptionPaneUtil
-
public final class ConditionalOptionPaneUtil extends java.lang.Object
ConditionalOptionPaneUtil provides static utility methods for displaying modal message dialogs which can be enabled/disabled by the user.They wrap the methods provided by
JOptionPane
. Within JOSM you should use these methods rather than the bare methods fromJOptionPane
because the methods provided by ConditionalOptionPaneUtil ensure that a dialog window is always on top and isn't hidden by one of the JOSM windows for detached dialogs, relation editors, history browser and the like.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ConditionalOptionPaneUtil.MessagePanel
This is a message panel used in dialogs which can be enabled/disabled with a preference setting.(package private) static class
ConditionalOptionPaneUtil.NotShowAgain
An enum designating how long to not show this message again, i.e., for how long to store
-
Field Summary
Fields Modifier and Type Field Description private static java.lang.String
CONFIG_PREFIX
The prefix for config optionsstatic int
DIALOG_DISABLED_OPTION
private static java.util.Set<java.lang.String>
immediateActive
a set indication that (preference key) is or may be stored for the currently active bulk operationprivate static java.util.Map<java.lang.String,java.lang.Integer>
immediateChoices
(preference key => return value) mappings valid for the current sessionprivate static java.util.Map<java.lang.String,java.lang.Integer>
sessionChoices
(preference key => return value) mappings valid for the current operation (no, those two maps cannot be combined)
-
Constructor Summary
Constructors Modifier Constructor Description private
ConditionalOptionPaneUtil()
this is a static utility class only
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
endBulkOperation(java.lang.String prefKey)
Marks the ending of a bulk operation.static int
getDialogReturnValue(java.lang.String prefKey)
Returns the preference value for the preference key "message." +prefKey
+ ".value".static boolean
isInBulkOperation(java.lang.String prefKey)
Determines whether the key has been marked to be part of a bulk operation (in order to provide a "Do not show again (this operation)" option).private static boolean
isYesOrNo(int returnCode)
static boolean
showConfirmationDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType, int trueOption)
Displays a confirmation dialog with some option buttons given byoptionType
.static void
showMessageDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int messageType)
Displays an message in modal dialog with an OK button.static int
showOptionDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType, java.lang.Object[] options, java.lang.Object defaultOption)
Displays an confirmation dialog with some option buttons given byoptionType
.static void
startBulkOperation(java.lang.String prefKey)
Marks the beginning of a bulk operation in order to provide a "Do not show again (this operation)" option.
-
-
-
Field Detail
-
DIALOG_DISABLED_OPTION
public static final int DIALOG_DISABLED_OPTION
- See Also:
- Constant Field Values
-
sessionChoices
private static final java.util.Map<java.lang.String,java.lang.Integer> sessionChoices
(preference key => return value) mappings valid for the current operation (no, those two maps cannot be combined)
-
immediateChoices
private static final java.util.Map<java.lang.String,java.lang.Integer> immediateChoices
(preference key => return value) mappings valid for the current session
-
immediateActive
private static final java.util.Set<java.lang.String> immediateActive
a set indication that (preference key) is or may be stored for the currently active bulk operation
-
CONFIG_PREFIX
private static final java.lang.String CONFIG_PREFIX
The prefix for config options- See Also:
- Constant Field Values
-
-
Constructor Detail
-
ConditionalOptionPaneUtil
private ConditionalOptionPaneUtil()
this is a static utility class only
-
-
Method Detail
-
getDialogReturnValue
public static int getDialogReturnValue(java.lang.String prefKey)
Returns the preference value for the preference key "message." +prefKey
+ ".value". The default value if the preference key is missing is -1.- Parameters:
prefKey
- the preference key- Returns:
- the preference value for the preference key "message." +
prefKey
+ ".value"
-
startBulkOperation
public static void startBulkOperation(java.lang.String prefKey)
Marks the beginning of a bulk operation in order to provide a "Do not show again (this operation)" option.- Parameters:
prefKey
- the preference key
-
isInBulkOperation
public static boolean isInBulkOperation(java.lang.String prefKey)
Determines whether the key has been marked to be part of a bulk operation (in order to provide a "Do not show again (this operation)" option).- Parameters:
prefKey
- the preference key- Returns:
true
if the key has been marked to be part of a bulk operation
-
endBulkOperation
public static void endBulkOperation(java.lang.String prefKey)
Marks the ending of a bulk operation. Removes the "Do not show again (this operation)" result value.- Parameters:
prefKey
- the preference key
-
showOptionDialog
public static int showOptionDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType, java.lang.Object[] options, java.lang.Object defaultOption)
Displays an confirmation dialog with some option buttons given byoptionType
. It is always on top even if there are other open windows like detached dialogs, relation editors, history browsers and the like.Set
optionType
toJOptionPane.YES_NO_OPTION
for a dialog with a YES and a NO button.Set
optionType
toJOptionPane.YES_NO_CANCEL_OPTION
for a dialog with a YES, a NO and a CANCEL buttonReturns 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.
- Parameters:
preferenceKey
- the preference keyparent
- the parent componentmessage
- the messagetitle
- the titleoptionType
- the option typemessageType
- the message typeoptions
- a list of optionsdefaultOption
- the default option; only meaningful if options is used; can be null- Returns:
- the option selected by user.
JOptionPane.CLOSED_OPTION
if the dialog was closed.
-
showConfirmationDialog
public static boolean showConfirmationDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int optionType, int messageType, int trueOption)
Displays a confirmation dialog with some option buttons given byoptionType
. It is always on top even if there are other open windows like detached dialogs, relation editors, history browsers and the like.Set
optionType
toJOptionPane.YES_NO_OPTION
for a dialog with a YES and a NO button.Set
optionType
toJOptionPane.YES_NO_CANCEL_OPTION
for a dialog with a YES, a NO and a CANCEL buttonReplies true, if the selected option is equal to
trueOption
, otherwise false. Replies true, if the dialog is not displayed because the respective preference optionpreferenceKey
is set to false and the user has previously chosentrueOption
.- Parameters:
preferenceKey
- the preference keyparent
- the parent componentmessage
- the messagetitle
- the titleoptionType
- the option typemessageType
- the message typetrueOption
- if this option is selected the method replies true- Returns:
- true, if the selected option is equal to
trueOption
, otherwise false. - See Also:
JOptionPane.INFORMATION_MESSAGE
,JOptionPane.WARNING_MESSAGE
,JOptionPane.ERROR_MESSAGE
-
isYesOrNo
private static boolean isYesOrNo(int returnCode)
-
showMessageDialog
public static void showMessageDialog(java.lang.String preferenceKey, java.awt.Component parent, java.lang.Object message, java.lang.String title, int messageType)
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 valuefalse
the dialog is not show.- Parameters:
preferenceKey
- the preference keyparent
- the parent componentmessage
- the messagetitle
- the titlemessageType
- the message type- See Also:
JOptionPane.INFORMATION_MESSAGE
,JOptionPane.WARNING_MESSAGE
,JOptionPane.ERROR_MESSAGE
-
-