org.openstreetmap.josm.gui
Class ConditionalOptionPaneUtil

java.lang.Object
  extended by org.openstreetmap.josm.gui.ConditionalOptionPaneUtil

public 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 from JOptionPane 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
private static class ConditionalOptionPaneUtil.MessagePanel
          This is a message panel used in dialogs which can be enabled/disabled with a preference setting.
 
Field Summary
static int DIALOG_DISABLED_OPTION
           
 
Constructor Summary
private ConditionalOptionPaneUtil()
          this is a static utility class only
 
Method Summary
static java.lang.Integer getDialogReturnValue(java.lang.String prefKey)
          Returns the preference value for the preference key "message." + prefKey + ".value".
static boolean getDialogShowingEnabled(java.lang.String prefKey)
          Replies the preference value for the preference key "message." + prefKey.
static void setDialogReturnValue(java.lang.String prefKey, java.lang.Integer value)
          sets the value for the preference key "message." + prefKey + ".value".
static void setDialogShowingEnabled(java.lang.String prefKey, boolean enabled)
          sets the value for the preference key "message." + prefKey.
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 by optionType.
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 by optionType.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DIALOG_DISABLED_OPTION

public static final int DIALOG_DISABLED_OPTION
See Also:
Constant Field Values
Constructor Detail

ConditionalOptionPaneUtil

private ConditionalOptionPaneUtil()
this is a static utility class only

Method Detail

getDialogShowingEnabled

public static boolean getDialogShowingEnabled(java.lang.String prefKey)
Replies the preference value for the preference key "message." + prefKey. The default value if the preference key is missing is true.

Parameters:
the - preference key
Returns:
prefKey the preference value for the preference key "message." + prefKey

setDialogShowingEnabled

public static void setDialogShowingEnabled(java.lang.String prefKey,
                                           boolean enabled)
sets the value for the preference key "message." + prefKey.

Parameters:
prefKey - the key
enabled - the value

getDialogReturnValue

public static java.lang.Integer 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:
the - preference key
Returns:
prefKey the preference value for the preference key "message." + prefKey + ".value"

setDialogReturnValue

public static void setDialogReturnValue(java.lang.String prefKey,
                                        java.lang.Integer value)
sets the value for the preference key "message." + prefKey + ".value".

Parameters:
prefKey - the key
value - the value

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)
                            throws java.awt.HeadlessException
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 JOptionPane.YES_NO_OPTION for a dialog with a YES and a NO button. Set optionType to 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.

Parameters:
preferenceKey - the preference key
parent - the parent component
message - the message
title - the title
optionType - the option type
messageType - the message type
options - a list of options
defaultOption - the default option
Returns:
the option selected by user. JOptionPane.CLOSED_OPTION if the dialog was closed.
Throws:
java.awt.HeadlessException

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)
                                      throws java.awt.HeadlessException
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 JOptionPane.YES_NO_OPTION for a dialog with a YES and a NO button. Set optionType to 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 trueOption.

Parameters:
preferenceKey - the preference key
parent - the parent component
message - the message
title - the title
optionType - the option type
messageType - the message type
trueOption - if this option is selected the method replies true
Returns:
true, if the selected option is equal to trueOption, otherwise false.
Throws:
java.awt.HeadlessException
See Also:
JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.ERROR_MESSAGE

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 value false the dialog is not show.

Parameters:
preferenceKey - the preference key
parent - the parent component
message - the message
title - the title
messageType - the message type
See Also:
JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.ERROR_MESSAGE


JOSM