Class Dialogs


  • public final class Dialogs
    extends java.lang.Object
    This is helper class which contains static methods for showing various types of dialog boxes containing messages, information, questions, etc.
    Version:
    1.5
    Author:
    Ivan Pribela
    • Constructor Summary

      Constructors 
      Constructor Description
      Dialogs()  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static boolean askConfirmation​(java.awt.Component component, java.lang.String text)
      Displays confirmation message box containing desired message, and asking from the user to answer {code Yes} or No.
      static java.lang.Boolean askConfirmationWithCancel​(java.awt.Component component, java.lang.String text)
      Displays confirmation message box containing desired message, and asking from the user to answer Yes, No or Cancel.
      static LoginData askLogin​(java.awt.Component component, java.lang.String text)
      Displays login dialog box containing desired message, and asking for user name and password.
      static LoginData askLogin​(java.awt.Component component, java.lang.String text, java.lang.String username)
      Displays login dialog box containing desired message, and asking for user name and password.
      static char[] askPassword​(java.awt.Component component, java.lang.String text)
      Displays password dialog box containing desired message, and asking from the user to enter password.
      static java.lang.String askQuestion​(java.awt.Component component, java.lang.String text)
      Displays question message box containing desired question, and asking the user to enter the answer.
      static java.lang.Object askQuestion​(java.awt.Component component, java.lang.String text, java.lang.Object[] options, java.lang.Object defaultOption)
      Displays question message box containing desired question, and asking the user to choose one of the provided options.
      static java.lang.String askQuestion​(java.awt.Component component, java.lang.String text, java.lang.String answer)
      Displays question message box containing desired question, and asking the user to enter the answer.
      static AutoCloseDialogFactory getFactory​(java.util.Locale locale)  
      static AutoCloseDialogFactory getFactory​(java.util.Locale locale, java.awt.datatransfer.Clipboard clipboard)  
      static AutoCloseDialogFactory getFactory​(java.util.Locale locale, java.awt.datatransfer.Clipboard clipboard, int timeout)  
      static void setClipboard​(java.awt.datatransfer.Clipboard newValue)
      Sets clipboard which will be used by displayed messages.
      static void setLocale​(java.util.Locale newValue)
      Sets locale which will be used to display messages.
      void setNewStackTraceStyle​(boolean newValue)
      Sets the stack trace style which will be used by displayed messages.
      static void setTimeout​(int newValue)
      Sets default time before automatically closing dialogs.
      static boolean showDialog​(java.awt.Component component, java.awt.Component content, java.lang.String title, javax.swing.Icon icon)
      Displays a dialog with the given icon and title containing the supplied component.
      static <T> T showDialog​(java.awt.Component component, DialogContent<T> content, java.lang.String title, javax.swing.Icon icon)
      Displays a dialog with the given icon and title containing the supplied content.
      static void showError​(java.awt.Component component, java.lang.String text)
      Displays error message box containing desired message.
      static void showError​(java.awt.Component component, java.lang.String text, java.lang.Throwable th)
      Displays error message box containing desired message and optionally stack-trace of the supplied exception.
      static void showException​(java.awt.Component component, java.lang.Throwable th)
      Displays error message box containing stack-trace of the supplied exception.
      static void showInformation​(java.awt.Component component, java.lang.String text)
      Displays informational message box containing desired message.
      static void showMessage​(java.awt.Component component, java.lang.String text)
      Displays message box containing desired message.
      static void showWarning​(java.awt.Component component, java.lang.String text)
      Displays warning message box containing desired message.
      • Methods inherited from class java.lang.Object

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

      • Dialogs

        public Dialogs()
    • Method Detail

      • setLocale

        public static void setLocale​(java.util.Locale newValue)
        Sets locale which will be used to display messages.
        Parameters:
        newValue - locale which will be used to display messages.
      • setClipboard

        public static void setClipboard​(java.awt.datatransfer.Clipboard newValue)
        Sets clipboard which will be used by displayed messages.
        Parameters:
        newValue - clipboard which will be used by displayed messages.
      • setNewStackTraceStyle

        public void setNewStackTraceStyle​(boolean newValue)
        Sets the stack trace style which will be used by displayed messages.
        Parameters:
        newValue - stack trace style which will be used by displayed messages.
      • setTimeout

        public static void setTimeout​(int newValue)
        Sets default time before automatically closing dialogs.
        Parameters:
        newValue - the auto close timeout; zero means don't auto close dialogs.
      • showMessage

        public static void showMessage​(java.awt.Component component,
                                       java.lang.String text)
        Displays message box containing desired message.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
      • showInformation

        public static void showInformation​(java.awt.Component component,
                                           java.lang.String text)
        Displays informational message box containing desired message.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
      • showWarning

        public static void showWarning​(java.awt.Component component,
                                       java.lang.String text)
        Displays warning message box containing desired message.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
      • showError

        public static void showError​(java.awt.Component component,
                                     java.lang.String text)
        Displays error message box containing desired message.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
      • showError

        public static void showError​(java.awt.Component component,
                                     java.lang.String text,
                                     java.lang.Throwable th)
        Displays error message box containing desired message and optionally stack-trace of the supplied exception.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        th - exception which is used to build up the stack-trace information.
      • showException

        public static void showException​(java.awt.Component component,
                                         java.lang.Throwable th)
        Displays error message box containing stack-trace of the supplied exception.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        th - exception which is used to build up the stack-trace information.
      • askConfirmation

        public static boolean askConfirmation​(java.awt.Component component,
                                              java.lang.String text)
        Displays confirmation message box containing desired message, and asking from the user to answer {code Yes} or No.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        Returns:
        true if user answered yes; false otherwise.
      • askConfirmationWithCancel

        public static java.lang.Boolean askConfirmationWithCancel​(java.awt.Component component,
                                                                  java.lang.String text)
        Displays confirmation message box containing desired message, and asking from the user to answer Yes, No or Cancel.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        Returns:
        True if user answered yes; False if user answered no; and null otherwise.
      • askQuestion

        public static java.lang.String askQuestion​(java.awt.Component component,
                                                   java.lang.String text)
        Displays question message box containing desired question, and asking the user to enter the answer.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        Returns:
        String object containing text that user entered; null if user has chosen not to answer.
      • askQuestion

        public static java.lang.String askQuestion​(java.awt.Component component,
                                                   java.lang.String text,
                                                   java.lang.String answer)
        Displays question message box containing desired question, and asking the user to enter the answer.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        answer - the initial answer for user to modify.
        Returns:
        String object containing text that user entered; null if user has chosen not to answer.
      • askQuestion

        public static java.lang.Object askQuestion​(java.awt.Component component,
                                                   java.lang.String text,
                                                   java.lang.Object[] options,
                                                   java.lang.Object defaultOption)
        Displays question message box containing desired question, and asking the user to choose one of the provided options.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the message box.
        options - list of available options for the user to choose from.
        defaultOption - initial option that is to be selected.
        Returns:
        one of the options provided or null if user has chosen not to answer.
      • askPassword

        public static char[] askPassword​(java.awt.Component component,
                                         java.lang.String text)
        Displays password dialog box containing desired message, and asking from the user to enter password.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the dialog box.
        Returns:
        password entered by the user as an array of char; null if user has chosen not to enter the password.
      • askLogin

        public static LoginData askLogin​(java.awt.Component component,
                                         java.lang.String text)
        Displays login dialog box containing desired message, and asking for user name and password.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the dialog box.
        Returns:
        user data (user name and password) stored in LoginData object; null if user has chosen not to enter login data.
      • askLogin

        public static LoginData askLogin​(java.awt.Component component,
                                         java.lang.String text,
                                         java.lang.String username)
        Displays login dialog box containing desired message, and asking for user name and password.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        text - text which will be displayed in the dialog box.
        username - default user name.
        Returns:
        user data (user name and password) stored in LoginData object; null if user has chosen not to enter login information.
      • showDialog

        public static boolean showDialog​(java.awt.Component component,
                                         java.awt.Component content,
                                         java.lang.String title,
                                         javax.swing.Icon icon)
        Displays a dialog with the given icon and title containing the supplied component.
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        content - the component to display on the dialog
        title - title of the dialog
        icon - icon to display on the dialog
        Returns:
        true if user answered ok; false otherwise.
      • showDialog

        public static <T> T showDialog​(java.awt.Component component,
                                       DialogContent<T> content,
                                       java.lang.String title,
                                       javax.swing.Icon icon)
        Displays a dialog with the given icon and title containing the supplied content.
        Type Parameters:
        T - type of dialog content
        Parameters:
        component - determines the frame in which the dialog is displayed; if the parentComponent has no Frame, a default Frame is used.
        content - the component to display on the dialog
        title - title of the dialog
        icon - icon to display on the dialog
        Returns:
        The object retrieved from the content component if user answered ok; null otherwise.
      • getFactory

        public static AutoCloseDialogFactory getFactory​(java.util.Locale locale,
                                                        java.awt.datatransfer.Clipboard clipboard)
      • getFactory

        public static AutoCloseDialogFactory getFactory​(java.util.Locale locale,
                                                        java.awt.datatransfer.Clipboard clipboard,
                                                        int timeout)