KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > jmeter > gui > action > AboutCommand


1 // $Header: /home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/gui/action/AboutCommand.java,v 1.4.2.1 2004/06/02 01:07:40 sebb Exp $
2
/*
3  * Copyright 2001-2004 The Apache Software Foundation.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17 */

18
19 package org.apache.jmeter.gui.action;
20
21 import java.awt.BorderLayout JavaDoc;
22 import java.awt.Color JavaDoc;
23 import java.awt.Container JavaDoc;
24 import java.awt.Dimension JavaDoc;
25 import java.awt.GridLayout JavaDoc;
26 import java.awt.Point JavaDoc;
27 import java.awt.event.ActionEvent JavaDoc;
28 import java.awt.event.MouseAdapter JavaDoc;
29 import java.awt.event.MouseEvent JavaDoc;
30 import java.util.Collections JavaDoc;
31 import java.util.HashSet JavaDoc;
32 import java.util.Set JavaDoc;
33
34 import javax.swing.JDialog JavaDoc;
35 import javax.swing.JFrame JavaDoc;
36 import javax.swing.JLabel JavaDoc;
37 import javax.swing.JPanel JavaDoc;
38 import javax.swing.border.EmptyBorder JavaDoc;
39
40 import org.apache.jmeter.gui.GuiPackage;
41 import org.apache.jmeter.util.JMeterUtils;
42
43 /**
44  * About Command. It may be extended in the future to add a list of
45  * installed protocols, config options, etc.
46  *
47  * @author <a HREF="bloritsch@apache.org">Berin Loritsch</a>
48  * @version CVS $Revision: 1.4.2.1 $ $Date: 2004/06/02 01:07:40 $
49  */

50 public class AboutCommand implements Command
51 {
52     private static Set JavaDoc commandSet;
53     private static JDialog JavaDoc about;
54
55     static
56     {
57         HashSet JavaDoc commands = new HashSet JavaDoc();
58         commands.add("about");
59         AboutCommand.commandSet = Collections.unmodifiableSet(commands);
60     }
61
62     /**
63      * Handle the "about" action by displaying the "About Apache JMeter..."
64      * dialog box. The Dialog Box is NOT modal, because those should be avoided
65      * if at all possible.
66      */

67     public void doAction(ActionEvent JavaDoc e)
68     {
69         if (e.getActionCommand().equals("about"))
70         {
71             this.about();
72         }
73     }
74
75     /**
76      * Provide the list of Action names that are available in this command.
77      */

78     public Set JavaDoc getActionNames()
79     {
80         return AboutCommand.commandSet;
81     }
82
83     /**
84      * Called by about button. Raises about dialog. Currently the about box has
85      * the product image and the copyright notice. The dialog box is centered
86      * over the MainFrame.
87      */

88     void about()
89     {
90         JFrame JavaDoc mainFrame = GuiPackage.getInstance().getMainFrame();
91         if (about == null)
92         {
93             about = new JDialog JavaDoc(mainFrame, "About Apache JMeter...", false);
94             about.addMouseListener(new MouseAdapter JavaDoc()
95             {
96                 public void mouseClicked(MouseEvent JavaDoc e)
97                 {
98                     about.setVisible(false);
99                 }
100             });
101
102             JLabel JavaDoc jmeter = new JLabel JavaDoc(JMeterUtils.getImage("jmeter.jpg"));
103             JLabel JavaDoc copyright =
104                 new JLabel JavaDoc(
105                     JMeterUtils.getJMeterCopyright(),
106                     JLabel.CENTER);
107             JLabel JavaDoc rights = new JLabel JavaDoc("All Rights Reserved.", JLabel.CENTER);
108             JLabel JavaDoc version =
109                 new JLabel JavaDoc(
110                     "Apache JMeter Version " + JMeterUtils.getJMeterVersion(),
111                     JLabel.CENTER);
112             JPanel JavaDoc infos = new JPanel JavaDoc();
113             infos.setOpaque(false);
114             infos.setLayout(new GridLayout JavaDoc(0, 1));
115             infos.setBorder(new EmptyBorder JavaDoc(5, 5, 5, 5));
116             infos.add(copyright);
117             infos.add(rights);
118             infos.add(version);
119             Container JavaDoc panel = about.getContentPane();
120             panel.setLayout(new BorderLayout JavaDoc());
121             panel.setBackground(Color.white);
122             panel.add(jmeter, BorderLayout.NORTH);
123             panel.add(infos, BorderLayout.SOUTH);
124         }
125
126         // NOTE: these lines center the about dialog in the
127
// current window. Some older Swing versions have
128
// a bug in getLocationOnScreen() and they may not
129
// make this behave properly.
130
Point JavaDoc p = mainFrame.getLocationOnScreen();
131         Dimension JavaDoc d1 = mainFrame.getSize();
132         Dimension JavaDoc d2 = about.getSize();
133         about.setLocation(
134             p.x + (d1.width - d2.width) / 2,
135             p.y + (d1.height - d2.height) / 2);
136         about.pack();
137         about.setVisible(true);
138     }
139 }
140
Popular Tags