OSDN Git Service

AboutとLicenseを別tabで表示
[coroid/inqubus.git] / frontend / src / saccubus / MainFrame_AboutBox.java
1 package saccubus;
2
3 import static javax.swing.WindowConstants.*;
4
5 import java.awt.Color;
6 import java.awt.Dimension;
7 import java.awt.Frame;
8 import java.awt.event.ActionEvent;
9 import java.awt.event.ActionListener;
10 import java.io.BufferedReader;
11 import java.io.IOException;
12 import java.io.InputStreamReader;
13 import java.util.logging.Level;
14 import java.util.logging.Logger;
15 import javax.swing.BorderFactory;
16 import javax.swing.GroupLayout;
17 import javax.swing.GroupLayout.Alignment;
18 import javax.swing.ImageIcon;
19 import javax.swing.JButton;
20 import javax.swing.JDialog;
21 import javax.swing.JLabel;
22 import javax.swing.JPanel;
23 import javax.swing.JScrollPane;
24 import javax.swing.JTabbedPane;
25 import javax.swing.JTextArea;
26 import javax.swing.SwingUtilities;
27
28 /**
29  * <p>
30  * タイトル: さきゅばす
31  * </p>
32  *
33  * <p>
34  * 説明: ニコニコ動画の動画をコメントつきで保存
35  * </p>
36  *
37  * <p>
38  * 著作権: Copyright (c) 2007 PSI
39  * </p>
40  *
41  * <p>
42  * 会社名:
43  * </p>
44  *
45  * @author 未入力
46  * @version 1.0
47  */
48 public class MainFrame_AboutBox extends JDialog implements ActionListener {
49
50     private static final String VERSION = "いんきゅばす 2.0.0";
51     private static final long serialVersionUID = -4256413309312729840L;
52     private static final Logger logger = Logger.getLogger(MainFrame_AboutBox.class.getName());
53     private static final String LINE_FEED = System.getProperty("line.separator");
54     private final JButton okButton = new JButton();
55
56     public MainFrame_AboutBox(Frame parent) {
57         super(parent);
58         try {
59             setDefaultCloseOperation(DISPOSE_ON_CLOSE);
60             jbInit();
61         } catch (Exception exception) {
62             logger.log(Level.SEVERE, null, exception);
63         }
64     }
65
66     public MainFrame_AboutBox() {
67         this(null);
68     }
69
70     /**
71      * コンポーネントの初期化。
72      *
73      * @throws java.lang.Exception
74      */
75     private void jbInit() {
76         final JTabbedPane tab = new JTabbedPane(JTabbedPane.BOTTOM);
77
78         final JLabel lblImage = new JLabel();
79         final ImageIcon icon = new ImageIcon(saccubus.MainFrame_AboutBox.class.getResource("icon.png"));
80         lblImage.setIcon(icon);
81
82         final JTextArea fldProduct = createProductField();
83         // Numbus bug 対応
84         // http://stackoverflow.com/questions/613603/java-nimbus-laf-with-transparent-text-fields
85         fldProduct.setOpaque(false);
86         fldProduct.setBorder(BorderFactory.createEmptyBorder());
87         fldProduct.setBackground(new Color(0, 0, 0, 0));
88
89         final JScrollPane pnlLicense = createLicensePane();
90
91         okButton.setText("OK");
92         okButton.addActionListener(this);
93
94
95         final JPanel pnlAbout = new JPanel();
96         GroupLayout glAbout = new GroupLayout(pnlAbout);
97         pnlAbout.setLayout(glAbout);
98
99         glAbout.setHorizontalGroup(glAbout.createParallelGroup(GroupLayout.Alignment.CENTER)
100             .addGroup(glAbout.createSequentialGroup()
101                 .addGap(15).addComponent(lblImage).addGap(30).addComponent(fldProduct).addGap(30))
102         );
103
104         glAbout.setVerticalGroup(glAbout.createSequentialGroup()
105             .addGap(15)
106             .addGroup(glAbout.createParallelGroup()
107                 .addComponent(lblImage).addComponent(fldProduct))
108             .addGap(15)
109         );
110
111         tab.add("About", pnlAbout);
112         tab.add("License", pnlLicense);
113
114         final JPanel pnlBase = new JPanel();
115         final GroupLayout glBase = new GroupLayout(pnlBase);
116         pnlBase.setLayout(glBase);
117         glBase.setAutoCreateContainerGaps(true);
118         glBase.setAutoCreateGaps(true);
119
120         glBase.setHorizontalGroup(glBase.createParallelGroup(Alignment.CENTER)
121             .addComponent(tab)
122             .addComponent(okButton)
123         );
124
125         glBase.setVerticalGroup(glBase.createSequentialGroup()
126             .addComponent(tab)
127             .addComponent(okButton)
128         );
129
130
131         setContentPane(pnlBase);
132
133         setTitle("バージョン情報");
134         setResizable(true);
135         pack();
136     }
137
138     private JTextArea createProductField() {
139         final JTextArea area = new JTextArea();
140         area.append(VERSION);
141         area.append(LINE_FEED);
142         area.append(LINE_FEED);
143
144         try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(
145                         "saccubus_description.txt"), "UTF-8"))) {
146             String line;
147             while ((line = reader.readLine()) != null) {
148                 area.append(line);
149                 area.append(LINE_FEED);
150             }
151         } catch (IOException ex) {
152             logger.log(Level.SEVERE, null, ex);
153         }
154
155         area.setEditable(false);
156         return area;
157     }
158
159     private JScrollPane createLicensePane() {
160         final JTextArea licenseField = new JTextArea();
161         try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(
162                         "LICENSE.txt"), "UTF-8"))) {
163             String line;
164             while ((line = reader.readLine()) != null) {
165                 licenseField.append(line);
166                 licenseField.append(LINE_FEED);
167             }
168         } catch (IOException ex) {
169             logger.log(Level.SEVERE, null, ex);
170         }
171
172         licenseField.setCaretPosition(0);
173         licenseField.setEditable(false);
174         final JScrollPane licensePane = new JScrollPane(licenseField);
175         licensePane.setPreferredSize(new Dimension(400, 400));
176         return licensePane;
177     }
178
179     /**
180      * ボタンイベントでダイアログを閉じる
181      *
182      * @param actionEvent
183      *            ActionEvent
184      */
185     @Override
186     public void actionPerformed(ActionEvent actionEvent) {
187         if (actionEvent.getSource() == okButton) {
188             dispose();
189         }
190     }
191
192     public static void main(String[] args) {
193         SwingUtilities.invokeLater(new Runnable() {
194
195             @Override
196             public void run() {
197                 MainFrame_AboutBox frame = new MainFrame_AboutBox();
198                 frame.pack();
199                 frame.setVisible(true);
200             }
201         });
202     }
203 }