AboutDialog.java revision 58a8b0aba2dec5695628a2bf25a3fae42c2c3533
1package junit.swingui;
2
3import java.awt.Font;
4import java.awt.GridBagConstraints;
5import java.awt.GridBagLayout;
6import java.awt.Insets;
7import java.awt.event.ActionEvent;
8import java.awt.event.ActionListener;
9import java.awt.event.WindowAdapter;
10import java.awt.event.WindowEvent;
11
12import javax.swing.Icon;
13import javax.swing.JButton;
14import javax.swing.JDialog;
15import javax.swing.JFrame;
16import javax.swing.JLabel;
17
18import junit.runner.BaseTestRunner;
19import junit.runner.Version;
20
21/**
22 * The AboutDialog.
23 */
24class AboutDialog extends JDialog {
25	public AboutDialog(JFrame parent) {
26		super(parent, true);
27
28		setResizable(false);
29		getContentPane().setLayout(new GridBagLayout());
30		setSize(330, 138);
31		setTitle("About");
32		// setLocationRelativeTo is only available in JDK 1.4
33		try {
34			setLocationRelativeTo(parent);
35		} catch (NoSuchMethodError e) {
36			TestSelector.centerWindow(this);
37		}
38
39		JButton close= new JButton("Close");
40		close.addActionListener(
41			new ActionListener() {
42				public void actionPerformed(ActionEvent e) {
43					dispose();
44				}
45			}
46		);
47		getRootPane().setDefaultButton(close);
48		JLabel label1= new JLabel("JUnit");
49		label1.setFont(new Font("dialog", Font.PLAIN, 36));
50
51		JLabel label2= new JLabel("JUnit "+Version.id()+" by Kent Beck and Erich Gamma");
52		label2.setFont(new Font("dialog", Font.PLAIN, 14));
53
54		JLabel logo= createLogo();
55
56		GridBagConstraints constraintsLabel1= new GridBagConstraints();
57		constraintsLabel1.gridx = 3; constraintsLabel1.gridy = 0;
58		constraintsLabel1.gridwidth = 1; constraintsLabel1.gridheight = 1;
59		constraintsLabel1.anchor = GridBagConstraints.CENTER;
60		getContentPane().add(label1, constraintsLabel1);
61
62		GridBagConstraints constraintsLabel2= new GridBagConstraints();
63		constraintsLabel2.gridx = 2; constraintsLabel2.gridy = 1;
64		constraintsLabel2.gridwidth = 2; constraintsLabel2.gridheight = 1;
65		constraintsLabel2.anchor = GridBagConstraints.CENTER;
66		getContentPane().add(label2, constraintsLabel2);
67
68		GridBagConstraints constraintsButton1= new GridBagConstraints();
69		constraintsButton1.gridx = 2; constraintsButton1.gridy = 2;
70		constraintsButton1.gridwidth = 2; constraintsButton1.gridheight = 1;
71		constraintsButton1.anchor = GridBagConstraints.CENTER;
72		constraintsButton1.insets= new Insets(8, 0, 8, 0);
73		getContentPane().add(close, constraintsButton1);
74
75		GridBagConstraints constraintsLogo1= new GridBagConstraints();
76		constraintsLogo1.gridx = 2; constraintsLogo1.gridy = 0;
77		constraintsLogo1.gridwidth = 1; constraintsLogo1.gridheight = 1;
78		constraintsLogo1.anchor = GridBagConstraints.CENTER;
79		getContentPane().add(logo, constraintsLogo1);
80
81		addWindowListener(
82			new WindowAdapter() {
83				public void windowClosing(WindowEvent e) {
84					dispose();
85				}
86			}
87		);
88	}
89	protected JLabel createLogo() {
90		Icon icon= TestRunner.getIconResource(BaseTestRunner.class, "logo.gif");
91		return new JLabel(icon);
92	}
93}