OSDN Git Service

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