OSDN Git Service

変数名変更
[coroid/inqubus.git] / frontend / src / saccubus / MainFrame.java
index cef745a..e431d0f 100644 (file)
@@ -18,6 +18,8 @@ import java.awt.event.KeyEvent;
 import java.awt.event.WindowAdapter;
 import java.awt.event.WindowEvent;
 import java.io.File;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
 import javax.swing.GroupLayout;
@@ -36,9 +38,10 @@ import javax.swing.JPasswordField;
 import javax.swing.JRadioButton;
 import javax.swing.JTabbedPane;
 import javax.swing.JTextField;
+import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SwingUtilities;
-import javax.swing.border.BevelBorder;
 import nicobrowser.entity.NicoContent;
+import nicobrowser.main.Main;
 import org.apache.commons.lang.StringUtils;
 import saccubus.ConvertStopFlag.State;
 import saccubus.converter.profile.FfmpegOption;
@@ -80,7 +83,7 @@ public class MainFrame extends JFrame {
 
     private static final long serialVersionUID = 2564486741331062989L;
     public static final String PRODUCT_NAME = "いんきゅばす";
-    public static final String VERSION = "1.5.0";
+    public static final String VERSION = "1.7.1 (NicoBrowser" + Main.VERSION + ")";
     public static final Image WinIcon = Toolkit.getDefaultToolkit().createImage(saccubus.MainFrame.class.getResource(
             "icon32.png"));
     // TODO GUIが無いためフィールドに保持.
@@ -96,9 +99,14 @@ public class MainFrame extends JFrame {
     JTabbedPane mainTabbedPane = new JTabbedPane();
     JPanel SavingInfoTabPanel = new JPanel();
     JPanel FFMpegTabPanel = new JPanel();
-    JPanel VideoInfoPanel = new JPanel();
-    JTextField VideoID_TextField = new JTextField();
-    JButton DoButton = new JButton();
+    // メインウィンドウ
+    private JPanel videoInfoPanel = new JPanel();
+    private JPanel opPanel = new JPanel();
+    private JLabel videoIdLabel = new JLabel();
+    private JTextField videoIdField = new JTextField();
+    private JLabel wayBackLabel = new JLabel();
+    private JTextField wayBackField = new JTextField();
+    private JButton doButton = new JButton();
     public static final String DoButtonDefString = "変換";
     public static final String DoButtonStopString = "停止";
     public static final String DoButtonWaitString = "待機";
@@ -114,6 +122,23 @@ public class MainFrame extends JFrame {
     ButtonGroup CommentSaveButtonGroup = new ButtonGroup();
     ButtonGroup ConvSaveButtonGroup = new ButtonGroup();
 
+    private class FfmpegOptionCheckBoxListener implements ActionListener{
+
+        @Override
+        public void actionPerformed(ActionEvent e) {
+            setFFMpegOptionCheckbox();
+        }
+    }
+    private final FfmpegOptionCheckBoxListener ffmpegOptionCheckBoxListener = new FfmpegOptionCheckBoxListener();
+
+    private void setFFMpegOptionCheckbox() {
+        boolean resizable = (resizeCheckBox.isEnabled() && resizeCheckBox.isSelected());
+        resizeWidthField.setEnabled(resizable);
+        resizeHeigitField.setEnabled(resizable);
+        adjustRatioCheckBox.setEnabled(resizable);
+
+    }
+
     private void setNames() {
         mainTabbedPane.setName("mainTabbedPane");
 
@@ -180,35 +205,6 @@ public class MainFrame extends JFrame {
                 GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 6);
         gridBagConstraints71.fill = GridBagConstraints.BOTH;
         gridBagConstraints71.ipady = 0;
-        GridBagConstraints gridBagConstraints70 = new GridBagConstraints();
-        gridBagConstraints70.fill = GridBagConstraints.HORIZONTAL;
-        gridBagConstraints70.gridy = 1;
-        gridBagConstraints70.ipadx = 0;
-        gridBagConstraints70.ipady = 0;
-        gridBagConstraints70.weightx = 1.0;
-        gridBagConstraints70.insets = new Insets(0, 0, 0, 0);
-        gridBagConstraints70.gridx = 1;
-        GridBagConstraints gridBagConstraints69 = new GridBagConstraints();
-        gridBagConstraints69.gridx = 0;
-        gridBagConstraints69.ipadx = 0;
-        gridBagConstraints69.ipady = 0;
-        gridBagConstraints69.insets = new Insets(0, 5, 0, 5);
-        gridBagConstraints69.anchor = GridBagConstraints.WEST;
-        gridBagConstraints69.gridy = 1;
-        GridBagConstraints gridBagConstraints68 = new GridBagConstraints();
-        gridBagConstraints68.fill = GridBagConstraints.BOTH;
-        gridBagConstraints68.gridy = 0;
-        gridBagConstraints68.ipady = 0;
-        gridBagConstraints68.weightx = 1.0;
-        gridBagConstraints68.insets = new Insets(0, 0, 0, 0);
-        gridBagConstraints68.gridx = 1;
-        GridBagConstraints gridBagConstraints67 = new GridBagConstraints();
-        gridBagConstraints67.gridx = 0;
-        gridBagConstraints67.ipadx = 0;
-        gridBagConstraints67.ipady = 0;
-        gridBagConstraints67.insets = new Insets(0, 5, 0, 5);
-        gridBagConstraints67.anchor = GridBagConstraints.WEST;
-        gridBagConstraints67.gridy = 0;
         GridBagConstraints gridBagConstraints66 = new GridBagConstraints();
         gridBagConstraints66.gridx = 0;
         gridBagConstraints66.insets = new Insets(0, 5, 5, 5);
@@ -333,10 +329,7 @@ public class MainFrame extends JFrame {
         jMenuHelpAbout.setText("バージョン情報");
         jMenuHelpAbout.addActionListener(new MainFrame_jMenuHelpAbout_ActionAdapter(
                 this));
-        VideoInfoPanel.setLayout(gridBagLayout1);
-        VideoID_TextField.setText("http://www.nicovideo.jp/watch/");
-        DoButton.setText(DoButtonDefString);
-        DoButton.addActionListener(new MainFrame_DoButton_actionAdapter(this));
+        videoInfoPanel.setLayout(gridBagLayout1);
         SavingInfoTabPanel.setLayout(new GridLayout());
         UserInfoPanel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "ユーザ設定"));
         UserInfoPanel.setLayout(gridBagLayout3);
@@ -376,9 +369,6 @@ public class MainFrame extends JFrame {
         avfilterOptionLabel.setText("avfilterオプション");
 
         FontIndexLabel.setText("フォント番号");
-        VideoID_Label.setText("URL/ID");
-        WayBackLabel.setText("過去ログ");
-        OpPanel.setLayout(new GridBagLayout());
 
         BasicInfoTabPanel.setLayout(gridBagLayout12);
         jMenuBar1.add(jMenuFile);
@@ -389,7 +379,7 @@ public class MainFrame extends JFrame {
 
         contentPane.add(statusBar, BorderLayout.SOUTH);
         contentPane.add(mainTabbedPane, java.awt.BorderLayout.CENTER);
-        contentPane.add(VideoInfoPanel, java.awt.BorderLayout.NORTH);
+        contentPane.add(videoInfoPanel, java.awt.BorderLayout.NORTH);
         UserInfoPanel.add(passwordField, new GridBagConstraints(1, 1, 1, 1,
                 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                 new Insets(0, 5, 5, 5), 0, 0));
@@ -428,57 +418,108 @@ public class MainFrame extends JFrame {
                         .addComponent(extOptionLabel)
                         .addComponent(mainOptionLabel)
                         .addComponent(inputOptionLabel)
-                        .addComponent(outputOptionLabel))
+                        .addComponent(outputOptionLabel)
+                        .addComponent(avfilterOptionLabel)
+                    )
+                    .addPreferredGap(ComponentPlacement.RELATED)
                     .addGroup(layout.createParallelGroup()
                         .addComponent(extOptionField)
                         .addComponent(mainOptionField)
                         .addComponent(inputOptionField)
-                        .addComponent(outputOptionField)))
+                        .addComponent(outputOptionField)
+                        .addComponent(avfilterOptionField)
+                    )
+                )
                 .addGroup(layout.createParallelGroup()
                     .addGroup(layout.createSequentialGroup()
                         .addComponent(resizeCheckBox)
+                        .addPreferredGap(ComponentPlacement.UNRELATED)
                         .addComponent(resizeWidthLabel)
+                        .addPreferredGap(ComponentPlacement.RELATED)
                         .addComponent(resizeWidthField)
+                        .addPreferredGap(ComponentPlacement.UNRELATED)
                         .addComponent(resizeHeightLabel)
-                        .addComponent(resizeHeigitField)))
-                    .addComponent(adjustRatioCheckBox)
-                    .addComponent(padCheckBox)
-                );
+                        .addPreferredGap(ComponentPlacement.RELATED)
+                        .addComponent(resizeHeigitField)
+                    )
+                )
+                .addGroup(layout.createSequentialGroup()
+                    .addGap(10)
+                    .addComponent(adjustRatioCheckBox))
+                .addGroup(layout.createSequentialGroup()
+                    .addGap(20)
+                )
+            );
 
         layout.setVerticalGroup(layout.createSequentialGroup()
-                .addComponent(getFFmpegOptionComboBoxPanel())
-                .addGroup(layout.createParallelGroup()
-                    .addComponent(extOptionLabel)
-                    .addComponent(extOptionField))
-                .addGroup(layout.createParallelGroup()
-                    .addComponent(mainOptionLabel)
-                    .addComponent(mainOptionField))
-                .addGroup(layout.createParallelGroup()
-                    .addComponent(inputOptionLabel)
-                    .addComponent(inputOptionField))
-                .addGroup(layout.createParallelGroup()
-                    .addComponent(outputOptionLabel)
-                    .addComponent(outputOptionField))
-                .addGroup(layout.createSequentialGroup()
-                    .addGroup(layout.createParallelGroup()
-                        .addComponent(resizeCheckBox)
-                        .addComponent(resizeWidthLabel)
-                        .addComponent(resizeWidthField)
-                        .addComponent(resizeHeightLabel)
-                        .addComponent(resizeHeigitField))
-                    .addComponent(adjustRatioCheckBox)
-                    .addComponent(padCheckBox)));
+            .addComponent(getFFmpegOptionComboBoxPanel())
+            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                .addComponent(extOptionLabel)
+                .addComponent(extOptionField))
+            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                .addComponent(mainOptionLabel)
+                .addComponent(mainOptionField))
+            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                .addComponent(inputOptionLabel)
+                .addComponent(inputOptionField))
+            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                .addComponent(outputOptionLabel)
+                .addComponent(outputOptionField))
+            .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                .addComponent(avfilterOptionLabel)
+                .addComponent(avfilterOptionField))
+            .addGroup(layout.createSequentialGroup()
+                .addGroup(layout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                    .addComponent(resizeCheckBox)
+                    .addComponent(resizeWidthLabel)
+                    .addComponent(resizeWidthField)
+                    .addComponent(resizeHeightLabel)
+                    .addComponent(resizeHeigitField))
+                .addComponent(adjustRatioCheckBox)
+                )
+            );
+
+        resizeCheckBox.addActionListener(ffmpegOptionCheckBoxListener);
+        adjustRatioCheckBox.addActionListener(ffmpegOptionCheckBoxListener);
+        setFFMpegOptionCheckbox();
+
+
+
+        videoIdLabel.setText("URL/ID");
+        wayBackLabel.setText("過去ログ");
+        videoIdField.setText("http://www.nicovideo.jp/watch/");
+
+        final GroupLayout oppLayout = new GroupLayout(opPanel);
+        opPanel.setLayout(oppLayout);
+
+        oppLayout.setHorizontalGroup(oppLayout.createSequentialGroup()
+                .addGroup(oppLayout.createParallelGroup()
+                    .addComponent(videoIdLabel)
+                    .addComponent(wayBackLabel))
+                .addGroup(oppLayout.createParallelGroup()
+                    .addComponent(videoIdField)
+                    .addGroup(oppLayout.createSequentialGroup()
+                        .addComponent(wayBackField)))
+                );
+
+        oppLayout.setVerticalGroup(oppLayout.createSequentialGroup()
+                    .addGroup(oppLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                        .addComponent(videoIdLabel)
+                        .addComponent(videoIdField))
+                    .addGroup(oppLayout.createParallelGroup(GroupLayout.Alignment.BASELINE)
+                        .addComponent(wayBackLabel)
+                        .addComponent(wayBackField))
+                );
 
+        doButton.setText(DoButtonDefString);
+        doButton.addActionListener(new MainFrame_DoButton_actionAdapter(this));
 
-        VideoInfoPanel.add(DoButton, gridBagConstraints71);
-        VideoInfoPanel.add(OpPanel, new GridBagConstraints(0, 0, 1, 1, 1.0,
+        videoInfoPanel.add(opPanel, new GridBagConstraints(0, 0, 1, 1, 1.0,
                 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
                 new Insets(0, 0, 0, 0), 0, 0));
-        OpPanel.add(VideoID_Label, gridBagConstraints67);
-        OpPanel.add(VideoID_TextField, gridBagConstraints68);
-        OpPanel.add(WayBackLabel, gridBagConstraints69);
-        OpPanel.add(WayBackField, gridBagConstraints70);
+        videoInfoPanel.add(doButton, gridBagConstraints71);
 
+        
         mainTabbedPane.add(BasicInfoTabPanel, "基本設定");
         mainTabbedPane.add(SavingInfoTabPanel, "保存設定");
         mainTabbedPane.add(FFMpegTabPanel, "動画設定");
@@ -560,14 +601,14 @@ public class MainFrame extends JFrame {
         ffmpegPathField.addMouseListener(new PopupRightClick(
                 this.ffmpegPathField));
         vhookPathField.addMouseListener(new PopupRightClick(this.vhookPathField));
-        VideoID_TextField.addMouseListener(new PopupRightClick(
-                this.VideoID_TextField));
+        videoIdField.addMouseListener(new PopupRightClick(
+                this.videoIdField));
         viewCommentField.addMouseListener(new PopupRightClick(
                 this.viewCommentField));
         fontPathField.addMouseListener(new PopupRightClick(this.fontPathField));
         mailAddressField.addMouseListener(new PopupRightClick(this.mailAddressField));
         passwordField.addMouseListener(new PopupRightClick(this.passwordField));
-        WayBackField.addMouseListener(new PopupRightClick(this.WayBackField));
+        wayBackField.addMouseListener(new PopupRightClick(this.wayBackField));
 
         proxyTextField.addMouseListener(new PopupRightClick(this.proxyTextField));
         proxyPortTextField.addMouseListener(new PopupRightClick(
@@ -748,6 +789,10 @@ public class MainFrame extends JFrame {
         inputOptionField.setText(movie.getFfmpegOption().getInOption());
         outputOptionField.setText(movie.getFfmpegOption().getOutOption());
         avfilterOptionField.setText(movie.getFfmpegOption().getAvfilterOption());
+        resizeCheckBox.setSelected(movie.getFfmpegOption().isResize());
+        resizeWidthField.setText(Integer.toString(movie.getFfmpegOption().getResizeWidth()));
+        resizeHeigitField.setText(Integer.toString(movie.getFfmpegOption().getResizeHeight()));
+        adjustRatioCheckBox.setSelected(movie.getFfmpegOption().isAdjustRatio());
         FFmpegOptionModel.reload(movie.getOptionFile());
 
         // 変換設定
@@ -771,8 +816,12 @@ public class MainFrame extends JFrame {
      *            ActionEvent
      */
     void jMenuFileExit_actionPerformed(ActionEvent actionEvent) {
-        SProperties setting = getSetting();
-        SProperties.saveSetting(setting);
+        try {
+            SProperties setting = getSetting();
+            SProperties.saveSetting(setting);
+        } catch (Throwable t) {
+            Logger.getLogger(MainFrame.class.getName()).log(Level.SEVERE, "設定保存に失敗", t);
+        }
         System.exit(0);
     }
 
@@ -802,26 +851,21 @@ public class MainFrame extends JFrame {
     private JTextField outputOptionField = new JTextField();
     private final JLabel avfilterOptionLabel = new JLabel();
     private final JTextField avfilterOptionField = new JTextField();
-    private final JCheckBox resizeCheckBox = new JCheckBox("次のサイズに収まるようリサイズ");
+    private final JCheckBox resizeCheckBox = new JCheckBox("次のサイズに収まるよう縮小(-s)");
     private final JLabel resizeWidthLabel = new JLabel("横");
-    private final JTextField resizeWidthField = new JTextField();
+    private final JTextField resizeWidthField = new NumberFormattedTextField();
     private final JLabel resizeHeightLabel = new JLabel("縦");
-    private final JTextField resizeHeigitField = new JTextField();
+    private final JTextField resizeHeigitField = new NumberFormattedTextField();
     private final JCheckBox adjustRatioCheckBox = new JCheckBox("アスペクト比を維持");
-    private final JCheckBox padCheckBox = new JCheckBox("黒幕を付与");
     // FFmpegの設定 ここまで
     private JLabel FontIndexLabel = new JLabel();
     private JTextField fontIndexField = new JTextField();
-    private JLabel VideoID_Label = new JLabel();
-    private JLabel WayBackLabel = new JLabel();
-    private JTextField WayBackField = new JTextField();
     private GridBagLayout gridBagLayout1 = new GridBagLayout();
-    private JPanel OpPanel = new JPanel();
     private JPanel BasicInfoTabPanel = new JPanel();
     private GridBagLayout gridBagLayout12 = new GridBagLayout();
     private JPanel ConvertingSettingPanel = null;
     private JPanel NGWordSettingPanel = null;
-    private JLabel NGWordLavel = null;
+    private JLabel NGWordLabel = null;
     private JTextField ngWordTextField = null;
     private JLabel NGIDLabel = null;
     private JTextField ngIdTextField = null;
@@ -880,7 +924,7 @@ public class MainFrame extends JFrame {
                 return;
             }
         } else {
-            url = VideoID_TextField.getText();
+            url = videoIdField.getText();
         }
 
         TextProgressListener sl = new TextProgressListener() {
@@ -903,19 +947,19 @@ public class MainFrame extends JFrame {
                     public void run() {
                         switch (s) {
                             case STOPPING:
-                                DoButton.setText(DoButtonWaitString);
+                                doButton.setText(DoButtonWaitString);
                                 break;
                             case FINISHED:
-                                DoButton.setText(DoButtonDefString);
+                                doButton.setText(DoButtonDefString);
                         }
                     }
                 });
             }
         };
 
-        Converter = new Converter(url, WayBackField.getText(), getSetting().toProfile(), sl,
+        Converter = new Converter(url, wayBackField.getText(), getSetting().toProfile(), sl,
                 new ConvertStopFlag(scl));
-        DoButton.setText(DoButtonStopString);
+        doButton.setText(DoButtonStopString);
         new Thread(Converter).start();
 
     }
@@ -998,13 +1042,13 @@ public class MainFrame extends JFrame {
             gridBagConstraints2.gridx = 0;
             gridBagConstraints2.insets = new Insets(0, 5, 5, 0);
             gridBagConstraints2.gridy = 0;
-            NGWordLavel = new JLabel();
-            NGWordLavel.setText("NGワード");
+            NGWordLabel = new JLabel();
+            NGWordLabel.setText("NGワード");
             NGWordSettingPanel = new JPanel();
             NGWordSettingPanel.setLayout(new GridBagLayout());
             NGWordSettingPanel.setBorder(BorderFactory.createTitledBorder(null,
-                    "NGワード・ID設定"));
-            NGWordSettingPanel.add(NGWordLavel, gridBagConstraints2);
+                    "NGワード・ID設定(半角スペース区切りで複数入力)"));
+            NGWordSettingPanel.add(NGWordLabel, gridBagConstraints2);
             NGWordSettingPanel.add(getNGWordTextField(), gridBagConstraints3);
             NGWordSettingPanel.add(NGIDLabel, gridBagConstraints4);
             NGWordSettingPanel.add(getNGIDTextField(), gridBagConstraints5);
@@ -1177,19 +1221,24 @@ public class MainFrame extends JFrame {
 
                 public void actionPerformed(java.awt.event.ActionEvent e) {
                     if (FFmpegOptionModel.isFile()) {// ファイル
-                        extOptionField.setEnabled(false);
-                        mainOptionField.setEnabled(false);
-                        inputOptionField.setEnabled(false);
-                        outputOptionField.setEnabled(false);
-                        avfilterOptionField.setEnabled(false);
+                        setFFMpegOptionEnabled(false);
                     } else {// ファイルでない
-                        extOptionField.setEnabled(true);
-                        mainOptionField.setEnabled(true);
-                        inputOptionField.setEnabled(true);
-                        outputOptionField.setEnabled(true);
-                        avfilterOptionField.setEditable(true);
+                        setFFMpegOptionEnabled(true);
+                        setFFMpegOptionCheckbox();
                     }
                 }
+
+                private void setFFMpegOptionEnabled(boolean enable) {
+                    extOptionField.setEnabled(enable);
+                    mainOptionField.setEnabled(enable);
+                    inputOptionField.setEnabled(enable);
+                    outputOptionField.setEnabled(enable);
+                    avfilterOptionField.setEnabled(enable);
+                    resizeCheckBox.setEnabled(enable);
+                    resizeWidthField.setEnabled(enable);
+                    resizeHeigitField.setEditable(enable);
+                    adjustRatioCheckBox.setEnabled(enable);
+                }
             });
         }
         return FFmpegOptionComboBox;
@@ -1368,9 +1417,13 @@ public class MainFrame extends JFrame {
         String in = inputOptionField.getText();
         String out = outputOptionField.getText();
         String avfilter = avfilterOptionField.getText();
+        boolean resize = resizeCheckBox.isSelected();
+        String width = resizeWidthField.getText();
+        String height = resizeHeigitField.getText();
+        boolean adjust = adjustRatioCheckBox.isSelected();
         File optionFile = FFmpegOptionModel.getSelectedFile();
 
-        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter);
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust);
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }
 
@@ -1496,7 +1549,7 @@ public class MainFrame extends JFrame {
 
         private void mask(boolean b) {
             final VideoSaveInfoPanel panel = videoSaveInfoPanel;
-            VideoID_TextField.setEditable(b);
+            videoIdField.setEditable(b);
             panel.getDelVideoCheckBox().setEnabled(b);
 
             panel.getSaveFolderRadioButton().setEnabled(b);