uic.widgets
Class StandardDialog

java.lang.Object
  extended byuic.widgets.AbstractWindow
      extended byuic.widgets.StandardDialog
Direct Known Subclasses:
ConfigDialog

public class StandardDialog
extends AbstractWindow

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

Since:
1.1

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

BUTTON_OK

public static final int BUTTON_OK
See Also:
Constant Field Values

BUTTON_CANCEL

public static final int BUTTON_CANCEL
See Also:
Constant Field Values

BUTTON_APPLY

public static final int BUTTON_APPLY
See Also:
Constant Field Values

BUTTON_DEFAULTS

public static final int BUTTON_DEFAULTS
See Also:
Constant Field Values

BUTTON_HELP

public static final int BUTTON_HELP
See Also:
Constant Field Values

BUTTON_USER1

public static final int BUTTON_USER1
See Also:
Constant Field Values

BUTTON_USER2

public static final int BUTTON_USER2
See Also:
Constant Field Values

BUTTON_USER3

public static final int BUTTON_USER3
See Also:
Constant Field Values

OK_CANCEL

public static final int OK_CANCEL
See Also:
Constant Field Values

OK_APPLY_CANCEL

public static final int OK_APPLY_CANCEL
See Also:
Constant Field Values

PROPERTY_ENABLE_OK

public static final String PROPERTY_ENABLE_OK
See Also:
Constant Field Values

PROPERTY_ENABLE_APPLY

public static final String PROPERTY_ENABLE_APPLY
See Also:
Constant Field Values

PROPERTY_ENABLE_USER1

public static final String PROPERTY_ENABLE_USER1
See Also:
Constant Field Values

PROPERTY_ENABLE_USER2

public static final String PROPERTY_ENABLE_USER2
See Also:
Constant Field Values

PROPERTY_ENABLE_USER3

public static final String PROPERTY_ENABLE_USER3
See Also:
Constant Field Values

PROPERTY_TEXT_USER1

public static final String PROPERTY_TEXT_USER1
See Also:
Constant Field Values

PROPERTY_TEXT_USER2

public static final String PROPERTY_TEXT_USER2
See Also:
Constant Field Values

PROPERTY_TEXT_USER3

public static final String PROPERTY_TEXT_USER3
See Also:
Constant Field Values

CONFIG_ALLOW_ESC_CLOSE

public static final String CONFIG_ALLOW_ESC_CLOSE
Config key for allowing ESC to close (cancel) a dialog. The key is used for ThemeStrore.getProperty to fetch the user setting.

See Also:
Constant Field Values
Constructor Detail

StandardDialog

public StandardDialog(Window owner,
                      String title,
                      int type)
Convinience constructor for a non-modal dialog


StandardDialog

public StandardDialog(Window owner,
                      String title,
                      boolean modal,
                      int type)
Convinience constructor


StandardDialog

public StandardDialog(Window owner,
                      String title,
                      boolean modal,
                      int type,
                      String user1Text)
Convinience constructor


StandardDialog

public StandardDialog(Window owner,
                      String title,
                      boolean modal,
                      int type,
                      String user1Text,
                      String user2Text)
Convinience constructor


StandardDialog

public 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. The buttons are specified with the 'type' argument. Use ORed button names to config your dialog. (BUTTON_OK | BUTTON_CANCEL) for example.

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()

Parameters:
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_USER1
user2Text - the text for button with code BUTTON_USER2
user3Text - the text for button with code BUTTON_USER3
Method Detail

createInternalWindow

protected Window createInternalWindow(Frame owner,
                                      String title,
                                      boolean modal)
Specified by:
createInternalWindow in class AbstractWindow

createInternalWindow

protected Window createInternalWindow(Dialog owner,
                                      String title,
                                      boolean modal)
Specified by:
createInternalWindow in class AbstractWindow

addCommandButton

public void addCommandButton(int type,
                             String name,
                             boolean left)
Add a button to the row of buttons on this dialog.

Parameters:
type - only BUTTON* types are allowed
name - the text put on the button, allows everything that Translate will eat.
left - if true position button left most.
Since:
1.2

setComponent

public void setComponent(Component c)
Place a Component on your dialog.

Overrides:
setComponent in class AbstractWindow

show

public int show(Point location,
                Dimension size)
Show the dialog at the given location.

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();
  

Overrides:
show in class AbstractWindow
Parameters:
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.
Returns:
the last pressed button is returned (the enum of which the values can be found above).
Throws:
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.
See Also:
showAndForget(Object,String)

showAndForget

public void showAndForget(Object targetObject,
                          String targetMethod)
Convinience method.

Since:
1.2

showAndForget

public 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.

Parameters:
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.
Since:
1.2

hide

public void hide(int buttonType)
Hide and register buttonPress by argument buttonType. Will make the 'show' method return.

Since:
1.2

hide

public void hide()
Hide the dialog making the 'show' method return.

Since:
1.2

buttonPressedSlot

protected void buttonPressedSlot(int type)
Called by the buttons.


addActionListener

public void addActionListener(ActionListener listener)
Add a listener to listen for non-closing buttons. The buttons that do not have the effect of closing the dialog (i.e. the ok and cancel) are broadcast as ActionEvent objects. The type of the action with be one of the BUTTON_* variables in this class. For example the BUTTON_APPLY


removeActionListener

public void removeActionListener(ActionListener listener)
Remove a previously registered actionListener.

Since:
1.2

enableApplyButtonSlot

public void enableApplyButtonSlot(boolean enable)
Set the apply button to be enabled per argument enable.

Since:
1.2

enableUser1ButtonSlot

public void enableUser1ButtonSlot(boolean enable)
Set the user1 button to be enabled per argument enable.

Since:
1.2

enableUser2ButtonSlot

public void enableUser2ButtonSlot(boolean enable)
Set the user2 button to be enabled per argument enable.

Since:
1.2

enableUser3ButtonSlot

public void enableUser3ButtonSlot(boolean enable)
Set the user3 button to be enabled per argument enable.

Since:
1.2

enableOKButtonSlot

public void enableOKButtonSlot(boolean enable)
Set the ok button to be enabled per argument enable.

Since:
1.2

changeUser1ButtonTextSlot

public void changeUser1ButtonTextSlot(String buttonText)
Set the user1 button text to the argument buttonText

Since:
1.2

changeUser2ButtonTextSlot

public void changeUser2ButtonTextSlot(String buttonText)
Set the user2 button text to the argument buttonText

Since:
1.2

changeUser3ButtonTextSlot

public void changeUser3ButtonTextSlot(String buttonText)
Set the user3 button text to the argument buttonText

Since:
1.2

translate

public TranslationInterface translate()


Copyright © 2002,2003 Thomas Zander Available under the Free Apache licence