OSDN Git Service

誤字修正
[coroid/inqubus.git] / frontend / src / saccubus / MainFrame.java
index 1bbcc08..a35e4b7 100644 (file)
@@ -18,8 +18,11 @@ 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;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
 import javax.swing.JComboBox;
@@ -35,6 +38,7 @@ 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 nicobrowser.entity.NicoContent;
 import org.apache.commons.lang.StringUtils;
@@ -78,7 +82,7 @@ public class MainFrame extends JFrame {
 
     private static final long serialVersionUID = 2564486741331062989L;
     public static final String PRODUCT_NAME = "いんきゅばす";
-    public static final String VERSION = "1.4.4";
+    public static final String VERSION = "1.7.0";
     public static final Image WinIcon = Toolkit.getDefaultToolkit().createImage(saccubus.MainFrame.class.getResource(
             "icon32.png"));
     // TODO GUIが無いためフィールドに保持.
@@ -112,6 +116,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");
 
@@ -277,43 +298,6 @@ public class MainFrame extends JFrame {
         gridBagConstraints58.fill = GridBagConstraints.HORIZONTAL;
         gridBagConstraints58.gridy = 0;
 
-
-        final GridBagConstraints gbcFFmpegOptionComboBoxPanel = new GridBagConstraints(0, 0, 2, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0);
-
-        final Insets ffmpegOptionInsets = new Insets(0, 0, 5, 5);
-
-        final GridBagConstraints gbcExtOptionLabel = new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
-                GridBagConstraints.WEST, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcExtOptionField = new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcMainOptionLabel = new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0,
-                GridBagConstraints.WEST, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcMainOptionField = new GridBagConstraints(1, 3, 1, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcInputOptionLabel = new GridBagConstraints(0, 4, 1, 1, 0.0, 0.0,
-                GridBagConstraints.WEST, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcInputOptionField = new GridBagConstraints(1, 4, 1, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcOutputOptionLabel = new GridBagConstraints(0, 5, 1, 1, 0.0, 0.0,
-                GridBagConstraints.WEST, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcOutputOptionField = new GridBagConstraints(1, 5, 1, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcAvfilterOptionLabel = new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0,
-                GridBagConstraints.WEST, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-        final GridBagConstraints gbcAvfilterOptionField = new GridBagConstraints(1, 6, 1, 1, 1.0, 0.0,
-                GridBagConstraints.CENTER, GridBagConstraints.BOTH, ffmpegOptionInsets, 0, 0);
-
-
         GridBagConstraints gridBagConstraints54 = new GridBagConstraints(0, 2, 2, 1, 1.0, 0.0, GridBagConstraints.CENTER,
                 GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0);
         gridBagConstraints54.gridwidth = 3;
@@ -452,17 +436,82 @@ public class MainFrame extends JFrame {
                 GridBagConstraints.BOTH, new Insets(0, 0, 5, 5), 0, 0));
         PathSettingPanel.add(VhookPathLabel, gridBagConstraints54);
 
-        FFmpegSettingPanel.add(getFFmpegOptionComboBoxPanel(), gbcFFmpegOptionComboBoxPanel);
-        FFmpegSettingPanel.add(extOptionLabel, gbcExtOptionLabel);
-        FFmpegSettingPanel.add(extOptionField, gbcExtOptionField);
-        FFmpegSettingPanel.add(mainOptionField, gbcMainOptionField);
-        FFmpegSettingPanel.add(mainOptionLabel, gbcMainOptionLabel);
-        FFmpegSettingPanel.add(inputOptionField, gbcInputOptionField);
-        FFmpegSettingPanel.add(inputOptionLabel, gbcInputOptionLabel);
-        FFmpegSettingPanel.add(outputOptionField, gbcOutputOptionField);
-        FFmpegSettingPanel.add(outputOptionLabel, gbcOutputOptionLabel);
-        FFmpegSettingPanel.add(avfilterOptionLabel, gbcAvfilterOptionLabel);
-        FFmpegSettingPanel.add(avfilterOptionField, gbcAvfilterOptionField);
+
+        final GroupLayout layout = new GroupLayout(FFmpegSettingPanel);
+        FFmpegSettingPanel.setLayout(layout);
+
+        layout.setHorizontalGroup(layout.createParallelGroup()
+                .addComponent(getFFmpegOptionComboBoxPanel())
+                .addGroup(layout.createSequentialGroup()
+                    .addGroup(layout.createParallelGroup()
+                        .addComponent(extOptionLabel)
+                        .addComponent(mainOptionLabel)
+                        .addComponent(inputOptionLabel)
+                        .addComponent(outputOptionLabel)
+                        .addComponent(avfilterOptionLabel)
+                    )
+                    .addPreferredGap(ComponentPlacement.RELATED)
+                    .addGroup(layout.createParallelGroup()
+                        .addComponent(extOptionField)
+                        .addComponent(mainOptionField)
+                        .addComponent(inputOptionField)
+                        .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)
+                        .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(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();
+
 
         VideoInfoPanel.add(DoButton, gridBagConstraints71);
         VideoInfoPanel.add(OpPanel, new GridBagConstraints(0, 0, 1, 1, 1.0,
@@ -739,8 +788,13 @@ public class MainFrame extends JFrame {
         vhookPathField.setText(movie.getVhook().toString());
         extOptionField.setText(movie.getFfmpegOption().getExtOption());
         mainOptionField.setText(movie.getFfmpegOption().getMainOption());
-        outputOptionField.setText(movie.getFfmpegOption().getOutOption());
         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());
 
         // 変換設定
@@ -764,8 +818,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);
     }
 
@@ -784,6 +842,7 @@ public class MainFrame extends JFrame {
 
     /* 変換・保存する */
     private Converter Converter = null;
+    // FFmpegの設定 ここから
     private final JLabel extOptionLabel = new JLabel();
     private final JTextField extOptionField = new JTextField();
     private JLabel mainOptionLabel = new JLabel();
@@ -794,6 +853,13 @@ 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("次のサイズに収まるよう縮小(-s)");
+    private final JLabel resizeWidthLabel = new JLabel("横");
+    private final JTextField resizeWidthField = new NumberFormattedTextField();
+    private final JLabel resizeHeightLabel = new JLabel("縦");
+    private final JTextField resizeHeigitField = new NumberFormattedTextField();
+    private final JCheckBox adjustRatioCheckBox = new JCheckBox("アスペクト比を維持");
+    // FFmpegの設定 ここまで
     private JLabel FontIndexLabel = new JLabel();
     private JTextField fontIndexField = new JTextField();
     private JLabel VideoID_Label = new JLabel();
@@ -805,7 +871,7 @@ public class MainFrame extends JFrame {
     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;
@@ -982,13 +1048,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);
+            NGWordSettingPanel.add(NGWordLabel, gridBagConstraints2);
             NGWordSettingPanel.add(getNGWordTextField(), gridBagConstraints3);
             NGWordSettingPanel.add(NGIDLabel, gridBagConstraints4);
             NGWordSettingPanel.add(getNGIDTextField(), gridBagConstraints5);
@@ -1161,17 +1227,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);
+                        setFFMpegOptionEnabled(false);
                     } else {// ファイルでない
-                        extOptionField.setEnabled(true);
-                        mainOptionField.setEnabled(true);
-                        inputOptionField.setEnabled(true);
-                        outputOptionField.setEnabled(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;
@@ -1349,9 +1422,14 @@ public class MainFrame extends JFrame {
         String main = mainOptionField.getText();
         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);
+        FfmpegOption opt = new FfmpegOption(ext, main, in, out, avfilter, resize, width, height, adjust);
         return new MovieSetting(new File(ffmpeg), new File(vhook), optionFile, opt);
     }