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