KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > enhydra > multiServer > launch > AboutBox


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

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