OSDN Git Service

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