be.ugent.caagt.swirl.dialogs
Class SimpleDialog
JDialog
be.ugent.caagt.swirl.dialogs.SimpleDialog
public class SimpleDialog
extends JDialog
Simple dialog window consisting of three different components:
-
A central panel, provided by the client.
-
An
OK
button and a CANCEL
button, placed at the
bottom right of the window.
-
An optional icon, placed to the left of the central panel.
To use a dialog object of this type, you should first construct it, then add
the central component to it, using
setCentralComponent(JComponent)
and finally
initialize it by calling
init
. Once initialized, you can call
launch
several times and inspect the user action using
getReturnValue()
.
Alternatively, consider extending the class
DialogPanel
and using one of its
createDialog
methods.
An icon can be installed, changed or removed
using
setIcon(Icon)
before the dialog is launched.
static SimpleDialog | createSimpleDialog(Component parent, String title, boolean modal) - Creates a new simple dialog with the given component as a parent.
|
JPanel | getButtonPanel() - Return the button panel for this dialog.
|
int | getReturnValue() - Get the last value returned by
launch .
|
void | init() - Initializes and populates the dialog.
|
protected void | initButtonPanel() - Creates the button panel and makes the
OK -button the
default button.
|
int | launch() - Show this dialog and wait for the user to respond to it.
|
int | launch(int x, int y) - Show this dialog and wait for the user to respond to it.
|
int | launchAtPointerPosition() - Show this dialog and wait for the user to respond to it.
|
void | setCentralComponent(JComponent component) - Add the central component to the dialog.
|
void | setIcon(Icon icon) - Add the icon to the dialog (or remove when null}.
|
static int | showSimpleDialog(Component parent, String title, JComponent panel) - Show a simple modal dialog with the given panel at its center and wait
for the user to respond to it.
|
static int | showSimpleDialog(Component parent, String title, JComponent panel, Icon icon) - Show a simple modal dialog with the given panel at its center and wait
for the user to respond to it.
|
APPROVE_OPTION
public static final int APPROVE_OPTION
Return value if approve (yes, ok) is chosen.
CANCEL_OPTION
public static final int CANCEL_OPTION
Return value if cancel is chosen (or window is simply closed).
ERROR_OPTION
public static final int ERROR_OPTION
Return value if an error occured.
buttonPanel
protected JPanel buttonPanel
Button panel.
createSimpleDialog
public static SimpleDialog createSimpleDialog(Component parent,
String title,
boolean modal)
Creates a new simple dialog with the given component as a parent.
getButtonPanel
public JPanel getButtonPanel()
Return the button panel for this dialog. Can be used
to add further buttons.
getReturnValue
public int getReturnValue()
Get the last value returned by launch
. One of
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.
init
public void init()
Initializes and populates the dialog. Must be called once before the
first call to launch
.
initButtonPanel
protected void initButtonPanel()
Creates the button panel and makes the OK
-button the
default button.
launch
public int launch()
Show this dialog and wait for the user to respond to it. Displays the dialog
centered with respect to the parent component.
- an indication of the users action, either
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.
launch
public int launch(int x,
int y)
Show this dialog and wait for the user to respond to it. Displays the
dialog window with its top left corner at the given relative position
with respect to the parent component.
- an indication of the users action, either
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.
launchAtPointerPosition
public int launchAtPointerPosition()
Show this dialog and wait for the user to respond to it. Displays the dialog
with the top left corner of its root pane at the current pointer position.
- an indication of the users action, either
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.
setCentralComponent
public void setCentralComponent(JComponent component)
Add the central component to the dialog.
setIcon
public void setIcon(Icon icon)
Add the icon to the dialog (or remove when null}.
showSimpleDialog
public static int showSimpleDialog(Component parent,
String title,
JComponent panel)
Show a simple modal dialog with the given panel at its center and wait
for the user to respond to it.
title
- Title of the dialog windowpanel
- Central component to be displayed
- an indication of the users action, either
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.
showSimpleDialog
public static int showSimpleDialog(Component parent,
String title,
JComponent panel,
Icon icon)
Show a simple modal dialog with the given panel at its center and wait
for the user to respond to it.
title
- Title of the dialog windowpanel
- Central component to be displayedicon
- Icon to be displayed to the left of the panel
- an indication of the users action, either
CANCEL_OPTION
, APPROVE_OPTION
or
ERROR_OPTION
.