/*
 * @(#)GeneralDialog.java    2.3.3  5 December 2004
 *
 * Copyright 2004
 * College of Computer and Information Science
 * Northeastern University
 * Boston, MA  02115
 *
 * The Java Power Tools software may be used for educational
 * purposes as long as this copyright notice is retained intact
 * at the top of all source files.
 *
 * To discuss possible commercial use of this software, 
 * contact Richard Rasala at Northeastern University, 
 * College of Computer and Information Science,
 * 617-373-2462 or rasala@ccs.neu.edu.
 *
 * The Java Power Tools software has been designed and built
 * in collaboration with Viera Proulx and Jeff Raab.
 *
 * Should this software be modified, the words "Modified from 
 * Original" must be included as a comment below this notice.
 *
 * All publication rights are retained.  This software or its 
 * documentation may not be published in any media either
 * in whole or in part without explicit permission.
 *
 * This software was created with support from Northeastern 
 * University and from NSF grant DUE-9950829.
 */

package edu.neu.ccs.gui;

import java.awt.*;
import javax.swing.*;
import java.util.*;

import edu.neu.ccs.*;
import edu.neu.ccs.gui.*;
import edu.neu.ccs.util.*;
import edu.neu.ccs.console.*;

/**
 * <P>A dialog box containing 
 * a <CODE>{@link Component Component}</CODE> 
 * and an <CODE>{@link ActionsPanel ActionsPanel}</CODE> 
 * that contains actions to respond to and dismiss the dialog.</P>
 *
 * @author  Jen McDonald
 * @author  Richard Rasala
 * @version 2.3.3
 * @since   2.0
 */
public class GeneralDialog
    extends JDialog
    implements JPTConstants, ConsoleAware
{
    /** Response returned by the default dialog window closing action. */
    public static final String WINDOW_CLOSED = "Window Closed";
    
    /** <CODE>Component</CODE> displayed in this dialog. */
    protected Component component = null;
    
    /** <CODE>ActionsPanel</CODE> with the user response buttons. */
    protected ActionsPanel actionsPanel = new ActionsPanel();
    
    /** Window closing action for this dialog. */
    protected DialogAction windowClosingAction = null;
    
    /** Window opened action for this dialog. */
    protected Action windowOpenedAction = null;
    
    /** Window action adapter for this dialog. */
    protected WindowActionAdapter windowActionAdapter = null;
    
    /** Parent <CODE>Frame</CODE> if any. */
    protected Frame parentFrame = null;
    
    /** Parent <CODE>Dialog</CODE> if any. */
    protected Dialog parentDialog = null;
    
    /** User response to this dialog. */
    protected String response = "";
    
    /** Whether or not this dialog was dismissed by cancellation. */
    protected boolean cancelled = false;

    //////////////////
    // Constructors //
    //////////////////    

    /**
     * <P>Constructs a modal general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * an empty dialog title,
     * an empty <CODE>ActionsPanel</CODE>,
     * and no parent window.</P>
     *
     * <p>Other constructors:</p>
     *
     * <ul><code>
     *   <li>GeneralDialog(Object, String)</li>
     *   <li>GeneralDialog(Object, String, Object[][])</li>
     *   <li>GeneralDialog(Object, String, Object[][], boolean)</li>
     *   <li>GeneralDialog(Object, String, Object[][], boolean, Frame)</li>
     *   <li>GeneralDialog(Object, String, Object[][], boolean, Dialog)</li>
     *   <li>GeneralDialog(Object, String, Object[][], Object)</li>
     *   <li>GeneralDialog(Object, String, Object[][], Object, boolean)</li>
     *   <li>GeneralDialog(Object, String, Object[][], Object, boolean, Frame)</li>
     *   <li>GeneralDialog(Object, String, Object[][], Object, boolean, Dialog)</li>
     * </code></ul>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * @param displayObject the object to display in the dialog
     */
    public GeneralDialog(Object displayObject) {
        this(displayObject, "", null, null, true, (Frame)null);
    }
    
    /**
     * <P>Constructs a modal general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an empty <CODE>ActionsPanel</CODE>,
     * and no parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE>
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object)
     */
    public GeneralDialog(Object displayObject, String title) {
        this(displayObject, title, null, null, true, (Frame)null);
    }
    
    /**
     * <P>Constructs a modal general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * and no parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @see #GeneralDialog(Object)
     */
    public GeneralDialog
        (Object displayObject, String title, Object[][] actionData)
    {
        this(displayObject, title, actionData, null, true, (Frame)null);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the given choice of whether or not the dialog is modal,
     * and no parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE>
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param modal the choice of whether or not the dialog is modal
     * @see #GeneralDialog(Object)
     */
    public GeneralDialog(
        Object     displayObject, 
        String     title, 
        Object[][] actionData, 
        boolean    modal)
    {
        this(displayObject, title, actionData, null, modal, (Frame)null);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the given choice of whether or not the dialog is modal,
     * and the given parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE>
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param modal the choice of whether or not the dialog is modal
     * @param parent the parent window
     * @see #GeneralDialog(Object)
     */
    public GeneralDialog(
        Object     displayObject,
        String     title,
        Object[][] actionData,
        boolean    modal,
        Frame      parent
    ) {
        this(displayObject, title, actionData, null, modal, parent);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the given choice of whether or not the dialog is modal,
     * and the given parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param modal the choice of whether or not the dialog is modal
     * @param parent the parent window
     * @see #GeneralDialog(Object)
     */
    public GeneralDialog(
        Object     displayObject,
        String     title,
        Object[][] actionData,
        boolean    modal,
        Dialog     parent
    ) {
        this(displayObject, title, actionData, null, modal, parent);
    }
    
    /**
     * <P>Constructs a modal general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the action for the default button,
     * and no parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * <p>The <code>Object</code> supplied for the default action must either be
     * an <code>Action</code> or a name that is supplied in the action data.  If
     * the parameter is <code>null</code>, no default action is set.</p>
     * 
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param defaultAction the default action
     * @see #GeneralDialog(Object)
     * @since 2.3.3
     */
    public GeneralDialog
        (Object displayObject, String title, Object[][] actionData, Object defaultAction)
    {
        this(displayObject, title, actionData, defaultAction, true, (Frame)null);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the action for the default button,
     * the given choice of whether or not the dialog is modal,
     * and no parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE>
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * <p>The <code>Object</code> supplied for the default action must either be
     * an <code>Action</code> or a name that is supplied in the action data.  If
     * the parameter is <code>null</code>, no default action is set.</p>
     * 
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param defaultAction the default action
     * @param modal the choice of whether or not the dialog is modal
     * @see #GeneralDialog(Object)
     * @since 2.3.3
     */
    public GeneralDialog(
        Object     displayObject, 
        String     title, 
        Object[][] actionData,
        Object     defaultAction, 
        boolean    modal)
    {
        this(displayObject, title, actionData, defaultAction, modal, (Frame)null);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the action for the default button,
     * the given choice of whether or not the dialog is modal,
     * and the given parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE>
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * <p>The <code>Object</code> supplied for the default action must either be
     * an <code>Action</code> or a name that is supplied in the action data.  If
     * the parameter is <code>null</code>, no default action is set.</p>
     * 
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param defaultAction the default action
     * @param modal the choice of whether or not the dialog is modal
     * @param parent the parent window
     * @see #GeneralDialog(Object)
     * @since 2.3.3
     */
    public GeneralDialog(
        Object     displayObject,
        String     title,
        Object[][] actionData,
        Object     defaultAction, 
        boolean    modal,
        Frame      parent
    ) {
        super(parent, (title == null) ? "" : title, modal);
        
        parentFrame = parent;
        
        initializeGeneralDialog(displayObject, actionData, defaultAction);
    }
    
    /**
     * <P>Constructs a general dialog containing the
     * <CODE>Component</CODE> associated with the given display object,
     * the given dialog title,
     * an <CODE>ActionsPanel</CODE> constructed from the given action data,
     * the action for the default button,
     * the given choice of whether or not the dialog is modal,
     * and the given parent window.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <p>The parameter <code>actionData</code> 
     * is an <code>Object[][]</code> array that specifies 
     * each dialog <code>Action</code> in one of the following ways:</p>
     * 
     * <ul>
     *   <li> A subarray { action }             with an <code>Action</code></li>
     *   <li> A subarray { name }               with an action name</li>
     *   <li> A subarray { name, icon }         with an action name and icon</li>
     *   <li> A subarray { action, option }
     *   <li> A subarray { name, option }
     *   <li> A subarray { name, icon, option }
     * </ul>
     *
     * <p>If the option parameter is specified, it must be one of the following
     * values that will determine what is done to the dialog when the action is
     * finished:</p>
     *
     * <ul><code>
     *   <li> DialogAction.KEEP_OPEN</li>
     *   <li> DialogAction.AUTO_CLOSE</li>
     *   <li> DialogAction.SET_CANCEL</li>
     * </code></ul>
     *
     * <p>If the option parameter is not specified, it is taken to be
     * <code>DialogAction.AUTO_CLOSE</code>.</p>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * <p>The <code>Object</code> supplied for the default action must either be
     * an <code>Action</code> or a name that is supplied in the action data.  If
     * the parameter is <code>null</code>, no default action is set.</p>
     * 
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param actionData the array used to generate the dialog actions
     * @param defaultAction the default action
     * @param modal the choice of whether or not the dialog is modal
     * @param parent the parent window
     * @see #GeneralDialog(Object)
     * @since 2.3.3
     */
    public GeneralDialog(
        Object     displayObject,
        String     title,
        Object[][] actionData,
        Object     defaultAction, 
        boolean    modal,
        Dialog     parent
    ) {
        super(parent, (title == null) ? "" : title, modal);
        
        parentDialog = parent;
        
        initializeGeneralDialog(displayObject, actionData, defaultAction);
    }
    
    ////////////////
    // Public API //
    ////////////////
    
    /**
     * Overrides the default <CODE>setVisible</CODE> behavior 
     * to automatically pack and center when the dialog is shown.
     *
     * @param makeVisible whether or not to make the dialog visible
     * @see #center()
     */
    public void setVisible(boolean makeVisible) {
        if (isVisible() == makeVisible)
            return;
        
        if (makeVisible) {
            pack();
            center();
            
            super.setVisible(true);
        }
        else {
            super.setVisible(false);
            
            dispose();
        }
    }
    
    /**
     * Centers this dialog on the user screen or in its parent window.
     *
     * @see #setVisible(boolean)
     */
    public void center() {
        int xCenter = 0;
        int yCenter = 0;
        
        if (parentFrame != null) {
            Rectangle bounds = parentFrame.getBounds();
            
            xCenter = bounds.x + bounds.width  / 2;
            yCenter = bounds.y + bounds.height / 2;
        }
        else
        if (parentDialog != null) {
            Rectangle bounds = parentDialog.getBounds();
            
            xCenter = bounds.x + bounds.width  / 2;
            yCenter = bounds.y + bounds.height / 2;
        }
        else {
            Dimension dimension = 
                Toolkit.getDefaultToolkit().getScreenSize();
            
            xCenter = dimension.width  / 2;
            yCenter = dimension.height / 2;
        }
        
        int xSize = getWidth();
        int ySize = getHeight();
        
        setLocation(xCenter  - xSize / 2, yCenter  - ySize / 2);
    }
    
    /**
     * Returns the main component in this dialog.
     *
     * @see #getDialogActionsPanel()
     */
    public Component getDialogContents() {
        return component;
    }
    
    /**
     * Returns the actions panel for this dialog.
     *
     * @see #getDialogContents()
     */
    public ActionsPanel getDialogActionsPanel() {
        return actionsPanel;
    }
    
    /**
     * Returns the <CODE>Action</CODE> objects 
     * in the actions panel for this dialog.
     *
     * @see #getDialogActions()
     */
    public Action[] getActions() {
        return getDialogActionsPanel().getActions();
    }
    
    /**
     * <P>Returns the <CODE>DialogAction</CODE> objects 
     * in the actions panel for this dialog.</P>
     *
     * <P>Uses the same indexing as in the
     * <CODE>{@link #getActions getActions}</CODE> method
     * and returns <CODE>null</CODE> for those <CODE>Action</CODE> objects 
     * that are not <CODE>DialogAction</CODE> objects.</P>
     *
     * @see #getActions()
     */
    public DialogAction[] getDialogActions() {
        Action[] actionList = getActions();
        
        int length = actionList.length;
        
        DialogAction[] dialogActionList = new DialogAction[length];
        
        for (int i = 0; i < length; i++)
            if (actionList[i] instanceof DialogAction)
                dialogActionList[i] = (DialogAction) actionList[i];
        
        return dialogActionList;
    }
    
    /**
     * Adds the given dialog action 
     * to the actions panel for this dialog
     * and returns the associated button.
     * 
     * @param action the dialog action to add to the actions panel
     * @see #addAction(Action, Object)
     * @see #addAction(String, Object)
     * @see #addAction(String, Icon, Object)
     */
    public JButton addAction(DialogAction action) {
        return getDialogActionsPanel().addAction(action);
    }
    
    /**
     * <P>Adds the given ordinary action with the given finish parameter
     * to the actions panel for this dialog
     * and returns the associated button.</P>
     *
     * <P>The finish parameter must be one of the following values:
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the finish parameter is <CODE>null</CODE>,
     * or is not one of these values,
     * is <CODE>DialogAction.AUTO_CLOSE</CODE>.</P>
     *
     * @param action the ordinary action to add to the actions panel
     * @param finish what to do to the dialog when the action is done
     * @see #addAction(DialogAction)
     * @see #addAction(String, Object)
     * @see #addAction(String, Icon, Object)
     */
    public JButton addAction(Action action, Object finish) {
        return addAction(new DialogAction(this, action, finish));
    }
    
    /**
     * <P>Adds a trivial action with the given name and finish parameter
     * to the actions panel for this dialog
     * and returns the associated button.</P>
     *
     * <P>The finish parameter must be one of the following values:</P>
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the finish parameter is <CODE>null</CODE>,
     * or is not one of these values,
     * is <CODE>DialogAction.AUTO_CLOSE</CODE>.</P>
     *
     * @param name the name for a trivial action
     * @param finish what to do to the dialog when the action is done
     * @see #addAction(DialogAction)
     * @see #addAction(Action, Object)
     * @see #addAction(String, Icon, Object)
     */
    public JButton addAction(String name, Object finish) {
        return addAction(new DialogAction(this, name, finish));
    }
    
    /**
     * <P>Adds a trivial action 
     * with the given name, icon, and finish parameter 
     * to the actions panel for this dialog
     * and returns the associated button.</P>
     *
     * <P>The finish parameter must be one of the following values:</P>
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the finish parameter is <CODE>null</CODE>,
     * or is not one of these values,
     * is <CODE>DialogAction.AUTO_CLOSE</CODE>.</P>
     *
     * @param name the name for a trivial action
     * @param icon the icon for a trivial action
     * @param finish what to do to the dialog when the action is done
     * @see #addAction(DialogAction)
     * @see #addAction(Action, Object)
     * @see #addAction(String, Object)
     */
    public JButton addAction(String name, Icon icon, Object finish) {
        return addAction(new DialogAction(this, name, icon, finish));
    }
    
    /**
     * Sets the given button as the default button for this dialog. 
     *
     * If the given button is not in this dialog,
     * this method does nothing.
     *
     * @param button the button to set as the default button
     * @see #setDefaultButton(Action)
     * @see #setDefaultButton(String)
     * @see ActionsPanel#setDefaultButton(JButton)
     */
    public void setDefaultButton(JButton button) {
        getDialogActionsPanel().setDefaultButton(button);
    }
    
    /**
     * Sets the button that corresponds to the given action
     * as the default button for this dialog.
     *
     * If the given button is not in this dialog,
     * this method does nothing.
     *
     * @param action the action whose button should be the default button
     * @see #setDefaultButton(JButton)
     * @see #setDefaultButton(String)
     * @see ActionsPanel#setDefaultButton(Action)
     */
    public void setDefaultButton(Action action) {
        getDialogActionsPanel().setDefaultButton(action);
    }
         
    /**
     * Sets the button that corresponds to the given name
     * as the default button for this dialog.
     *
     * If the given button is not in this dialog,
     * this method does nothing.
     *
     * @param name the name whose button should be the default button
     * @see #setDefaultButton(JButton)
     * @see #setDefaultButton(Action)
     * @see ActionsPanel#setDefaultButton(String)
     */
    public void setDefaultButton(String name) {
        getDialogActionsPanel().setDefaultButton(name);
    }
         
    /**
     * Returns the current dialog window opened action.
     *
     * @see #setWindowOpenedAction(Action)
     */
    public Action getWindowOpenedAction() {
        return windowOpenedAction;
    }
    
    /**
     * Sets the dialog window opened action to the given action.
     *
     * @param action the action to perform when the user opens the dialog
     * @see #getWindowOpenedAction()
     */
    public void setWindowOpenedAction(Action action) {
        if (windowOpenedAction != null)
            windowActionAdapter.removeWindowOpenedAction(windowOpenedAction);
        
        windowOpenedAction = action;
        
        if (windowOpenedAction != null)
            windowActionAdapter.addWindowOpenedAction(windowOpenedAction);
    }
    
    /**
     * Returns the current dialog window closing action.
     *
     * @see #getDefaultWindowClosingAction()
     * @see #setWindowClosingAction(DialogAction)
     * @see #setWindowClosingAction(Action, Object)
     * @see #setWindowClosingAction(String, Object)
     */
    public DialogAction getWindowClosingAction() {
        return windowClosingAction;
    }
    
    /**
     * Returns the default dialog window closing action.
     * 
     * This action will close the dialog and set the dialog response 
     * to the value of the <CODE>String WINDOW_CLOSED</CODE>.
     *
     * @see #getWindowClosingAction()
     * @see #setWindowClosingAction(DialogAction)
     * @see #setWindowClosingAction(Action, Object)
     * @see #setWindowClosingAction(String, Object)
     */
    public DialogAction getDefaultWindowClosingAction() {
        return new DialogAction(
            this, WINDOW_CLOSED, DialogAction.AUTO_CLOSE);
    }
    
    /**
     * Sets the dialog window closing action
     * to the given dialog action.
     *
     * If the given <CODE>action</CODE> is <CODE>null</CODE>
     * then the default window closing action will be installed.
     *
     * @param action the action to perform if the user closes the dialog
     * @see #getWindowClosingAction()
     * @see #getDefaultWindowClosingAction()
     * @see #setWindowClosingAction(Action, Object)
     * @see #setWindowClosingAction(String, Object)
     */
    public void setWindowClosingAction(DialogAction action) {
        if (windowClosingAction != null)
            windowActionAdapter.removeWindowClosingAction(windowClosingAction);
        
        if (action != null)
            windowClosingAction = action;
        else
            windowClosingAction = getDefaultWindowClosingAction();
        
        windowActionAdapter.addWindowClosingAction(windowClosingAction);
    }
    
    /**
     * <P>Sets the dialog window closing action
     * to a dialog action created from the given ordinary action
     * and the given dialog finish parameter.</P>
     *
     * <P>The finish parameter must be one of the following values:</P>
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the finish parameter is <CODE>null</CODE>,
     * or is not one of these values,
     * is <CODE>DialogAction.AUTO_CLOSE</CODE>.</P>
     *
     * @param action the action to perform if the user closes the dialog
     * @param finish what to do to the dialog when the action is done
     * @see #getWindowClosingAction()
     * @see #getDefaultWindowClosingAction()
     * @see #setWindowClosingAction(DialogAction)
     * @see #setWindowClosingAction(String, Object)
     */
    public void setWindowClosingAction(Action action, Object finish) {
        setWindowClosingAction(new DialogAction(this, action, finish));
    }
    
    /**
     * <P>Sets the dialog window closing action
     * to a dialog action created with the given name
     * and the given dialog finish parameter.
     *
     * The created action will do work.</P>
     *
     * <P>The finish parameter must be one of the following values:</P>
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the finish parameter is <CODE>null</CODE>,
     * or is not one of these values,
     * is <CODE>DialogAction.AUTO_CLOSE</CODE>.</P>
     *
     * @param name the name for a trivial action
     * @param finish what to do to the dialog when the action is done
     * @see #getWindowClosingAction()
     * @see #getDefaultWindowClosingAction()
     * @see #setWindowClosingAction(DialogAction)
     * @see #setWindowClosingAction(Action, Object)
     */
    public void setWindowClosingAction(String name, Object finish) {
        setWindowClosingAction(new DialogAction(this, name, finish));
    }
    
    /**
     * Returns the <CODE>WindowActionAdapter</CODE> for this dialog.
     */
    public WindowActionAdapter getWindowActionAdapter() {
        return windowActionAdapter;
    }
    
    /**
     * Returns the user's response to this dialog.
     * 
     * If this method is called before the dialog is closed
     * then the return value is undefined.
     *
     * @see #setResponseAndClose(String)
     * @see #closeDialog()
     */
    public String getResponse() {
        return response;
    }
    
    /**
     * Returns whether or not this dialog was dismissed by cancellation.
     *
     * If this method is called before the dialog has been dismissed,
     * this method will return <CODE>false</CODE>.     
     */
    public boolean wasCancelled() {
        return cancelled;
    }
    
    ////////////////////
    // Static Methods //
    ////////////////////
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single action button that is the default button.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param action the action to install as a button
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static GeneralDialog makeOneButtonDialog
        (Object displayObject, String title, Action action)
    {
        GeneralDialog dialog = new GeneralDialog
            (displayObject, title, new Object[][] {{ action }}, action);
        
        dialog.setWindowClosingAction(action, DialogAction.AUTO_CLOSE);
        
        return dialog;
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single action button that is the default button.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param action the action to install as a button
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static String showOneButtonDialog
        (Object displayObject, String title, Action action)
    {
        GeneralDialog dialog = makeOneButtonDialog
            (displayObject, title, action);
        
        dialog.setVisible(true);
        
        return dialog.getResponse();
    }
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single default button with the given name.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param name the name to install on the button
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static GeneralDialog makeOneButtonDialog
        (Object displayObject, String title, String name)
    {
        return makeOneButtonDialog
            (displayObject, title, DialogAction.makeTrivialAction(name));
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single default button with the given name.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param name the name to install on the button
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static String showOneButtonDialog
        (Object displayObject, String title, String name)
    {
        GeneralDialog dialog = makeOneButtonDialog
            (displayObject, title, name);
        
        dialog.setVisible(true);
        
        return dialog.getResponse();
    }
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single default button with the given name and icon.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param name the name to install on the button
     * @param icon the icon to install on the button
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static GeneralDialog makeOneButtonDialog
        (Object displayObject, String title, String name, Icon icon)
    {
        return makeOneButtonDialog
            (displayObject, 
             title, 
             DialogAction.makeTrivialAction(name, icon));
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and a single default button with the given name and icon.
     *
     * Closing the dialog window is equivalent to clicking the button.
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @param name the name to install on the button
     * @param icon the icon to install on the button
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     * @see #showOKDialog(Object, String)
     */
    public static String showOneButtonDialog
        (Object displayObject, String title, String name, Icon icon)
    {
        GeneralDialog dialog = makeOneButtonDialog
            (displayObject, title, name, icon);
        
        dialog.setVisible(true);
        
        return dialog.getResponse();
    }
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and with an "OK" button that is the default button.
     *
     * Closing the dialog window is equivalent to clicking "OK".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #showOKDialog(Object, String)
     */
    public static GeneralDialog makeOKDialog(
        Object displayObject, 
        String title) 
    {
        return makeOneButtonDialog(displayObject, title, "OK");
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> with the given display object and
     * title and with an "OK" button that is the default button.
     *
     * Closing the dialog window is equivalent to clicking "OK".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOneButtonDialog(Object, String, Action)
     * @see #showOneButtonDialog(Object, String, Action)
     * @see #makeOneButtonDialog(Object, String, String)
     * @see #showOneButtonDialog(Object, String, String)
     * @see #makeOneButtonDialog(Object, String, String, Icon)
     * @see #showOneButtonDialog(Object, String, String, Icon)
     * @see #makeOKDialog(Object, String)
     */
    public static String showOKDialog(Object displayObject, String title) {
        GeneralDialog dialog = makeOKDialog(displayObject, title);
        
        dialog.setVisible(true);
        
        return dialog.getResponse();
    }
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and "OK" and a "Cancel" buttons with "OK" as the default.
     *
     * Clicking "Cancel" will set the cancelled state of the dialog to true.
     *
     * Closing the dialog window is equivalent to clicking "Cancel".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #showOKCancelDialog(Object, String)
     */
    public static GeneralDialog makeOKCancelDialog
        (Object displayObject, String title)
    {
        Action OK     = DialogAction.makeTrivialAction("OK");
        Action Cancel = DialogAction.makeTrivialAction("Cancel");
        
        Object[][] actionData =
            new Object[][] {
                { OK },
                { Cancel, DialogAction.SET_CANCEL }
            };
        
        GeneralDialog dialog =
            new GeneralDialog(displayObject, title, actionData, OK);
        
        dialog.setWindowClosingAction(Cancel, DialogAction.SET_CANCEL);
        
        return dialog;
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and "OK" and a "Cancel" buttons with "OK" as the default.
     *
     * Clicking "Cancel" will throw a <CODE>CancelledException</CODE>.
     *
     * Closing the dialog window is equivalent to clicking "Cancel".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeOKCancelDialog(Object, String)
     */
    public static String showOKCancelDialog
        (Object displayObject, String title) throws CancelledException
    {
        GeneralDialog dialog = makeOKCancelDialog(displayObject, title);
        
        dialog.setVisible(true);
        
        if (dialog.wasCancelled())
            throw new CancelledException();
        
        return dialog.getResponse();
    }
    
    /**
     * Makes a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and "Yes", "No", and "Cancel" buttons 
     * with "Yes" as the default.
     *
     * Clicking "Cancel" will set the cancelled state of the dialog to true.
     *
     * Closing the dialog window is equivalent to clicking "Cancel".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #showYesNoCancelDialog(Object, String)
     */
    public static GeneralDialog makeYesNoCancelDialog
        (Object displayObject, String title)
    {
        Action Yes    = DialogAction.makeTrivialAction("Yes");
        Action No     = DialogAction.makeTrivialAction("No");
        Action Cancel = DialogAction.makeTrivialAction("Cancel");
        
        Object[][] actionData =
            new Object[][] {
                { Yes },
                { No },
                { Cancel, DialogAction.SET_CANCEL }
            };
        
        GeneralDialog dialog =
            new GeneralDialog(displayObject, title, actionData, Yes);
        
        dialog.setWindowClosingAction(Cancel, DialogAction.SET_CANCEL);
        
        return dialog;
    }
    
    /**
     * Shows a <CODE>GeneralDialog</CODE> 
     * with the given display object and title 
     * and "Yes", "No", and "Cancel" buttons 
     * with "Yes" as the default.
     *
     * Clicking "Cancel" will throw a <CODE>CancelledException</CODE>.
     *
     * Closing the dialog window is equivalent to clicking "Cancel".
     *
     * @param displayObject the object to display in the dialog
     * @param title the title text for the dialog
     * @see #GeneralDialog(Object, String, Object[][])
     * @see #makeYesNoCancelDialog(Object, String)
     */
    public static String showYesNoCancelDialog
        (Object displayObject, String title) throws CancelledException
    {
        GeneralDialog dialog = makeYesNoCancelDialog(displayObject, title);
        
        dialog.setVisible(true);
        
        if (dialog.wasCancelled())
            throw new CancelledException();
        
        return dialog.getResponse();
    }
    
    ////////////////////
    // Hidden methods //
    ////////////////////

    /**
     * <P>Performs the common tasks required for constructors of this class
     * using the given display object, action data, and default action.</P>
     *
     * <P>The given <CODE>displayObject</CODE> parameter
     * will be converted to a <CODE>Component</CODE> 
     * using the <CODE>{@link #makeComponent makeComponent}</CODE> method.</P>
     *
     * <P>If the given display object is <CODE>null</CODE> 
     * or has no associated <CODE>Component</CODE>, 
     * an empty <CODE>JPanel</CODE> will be added.</P>
     *
     * <P>The parameter <CODE>actionData</CODE> 
     * is an <CODE>Object[][]</CODE> array that specifies 
     * each <CODE>Action</CODE> in one of the following ways:</P>
     * 
     * <UL>
     *   <LI> A subarray { action }             with an action.
     *   <LI> A subarray { name }               with an action name.
     *   <LI> A subarray { name, icon }         with an action name and icon.
     *   <LI> A subarray { action, option }
     *   <LI> A subarray { name, option }
     *   <LI> A subarray { name, icon, option }
     * </UL>
     *
     * <P>The option parameter must be one of the following values 
     * that will determine what is done to the dialog 
     * when the action is finished:</P>
     *
     * <UL>
     *   <LI> DialogAction.KEEP_OPEN
     *   <LI> DialogAction.AUTO_CLOSE
     *   <LI> DialogAction.SET_CANCEL
     * </UL>
     *
     * <P>The default if the option is not specified 
     * is DialogAction.AUTO_CLOSE.</P>
     *
     * <P>All actions specified by the parameter <CODE>actionData</CODE> 
     * will be encapsulated as <CODE>DialogAction</CODE> objects.</P>
     *
     * <p>The <code>Object</code> supplied for the default action must either be
     * an <code>Action</code> or a name that is supplied in the action data.  If
     * the parameter is <code>null</code>, no default action is set.</p>
     * 
     * @param displayObject the object to display in the dialog
     * @param actionData    the array used to generate the dialog actions
     * @param defaultAction the default action
     */
    protected void initializeGeneralDialog
        (Object displayObject, Object[][] actionData, Object defaultAction)
    {
        // build the component 
        component = makeComponent(displayObject);
        
        if (component == null)
            component = new JPanel();
        
        // add the actions
        actionsPanel.addActions
            (DialogAction.makeDialogActions(this, actionData));
        
        createContentPane();
        
        if (defaultAction instanceof Action)
            setDefaultButton((Action) defaultAction);
        else
        if (defaultAction instanceof String)
            setDefaultButton((String) defaultAction);
        
        installWindowActionAdapter();
    }
    
    /**
     * Returns a <CODE>Component</CODE> for the given object
     * constructed using the 
     * <CODE>{@link ComponentFactory#makeComponent makeComponent}</CODE>
     * method in <CODE>{@link ComponentFactory ComponentFactory}</CODE>.
     */
    protected Component makeComponent(Object o) {
        return ComponentFactory.makeComponent(o);
    }
    
    /** Creates the dialog content pane. */
    protected void createContentPane() {
        // create table panel for component and actions panel
        TablePanel panel = new TablePanel(2, 1, 5, 5, NORTH);

        // add the component and actions panel to the table panel
        panel.add(component);
        panel.add(actionsPanel);
        
        // make a wrapper panel so the contents and actions 
        // will keep centered
        JPanel wrapperPanel = new JPanel(new CenterLayout());
        wrapperPanel.add(panel);
        setContentPane(wrapperPanel);
    }
    
    /**
     * Installs the default window action adapter for this dialog
     * using the default window closing action.
     *
     * @see #getWindowClosingAction()
     * @see #setWindowClosingAction(DialogAction)
     * @see #getDefaultWindowClosingAction()
     */
    protected void installWindowActionAdapter() 
    {   
        setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
             
        windowActionAdapter = new WindowActionAdapter(this);

        setWindowClosingAction(null);
    }
    
    /**
     * Sets the user response <CODE>String</CODE> and closes this dialog.
     *
     * If the parameter <CODE>userResponse</CODE> is <CODE>null</CODE> 
     * then an empty <CODE>String</CODE> will be set as the user response.
     *
     * @param userResponse a <CODE>String</CODE> 
     *      representing the user's choice
     * @see #getResponse()
     * @see #closeDialog()
     */
    protected void setResponseAndClose(String userResponse) {
    
        if (userResponse != null)
            response = userResponse;
        else
            response = "";
            
        closeDialog();
    }
    
    /** Closes and disposes this dialog. */   
    protected void closeDialog() {
        setVisible(false);
    }    
    
    /** Sets whether or not this dialog was cancelled. */
    protected void setCancelled(boolean cancelled) {
        this.cancelled = cancelled;
    }
}
