be.ugent.caagt.swirl.dialogs

Class SimpleDialog


public class SimpleDialog
extends JDialog

Simple dialog window consisting of three different components:

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.

Field Summary

static int
APPROVE_OPTION
Return value if approve (yes, ok) is chosen.
static int
CANCEL_OPTION
Return value if cancel is chosen (or window is simply closed).
static int
ERROR_OPTION
Return value if an error occured.
protected JPanel
buttonPanel
Button panel.

Method Summary

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.

Field Details

APPROVE_OPTION

public static final int APPROVE_OPTION
Return value if approve (yes, ok) is chosen.
Field Value:
0

CANCEL_OPTION

public static final int CANCEL_OPTION
Return value if cancel is chosen (or window is simply closed).
Field Value:
1

ERROR_OPTION

public static final int ERROR_OPTION
Return value if an error occured.
Field Value:
-1

buttonPanel

protected JPanel buttonPanel
Button panel.

Method Details

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.
Returns:
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.
Returns:
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.
Returns:
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.
Parameters:
title - Title of the dialog window
panel - Central component to be displayed
Returns:
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.
Parameters:
title - Title of the dialog window
panel - Central component to be displayed
icon - Icon to be displayed to the left of the panel
Returns:
an indication of the users action, either CANCEL_OPTION, APPROVE_OPTION or ERROR_OPTION.