OSDN Git Service

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