KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > ui > StandardDialog


1 /* ========================================================================
2  * JCommon : a free general purpose class library for the Java(tm) platform
3  * ========================================================================
4  *
5  * (C) Copyright 2000-2005, 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-2004, 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.5 2005/11/16 15:58:41 taqua 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 resourceBundle (RFE 690236) (AL);
41  *
42  */

43
44 package org.jfree.ui;
45
46 import java.awt.Dialog JavaDoc;
47 import java.awt.Frame JavaDoc;
48 import java.awt.event.ActionEvent JavaDoc;
49 import java.awt.event.ActionListener JavaDoc;
50 import java.util.ResourceBundle JavaDoc;
51
52 import javax.swing.BorderFactory JavaDoc;
53 import javax.swing.JButton JavaDoc;
54 import javax.swing.JDialog JavaDoc;
55 import javax.swing.JPanel JavaDoc;
56
57 /**
58  * The base class for standard dialogs.
59  *
60  * @author David Gilbert
61  */

62 public class StandardDialog extends JDialog JavaDoc implements ActionListener JavaDoc {
63
64     /** Flag that indicates whether or not the dialog was cancelled. */
65     private boolean cancelled;
66
67     /** The resourceBundle for the localization. */
68     protected static final ResourceBundle JavaDoc localizationResources =
69         ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
70
71     /**
72      * Standard constructor - builds a dialog...
73      *
74      * @param owner the owner.
75      * @param title the title.
76      * @param modal modal?
77      */

78     public StandardDialog(final Frame JavaDoc owner, final String JavaDoc title, final boolean modal) {
79         super(owner, title, modal);
80         this.cancelled = false;
81     }
82
83     /**
84      * Standard constructor - builds a dialog...
85      *
86      * @param owner the owner.
87      * @param title the title.
88      * @param modal modal?
89      */

90     public StandardDialog(final Dialog JavaDoc owner, final String JavaDoc title, final boolean modal) {
91         super(owner, title, modal);
92         this.cancelled = false;
93     }
94
95     /**
96      * Returns a flag that indicates whether or not the dialog has been cancelled.
97      *
98      * @return boolean.
99      */

100     public boolean isCancelled() {
101         return this.cancelled;
102     }
103
104     /**
105      * Handles clicks on the standard buttons.
106      *
107      * @param event the event.
108      */

109     public void actionPerformed(final ActionEvent JavaDoc event) {
110         final String JavaDoc command = event.getActionCommand();
111         if (command.equals("helpButton")) {
112             // display help information
113
}
114         else if (command.equals("okButton")) {
115             this.cancelled = false;
116             setVisible(false);
117         }
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 JavaDoc createButtonPanel() {
131
132         final L1R2ButtonPanel buttons = new L1R2ButtonPanel(localizationResources.getString("Help"),
133                                                       localizationResources.getString("OK"),
134                                                       localizationResources.getString("Cancel"));
135
136         final JButton JavaDoc helpButton = buttons.getLeftButton();
137         helpButton.setActionCommand("helpButton");
138         helpButton.addActionListener(this);
139
140         final JButton JavaDoc okButton = buttons.getRightButton1();
141         okButton.setActionCommand("okButton");
142         okButton.addActionListener(this);
143
144         final JButton JavaDoc 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 }
153
Popular Tags