KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > tool > common > AboutBox


1
2 /*
3  * Enhydra Java Application Server Project
4  *
5  * The contents of this file are subject to the Enhydra Public License
6  * Version 1.1 (the "License"); you may not use this file except in
7  * compliance with the License. You may obtain a copy of the License on
8  * the Enhydra web site ( http://www.enhydra.org/ ).
9  *
10  * Software distributed under the License is distributed on an "AS IS"
11  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
12  * the License for the specific terms governing rights and limitations
13  * under the License.
14  *
15  * The Initial Developer of the Enhydra Application Server is Lutris
16  * Technologies, Inc. The Enhydra Application Server and portions created
17  * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
18  * All Rights Reserved.
19  *
20  * Contributor(s):
21  * Paul Mahar
22  *
23  */

24 package org.enhydra.tool.common;
25
26 // Standard imports
27
import javax.swing.BorderFactory JavaDoc;
28 import javax.swing.ImageIcon JavaDoc;
29 import javax.swing.JDialog JavaDoc;
30 import javax.swing.JButton JavaDoc;
31 import javax.swing.JLabel JavaDoc;
32 import javax.swing.JPanel JavaDoc;
33 import javax.swing.JTextArea JavaDoc;
34 import javax.swing.SwingConstants JavaDoc;
35 import java.awt.event.ActionEvent JavaDoc;
36 import java.awt.event.ActionListener JavaDoc;
37 import java.awt.event.WindowEvent JavaDoc;
38 import java.awt.AWTEvent JavaDoc;
39 import java.awt.BorderLayout JavaDoc;
40 import java.awt.Dialog JavaDoc;
41 import java.awt.Dimension JavaDoc;
42 import java.awt.GridBagConstraints JavaDoc;
43 import java.awt.GridBagLayout JavaDoc;
44 import java.awt.Insets JavaDoc;
45 import java.awt.Frame JavaDoc;
46 import java.awt.Font JavaDoc;
47 import java.awt.Point JavaDoc;
48 import java.awt.SystemColor JavaDoc;
49 import java.beans.Beans JavaDoc;
50 import java.util.ResourceBundle JavaDoc;
51 public class AboutBox extends JDialog JavaDoc {
52     static ResourceBundle JavaDoc res =
53         ResourceBundle.getBundle("org.enhydra.tool.common.Res"); // nores
54

55     //
56
private JPanel JavaDoc panelMain;
57     private JPanel JavaDoc panelButton;
58     private JPanel JavaDoc panelLabel;
59     private JLabel JavaDoc labelTitle;
60     private JTextArea JavaDoc textMedium;
61     private JTextArea JavaDoc textSmall;
62     private JButton JavaDoc buttonOK;
63     private JButton JavaDoc buttonInfo;
64     private GridBagLayout JavaDoc layoutMain;
65     private GridBagLayout JavaDoc layoutButton;
66     private GridBagLayout JavaDoc layoutLabel;
67     private boolean standalone = false;
68     private LocalActionListener actionListener = null;
69
70     public AboutBox(Frame JavaDoc owner) {
71         super(owner, null, true);
72         construct();
73     }
74
75     public AboutBox(Dialog JavaDoc owner) {
76         super(owner, null, true);
77         construct();
78     }
79
80     private void construct() {
81         try {
82             jbInit();
83             pmInit();
84             pack();
85             setResizable(true);
86         } catch (Exception JavaDoc e) {
87             e.printStackTrace();
88         }
89         enableEvents(AWTEvent.WINDOW_EVENT_MASK);
90     }
91
92     // /
93
protected void clearAll() {
94         buttonOK.removeAll();
95         buttonOK.removeActionListener(actionListener);
96         buttonInfo.removeAll();
97         buttonInfo.removeActionListener(actionListener);
98         labelTitle.removeAll();
99         textMedium.removeAll();
100         textSmall.removeAll();
101         panelButton.removeAll();
102         panelLabel.removeAll();
103         panelMain.removeAll();
104         removeAll();
105         getContentPane().removeAll();
106         actionListener = null;
107         buttonOK = null;
108         buttonInfo = null;
109         textSmall = null;
110         layoutButton = null;
111         layoutLabel = null;
112         layoutMain = null;
113         panelButton = null;
114         panelLabel = null;
115         panelMain = null;
116         setTitle(null);
117     }
118
119     // /
120
public void show() {
121         Point JavaDoc centeringPoint;
122
123         pack();
124         centeringPoint = SwingUtil.getCenteringPoint(getSize());
125         setLocation(centeringPoint);
126         buttonOK.requestFocus();
127         super.show();
128     }
129
130     public static void main(String JavaDoc[] args) {
131         SwingUtil.setLookAndFeelToSystem();
132         AboutBox dlg;
133
134         dlg = new AboutBox(new Frame JavaDoc());
135         dlg.standalone = true;
136         dlg.show();
137     }
138
139     public String JavaDoc getTitleText() {
140         return labelTitle.getText();
141     }
142
143     public String JavaDoc getMediumText() {
144         return textMedium.getText();
145     }
146
147     public void setTitleText(String JavaDoc p) {
148         labelTitle.setText(p);
149         setTitle(ResUtil.format(res.getString("About_0_"), p));
150     }
151
152     public void setMediumText(String JavaDoc s) {
153         textMedium.setText(s);
154     }
155
156     public String JavaDoc getSmallText() {
157         return textSmall.getText();
158     }
159
160     public void setSmallText(String JavaDoc s) {
161         textSmall.setText(s);
162     }
163
164     // /
165
// /
166
protected void processWindowEvent(WindowEvent JavaDoc e) {
167         if (e.getID() == WindowEvent.WINDOW_CLOSING) {
168             closeDialog();
169         }
170         super.processWindowEvent(e);
171     }
172
173     protected void disposeDialog() {
174         setVisible(false);
175         removeAll();
176         dispose();
177     }
178
179     // /
180
// /
181
private void closeDialog() {
182         disposeDialog();
183         if (standalone) {
184             System.exit(0);
185         }
186     }
187
188     private void pmInit() {
189         textMedium.setFont(new Font JavaDoc(labelTitle.getFont().getName(), 0, 16));
190         textSmall.setFont(new Font JavaDoc(textMedium.getFont().getName(), 0, 10));
191
192         actionListener = new LocalActionListener();
193         buttonOK.addActionListener(actionListener);
194         buttonInfo.addActionListener(actionListener);
195     }
196
197     private void jbInit() throws Exception JavaDoc {
198         panelMain = (JPanel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
199                                                JPanel JavaDoc.class.getName());
200         panelLabel = (JPanel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
201                                                 JPanel JavaDoc.class.getName());
202         panelButton = (JPanel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
203                                                  JPanel JavaDoc.class.getName());
204         labelTitle = (JLabel JavaDoc) Beans.instantiate(getClass().getClassLoader(),
205                                                 JLabel JavaDoc.class.getName());
206         textMedium = (JTextArea JavaDoc) Beans.instantiate(getClass().getClassLoader(),
207                                                  JTextArea JavaDoc.class.getName());
208         textSmall = (JTextArea JavaDoc) Beans.instantiate(getClass().getClassLoader(),
209                                                 JTextArea JavaDoc.class.getName());
210         buttonOK = (JButton JavaDoc) Beans.instantiate(getClass().getClassLoader(),
211                                                JButton JavaDoc.class.getName());
212         buttonInfo = (JButton JavaDoc) Beans.instantiate(getClass().getClassLoader(),
213                                                  JButton JavaDoc.class.getName());
214         layoutMain =
215             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
216                                               GridBagLayout JavaDoc.class.getName());
217         layoutButton =
218             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
219                                               GridBagLayout JavaDoc.class.getName());
220         layoutLabel =
221             (GridBagLayout JavaDoc) Beans.instantiate(getClass().getClassLoader(),
222                                               GridBagLayout JavaDoc.class.getName());
223         buttonOK.setText(res.getString("OK"));
224         buttonOK.setMaximumSize(new Dimension JavaDoc(100, 30));
225         buttonOK.setMinimumSize(new Dimension JavaDoc(60, 15));
226         buttonOK.setPreferredSize(new Dimension JavaDoc(75, 20));
227         buttonOK.setMargin(new Insets JavaDoc(2, 12, 2, 12));
228         buttonOK.setMnemonic('0');
229         buttonInfo.setText(res.getString("Info"));
230         buttonInfo.setMaximumSize(new Dimension JavaDoc(100, 30));
231         buttonInfo.setMinimumSize(new Dimension JavaDoc(60, 15));
232         buttonInfo.setPreferredSize(new Dimension JavaDoc(75, 20));
233         buttonInfo.setMargin(new Insets JavaDoc(2, 12, 2, 12));
234         buttonInfo.setMnemonic('I');
235         panelLabel.setLayout(layoutLabel);
236         labelTitle.setBackground(SystemColor.controlLtHighlight);
237         labelTitle.setFont(new Font JavaDoc(labelTitle.getFont().getName(), 3, 18));
238         labelTitle.setForeground(SystemColor.infoText);
239         textMedium.setDisabledTextColor(SystemColor.infoText);
240         textMedium.setBackground(SystemColor.controlLtHighlight);
241         textMedium.setEnabled(false);
242         textMedium.setForeground(SystemColor.infoText);
243         textMedium.setEditable(false);
244         textSmall.setBackground(SystemColor.controlLtHighlight);
245         textSmall.setForeground(SystemColor.infoText);
246         textSmall.setMaximumSize(new Dimension JavaDoc(200, 17));
247         textSmall.setDisabledTextColor(SystemColor.infoText);
248         textSmall.setBackground(SystemColor.controlLtHighlight);
249         textSmall.setEnabled(false);
250         textSmall.setForeground(SystemColor.infoText);
251         textSmall.setEditable(false);
252
253         panelLabel.setBackground(SystemColor.controlLtHighlight);
254         panelLabel.setBorder(BorderFactory.createLoweredBevelBorder());
255         panelLabel.add(labelTitle,
256                        new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.0, 0.0,
257                                               GridBagConstraints.CENTER,
258                                               GridBagConstraints.BOTH,
259                                               new Insets JavaDoc(10, 10, 5, 10), 40,
260                                               0));
261         panelLabel.add(textMedium,
262                        new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.5, 0.5,
263                                               GridBagConstraints.CENTER,
264                                               GridBagConstraints.BOTH,
265                                               new Insets JavaDoc(5, 10, 5, 10), 40,
266                                               0));
267         panelLabel.add(textSmall,
268                        new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.0, 0.0,
269                                               GridBagConstraints.WEST,
270                                               GridBagConstraints.HORIZONTAL,
271                                               new Insets JavaDoc(5, 10, 10, 10), 40,
272                                               0));
273         panelButton.setLayout(layoutButton);
274         panelButton.add(buttonOK,
275                         new GridBagConstraints JavaDoc(0, 0, 1, 1, 0.5, 0.5,
276                                                GridBagConstraints.CENTER,
277                                                GridBagConstraints.NONE,
278                                                new Insets JavaDoc(5, 0, 10, 0), 0,
279                                                11));
280         panelButton.add(buttonInfo,
281                         new GridBagConstraints JavaDoc(1, 0, 1, 1, 0.5, 0.5,
282                                                GridBagConstraints.CENTER,
283                                                GridBagConstraints.NONE,
284                                                new Insets JavaDoc(5, 0, 10, 0), 0,
285                                                11));
286         panelMain.setLayout(layoutMain);
287         panelMain.setMaximumSize(new Dimension JavaDoc(500, 400));
288         panelMain.setMinimumSize(new Dimension JavaDoc(300, 150));
289         panelMain.setPreferredSize(new Dimension JavaDoc(450, 250));
290         panelMain.add(panelLabel,
291                       new GridBagConstraints JavaDoc(0, 1, 1, 1, 0.1, 0.1,
292                                              GridBagConstraints.CENTER,
293                                              GridBagConstraints.BOTH,
294                                              new Insets JavaDoc(0, 0, 0, 0), 0, 0));
295         panelMain.add(panelButton,
296                       new GridBagConstraints JavaDoc(0, 2, 1, 1, 0.1, 0.1,
297                                              GridBagConstraints.CENTER,
298                                              GridBagConstraints.BOTH,
299                                              new Insets JavaDoc(0, 0, 0, 0), 0, 0));
300         this.getContentPane().add(panelMain);
301     }
302
303     private class LocalActionListener implements ActionListener JavaDoc {
304         public void actionPerformed(ActionEvent JavaDoc event) {
305             Object JavaDoc source = event.getSource();
306
307             if (source == buttonOK) {
308                 closeDialog();
309             } else if (source == buttonInfo) {
310                 JDialog JavaDoc info = new JDialog JavaDoc();
311
312                 info.getContentPane().setLayout(new BorderLayout JavaDoc());
313                 info.getContentPane().add(new InfoPanel(),
314                                           BorderLayout.CENTER);
315                 info.pack();
316                 info.setTitle(res.getString("System_Information"));
317                 info.show();
318             }
319         }
320
321     }
322 }
323
Popular Tags