    001/* ========================================================================
    002 * JCommon : a free general purpose class library for the Java(tm) platform
    003 * ========================================================================
    004 *
    005 * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
    006 *
    007 * Project Info:  http://www.jfree.org/jcommon/index.html
    008 *
    009 * This library is free software; you can redistribute it and/or modify it
    010 * under the terms of the GNU Lesser General Public License as published by
    011 * the Free Software Foundation; either version 2.1 of the License, or
    012 * (at your option) any later version.
    013 *
    014 * This library is distributed in the hope that it will be useful, but
    015 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
    016 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
    017 * License for more details.
    018 *
    019 * You should have received a copy of the GNU Lesser General Public
    020 * License along with this library; if not, write to the Free Software
    021 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
    022 * USA.
    023 *
    024 * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
    025 * in the United States and other countries.]
    026 *
    027 * -------------------
    028 * StandardDialog.java
    029 * -------------------
    030 * (C) Copyright 2000-2008, by Object Refinery Limited.
    031 *
    032 * Original Author:  David Gilbert (for Object Refinery Limited);
    033 * Contributor(s):   Arnaud Lelievre;
    034 *
    035 * $Id: StandardDialog.java,v 1.7 2008/12/18 09:57:32 mungady Exp $
    036 *
    037 * Changes (from 26-Oct-2001)
    038 * --------------------------
    039 * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
    040 * 08-Sep-2003 : Added internationalization via use of properties
    041 *               resourceBundle (RFE 690236) (AL);
    042 * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
    043 *               Jess Thrysoee (DG);
    044 *
    045 */
    046
    047package org.jfree.ui;
    048
    049import java.awt.Dialog;
    050import java.awt.Frame;
    051import java.awt.event.ActionEvent;
    052import java.awt.event.ActionListener;
    053import java.util.ResourceBundle;
    054
    055import javax.swing.BorderFactory;
    056import javax.swing.JButton;
    057import javax.swing.JDialog;
    058import javax.swing.JPanel;
    059
    060import org.jfree.util.ResourceBundleWrapper;
    061
    062/**
    063 * The base class for standard dialogs.
    064 *
    065 * @author David Gilbert
    066 */
    067public class StandardDialog extends JDialog implements ActionListener {
    068
    069    /** Flag that indicates whether or not the dialog was cancelled. */
    070    private boolean cancelled;
    071
    072    /** The resourceBundle for the localization. */
    073    protected static final ResourceBundle localizationResources
    074            = ResourceBundleWrapper.getBundle(
    075                    "org.jfree.ui.LocalizationBundle");
    076
    077    /**
    078     * Standard constructor - builds a dialog...
    079     *
    080     * @param owner  the owner.
    081     * @param title  the title.
    082     * @param modal  modal?
    083     */
    084    public StandardDialog(final Frame owner, final String title,
    085            final boolean modal) {
    086        super(owner, title, modal);
    087        this.cancelled = false;
    088    }
    089
    090    /**
    091     * Standard constructor - builds a dialog...
    092     *
    093     * @param owner  the owner.
    094     * @param title  the title.
    095     * @param modal  modal?
    096     */
    097    public StandardDialog(final Dialog owner, final String title,
    098            final boolean modal) {
    099        super(owner, title, modal);
    100        this.cancelled = false;
    101    }
    102
    103    /**
    104     * Returns a flag that indicates whether or not the dialog has been
    105     * cancelled.
    106     *
    107     * @return boolean.
    108     */
    109    public boolean isCancelled() {
    110        return this.cancelled;
    111    }
    112
    113    /**
    114     * Handles clicks on the standard buttons.
    115     *
    116     * @param event  the event.
    117     */
    118    public void actionPerformed(final ActionEvent event) {
    119        final String command = event.getActionCommand();
    120        if (command.equals("helpButton")) {
    121            // display help information
    122        }
    123        else if (command.equals("okButton")) {
    124            this.cancelled = false;
    125            setVisible(false);
    126        }
    127        else if (command.equals("cancelButton")) {
    128            this.cancelled = true;
    129            setVisible(false);
    130        }
    131    }
    132
    133    /**
    134     * Builds and returns the user interface for the dialog.  This method is
    135     * shared among the constructors.
    136     *
    137     * @return the button panel.
    138     */
    139    protected JPanel createButtonPanel() {
    140
    141        final L1R2ButtonPanel buttons = new L1R2ButtonPanel(
    142                localizationResources.getString("Help"),
    143                localizationResources.getString("OK"),
    144                localizationResources.getString("Cancel"));
    145
    146        final JButton helpButton = buttons.getLeftButton();
    147        helpButton.setActionCommand("helpButton");
    148        helpButton.addActionListener(this);
    149
    150        final JButton okButton = buttons.getRightButton1();
    151        okButton.setActionCommand("okButton");
    152        okButton.addActionListener(this);
    153
    154        final JButton cancelButton = buttons.getRightButton2();
    155        cancelButton.setActionCommand("cancelButton");
    156        cancelButton.addActionListener(this);
    157
    158        buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
    159        return buttons;
    160    }
    161
    162}