Initial commit
[debian/openrocket] / src / net / sf / openrocket / gui / main / AboutDialog.java
1 package net.sf.openrocket.gui.main;
2
3 import java.awt.Desktop;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.awt.event.MouseAdapter;
7 import java.awt.event.MouseEvent;
8 import java.io.IOException;
9 import java.net.URI;
10 import java.net.URISyntaxException;
11
12 import javax.swing.JButton;
13 import javax.swing.JDialog;
14 import javax.swing.JFrame;
15 import javax.swing.JLabel;
16 import javax.swing.JPanel;
17
18 import net.miginfocom.swing.MigLayout;
19 import net.sf.openrocket.gui.ResizeLabel;
20 import net.sf.openrocket.util.GUIUtil;
21 import net.sf.openrocket.util.Prefs;
22
23 public class AboutDialog extends JDialog {
24         
25         public static final String OPENROCKET_URL = "http://openrocket.sourceforge.net/";
26         
27
28         public AboutDialog(JFrame parent) {
29                 super(parent, true);
30                 
31                 final String version = Prefs.getVersion();
32                 
33                 JPanel panel = new JPanel(new MigLayout("fill"));
34                 
35                 panel.add(new ResizeLabel("OpenRocket", 20), "ax 50%, wrap para");
36                 panel.add(new ResizeLabel("Version " + version, 3), "ax 50%, wrap 30lp");
37                 
38                 panel.add(new ResizeLabel("Copyright \u00A9 2007-2009 Sampo Niskanen"), "ax 50%, wrap para");
39                 
40                 JLabel link;
41                 
42                 if (Desktop.isDesktopSupported()) {
43                         
44                         link = new JLabel("<html><a href=\"" + OPENROCKET_URL + "\">" +
45                                         OPENROCKET_URL + "</a>");
46                         link.addMouseListener(new MouseAdapter() {
47                                 @Override
48                                 public void mouseClicked(MouseEvent e) {
49                                         Desktop d = Desktop.getDesktop();
50                                         try {
51                                                 d.browse(new URI(OPENROCKET_URL));
52                                                 
53                                         } catch (URISyntaxException e1) {
54                                                 throw new RuntimeException("BUG: Illegal OpenRocket URL: "+OPENROCKET_URL,
55                                                                 e1);
56                                         } catch (IOException e1) {
57                                                 System.err.println("Unable to launch browser:");
58                                                 e1.printStackTrace();
59                                         }
60                                 }
61                         });
62                         
63                 } else {
64                         link = new JLabel(OPENROCKET_URL);
65                 }
66                 panel.add(link, "ax 50%, wrap para");
67                 
68
69                 JButton close = new JButton("Close");
70                 close.addActionListener(new ActionListener() {
71                         @Override
72                         public void actionPerformed(ActionEvent e) {
73                                 AboutDialog.this.dispose();
74                         }
75                 });
76                 panel.add(close, "right");
77                 
78                 this.add(panel);
79                 this.setTitle("OpenRocket " + version);
80                 this.pack();
81                 this.setResizable(false);
82                 this.setLocationRelativeTo(null);
83                 GUIUtil.setDefaultButton(close);
84                 GUIUtil.installEscapeCloseOperation(this);
85         }
86         
87         
88 }