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