Class CommonDialogs


  • public class CommonDialogs
    extends java.lang.Object
    Provides convenience methods for displaying common dialogs.
    • Constructor Summary

      Constructors 
      Constructor Description
      CommonDialogs()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean getConfirmation​(java.awt.Component parentComponent, java.lang.String message, java.lang.String title)
      Shows a confirmation dialog where the users selects "Yes" or "No".
      static boolean getConfirmation​(java.lang.String message)
      Shows a confirmation dialog where the users selects "Yes" or "No".
      static boolean getConfirmation​(java.lang.String message, java.lang.String title)
      Shows a confirmation dialog where the users selects "Yes" or "No".
      static java.io.File getDirectory​(java.io.File initialDirectory, java.lang.String title)
      Shows a dialog allowing the user to select a directory.
      static java.io.File getDirectory​(java.lang.String initialDirectory, java.lang.String title)
      Shows a dialog allowing the user to select a directory.
      static java.lang.String getInput​(java.lang.String message)
      Shows a dialog allowing the user to input some text.
      static java.lang.String getInput​(java.lang.String message, java.lang.String defaultValue)
      Shows a dialog allowing the user to input some text.
      static java.lang.String getSelection​(java.lang.String message, java.util.List<java.lang.String> choices)
      Shows a dialog with a drop down, allowing the user to select one of several values.
      static java.lang.String getSelection​(java.lang.String message, java.util.List<java.lang.String> choices, java.lang.String defaultValue)
      Shows a dialog with a drop down, allowing the user to select one of several values.
      static java.lang.String getSelection​(java.lang.String message, java.util.List<java.lang.String> choices, java.lang.String defaultValue, java.lang.String title)
      Shows a dialog with a drop down, allowing the user to select one of several values.
      static java.io.File openFileDialog​(java.io.File initialDirectory, java.lang.String title)
      Shows a dialog allowing the user to select a file to open.
      static java.io.File openFileDialog​(java.io.File initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select a file to open.
      static java.io.File openFileDialog​(java.lang.String initialDirectory, java.lang.String title)
      Shows a dialog allowing the user to select a file to open.
      static java.io.File openFileDialog​(java.lang.String initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select a file to open.
      static java.io.File[] openMultipleFilesDialog​(java.io.File initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select one or more files to open.
      static java.io.File[] openMultipleFilesDialog​(java.lang.String initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select one or more files to open.
      static java.io.File saveFileDialog​(java.io.File initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select a file to save.
      static java.io.File saveFileDialog​(java.lang.String initialDirectory, java.lang.String fileTypeName, java.lang.String fileExtension, java.lang.String title)
      Shows a dialog allowing the user to select a file to save.
      static java.io.File[] selectDirectories​(java.io.File initialDirectory, java.lang.String title)  
      static java.io.File[] selectDirectories​(java.lang.String initialDirectory, java.lang.String title)  
      static java.io.File[] selectFilesDialog​(java.io.File initialDirectory, java.lang.String title)  
      static java.io.File[] selectFilesDialog​(java.lang.String initialDirectory, java.lang.String title)  
      static void showError​(java.lang.String message)
      Shows an error message dialog.
      static void showError​(java.lang.String message, java.lang.String title)
      Shows an error message dialog.
      static void showInformation​(java.lang.String message)
      Shows an information message dialog.
      static void showInformation​(java.lang.String message, java.lang.String title)
      Shows an information message dialog.
      static void showMessage​(java.lang.String message)
      Shows a plain message dialog.
      static void showMessage​(java.lang.String message, java.lang.String title)
      Shows a plain message dialog.
      static void showWarning​(java.lang.String message)
      Shows a warning message dialog.
      static void showWarning​(java.lang.String message, java.lang.String title)
      Shows a warning message dialog.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • CommonDialogs

        public CommonDialogs()
    • Method Detail

      • showMessage

        public static void showMessage​(java.lang.String message,
                                       java.lang.String title)
        Shows a plain message dialog.
        Parameters:
        message - The message
        title - The dialog title
      • showMessage

        public static void showMessage​(java.lang.String message)
        Shows a plain message dialog.
        Parameters:
        message - The message
      • showError

        public static void showError​(java.lang.String message,
                                     java.lang.String title)
        Shows an error message dialog.
        Parameters:
        message - The message
        title - The dialog title
      • showError

        public static void showError​(java.lang.String message)
        Shows an error message dialog.
        Parameters:
        message - The message
      • showInformation

        public static void showInformation​(java.lang.String message,
                                           java.lang.String title)
        Shows an information message dialog.
        Parameters:
        message - The message
        title - The title
      • showInformation

        public static void showInformation​(java.lang.String message)
        Shows an information message dialog.
        Parameters:
        message - The message
      • showWarning

        public static void showWarning​(java.lang.String message,
                                       java.lang.String title)
        Shows a warning message dialog.
        Parameters:
        message - The message
        title - The title
      • showWarning

        public static void showWarning​(java.lang.String message)
        Shows a warning message dialog.
        Parameters:
        message - The message
      • getConfirmation

        public static boolean getConfirmation​(java.awt.Component parentComponent,
                                              java.lang.String message,
                                              java.lang.String title)
        Shows a confirmation dialog where the users selects "Yes" or "No".
        Parameters:
        parentComponent - The parent component that this dialog is modal to.
        message - The message
        title - The dialog title
        Returns:
        True if the user selects "Yes", False if the user selects "No" or closes the dialog.
      • getConfirmation

        public static boolean getConfirmation​(java.lang.String message,
                                              java.lang.String title)
        Shows a confirmation dialog where the users selects "Yes" or "No".
        Parameters:
        message - The message
        title - The dialog title
        Returns:
        True if the user selects "Yes", False if the user selects "No" or closes the dialog.
      • getConfirmation

        public static boolean getConfirmation​(java.lang.String message)
        Shows a confirmation dialog where the users selects "Yes" or "No".
        Parameters:
        message - The message
        Returns:
        True if the user selects "Yes", False if the user selects "No" or closes the dialog.
      • getInput

        public static java.lang.String getInput​(java.lang.String message,
                                                java.lang.String defaultValue)
        Shows a dialog allowing the user to input some text.
        Parameters:
        message - The message
        defaultValue - The default value of the text field when the dialog is displayed.
        Returns:
        The text the user provided.
      • getInput

        public static java.lang.String getInput​(java.lang.String message)
        Shows a dialog allowing the user to input some text.
        Parameters:
        message - The message
        Returns:
        The text the user provided.
      • getSelection

        public static java.lang.String getSelection​(java.lang.String message,
                                                    java.util.List<java.lang.String> choices,
                                                    java.lang.String defaultValue,
                                                    java.lang.String title)
        Shows a dialog with a drop down, allowing the user to select one of several values.
        Parameters:
        message - The message
        choices - The choices to present to the user.
        defaultValue - The default choice.
        title - The dialog title
        Returns:
        The choice the user selected.
      • getSelection

        public static java.lang.String getSelection​(java.lang.String message,
                                                    java.util.List<java.lang.String> choices,
                                                    java.lang.String defaultValue)
        Shows a dialog with a drop down, allowing the user to select one of several values.
        Parameters:
        message - The message
        choices - The choices to present to the user.
        defaultValue - The default choice.
        Returns:
        The choice the user selected.
      • getSelection

        public static java.lang.String getSelection​(java.lang.String message,
                                                    java.util.List<java.lang.String> choices)
        Shows a dialog with a drop down, allowing the user to select one of several values.
        Parameters:
        message - The message
        choices - The choices to present to the user.
        Returns:
        The choice the user selected.
      • getDirectory

        public static java.io.File getDirectory​(java.io.File initialDirectory,
                                                java.lang.String title)
        Shows a dialog allowing the user to select a directory.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • getDirectory

        public static java.io.File getDirectory​(java.lang.String initialDirectory,
                                                java.lang.String title)
        Shows a dialog allowing the user to select a directory.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • openFileDialog

        public static java.io.File openFileDialog​(java.io.File initialDirectory,
                                                  java.lang.String fileTypeName,
                                                  java.lang.String fileExtension,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to open.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • openMultipleFilesDialog

        public static java.io.File[] openMultipleFilesDialog​(java.io.File initialDirectory,
                                                             java.lang.String fileTypeName,
                                                             java.lang.String fileExtension,
                                                             java.lang.String title)
        Shows a dialog allowing the user to select one or more files to open.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv". If null will default to "All Files".
        title - The dialog title
        Returns:
        An array of java.io.File objects representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • openMultipleFilesDialog

        public static java.io.File[] openMultipleFilesDialog​(java.lang.String initialDirectory,
                                                             java.lang.String fileTypeName,
                                                             java.lang.String fileExtension,
                                                             java.lang.String title)
        Shows a dialog allowing the user to select one or more files to open.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv". If null will default to "All Files".
        title - The dialog title
        Returns:
        An array of java.io.File objects representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • openFileDialog

        public static java.io.File openFileDialog​(java.io.File initialDirectory,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to open. Applies no extension filtering.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • selectFilesDialog

        public static java.io.File[] selectFilesDialog​(java.io.File initialDirectory,
                                                       java.lang.String title)
      • selectFilesDialog

        public static java.io.File[] selectFilesDialog​(java.lang.String initialDirectory,
                                                       java.lang.String title)
      • selectDirectories

        public static java.io.File[] selectDirectories​(java.io.File initialDirectory,
                                                       java.lang.String title)
      • selectDirectories

        public static java.io.File[] selectDirectories​(java.lang.String initialDirectory,
                                                       java.lang.String title)
      • openFileDialog

        public static java.io.File openFileDialog​(java.lang.String initialDirectory,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to open. Applies no extension filtering.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • openFileDialog

        public static java.io.File openFileDialog​(java.lang.String initialDirectory,
                                                  java.lang.String fileTypeName,
                                                  java.lang.String fileExtension,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to open.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • saveFileDialog

        public static java.io.File saveFileDialog​(java.io.File initialDirectory,
                                                  java.lang.String fileTypeName,
                                                  java.lang.String fileExtension,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to save.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.
      • saveFileDialog

        public static java.io.File saveFileDialog​(java.lang.String initialDirectory,
                                                  java.lang.String fileTypeName,
                                                  java.lang.String fileExtension,
                                                  java.lang.String title)
        Shows a dialog allowing the user to select a file to save.
        Parameters:
        initialDirectory - The initial directory to start in. If null, will default to "C:\".
        fileTypeName - The name of the file type to show in the filter such as "Comma Separated Values (*.csv)"
        fileExtension - The extension of the file type to show in the filter such as "csv".
        title - The dialog title
        Returns:
        A java.io.File object representing the users selection, or null if the user selected "Cancel" or closed the dialog.