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