Source for org.jfree.ui.StandardDialog

   1: /* ========================================================================
   2:  * JCommon : a free general purpose class library for the Java(tm) platform
   3:  * ========================================================================
   4:  *
   5:  * (C) Copyright 2000-2008, by Object Refinery Limited and Contributors.
   6:  *
   7:  * Project Info:  http://www.jfree.org/jcommon/index.html
   8:  *
   9:  * This library is free software; you can redistribute it and/or modify it
  10:  * under the terms of the GNU Lesser General Public License as published by
  11:  * the Free Software Foundation; either version 2.1 of the License, or
  12:  * (at your option) any later version.
  13:  *
  14:  * This library is distributed in the hope that it will be useful, but
  15:  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
  16:  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  17:  * License for more details.
  18:  *
  19:  * You should have received a copy of the GNU Lesser General Public
  20:  * License along with this library; if not, write to the Free Software
  21:  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301,
  22:  * USA.
  23:  *
  24:  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  25:  * in the United States and other countries.]
  26:  *
  27:  * -------------------
  28:  * StandardDialog.java
  29:  * -------------------
  30:  * (C) Copyright 2000-2008, by Object Refinery Limited.
  31:  *
  32:  * Original Author:  David Gilbert (for Object Refinery Limited);
  33:  * Contributor(s):   Arnaud Lelievre;
  34:  *
  35:  * $Id: StandardDialog.java,v 1.7 2008/12/18 09:57:32 mungady Exp $
  36:  *
  37:  * Changes (from 26-Oct-2001)
  38:  * --------------------------
  39:  * 26-Oct-2001 : Changed package to com.jrefinery.ui.*;
  40:  * 08-Sep-2003 : Added internationalization via use of properties
  41:  *               resourceBundle (RFE 690236) (AL);
  42:  * 18-Dec-2008 : Use ResourceBundleWrapper - see JFreeChart patch 1607918 by
  43:  *               Jess Thrysoee (DG);
  44:  *
  45:  */
  46: 
  47: package org.jfree.ui;
  48: 
  49: import java.awt.Dialog;
  50: import java.awt.Frame;
  51: import java.awt.event.ActionEvent;
  52: import java.awt.event.ActionListener;
  53: import java.util.ResourceBundle;
  54: 
  55: import javax.swing.BorderFactory;
  56: import javax.swing.JButton;
  57: import javax.swing.JDialog;
  58: import javax.swing.JPanel;
  59: 
  60: import org.jfree.util.ResourceBundleWrapper;
  61: 
  62: /**
  63:  * The base class for standard dialogs.
  64:  *
  65:  * @author David Gilbert
  66:  */
  67: public class StandardDialog extends JDialog implements ActionListener {
  68: 
  69:     /** Flag that indicates whether or not the dialog was cancelled. */
  70:     private boolean cancelled;
  71: 
  72:     /** The resourceBundle for the localization. */
  73:     protected static final ResourceBundle localizationResources
  74:             = ResourceBundleWrapper.getBundle(
  75:                     "org.jfree.ui.LocalizationBundle");
  76: 
  77:     /**
  78:      * Standard constructor - builds a dialog...
  79:      *
  80:      * @param owner  the owner.
  81:      * @param title  the title.
  82:      * @param modal  modal?
  83:      */
  84:     public StandardDialog(final Frame owner, final String title,
  85:             final boolean modal) {
  86:         super(owner, title, modal);
  87:         this.cancelled = false;
  88:     }
  89: 
  90:     /**
  91:      * Standard constructor - builds a dialog...
  92:      *
  93:      * @param owner  the owner.
  94:      * @param title  the title.
  95:      * @param modal  modal?
  96:      */
  97:     public StandardDialog(final Dialog owner, final String title,
  98:             final boolean modal) {
  99:         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: }