Class ConditionalOptionPaneUtil


  • public final class ConditionalOptionPaneUtil
    extends 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.
    • Method Detail

      • getDialogReturnValue

        public static int getDialogReturnValue​(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​(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​(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​(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​(String preferenceKey,
                                           Component parent,
                                           Object message,
                                           String title,
                                           int optionType,
                                           int messageType,
                                           Object[] options,
                                           Object defaultOption)
        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; 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​(String preferenceKey,
                                                     Component parent,
                                                     Object message,
                                                     String title,
                                                     int optionType,
                                                     int messageType,
                                                     int trueOption)
        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.
        See Also:
        JOptionPane.INFORMATION_MESSAGE, JOptionPane.WARNING_MESSAGE, JOptionPane.ERROR_MESSAGE
      • isYesOrNo

        private static boolean isYesOrNo​(int returnCode)
      • showMessageDialog

        public static void showMessageDialog​(String preferenceKey,
                                             Component parent,
                                             Object message,
                                             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