    001    /* ========================================================================
    002     * JCommon : a free general purpose class library for the Java(tm) platform
    003     * ========================================================================
    004     *
    005     * (C) Copyright 2000-2005, 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-2004, 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.6 2007/11/02 17:50:36 taqua 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 resourceBundle (RFE 690236) (AL);
    041     *
    042     */
    043
    044    package org.jfree.ui;
    045
    046    import java.awt.Dialog;
    047    import java.awt.Frame;
    048    import java.awt.event.ActionEvent;
    049    import java.awt.event.ActionListener;
    050    import java.util.ResourceBundle;
    051    import javax.swing.BorderFactory;
    052    import javax.swing.JButton;
    053    import javax.swing.JDialog;
    054    import javax.swing.JPanel;
    055
    056    /**
    057     * The base class for standard dialogs.
    058     *
    059     * @author David Gilbert
    060     */
    061    public class StandardDialog extends JDialog implements ActionListener {
    062
    063        /** Flag that indicates whether or not the dialog was cancelled. */
    064        private boolean cancelled;
    065
    066        /** The resourceBundle for the localization. */
    067        protected static final ResourceBundle localizationResources =
    068            ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
    069
    070        /**
    071         * Standard constructor - builds a dialog...
    072         *
    073         * @param owner  the owner.
    074         * @param title  the title.
    075         * @param modal  modal?
    076         */
    077        public StandardDialog(final Frame owner, final String title, final boolean modal) {
    078            super(owner, title, modal);
    079            this.cancelled = false;
    080        }
    081
    082        /**
    083         * Standard constructor - builds a dialog...
    084         *
    085         * @param owner  the owner.
    086         * @param title  the title.
    087         * @param modal  modal?
    088         */
    089        public StandardDialog(final Dialog owner, final String title, final boolean modal) {
    090            super(owner, title, modal);
    091            this.cancelled = false;
    092        }
    093
    094        /**
    095         * Returns a flag that indicates whether or not the dialog has been cancelled.
    096         *
    097         * @return boolean.
    098         */
    099        public boolean isCancelled() {
    100            return this.cancelled;
    101        }
    102
    103        /**
    104         * Handles clicks on the standard buttons.
    105         *
    106         * @param event  the event.
    107         */
    108        public void actionPerformed(final ActionEvent event) {
    109            final String command = event.getActionCommand();
    110            if (command.equals("helpButton")) {
    111                // display help information
    112            }
    113            else if (command.equals("okButton")) {
    114                this.cancelled = false;
    115                setVisible(false);
    116            }
    117            else if (command.equals("cancelButton")) {
    118                this.cancelled = true;
    119                setVisible(false);
    120            }
    121        }
    122
    123        /**
    124         * Builds and returns the user interface for the dialog.  This method is shared among the
    125         * constructors.
    126         *
    127         * @return the button panel.
    128         */
    129        protected JPanel createButtonPanel() {
    130
    131            final L1R2ButtonPanel buttons = new L1R2ButtonPanel(localizationResources.getString("Help"),
    132                                                          localizationResources.getString("OK"),
    133                                                          localizationResources.getString("Cancel"));
    134
    135            final JButton helpButton = buttons.getLeftButton();
    136            helpButton.setActionCommand("helpButton");
    137            helpButton.addActionListener(this);
    138
    139            final JButton okButton = buttons.getRightButton1();
    140            okButton.setActionCommand("okButton");
    141            okButton.addActionListener(this);
    142
    143            final JButton cancelButton = buttons.getRightButton2();
    144            cancelButton.setActionCommand("cancelButton");
    145            cancelButton.addActionListener(this);
    146
    147            buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
    148            return buttons;
    149        }
    150
    151    }