org.xnap.commons.gui
Class Dialogs

java.lang.Object
  extended by org.xnap.commons.gui.Dialogs

public class Dialogs
extends Object

Provides a set of static methods to display common dialogs.


Nested Class Summary
static class Dialogs.FileListCellRenderer
          This class provides a list renderer for File objects.
 
Constructor Summary
Dialogs()
           
 
Method Summary
static boolean executeCopy(Component parent, File[] files, File target)
          Copies files to target.
static boolean executeMove(Component parent, File[] files, File target)
          Moves files to target.
static String requestInput(Component parent, String message, String title)
          Shows an input dialog and returns the entered value or null.
static String requestPassword(Component parent, String message, String title)
          Shows a password input dialog and returns the entered value or null.
static boolean showCloseDialog(Component parent, String message, BooleanSetting setting)
          Shows a confirmation dialog asking the user if he really wants to quit the application.
static int showConfirmDialog(Component parent, String message, String title, int optionType, BooleanSetting setting)
          Shows a confirmation dialog and with a message and check box that can be selected to not display the dialog in the future anymore.
static File[] showCopyDialog(Component parent, File[] files, File target, BooleanSetting setting)
          Displays a dialog that with a list of files asking the user to confirm a copy operation to the specified target.
static File[] showDeleteDialog(Component parent, File[] files, BooleanSetting setting)
          Displays a dialog that with a list of files asking the user to confirm a delete operation.
static void showError(Component parent, String message)
          Displays a dialog with a message indicating the cause of an error.
static void showError(Component parent, String message, Exception e)
          Displays a dialog with a message indicating the cause of an error a stack trace of the specified exception providing details.
static void showError(Component parent, String message, String title)
          Displays a dialog with a message indicating the cause of an error.
static void showError(Component parent, String message, String title, Exception exception)
          Displays a dialog with a message indicating the cause of an error a stack trace of the specified exception providing details.
static File[] showFilesActionDialog(Component parent, File[] files, String message, String title, BooleanSetting setting)
          Displays a dialog with a message, a list of files and a check box that can be selected to not display the dialog in the future anymore.
static void showInfo(Component parent, String message, String title)
          Displays a dialog with an information message.
static File[] showMoveDialog(Component parent, File[] files, File target, BooleanSetting setting)
          Displays a dialog that with a list of files asking the user to confirm a delete operation.
 
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

executeCopy

public static boolean executeCopy(Component parent,
                                  File[] files,
                                  File target)
Copies files to target. Shows a dialog in case of an error.

Parameters:
files - the files to copy
target - the target directory
Returns:
true, if copy was successful; false, otherwise or if files is empty TODO copying could be costly, show progress dialog here too, see DropFileTree..
See Also:
FileHelper.copy(File, File)

executeMove

public static boolean executeMove(Component parent,
                                  File[] files,
                                  File target)
Moves files to target. Shows a dialog in case of an error. Renames each file in case it already exists in target.

Parameters:
files - the files to copy
target - the target directory
Returns:
true, if move was successful; false, otherwise or if files is empty

requestInput

public static String requestInput(Component parent,
                                  String message,
                                  String title)
Shows an input dialog and returns the entered value or null.

Parameters:
parent - the parent component the input dialog is centered on
message - the message giving details about the requested input
title - the title of the dialog
Returns:
the entered value or null if the dialog was cancelled

requestPassword

public static String requestPassword(Component parent,
                                     String message,
                                     String title)
Shows a password input dialog and returns the entered value or null.

Parameters:
parent - the parent component the input dialog is centered on
message - the message giving details about the requested input
title - the title of the dialog
Returns:
the entered value or null if the dialog was cancelled

showCloseDialog

public static boolean showCloseDialog(Component parent,
                                      String message,
                                      BooleanSetting setting)
Shows a confirmation dialog asking the user if he really wants to quit the application.

It also offers a checkbox "Always quit without prompting me." If the user checks it, the next time this function is called it will return true without showing the dialog.

Parameters:
parent - the parent component this dialog is centered on
message - a message explaining what it means to quit the application
setting - the boolean setting that stores the state of the checkbox
Returns:
true, if user presses okay button.

showConfirmDialog

public static int showConfirmDialog(Component parent,
                                    String message,
                                    String title,
                                    int optionType,
                                    BooleanSetting setting)
Shows a confirmation dialog and with a message and check box that can be selected to not display the dialog in the future anymore.

If the specified setting is not null and it's value is false the dialog is not displayed and JOptionPane.YES_OPTION is returned.

Parameters:
parent - parent component used for centering the dialog
message - the message to show
title - the title of the message border
optionType - an int designating the options available on the dialog: JOptionPane.YES_NO_OPTION, or JOptionPane.YES_NO_CANCEL_OPTION
setting - used to store the reverse state of the Do not ask me again check box; if null, the state is not saved
Returns:
an int indicating the option selected by user

showCopyDialog

public static File[] showCopyDialog(Component parent,
                                    File[] files,
                                    File target,
                                    BooleanSetting setting)
Displays a dialog that with a list of files asking the user to confirm a copy operation to the specified target.

If the specified setting is not null and it's value is false the dialog is not displayed and the specified files are returned.

Parameters:
parent - the dialog parent
files - the files that are to be displayed in the list
target - the destination path
setting - used to store the reverse state of the Do not ask me again check box; if null, the state is not saved
Returns:
the selected files, i.e. the ones that should be copied; if the user selected cancel an empty array is returned, never returns null
See Also:
showFilesActionDialog(Component, File[], String, String, BooleanSetting)

showDeleteDialog

public static File[] showDeleteDialog(Component parent,
                                      File[] files,
                                      BooleanSetting setting)
Displays a dialog that with a list of files asking the user to confirm a delete operation.

If the specified setting is not null and it's value is false the dialog is not displayed and the specified files are returned.

Parameters:
parent - the dialog parent
files - the files that are to be displayed in the list
setting - used to store the reverse state of the Do not ask me again check box; if null, the state is not saved
Returns:
the selected files, i.e. the ones that should be copied; if the user selected cancel an empty array is returned, never returns null
See Also:
showFilesActionDialog(Component, File[], String, String, BooleanSetting)

showError

public static void showError(Component parent,
                             String message)
Displays a dialog with a message indicating the cause of an error. The dialog's title is set to Error.

Parameters:
parent - the parent component
message - the error message

showError

public static void showError(Component parent,
                             String message,
                             Exception e)
Displays a dialog with a message indicating the cause of an error a stack trace of the specified exception providing details. The dialog's title is set to Error.

Parameters:
parent - the parent component
message - the error message

showError

public static void showError(Component parent,
                             String message,
                             String title)
Displays a dialog with a message indicating the cause of an error.

Parameters:
parent - the parent component
message - the error message
title - the dialog title

showError

public static void showError(Component parent,
                             String message,
                             String title,
                             Exception exception)
Displays a dialog with a message indicating the cause of an error a stack trace of the specified exception providing details.

Parameters:
parent - the parent component
message - the error message
title - the dialog title
exception - the exception that caused the error

showFilesActionDialog

public static File[] showFilesActionDialog(Component parent,
                                           File[] files,
                                           String message,
                                           String title,
                                           BooleanSetting setting)
Displays a dialog with a message, a list of files and a check box that can be selected to not display the dialog in the future anymore.

If the specified setting is not null and it's value is false the dialog is not displayed and the specified files are returned.

Parameters:
parent - the dialog parent
files - the files that are to be displayed in the list
title - the dialog's title
message - the message
setting - used to store the reverse state of the Do not ask me again check box; if null, the state is not saved
Returns:
the selected files; if the dialog was cancelled an empty array is returned, never returns null

showInfo

public static void showInfo(Component parent,
                            String message,
                            String title)
Displays a dialog with an information message.

Parameters:
parent - the parent component
message - the error message
title - the dialog title
See Also:
JOptionPane.showMessageDialog(java.awt.Component, java.lang.Object, java.lang.String, int)

showMoveDialog

public static File[] showMoveDialog(Component parent,
                                    File[] files,
                                    File target,
                                    BooleanSetting setting)
Displays a dialog that with a list of files asking the user to confirm a delete operation.

If the specified setting is not null and it's value is false the dialog is not displayed and the specified files are returned.

Parameters:
parent - the dialog parent
files - the files that are to be displayed in the list
target - the destination path
setting - used to store the reverse state of the Do not ask me again check box; if null, the state is not saved
Returns:
the selected files, i.e. the ones that should be copied; if the user selected cancel an empty array is returned, never returns null
See Also:
showFilesActionDialog(Component, File[], String, String, BooleanSetting)


Copyright © 2004-2007 XNap Commons Team. All Rights Reserved.