Class OptionDialog
- java.lang.Object
-
- docking.DialogComponentProvider
-
- docking.widgets.OptionDialog
-
- All Implemented Interfaces:
ActionContextProvider
,StatusListener
,TaskListener
- Direct Known Subclasses:
OkDialog
public class OptionDialog extends DialogComponentProvider
A utility class to easily show dialogs that require input from the user.Option Dialogs
The primary type of dialog provided herein is the basic option dialog that allows the user to specify the buttons that appear on the dialog. By default, the given option text will appear as a button(s), followed by a
Cancel
button (you can call theshowOptionNoCancelDialog(Component, String, String, String, String, int)
methods if you do not want aCancel
button. To use this type of dialog you can use the variousshowOptionDialog*
methods.Each of the option dialog methods will return a result, which is a number indicating the choice made by the user. See each method for more details.
Data Input and Choice Dialogs
The methods listed here allow the user to either enter data from the keyboard or to choose from a pre-populated list of data.
showInputChoiceDialog(Component, String, String, String[], String, int)
showInputMultilineDialog(Component, String, String, String)
showInputSingleLineDialog(Component, String, String, String)
Yes/No Dialogs
Finally, there are a series of methods that present
Yes
andNo
buttons in a dialog. There are versions that do and do not have aCancel
button.Basic Message / Warning / Error Dialogs
If you would like to display a simple message to the user, but do not require input from the user, then you should use the various methods of
Msg
, such asMsg.showInfo(Object, Component, String, Object)
.Note, the user will be unable to select any text shown in the message area of the dialog.
"Apply to All" / "Don't Show Again"
For more advanced input dialog usage, to include allowing the user to tell the dialog to remember a particular decision, or to apply a given choice to all future request, see
OptionDialogBuilder
.- See Also:
Msg
,OptionDialogBuilder
-
-
Field Summary
Fields Modifier and Type Field Description static int
CANCEL_OPTION
Identifier for the cancel option.static int
ERROR_MESSAGE
Used for error messages.static int
INFORMATION_MESSAGE
Used for information messages.static java.lang.String
MESSAGE_COMPONENT_NAME
static int
NO_OPTION
static int
OPTION_ONE
Identifier for option one.static int
OPTION_THREE
Identifier for option three.static int
OPTION_TWO
Identifier for option two.static int
PLAIN_MESSAGE
No icon is used.static int
QUESTION_MESSAGE
Used for questions.static int
WARNING_MESSAGE
Used for warning messages.static int
YES_OPTION
-
Fields inherited from class docking.DialogComponentProvider
applyButton, buttonPanel, cancelButton, dismissButton, okButton, rootPanel
-
-
Constructor Summary
Constructors Modifier Constructor Description protected
OptionDialog(java.lang.String title, java.lang.String message, int messageType, javax.swing.Icon icon)
Construct a simple informational dialog with a single OK button.protected
OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, javax.swing.Icon icon)
Construct a simple one-option dialog with a Cancel button.protected
OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, javax.swing.Icon icon, java.lang.String defaultButtonName)
Construct a simple one-option dialog with a Cancel button.protected
OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType, javax.swing.Icon icon, boolean addCancel)
Construct a simple two-option dialog.protected
OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType, javax.swing.Icon icon, boolean addCancel, java.lang.String defaultButtonName)
Construct a simple two-option dialog.protected
OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType, javax.swing.Icon icon, boolean addCancel)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
cancelCallback()
Callback for when the cancel button is pressed.static OptionDialogBuilder
createBuilder(java.lang.String title, java.lang.String message)
A convenience method to create aOptionDialogBuilder
protected javax.swing.JPanel
createTextPanel(java.lang.String message)
static javax.swing.Icon
getIconForMessageType(int messageType)
Returns the Icon to use for the given message type.java.lang.String
getMessage()
Returns the dialog's message to the userint
getResult()
Returns which option was selected: CANCEL_OPTION if the operation was cancelled; OPTION_ONE if Option 1 was selected; OPTION_TWO if Option 2 was selected.protected void
okCallback()
callback for when the "OK" button is pressed.int
show()
int
show(java.awt.Component parent)
static java.lang.String
showEditableInputChoiceDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String[] selectableValues, java.lang.String initialValue, int messageType)
Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings.static java.lang.String
showInputChoiceDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String[] selectableValues, java.lang.String initialValue, int messageType)
Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings.static java.lang.String
showInputMultilineDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String initialValue)
Displays a dialog for the user to enter a multi-line string value.static java.lang.String
showInputSingleLineDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String initialValue)
Displays a dialog for the user to enter a string value on a single line.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1)
Static helper method to easily display an single-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType)
Static helper method to easily display an single-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, java.lang.String defaultButtonName)
Static helper method to easily display an single-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2)
Static helper method to easily display an two-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType)
Static helper method to easily display an two-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType)
Static helper method to easily display an three-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, javax.swing.Icon icon)
Static helper method to easily display an two-option dialog.static int
showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, javax.swing.Icon icon)
Static helper method to easily display an single-option dialog.static int
showOptionDialogWithCancelAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1)
Static helper method to easily display an single-option dialog.static int
showOptionDialogWithCancelAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType)
Static helper method to easily display an single-option dialog.static int
showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType)
Static helper method to easily display an two-option dialog.static int
showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType)
Static helper method to easily display an three-option dialog with no Cancel button.static int
showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, javax.swing.Icon icon)
Static helper method to easily display an two-option dialog with no Cancel button.static int
showYesNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCELstatic int
showYesNoDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCELstatic int
showYesNoDialogWithNoAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCEL-
Methods inherited from class docking.DialogComponentProvider
addAction, addApplyButton, addButton, addCancelButton, addDismissButton, addOKButton, addWorkPanel, alertMessage, alertMessage, applyCallback, cancelCurrentTask, clearScheduledTask, clearStatusText, close, dialogClosed, dialogShown, dismissCallback, dispose, doInitialize, escapeCallback, executeProgressTask, getActionContext, getActions, getBackground, getBounds, getComponent, getDefaultButton, getDefaultSize, getDialogSize, getFocusComponent, getGlassPane, getHelpLocatdion, getId, getIntialLocation, getLocationOnScreen, getParent, getPreferredSize, getRemberSize, getRememberLocation, getStatusColor, getStatusLabel, getStatusText, getTaskMonitorComponent, getTaskScheduler, getTitle, getUseSharedLocation, hideTaskMonitorComponent, isApplyEnabled, isCancelEnabled, isModal, isOKEnabled, isResizeable, isRunningTask, isShowing, isTransient, isVisible, notifyContextChanged, removeAction, removeButton, removeWorkPanel, repack, setApplyEnabled, setApplyToolTip, setBackground, setCancelButtonText, setCancelEnabled, setCancelToolTip, setCursor, setDefaultButton, setDefaultSize, setDialogSize, setDismissToolTip, setFocusComponent, setGlassPane, setHelpLocation, setInitialLocation, setMinimumSize, setMinimumSize, setOkButtonText, setOkEnabled, setOkToolTip, setPreferredSize, setRememberLocation, setRememberSize, setResizable, setStatusJustification, setStatusText, setStatusText, setStatusText, setTitle, setTransient, setUseSharedLocation, showProgressBar, showTaskMonitorComponent, stopProgressTimer, taskCancelled, taskCompleted, toFront, toString, waitForCurrentTask
-
-
-
-
Field Detail
-
MESSAGE_COMPONENT_NAME
public static final java.lang.String MESSAGE_COMPONENT_NAME
- See Also:
- Constant Field Values
-
ERROR_MESSAGE
public static final int ERROR_MESSAGE
Used for error messages.- See Also:
- Constant Field Values
-
INFORMATION_MESSAGE
public static final int INFORMATION_MESSAGE
Used for information messages.- See Also:
- Constant Field Values
-
WARNING_MESSAGE
public static final int WARNING_MESSAGE
Used for warning messages.- See Also:
- Constant Field Values
-
QUESTION_MESSAGE
public static final int QUESTION_MESSAGE
Used for questions.- See Also:
- Constant Field Values
-
PLAIN_MESSAGE
public static final int PLAIN_MESSAGE
No icon is used.- See Also:
- Constant Field Values
-
CANCEL_OPTION
public static final int CANCEL_OPTION
Identifier for the cancel option.- See Also:
- Constant Field Values
-
YES_OPTION
public static final int YES_OPTION
- See Also:
- Constant Field Values
-
NO_OPTION
public static final int NO_OPTION
- See Also:
- Constant Field Values
-
OPTION_ONE
public static final int OPTION_ONE
Identifier for option one.- See Also:
- Constant Field Values
-
OPTION_TWO
public static final int OPTION_TWO
Identifier for option two.- See Also:
- Constant Field Values
-
OPTION_THREE
public static final int OPTION_THREE
Identifier for option three.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, int messageType, javax.swing.Icon icon)
Construct a simple informational dialog with a single OK button.- Parameters:
title
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.messageType
- used to specify a default icon- ERROR_MESSAGE
- INFORMATION_MESSAGE
- WARNING_MESSAGE
- QUESTION_MESSAGE
- PLAIN_MESSAGE
icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType, javax.swing.Icon icon, boolean addCancel)
Construct a simple two-option dialog.- Parameters:
title
- the String to place in the dialog's title area.message
- the message string explaining the user's option.option1
- The text to place on the first option button.option2
- The text to place on the second option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.addCancel
- true means add a Cancel button
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType, javax.swing.Icon icon, boolean addCancel, java.lang.String defaultButtonName)
Construct a simple two-option dialog.- Parameters:
title
- the String to place in the dialog's title area.message
- the message string explaining the user's option.option1
- The text to place on the first option button.option2
- The text to place on the second option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.addCancel
- true means add a Cancel buttondefaultButtonName
- The default button name
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, javax.swing.Icon icon)
Construct a simple one-option dialog with a Cancel button.- Parameters:
title
- the String to place in the dialog's title area.message
- the message string explaining the user's option.option1
- The text to place on the first option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, javax.swing.Icon icon, java.lang.String defaultButtonName)
Construct a simple one-option dialog with a Cancel button.- Parameters:
title
- the String to place in the dialog's title area.message
- the message string explaining the user's option.option1
- The text to place on the first option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.defaultButtonName
- the name of the button to be made the default.
-
OptionDialog
protected OptionDialog(java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType, javax.swing.Icon icon, boolean addCancel)
-
-
Method Detail
-
createTextPanel
protected javax.swing.JPanel createTextPanel(java.lang.String message)
-
getMessage
public java.lang.String getMessage()
Returns the dialog's message to the user- Returns:
- the message
-
show
public int show()
-
show
public int show(java.awt.Component parent)
-
createBuilder
public static OptionDialogBuilder createBuilder(java.lang.String title, java.lang.String message)
A convenience method to create aOptionDialogBuilder
- Parameters:
title
- the dialog titlemessage
- the dialog message- Returns:
- the builder
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialogWithCancelAsDefaultButton
public static int showOptionDialogWithCancelAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.The dialog shown by this method will have the cancel button set as the default button so that an Enter key press will trigger a cancel action.
- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialogWithCancelAsDefaultButton
public static int showOptionDialogWithCancelAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.The dialog shown by this method will have the cancel button set as the default button so that an Enter key press will trigger a cancel action.
- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, int messageType, java.lang.String defaultButtonName)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)defaultButtonName
- the name of the button to be the default. Null will make the first button the default- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, javax.swing.Icon icon)
Static helper method to easily display an single-option dialog. The dialog will remain until the user presses the Option1 button or the Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the option button.icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.- Returns:
- The options selected by the user. 1 if the option button is pressed or 0 if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType)
Static helper method to easily display an three-option dialog. The dialog will remain until the user presses the Option1, Option2, Option3 or Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used.title
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.option3
- The text to place on the third option button.messageType
- The type of message to display- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option and so on. 0 is returned if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2)
Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.\- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType)
Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showOptionDialog
public static int showOptionDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, javax.swing.Icon icon)
Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showOptionNoCancelDialog
public static int showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, int messageType)
Static helper method to easily display an two-option dialog. The dialog will remain until the user presses the Option1, Option2 or Cancel button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showOptionNoCancelDialog
public static int showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, javax.swing.Icon icon)
Static helper method to easily display an two-option dialog with no Cancel button. The dialog will remain until the user presses the Option1 or Option 2 button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.icon
- allows the user to specify the icon to be used. If non-null, this will override the messageType.- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showOptionNoCancelDialog
public static int showOptionNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message, java.lang.String option1, java.lang.String option2, java.lang.String option3, int messageType)
Static helper method to easily display an three-option dialog with no Cancel button. The dialog will remain until the user presses the Option1, Option 2, or Option 3 button.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.option1
- The text to place on the first option button.option2
- The text to place on the second option button.option3
- The text to place on the third option button.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- The options selected by the user. 1 for the first option and 2 for the second option. 0 is returned if the operation is cancelled.
-
showYesNoDialog
public static int showYesNoDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCEL- Parameters:
parent
- The parent dialog or frame of this dialog. (Can be null)title
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.- Returns:
- The options selected by the user:
0 is returned if the operation is cancelled 1 for Yes 2 for No
-
showYesNoDialogWithNoAsDefaultButton
public static int showYesNoDialogWithNoAsDefaultButton(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCELThe dialog shown by this method will have the
No
button set as the default button so that an Enter key press will trigger aNo
action.- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.- Returns:
- The options selected by the user:
1 for Yes 2 for No
-
showYesNoCancelDialog
public static int showYesNoCancelDialog(java.awt.Component parent, java.lang.String title, java.lang.String message)
Dialog with only YES/NO options, no CANCEL- Parameters:
parent
- The parent component of this dialog. If the given component is a frame or dialog, then the component will be used to parent the option dialog. Otherwise, the parent frame or dialog will be found by traversing up the given component's parent hierarchy. Also, null can be used to not parent the dialog at all, but this promotes poor dialog behaviortitle
- The String to be placed in the dialogs title area.message
- The information message to be displayed in the dialog.- Returns:
- The options selected by the user:
0 is returned if the operation is cancelled 1 for the first option 2 for the second option
-
showInputSingleLineDialog
public static java.lang.String showInputSingleLineDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String initialValue)
Displays a dialog for the user to enter a string value on a single line.- Parameters:
parent
- the component to parent this dialog totitle
- the title to display on the input dialoglabel
- the label to display in front of the text fieldinitialValue
- an optional value to set in the text field, can be null- Returns:
- the string entered OR null if the dialog was canceled.
-
showInputMultilineDialog
public static java.lang.String showInputMultilineDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String initialValue)
Displays a dialog for the user to enter a multi-line string value.- Parameters:
parent
- the component to parent this dialog totitle
- the title to display on the input dialoglabel
- the label to display in front of the text areainitialValue
- an optional value that will be set in the text area, can be null- Returns:
- the string entered OR null if the dialog was canceled.
-
showInputChoiceDialog
public static java.lang.String showInputChoiceDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String[] selectableValues, java.lang.String initialValue, int messageType)
Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings.- Parameters:
parent
- the component to parent this dialog totitle
- the title to display on the input dialoglabel
- the label to display in front of the combo boxselectableValues
- an array of string to choose frominitialValue
- an optional value to set the combo box to, can be null in which the combo box will have the first item from the selectable values.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- the string entered or chosen OR null if the dialog was canceled.
-
showEditableInputChoiceDialog
public static java.lang.String showEditableInputChoiceDialog(java.awt.Component parent, java.lang.String title, java.lang.String label, java.lang.String[] selectableValues, java.lang.String initialValue, int messageType)
Displays a dialog for the user to enter a string value by either typing it or selecting from a list of possible strings. The list of possible values is editable such that the user can enter their own value by typing text.- Parameters:
parent
- the component to parent this dialog totitle
- the title to display on the input dialoglabel
- the label to display in front of the combo boxselectableValues
- an array of string to choose frominitialValue
- an optional value to set the combo box to, can be null in which the combo box will have the first item from the selectable values.messageType
- used to specify a default icon, can be ERROR_MESSAGE, INFORMATION_MESSAGE, WARNING_MESSAGE, QUESTION_MESSAGE, or PLAIN_MESSAGE)- Returns:
- the string entered or chosen OR null if the dialog was canceled.
-
getResult
public final int getResult()
Returns which option was selected: CANCEL_OPTION if the operation was cancelled; OPTION_ONE if Option 1 was selected; OPTION_TWO if Option 2 was selected.- Returns:
- selected option; returns CANCEL_OPTION for informational dialogs
-
okCallback
protected void okCallback()
callback for when the "OK" button is pressed.- Overrides:
okCallback
in classDialogComponentProvider
-
cancelCallback
protected void cancelCallback()
Callback for when the cancel button is pressed.- Overrides:
cancelCallback
in classDialogComponentProvider
-
getIconForMessageType
public static javax.swing.Icon getIconForMessageType(int messageType)
Returns the Icon to use for the given message type.- Parameters:
messageType
- the type of message being displayed.- Returns:
- the appropriate Icon.
-
-