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.5 2005/11/16 15:58:41 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:
052: import javax.swing.BorderFactory;
053: import javax.swing.JButton;
054: import javax.swing.JDialog;
055: import javax.swing.JPanel;
056:
057: /**
058: * The base class for standard dialogs.
059: *
060: * @author David Gilbert
061: */
062: public class StandardDialog extends JDialog implements ActionListener {
063:
064: /** Flag that indicates whether or not the dialog was cancelled. */
065: private boolean cancelled;
066:
067: /** The resourceBundle for the localization. */
068: protected static final ResourceBundle localizationResources = ResourceBundle
069: .getBundle("org.jfree.ui.LocalizationBundle");
070:
071: /**
072: * Standard constructor - builds a dialog...
073: *
074: * @param owner the owner.
075: * @param title the title.
076: * @param modal 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 the owner.
088: * @param title the title.
089: * @param modal modal?
090: */
091: public StandardDialog(final Dialog owner, final String title,
092: final boolean modal) {
093: super (owner, title, modal);
094: this .cancelled = false;
095: }
096:
097: /**
098: * Returns a flag that indicates whether or not the dialog has been cancelled.
099: *
100: * @return boolean.
101: */
102: public boolean isCancelled() {
103: return this .cancelled;
104: }
105:
106: /**
107: * Handles clicks on the standard buttons.
108: *
109: * @param event the event.
110: */
111: public void actionPerformed(final ActionEvent event) {
112: final String command = event.getActionCommand();
113: if (command.equals("helpButton")) {
114: // display help information
115: } else if (command.equals("okButton")) {
116: this .cancelled = false;
117: setVisible(false);
118: } else if (command.equals("cancelButton")) {
119: this .cancelled = true;
120: setVisible(false);
121: }
122: }
123:
124: /**
125: * Builds and returns the user interface for the dialog. This method is shared among the
126: * constructors.
127: *
128: * @return the button panel.
129: */
130: protected JPanel createButtonPanel() {
131:
132: final L1R2ButtonPanel buttons = new L1R2ButtonPanel(
133: localizationResources.getString("Help"),
134: localizationResources.getString("OK"),
135: localizationResources.getString("Cancel"));
136:
137: final JButton helpButton = buttons.getLeftButton();
138: helpButton.setActionCommand("helpButton");
139: helpButton.addActionListener(this );
140:
141: final JButton okButton = buttons.getRightButton1();
142: okButton.setActionCommand("okButton");
143: okButton.addActionListener(this );
144:
145: final JButton cancelButton = buttons.getRightButton2();
146: cancelButton.setActionCommand("cancelButton");
147: cancelButton.addActionListener(this );
148:
149: buttons.setBorder(BorderFactory.createEmptyBorder(4, 0, 0, 0));
150: return buttons;
151: }
152:
153: }
|