Package docking.widgets.dialogs
Class NumberInputDialog
- java.lang.Object
-
- docking.DialogComponentProvider
-
- docking.widgets.dialogs.NumberInputDialog
-
- All Implemented Interfaces:
ActionContextProvider
,StatusListener
,TaskListener
public class NumberInputDialog extends DialogComponentProvider
DialogComponentProvider that provides information to create a modal dialog to prompt for a number (int) to be input by the user.
If an initial value is specified it is not in the range of min,max, it will be set to the min.
If the maximum value indicated is less than the minimum then the max is the largest positive integer. Otherwise the maximum valid value is as indicated.
This dialog component provider class can be used by various classes and therefore should not have its size or position remembered by the tool.showDialog() call parameters.
To display the dialog call:String entryType = "items"; int initial = 5; // initial value in text field. int min = 1; // minimum valid value in text field. int max = 10; // maximum valid value in text field. NumberInputDialog numInputProvider = new NumberInputProvider(entryType, initial, min, max); if (numInputProvider.show()) { // not cancelled int result = numInputProvider.getValue(); }
-
-
Field Summary
-
Fields inherited from class docking.DialogComponentProvider
applyButton, cancelButton, dismissButton, okButton, rootPanel
-
-
Constructor Summary
Constructors Constructor Description NumberInputDialog(java.lang.String entryType, int initial, int min)
NumberInputDialog(java.lang.String entryType, int initial, int min, int max)
Constructs a new NumberInputDialog.NumberInputDialog(java.lang.String title, java.lang.String prompt, java.lang.Integer initialValue)
Create a numberInputDialog where the the min is 0 and the max is INTEGER.MAX_VALUENumberInputDialog(java.lang.String title, java.lang.String prompt, java.lang.Integer initialValue, int min, int max, boolean showAsHex)
Show a number input dialog.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected javax.swing.JPanel
buildMainPanel(java.lang.String prompt, boolean showAsHex)
Define the Main panel for the dialog here.protected void
cancelCallback()
Gets called when the user clicks on the Cancel Action for the dialog.int
getMax()
Return the maximum acceptable value.int
getMin()
Return the minimum acceptable value.int
getValue()
Convert the input to an int value.protected void
okCallback()
Gets called when the user clicks on the OK Action for the dialog.void
setDefaultMessage(java.lang.String defaultMessage)
Sets the default message to be displayed when valid values are in the text fields.void
setInput(int value)
Sets the value in the input field to the indicated value.boolean
show()
show
displays the dialog, gets the user inputprotected void
updateOKButtonEnablement()
boolean
wasCancelled()
Return whether the user cancelled the input dialog.-
Methods inherited from class docking.DialogComponentProvider
addAction, addApplyButton, addButton, addCancelButton, addDismissButton, addOKButton, addWorkPanel, alertMessage, alertMessage, applyCallback, cancelCurrentTask, clearScheduledTask, clearStatusText, close, dialogClosed, dialogShown, dismissCallback, doInitialize, escapeCallback, executeProgressTask, getActionContext, getActions, getBackground, getBounds, getComponent, getDefaultButton, getDefaultSize, getDialogSize, getFocusComponent, getGlassPane, getHelpLocatdion, getIntialLocation, getLocationOnScreen, getPreferredSize, getRemberSize, getRememberLocation, getStatusLabel, getStatusText, getTaskMonitorComponent, getTaskScheduler, getTitle, getUseSharedLocation, hideTaskMonitorComponent, isApplyEnabled, isCancelEnabled, isModal, isOKEnabled, isResizeable, isRunningTask, isShowing, isTransient, isVisible, main, 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
-
-
-
-
Constructor Detail
-
NumberInputDialog
public NumberInputDialog(java.lang.String entryType, int initial, int min)
-
NumberInputDialog
public NumberInputDialog(java.lang.String entryType, int initial, int min, int max)
Constructs a new NumberInputDialog.- Parameters:
entryType
- item type the number indicates (i.e. "duplicates", "items", or "elements").initial
- default value displayed in the text field.min
- minimum value allowed.max
- maximum value allowed.
-
NumberInputDialog
public NumberInputDialog(java.lang.String title, java.lang.String prompt, java.lang.Integer initialValue)
Create a numberInputDialog where the the min is 0 and the max is INTEGER.MAX_VALUE- Parameters:
title
- the title of the dialogprompt
- the prompt in the dialoginitialValue
- the initial value. If null, the text input will be blank.
-
NumberInputDialog
public NumberInputDialog(java.lang.String title, java.lang.String prompt, java.lang.Integer initialValue, int min, int max, boolean showAsHex)
Show a number input dialog.- Parameters:
title
- The title of the dialog.prompt
- the prompt to display before the number input field.initialValue
- the default value to display, null will leave the field blank.min
- the minimum allowed value of the field.max
- the maximum allowed value of the field.showAsHex
- if true, the initial value will be displayed as hex.
-
-
Method Detail
-
buildMainPanel
protected javax.swing.JPanel buildMainPanel(java.lang.String prompt, boolean showAsHex)
Define the Main panel for the dialog here.- Parameters:
showAsHex
-- Returns:
- JPanel the completed
Main Panel<\CODE>
-
okCallback
protected void okCallback()
Gets called when the user clicks on the OK Action for the dialog.- Overrides:
okCallback
in classDialogComponentProvider
-
cancelCallback
protected void cancelCallback()
Gets called when the user clicks on the Cancel Action for the dialog.- Overrides:
cancelCallback
in classDialogComponentProvider
-
wasCancelled
public boolean wasCancelled()
Return whether the user cancelled the input dialog.
-
show
public boolean show()
show
displays the dialog, gets the user input- Returns:
- false if the user cancelled the operation
-
getValue
public int getValue()
Convert the input to an int value.- Throws:
java.lang.NumberFormatException
- if entered value cannot be parsed.
-
setInput
public void setInput(int value)
Sets the value in the input field to the indicated value.
-
setDefaultMessage
public void setDefaultMessage(java.lang.String defaultMessage)
Sets the default message to be displayed when valid values are in the text fields.- Parameters:
defaultMessage
- the message to be displayed when valid values are in the text fields.
-
getMin
public int getMin()
Return the minimum acceptable value.
-
getMax
public int getMax()
Return the maximum acceptable value.
-
updateOKButtonEnablement
protected void updateOKButtonEnablement()
-
-