001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: *
017: */
018:
019: package org.apache.jmeter.gui.action;
020:
021: import java.awt.BorderLayout;
022: import java.awt.Color;
023: import java.awt.Container;
024: import java.awt.Dimension;
025: import java.awt.GridLayout;
026: import java.awt.Point;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.MouseAdapter;
029: import java.awt.event.MouseEvent;
030: import java.util.Collections;
031: import java.util.HashSet;
032: import java.util.Set;
033:
034: import javax.swing.JDialog;
035: import javax.swing.JFrame;
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import javax.swing.border.EmptyBorder;
039:
040: import org.apache.jmeter.gui.GuiPackage;
041: import org.apache.jmeter.util.JMeterUtils;
042:
043: /**
044: * About Command. It may be extended in the future to add a list of installed
045: * protocols, config options, etc.
046: *
047: * @author <a href="bloritsch@apache.org">Berin Loritsch</a>
048: * @version CVS $Revision: 493779 $ $Date: 2007-01-07 17:46:38 +0000 (Sun, 07 Jan 2007) $
049: */
050: public class AboutCommand implements Command {
051: private static Set commandSet;
052:
053: private static JDialog about;
054:
055: static {
056: HashSet commands = new HashSet();
057: commands.add(ActionNames.ABOUT);
058: commandSet = Collections.unmodifiableSet(commands);
059: }
060:
061: /**
062: * Handle the "about" action by displaying the "About Apache JMeter..."
063: * dialog box. The Dialog Box is NOT modal, because those should be avoided
064: * if at all possible.
065: */
066: public void doAction(ActionEvent e) {
067: if (e.getActionCommand().equals(ActionNames.ABOUT)) {
068: this .about();
069: }
070: }
071:
072: /**
073: * Provide the list of Action names that are available in this command.
074: */
075: public Set getActionNames() {
076: return AboutCommand.commandSet;
077: }
078:
079: /**
080: * Called by about button. Raises about dialog. Currently the about box has
081: * the product image and the copyright notice. The dialog box is centered
082: * over the MainFrame.
083: */
084: void about() {
085: JFrame mainFrame = GuiPackage.getInstance().getMainFrame();
086: if (about == null) {
087: about = new JDialog(mainFrame, "About Apache JMeter...",
088: false);
089: about.addMouseListener(new MouseAdapter() {
090: public void mouseClicked(MouseEvent e) {
091: about.setVisible(false);
092: }
093: });
094:
095: JLabel jmeter = new JLabel(JMeterUtils
096: .getImage("jmeter.jpg"));
097: JLabel copyright = new JLabel(JMeterUtils
098: .getJMeterCopyright(), JLabel.CENTER);
099: JLabel rights = new JLabel("All Rights Reserved.",
100: JLabel.CENTER);
101: JLabel version = new JLabel("Apache JMeter Version "
102: + JMeterUtils.getJMeterVersion(), JLabel.CENTER);
103: JPanel infos = new JPanel();
104: infos.setOpaque(false);
105: infos.setLayout(new GridLayout(0, 1));
106: infos.setBorder(new EmptyBorder(5, 5, 5, 5));
107: infos.add(copyright);
108: infos.add(rights);
109: infos.add(version);
110: Container panel = about.getContentPane();
111: panel.setLayout(new BorderLayout());
112: panel.setBackground(Color.white);
113: panel.add(jmeter, BorderLayout.NORTH);
114: panel.add(infos, BorderLayout.SOUTH);
115: }
116:
117: // NOTE: these lines center the about dialog in the
118: // current window. Some older Swing versions have
119: // a bug in getLocationOnScreen() and they may not
120: // make this behave properly.
121: Point p = mainFrame.getLocationOnScreen();
122: Dimension d1 = mainFrame.getSize();
123: Dimension d2 = about.getSize();
124: about.setLocation(p.x + (d1.width - d2.width) / 2, p.y
125: + (d1.height - d2.height) / 2);
126: about.pack();
127: about.setVisible(true);
128: }
129: }
|