A base class for custom dialog windows. This class provides some base
functionality that can be useful across many different types of dialogs.
The class constructs a skeleton dialog consisting of an optional comment
line, an icon, OK and Cancel buttons, and a middle area that
must be filled in by subclassers.
A ComponentDialog is accepted by clicking the
OK button, though subclassers can determine the conditions under
which a dialog may be accepted by overriding the accept()
method; it is cancelled by clicking the Cancel button or
closing the window.
Construct the component that will be displayed in the center of the
dialog window. Subclassers implement this method to customize the look of
the dialog.
protected void registerTextInputComponent(JTextField c)
Register a text field with this dialog. In some dialogs, most notably
KInputDialog, pressing Return in a text field is
equivalent to pressing the dialog's OK button. Subclassers may use
this method to register a text field that should function in this way.
Get the icon to display in the left part of the dialog window. By
default, this method returns null, which signifies that no icon
will be displayed. The method can be called by classes that extend this
class to provide an appropriate icon for the dialog.
Returns:
A Icon to display in the dialog.
isCancelled
public boolean isCancelled()
Get the cancelled state of the dialog. This method should be
called after the dialog is dismissed to determine if it was cancelled by
the user.
Returns:
true if the dialog was cancelled, and false
otherwise.
accept
protected boolean accept()
Accept user input. The dialog calls this method in response to a click on
the dialog's OK button. If this method returns true, the
dialog disappears; otherwise, it remains on the screen. This method can
be overridden to check input in the dialog before allowing it to be
dismissed. The default implementation of this method returns true.
Returns:
true if the dialog may be dismissed, and false
otherwise.
cancel
protected void cancel()
Cancel the dialog. The dialog calls this method in response to a click on
the dialog's Cancel button, or on a close of the dialog window
itself. Subclassers may override this method to provide any special
processing that is required when the dialog is cancelled. The default
implementation of this method does nothing.
canCancel
protected boolean canCancel()
Determine if the dialog can be cancelled. This method is called in
response to a click on the Cancel button or on the dialog
window's close icon/option. Subclassers may wish to override this
method to prevent cancellation of a window in certain circumstances.
Returns:
true if the dialog may be cancelled, false
otherwise. The default implementation returns true.
Add a button to the dialog's button panel at the specified position.
Parameters:
button - The button to add.
pos - The position at which to add the button. A value of 0 denotes
the first position, and -1 denotes the last position. The possible
range of values for pos excludes the OK and
(if present) Cancel buttons; buttons may not be added after
these "fixed" buttons.
button - The button to remove. Neither the OK nor the
Cancel button may be removed.
removeButton
protected void removeButton(int pos)
Remove a button from the specified position in the dialog's button
panel.
Parameters:
button - The button to remove.
pos - The position of the button to remove, where 0 denotes
the first position, and -1 denotes the last position. The possible
range of values for pos excludes the OK and
(if present) Cancel buttons; these "fixed" buttons may not be
removed.