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