OSDN Git Service

バージョン情報ダイアログをtry-with-resourcesを使って書き換え
[coroid/inqubus.git] / frontend / src / saccubus / MainFrame_AboutBox.java
index fda937c..fd69a25 100644 (file)
@@ -1,74 +1,67 @@
 package saccubus;
 
-import java.awt.*;
+import static javax.swing.WindowConstants.*;
+
+import java.awt.Dimension;
+import java.awt.Frame;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import javax.swing.GroupLayout;
+import javax.swing.ImageIcon;
+import javax.swing.JButton;
+import javax.swing.JDialog;
+import javax.swing.JLabel;
+import javax.swing.JPanel;
+import javax.swing.JScrollPane;
+import javax.swing.JTextArea;
+import javax.swing.SwingUtilities;
 
-import javax.swing.*;
 
-import saccubus.util.PopupRightClick;
 
 /**
  * <p>
  * タイトル: さきゅばす
  * </p>
- * 
+ *
  * <p>
  * 説明: ニコニコ動画の動画をコメントつきで保存
  * </p>
- * 
+ *
  * <p>
  * 著作権: Copyright (c) 2007 PSI
  * </p>
- * 
+ *
  * <p>
  * 会社名:
  * </p>
- * 
+ *
  * @author 未入力
  * @version 1.0
  */
 public class MainFrame_AboutBox extends JDialog implements ActionListener {
        /**
-        * 
+        *
         */
        private static final long serialVersionUID = -4256413309312729840L;
+    private static final Logger logger = Logger.getLogger(MainFrame_AboutBox.class.getName());
+    private static final String LINE_FEED = System.getProperty("line.separator");
+
+       private static final String version = "ver1.22r(2008/04/27)";
 
-       String version = "ver1.22r(2008/04/27)";
-       
-       String product =
+       private static final String product =
             "本プログラムは「さきゅばす」を改変したものであり, \n" + "オリジナルの著作権は以下の通りです.\n\n" +
                "さきゅばす\n"+
                version + "\n\n"+
                "Copyright (C) 2008 Saccubus Developers Team\n"+
                "              2007-2008 PSI\n\n"+
                "ニコニコ動画の動画をコメントつきで保存";
-       
-       JPanel panel1 = new JPanel();
-
-       JPanel panel2 = new JPanel();
-
-       JPanel insetsPanel1 = new JPanel();
-
-       JPanel insetsPanel2 = new JPanel();
-
-       JPanel insetsPanel3 = new JPanel();
-
-       JButton button1 = new JButton();
-
-       JLabel imageLabel = new JLabel();
-
-       JTextArea product_field = new JTextArea(product);
-
-       ImageIcon image1 = new ImageIcon();
-
-       BorderLayout borderLayout1 = new BorderLayout();
-
-       BorderLayout borderLayout2 = new BorderLayout();
-
-       FlowLayout flowLayout1 = new FlowLayout();
 
-       GridLayout gridLayout1 = new GridLayout();
+       private final JButton okButton = new JButton();
 
        public MainFrame_AboutBox(Frame parent) {
                super(parent);
@@ -76,7 +69,7 @@ public class MainFrame_AboutBox extends JDialog implements ActionListener {
                        setDefaultCloseOperation(DISPOSE_ON_CLOSE);
                        jbInit();
                } catch (Exception exception) {
-                       exception.printStackTrace();
+            logger.log(Level.SEVERE, null, exception);
                }
        }
 
@@ -86,48 +79,91 @@ public class MainFrame_AboutBox extends JDialog implements ActionListener {
 
        /**
         * コンポーネントの初期化。
-        * 
+        *
         * @throws java.lang.Exception
         */
-       private void jbInit() throws Exception {
-               image1 = new ImageIcon(saccubus.MainFrame.class.getResource("icon.png"));
-               imageLabel.setIcon(image1);
+       private void jbInit() {
+        final JPanel basePanel = new JPanel();
+
+        final JLabel imageLabel = new JLabel();
+        final ImageIcon icon = new ImageIcon(saccubus.MainFrame_AboutBox.class.getResource("icon.png"));
+               imageLabel.setIcon(icon);
+
+        final JTextArea productField = new JTextArea(product);
+               productField.setBackground(basePanel.getBackground());
+               productField.setEditable(false);
+
+        final JScrollPane licensePane = createLicensePane();
+
+        okButton.setText("OK");
+        okButton.addActionListener(this);
+
+
+        basePanel.setPreferredSize(new Dimension(500, 500));
+        GroupLayout gl = new GroupLayout(basePanel);
+        basePanel.setLayout(gl);
+
+        gl.setHorizontalGroup(gl.createParallelGroup(GroupLayout.Alignment.CENTER)
+                .addGroup(gl.createSequentialGroup()
+                    .addGap(15).addComponent(imageLabel).addGap(30).addComponent(productField).addGap(30))
+                .addComponent(licensePane)
+                .addComponent(okButton));
+
+        gl.setVerticalGroup(gl.createSequentialGroup()
+                .addGap(15)
+                .addGroup(gl.createParallelGroup()
+                    .addComponent(imageLabel).addComponent(productField))
+                .addGap(15)
+                .addComponent(licensePane)
+                .addComponent(okButton));
+
+               getContentPane().add(basePanel, null);
+
                setTitle("バージョン情報");
-               panel1.setLayout(borderLayout1);
-               panel2.setLayout(borderLayout2);
-               insetsPanel1.setLayout(flowLayout1);
-               insetsPanel2.setLayout(flowLayout1);
-               insetsPanel2.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
-               gridLayout1.setRows(1);
-               gridLayout1.setColumns(1);
-               insetsPanel3.setLayout(gridLayout1);
-               insetsPanel3.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
-               button1.setText("OK");
-               button1.addActionListener(this);
-               insetsPanel2.add(imageLabel, null);
-               panel2.add(insetsPanel2, BorderLayout.WEST);
-               getContentPane().add(panel1, null);
-               product_field.setForeground(insetsPanel3.getForeground());
-               product_field.setBackground(insetsPanel3.getBackground());
-               product_field.addMouseListener(new PopupRightClick(product_field));
-               product_field.setEditable(false);
-               insetsPanel3.add(product_field, null);
-               panel2.add(insetsPanel3, BorderLayout.CENTER);
-               insetsPanel1.add(button1, null);
-               panel1.add(insetsPanel1, BorderLayout.SOUTH);
-               panel1.add(panel2, BorderLayout.NORTH);
-               setResizable(true);
+        setResizable(true);
        }
 
+    private JScrollPane createLicensePane() {
+        final JTextArea licenseField = new JTextArea();
+        try (BufferedReader reader = new BufferedReader(new InputStreamReader(getClass().getResourceAsStream(
+                        "LICENSE.txt"), "UTF-8"))) {
+            String line;
+            while ((line = reader.readLine()) != null) {
+                licenseField.append(line);
+                licenseField.append(LINE_FEED);
+            }
+        }catch(IOException ex){
+            logger.log(Level.SEVERE, null, ex);
+        }
+
+        licenseField.setCaretPosition(0);
+        licenseField.setEditable(false);
+        final JScrollPane licensePane = new JScrollPane(licenseField);
+        return licensePane;
+    }
+
        /**
         * ボタンイベントでダイアログを閉じる
-        * 
+        *
         * @param actionEvent
         *            ActionEvent
         */
+    @Override
        public void actionPerformed(ActionEvent actionEvent) {
-               if (actionEvent.getSource() == button1) {
+               if (actionEvent.getSource() == okButton) {
                        dispose();
                }
        }
+
+    public static void main(String[] args){
+        SwingUtilities.invokeLater(new Runnable() {
+
+            @Override
+            public void run() {
+                MainFrame_AboutBox frame = new MainFrame_AboutBox();
+                frame.pack();
+                frame.setVisible(true);
+            }
+        });
+    }
 }