uic.widgets
Class StandardDialog

java.lang.Object
  |
  +--uic.widgets.StandardDialog
Direct Known Subclasses:
ConfigDialog

public class StandardDialog
extends Object

A replacement for all you 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) {
              content.setFont(selected);
          }
      });
      // the show follows here just like above.
  

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
           
protected  JDialog internalDialog
           
static int OK_APPLY_CANCEL
           
static int OK_CANCEL
           
 
Constructor Summary
StandardDialog(Window owner, String title, boolean modal, int type)
          Create an invisible dialog with an optional owner, title and buttons.
StandardDialog(Window owner, String title, int type)
          Convinience constructor for a modal dialog
 
Method Summary
 void addActionListener(ActionListener listener)
          Add a listener to listen for non-closing buttons.
 void addToolbar(JToolBar toolbar, int side)
          Place a toolbar on the dialog.
protected  void buttonPressedSlot(int type)
           
 Rectangle getBounds()
          During or after showing you can query the rectangle of the dialog.
 Point getLocation()
          During or after showing you can query the location of the dialog.
 Dimension getSize()
          During or after showing you can query the size of the dialog.
protected  void positionDialog(boolean move)
          Place the dialog on screen.
 void setComponent(Component c)
          Place a Component on your dialog.
 int show()
          Convenience method for the next version.
 int show(Point location, Dimension size)
          Show the dialog at the given location.
 int show(Rectangle dialogBounds)
          Convenience method for the above version.
 uic.TranslationInterface translate()
          Overload this method to provide translations...
 
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

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

internalDialog

protected JDialog internalDialog
Constructor Detail

StandardDialog

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


StandardDialog

public StandardDialog(Window owner,
                      String title,
                      boolean modal,
                      int type)
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.
Method Detail

setComponent

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


show

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

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

show

public int show(Rectangle dialogBounds)
Convenience method for the above version.

Returns:
the last pressed button is returned (the enum of which the values can be found above).

show

public int show()
Convenience method for the next version.

Returns:
the last pressed button is returned (the enum of which the values can be found above).

addToolbar

public void addToolbar(JToolBar toolbar,
                       int side)
Place a toolbar on the dialog. Note that you can add as many toolbars as you like, they will all be visible at the same time.

Parameters:
toolbar - the toolbar to place on the dialog
side - the position SwingConstants.TOP, SwingConstants.LEFT, SwingConstants.BOTTOM and SwingConstants.RIGHT are allowed.

positionDialog

protected void positionDialog(boolean move)
Place the dialog on screen. Note that this dialog also checks constraints like monitor edges (usefull on multi-monitor setups) and therefor can move slightly even if the move argument is false.

Parameters:
move - the user allows us to move the dialog.

getLocation

public Point getLocation()
During or after showing you can query the location of the dialog. This is usefull to remember and position the same dialog at the same location again next time it is shown.

Returns:
the location
See Also:
show(Point, Dimension)

getSize

public Dimension getSize()
During or after showing you can query the size of the dialog. This is usefull to remember and position the same dialog with the same size again next time it is shown.

Returns:
the size
See Also:
show(Point, Dimension)

getBounds

public Rectangle getBounds()
During or after showing you can query the rectangle of the dialog. This is usefull to remember and position the same dialog with the same size and position again next time it is shown.

Returns:
the size and location bound in a rectangle
See Also:
show(Rectangle)

buttonPressedSlot

protected void buttonPressedSlot(int type)

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


translate

public uic.TranslationInterface translate()
Overload this method to provide translations...



Copyright © 2002,2003 Thomas Zander