ccs.utils
Class FormDialog

java.lang.Object
  extended by ccs.utils.FormDialog
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class FormDialog
extends java.lang.Object
implements java.awt.event.ActionListener

A Form dialog is a wrapper aorund a JOptionPane.confirmDialog which implements CP-compliant keyboard handling, and a slightly terser syntax. It can be used directly; however, it may be easier to use one of the pre-packaged dialog classes instead. These all use FormDialog as an infrastructure layer.


Constructor Summary
FormDialog(java.awt.Component parent, java.lang.Object[] oa, int iconCode, javax.swing.JButton[] buttons, int[] codes, java.lang.String title)
          Create a new FormDialog.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
           
static int[] createButtonCodeSet(int buttonsCode)
          Create a set of buttons codes corresponding to the given JOptionPane code.
static javax.swing.JButton[] createButtonSet(int buttonsCode)
          Create a set of buttons corresponding to the given JOptionPane code.
 void emulateButtonPress(int idx)
          Programmatically "presses" a button.
static javax.swing.KeyStroke enterStroke()
          Utility to make registerKeyboardAction syntax more compact.
static javax.swing.KeyStroke escapeStroke()
          Utility to make registerKeyboardAction syntax more compact.
static java.awt.Font getTitleFont()
           
static void setDefaultFonts()
          Asserts our default fonts.
 int show()
          shows the dialog.
static boolean show(java.awt.Component parent, java.lang.Object content, java.lang.String title)
          Show a standard "data entry" dialog.
static boolean show(java.awt.Component parent, java.lang.Object content, java.lang.String title, boolean isConfirm, int iconCode, int buttonsCode)
          Show a standard "data entry" or "message" dialog.
static int showCode(java.awt.Component parent, java.lang.Object content, java.lang.String title, boolean isConfirm, int iconCode, int buttonsCode)
          Show a standard "data entry" or "message" dialog.
static int when()
          Utility to make registerKeyboardAction syntax more compact.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FormDialog

public FormDialog(java.awt.Component parent,
                  java.lang.Object[] oa,
                  int iconCode,
                  javax.swing.JButton[] buttons,
                  int[] codes,
                  java.lang.String title)
Create a new FormDialog. You can use this directly (followed by show) if you need maximum flexibility. However, you should generally use one of the show or showCode wrapper methods. They're easier, and more stable. Note: Killing the dialog is deemed to be equivalent to pressing the last button in the list. Therefore, this button had better be logically equivalent to pressing Cancel.

Parameters:
parent - The Component this dangles from. If null, uses its initiative.
oa - The objects which form the body of the dialog.
iconCode - The JOptionPane code for the icon to use.
buttons - The array of buttons to use. These can be newly-created and not hooked up to anything; the FormDialog takes care of all that.
codes - the JOptionPane codes corresponding to the buttons
title - The dialog box title.
Method Detail

setDefaultFonts

public static void setDefaultFonts()
Asserts our default fonts. Java1.4's defaults are horrible.


getTitleFont

public static java.awt.Font getTitleFont()

show

public int show()
shows the dialog. Note that, unlike all the other show variants, this is not static.

Returns:
The JOptionPane code corresponding to the button pushed to close the dialog.

enterStroke

public static javax.swing.KeyStroke enterStroke()
Utility to make registerKeyboardAction syntax more compact. This started here for historical reasons, and remains because this class is all about dialog infrastructure, so it's a good enough fit not to be worth disturbing.


escapeStroke

public static javax.swing.KeyStroke escapeStroke()
Utility to make registerKeyboardAction syntax more compact. This started here for historical reasons, and remains because this class is all about dialog infrastructure, so it's a good enough fit not to be worth disturbing.


when

public static int when()
Utility to make registerKeyboardAction syntax more compact. This started here for historical reasons, and remains because this class is all about dialog infrastructure, so it's a good enough fit not to be worth disturbing.


show

public static boolean show(java.awt.Component parent,
                           java.lang.Object content,
                           java.lang.String title)
Show a standard "data entry" dialog. content is interpreted flexibly as for JOptionPane and can be pretty much any object, or any array of objects, you like!

Parameters:
parent - The frame to dangle the dialog from. If null, it uses its initiative.
content - The object or array of objects to display.
title - The box title.
Returns:
true if the user committed the form (clicking OK or equivalent), false if they aborted it (clicking Cancel or equivalent).

show

public static boolean show(java.awt.Component parent,
                           java.lang.Object content,
                           java.lang.String title,
                           boolean isConfirm,
                           int iconCode,
                           int buttonsCode)
Show a standard "data entry" or "message" dialog. content is interpreted flexibly as for JOptionPane and can be pretty much any object, or any array of objects, you like! It does not make sense to use this wrapper for a message with more than two possible replies.

Parameters:
parent - The frame to dangle the dialog from. If null, it uses its initiative.
content - The object or array of objects to display.
title - The box title.
isConfirm - True for a confirmDialog, false for a messageDialog.
iconCode - For a messageDialog only, the JOptionPane code for the icon.
buttonsCode - For a confirmDialog only, the JOptionPane code for which buttons are needed.
Returns:
true if the user committed the form (clicking OK / Yes or equivalent), false if they aborted it (clicking No / Cancel or equivalent). A messageDialog always returns true.

showCode

public static int showCode(java.awt.Component parent,
                           java.lang.Object content,
                           java.lang.String title,
                           boolean isConfirm,
                           int iconCode,
                           int buttonsCode)
Show a standard "data entry" or "message" dialog. content is interpreted flexibly as for JOptionPane and can be pretty much any object, or any array of objects, you like!

Parameters:
parent - The frame to dangle the dialog from. If null, it uses its initiative.
content - The object or array of objects to display.
title - The box title.
isConfirm - True for a confirmDialog, false for a messageDialog.
iconCode - For a messageDialog, the JOptionPane code for the icon.
buttonsCode - For a confirmDialog, the JOptionPane code for which buttons are needed.
Returns:
For a confirmDialog, the JOptionPane code for the return, else JOptionPane.OK_OPTION.

createButtonSet

public static javax.swing.JButton[] createButtonSet(int buttonsCode)
Create a set of buttons corresponding to the given JOptionPane code. Use with createButtonCodeSet.


createButtonCodeSet

public static int[] createButtonCodeSet(int buttonsCode)
Create a set of buttons codes corresponding to the given JOptionPane code. Use with createButtonSet.


emulateButtonPress

public void emulateButtonPress(int idx)
Programmatically "presses" a button.

Parameters:
idx - The index of the button to press, in the array of buttons passed to the constructor.

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Specified by:
actionPerformed in interface java.awt.event.ActionListener