|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object uic.widgets.AbstractWindow uic.widgets.StandardDialog
A replacement for all your usages of JDialog. This class provides a dialog for your panel, including a set of buttons and all the things you would normally manually configure in JDialog.
Below two examples of a standard dialog with a selection of buttons
OK/Apply/Cancel dialog
OK/Cancel with Defaults
Simple usage:
FontSelection content = new FontSelection(selected); StandardDialog diag = new StandardDialog(parent, "Select font", StandardDialog.OK_CANCEL); diag.setComponent(content); if(diag.show() == StandardDialog.BUTTON_OK) { return content.getFont(); } return selected;
The StandardDialog also allows extra buttons like 'Apply' and 'Help'. The way to handle the events in your application when the user presses one of these is simple;
final FontSelection content = new FontSelection(); content.setFont(selected); StandardDialog diag = new StandardDialog(parent, "Select font", StandardDialog.OK_CANCEL | StandardDialog.BUTTON_DEFAULTS); diag.setComponent(content); diag.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent ae) { if(ae.getID() == StandardDialog.BUTTON_DEFAULTS) content.setFont(selected); } }); // the show() follows here just like above.
A widget that is placed on this dialog can enable/disable the OK button with the following line:
firePropertyChange("enableOK", formerState, newState); // states are booleans
Field Summary | |
static int |
BUTTON_APPLY
|
static int |
BUTTON_CANCEL
|
static int |
BUTTON_DEFAULTS
|
static int |
BUTTON_HELP
|
static int |
BUTTON_OK
|
static int |
BUTTON_USER1
|
static int |
BUTTON_USER2
|
static int |
BUTTON_USER3
|
static String |
CONFIG_ALLOW_ESC_CLOSE
Config key for allowing ESC to close (cancel) a dialog. |
static int |
OK_APPLY_CANCEL
|
static int |
OK_CANCEL
|
static String |
PROPERTY_ENABLE_APPLY
|
static String |
PROPERTY_ENABLE_OK
|
static String |
PROPERTY_ENABLE_USER1
|
static String |
PROPERTY_ENABLE_USER2
|
static String |
PROPERTY_ENABLE_USER3
|
static String |
PROPERTY_TEXT_USER1
|
static String |
PROPERTY_TEXT_USER2
|
static String |
PROPERTY_TEXT_USER3
|
Fields inherited from class uic.widgets.AbstractWindow |
internalWindow |
Constructor Summary | |
StandardDialog(Window owner,
String title,
boolean modal,
int type)
Convinience constructor |
|
StandardDialog(Window owner,
String title,
boolean modal,
int type,
String user1Text)
Convinience constructor |
|
StandardDialog(Window owner,
String title,
boolean modal,
int type,
String user1Text,
String user2Text)
Convinience constructor |
|
StandardDialog(Window owner,
String title,
boolean modal,
int type,
String user1Text,
String user2Text,
String user3Text)
Create an invisible dialog with an optional owner, title and buttons. |
|
StandardDialog(Window owner,
String title,
int type)
Convinience constructor for a non-modal dialog |
Method Summary | |
void |
addActionListener(ActionListener listener)
Add a listener to listen for non-closing buttons. |
void |
addCommandButton(int type,
String name,
boolean left)
Add a button to the row of buttons on this dialog. |
protected void |
buttonPressedSlot(int type)
Called by the buttons. |
void |
changeUser1ButtonTextSlot(String buttonText)
Set the user1 button text to the argument buttonText |
void |
changeUser2ButtonTextSlot(String buttonText)
Set the user2 button text to the argument buttonText |
void |
changeUser3ButtonTextSlot(String buttonText)
Set the user3 button text to the argument buttonText |
protected Window |
createInternalWindow(Dialog owner,
String title,
boolean modal)
|
protected Window |
createInternalWindow(Frame owner,
String title,
boolean modal)
|
void |
enableApplyButtonSlot(boolean enable)
Set the apply button to be enabled per argument enable. |
void |
enableOKButtonSlot(boolean enable)
Set the ok button to be enabled per argument enable. |
void |
enableUser1ButtonSlot(boolean enable)
Set the user1 button to be enabled per argument enable. |
void |
enableUser2ButtonSlot(boolean enable)
Set the user2 button to be enabled per argument enable. |
void |
enableUser3ButtonSlot(boolean enable)
Set the user3 button to be enabled per argument enable. |
void |
hide()
Hide the dialog making the 'show' method return. |
void |
hide(int buttonType)
Hide and register buttonPress by argument buttonType. |
void |
removeActionListener(ActionListener listener)
Remove a previously registered actionListener. |
void |
setComponent(Component c)
Place a Component on your dialog. |
int |
show(Point location,
Dimension size)
Show the dialog at the given location. |
void |
showAndForget(Object targetObject,
String targetMethod)
Convinience method. |
void |
showAndForget(Object targetObject,
String targetMethod,
JComponent component)
Open the initialized dialog and wait until it has been closed by user, performing the targetMethod on OK. |
TranslationInterface |
translate()
|
Methods inherited from class uic.widgets.AbstractWindow |
getBounds, getDialogSizePanel, getLocation, getRPContainer, getSize, positionDialog, positionDialog, show, show |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
public static final int BUTTON_OK
public static final int BUTTON_CANCEL
public static final int BUTTON_APPLY
public static final int BUTTON_DEFAULTS
public static final int BUTTON_HELP
public static final int BUTTON_USER1
public static final int BUTTON_USER2
public static final int BUTTON_USER3
public static final int OK_CANCEL
public static final int OK_APPLY_CANCEL
public static final String PROPERTY_ENABLE_OK
public static final String PROPERTY_ENABLE_APPLY
public static final String PROPERTY_ENABLE_USER1
public static final String PROPERTY_ENABLE_USER2
public static final String PROPERTY_ENABLE_USER3
public static final String PROPERTY_TEXT_USER1
public static final String PROPERTY_TEXT_USER2
public static final String PROPERTY_TEXT_USER3
public static final String CONFIG_ALLOW_ESC_CLOSE
ThemeStrore.getProperty
to fetch the user setting.
Constructor Detail |
public StandardDialog(Window owner, String title, int type)
public StandardDialog(Window owner, String title, boolean modal, int type)
public StandardDialog(Window owner, String title, boolean modal, int type, String user1Text)
public StandardDialog(Window owner, String title, boolean modal, int type, String user1Text, String user2Text)
public StandardDialog(Window owner, String title, boolean modal, int type, String user1Text, String user2Text, String user3Text)
OK_CANCEL and OK_APPLY_CANCEL are convinience variables to group much used variables together.
After creating the dialog do a setComponent() and a show()
owner
- The owner should either be a JFrame or a JDialog extending
class (such as another StandardDialog). It can also be null.title
- the name the dialog will get.modal
- true for a modal dialog, false for one that allows other windows to
be active at the same time.type
- the buttons that should be at the bottom. If none specified then OK is showed.user1Text
- the text for button with code BUTTON_USER1user2Text
- the text for button with code BUTTON_USER2user3Text
- the text for button with code BUTTON_USER3Method Detail |
protected Window createInternalWindow(Frame owner, String title, boolean modal)
createInternalWindow
in class AbstractWindow
protected Window createInternalWindow(Dialog owner, String title, boolean modal)
createInternalWindow
in class AbstractWindow
public void addCommandButton(int type, String name, boolean left)
type
- only BUTTON* types are allowedname
- the text put on the button, allows everything that Translate will eat.left
- if true position button left most.public void setComponent(Component c)
setComponent
in class AbstractWindow
public int show(Point location, Dimension size)
An example call for a non-modal dialog (a non-modal dialog should be used in all but the most extreme cases)
StandardDialog myDialog = new StandardDialog(SwingUtilities.windowForComponent(this), "Title", true, StandardDialog.BUTTON_OK); if(myDialog.show(location, size) == StandardDialog.OK_BUTTON) { // dialog closed with ok... }
In the case you call the showWizard from a buttonPress or other GUI action you have to do a little extra; here is some example code:
final StandardDialog myDialog = new StandardDialog(SwingUtilities.windowForComponent(this), "Title", false, StandardDialog.BUTTON_OK); Thread handling = new Thread("StandardDialogHandler") { public void run() { if(myDialog.show(location, size) == StandardDialog.OK_BUTTON) { // dialog closed with ok... } } }; handling.start();
show
in class AbstractWindow
location
- the x and y coordinates on the screen where the dialog should appear, can be null to use parents position.size
- a size hint for the dialog, can be null to use default based on the preferredSize.
IllegalStateException
- since this method will not return until the wizard has been
closed we can not be non-modal (modal = false) and be called from the EventDispatch Thread.showAndForget(Object,String)
public void showAndForget(Object targetObject, String targetMethod)
public void showAndForget(Object targetObject, String targetMethod, JComponent component)
targetObject
- the target object where the targetMethod can be found.targetMethod
- the full method name (including things like 'set') which will be executed afterwards.component
- when passed a component it will be disabled at start, and enabled again at leaving
this method. Use this to disable the button that triggered this action.public void hide(int buttonType)
public void hide()
protected void buttonPressedSlot(int type)
public void addActionListener(ActionListener listener)
public void removeActionListener(ActionListener listener)
public void enableApplyButtonSlot(boolean enable)
public void enableUser1ButtonSlot(boolean enable)
public void enableUser2ButtonSlot(boolean enable)
public void enableUser3ButtonSlot(boolean enable)
public void enableOKButtonSlot(boolean enable)
public void changeUser1ButtonTextSlot(String buttonText)
public void changeUser2ButtonTextSlot(String buttonText)
public void changeUser3ButtonTextSlot(String buttonText)
public TranslationInterface translate()
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |