updates for 0.9.3
[debian/openrocket] / src / net / sf / openrocket / gui / dialogs / LicenseDialog.java
1 package net.sf.openrocket.gui.dialogs;
2
3 import java.awt.Font;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
6 import java.io.BufferedReader;
7 import java.io.InputStreamReader;
8
9 import javax.swing.JButton;
10 import javax.swing.JDialog;
11 import javax.swing.JFrame;
12 import javax.swing.JPanel;
13 import javax.swing.JScrollPane;
14 import javax.swing.JTextArea;
15
16 import net.miginfocom.swing.MigLayout;
17 import net.sf.openrocket.gui.components.ResizeLabel;
18 import net.sf.openrocket.util.GUIUtil;
19
20 public class LicenseDialog extends JDialog {
21         private static final String LICENSE_FILENAME = "LICENSE.TXT";
22         
23         private static final String DEFAULT_LICENSE_TEXT =
24                 "\n" +
25                 "Error:  Unable to load " + LICENSE_FILENAME + "!\n" +
26                 "\n" +
27                 "OpenRocket is licensed under the GNU GPL version 3, with additional permissions.\n" +
28                 "See http://openrocket.sourceforge.net/ for details.";
29
30         public LicenseDialog(JFrame parent) {
31                 super(parent, true);
32                 
33                 JPanel panel = new JPanel(new MigLayout("fill"));
34                 
35                 panel.add(new ResizeLabel("OpenRocket license", 10), "ax 50%, wrap para");
36
37                 String licenseText;
38                 try {
39                         
40                         BufferedReader reader = new BufferedReader(
41                                         new InputStreamReader(ClassLoader.getSystemResourceAsStream(LICENSE_FILENAME)));
42                         StringBuffer sb = new StringBuffer();
43                         for (String s = reader.readLine(); s != null; s = reader.readLine()) {
44                                 sb.append(s);
45                                 sb.append('\n');
46                         }
47                         licenseText = sb.toString();
48                         
49                 } catch (Exception e) {
50
51                         licenseText = DEFAULT_LICENSE_TEXT;
52                         
53                 }
54                 
55                 JTextArea text = new JTextArea(licenseText);
56                 text.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
57                 text.setRows(20);
58                 text.setColumns(80);
59                 text.setEditable(false);
60                 panel.add(new JScrollPane(text),"grow, wrap para");
61                 
62                 JButton close = new JButton("Close");
63                 close.addActionListener(new ActionListener() {
64                         @Override
65                         public void actionPerformed(ActionEvent e) {
66                                 LicenseDialog.this.dispose();
67                         }
68                 });
69                 panel.add(close, "right");
70                 
71                 this.add(panel);
72                 this.setTitle("OpenRocket license");
73                 this.pack();
74                 this.setLocationRelativeTo(parent);
75                 GUIUtil.setDefaultButton(close);
76                 GUIUtil.installEscapeCloseOperation(this);
77         }
78         
79 }