OSDN Git Service

ffmpegオプションパネルのイベント処理
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index 0920675..082b46a 100644 (file)
@@ -42,6 +42,7 @@ import javax.swing.JMenuItem;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JScrollPane;
+import javax.swing.JTabbedPane;
 import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
@@ -49,10 +50,12 @@ import javax.swing.LayoutStyle.ComponentPlacement;
 import javax.swing.SwingUtilities;
 import javax.swing.TransferHandler;
 import javax.swing.WindowConstants;
+import javax.swing.border.BevelBorder;
 import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.builder.ToStringBuilder;
 import saccubus.FfmpegOption;
 import saccubus.MainFrame_AboutBox;
+import saccubus.OptionComboBoxModel;
 import saccubus.util.WayBackTimeParser;
 import saccubus.worker.impl.convert.ConvertProgress;
 import saccubus.worker.impl.download.DownloadProgress;
@@ -113,6 +116,7 @@ public class MainFrame extends JFrame {
         tblDisplay = new JTable(targetModel, new TargetsColumnModel());
         tblDisplay.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
         final JPanel pnlButton = new JPanel();
+        final JTabbedPane tbpInput = new JTabbedPane();
         final JPanel pnlInputMain = new JPanel();
         final JLabel lblId = new JLabel();
         fldId.setToolTipText(ID_FIELD_TOOLTIP);
@@ -199,8 +203,6 @@ public class MainFrame extends JFrame {
                 .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
         );
 
-        pnlInputMain.setBorder(BorderFactory.createEtchedBorder());
-
         lblId.setText("ID");
 
         fldId.addFocusListener(new java.awt.event.FocusAdapter() {
@@ -245,54 +247,59 @@ public class MainFrame extends JFrame {
         });
 
 
-        GroupLayout gl_pnlInputMain = new GroupLayout(pnlInputMain);
-        pnlInputMain.setLayout(gl_pnlInputMain);
-        gl_pnlInputMain.setHorizontalGroup(
-            gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
-            .addGroup(gl_pnlInputMain.createSequentialGroup()
+        final GroupLayout glInputMain = new GroupLayout(pnlInputMain);
+        pnlInputMain.setLayout(glInputMain);
+        glInputMain.setHorizontalGroup(
+            glInputMain.createParallelGroup(Alignment.LEADING)
+            .addGroup(glInputMain.createSequentialGroup()
                 .addContainerGap()
-                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
-                    .addGroup(gl_pnlInputMain.createSequentialGroup()
-                        .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
-                            .addComponent(lblComment)
+                .addComponent(lblId)
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, Short.MAX_VALUE)
+                .addPreferredGap(ComponentPlacement.UNRELATED)
+                .addComponent(cbBackLogReduce)
+                .addPreferredGap(ComponentPlacement.UNRELATED)
+                .addComponent(cbBackLog)
+                .addPreferredGap(ComponentPlacement.RELATED)
+                .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
+                .addContainerGap()
+            )
+            .addGroup(glInputMain.createSequentialGroup()
+                .addContainerGap()
+                .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
+                    .addGroup(glInputMain.createSequentialGroup()
+                        .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
                             .addComponent(lblVideo)
-                            .addComponent(lblId)
+                            .addComponent(lblComment)
                             .addComponent(lblOutput))
                         .addPreferredGap(ComponentPlacement.RELATED)
-                        .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
-                            .addGroup(gl_pnlInputMain.createSequentialGroup()
+                        .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
+                            .addGroup(glInputMain.createSequentialGroup()
                                 .addComponent(cbVideoLocal)
                                 .addPreferredGap(ComponentPlacement.RELATED)
                                 .addComponent(fldVideo, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)
                                 .addPreferredGap(ComponentPlacement.RELATED)
                                 .addComponent(btnVideo))
-                            .addGroup(gl_pnlInputMain.createSequentialGroup()
-                                .addComponent(fldId, GroupLayout.PREFERRED_SIZE, 100, GroupLayout.PREFERRED_SIZE)
-                                .addPreferredGap(ComponentPlacement.UNRELATED)
-                                .addComponent(cbBackLogReduce)
-                                .addComponent(cbBackLog)
-                                .addComponent(fldBackLog, GroupLayout.PREFERRED_SIZE, 150, GroupLayout.PREFERRED_SIZE)
-                            )
-                            .addGroup(Alignment.TRAILING, gl_pnlInputMain.createSequentialGroup()
-                                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.TRAILING)
-                                    .addGroup(Alignment.LEADING, gl_pnlInputMain.createSequentialGroup()
+                            .addGroup(Alignment.TRAILING, glInputMain.createSequentialGroup()
+                                .addGroup(glInputMain.createParallelGroup(Alignment.TRAILING)
+                                    .addGroup(Alignment.LEADING, glInputMain.createSequentialGroup()
                                         .addComponent(cbOutputEnable)
                                         .addPreferredGap(ComponentPlacement.RELATED)
                                         .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE))
-                                    .addGroup(gl_pnlInputMain.createSequentialGroup()
+                                    .addGroup(glInputMain.createSequentialGroup()
                                         .addComponent(cbCommentLocal)
                                         .addPreferredGap(ComponentPlacement.RELATED)
                                         .addComponent(fldComment, GroupLayout.DEFAULT_SIZE, 317, Short.MAX_VALUE)))
                                 .addPreferredGap(ComponentPlacement.RELATED)
                                 .addComponent(btnComment))))
-                    .addComponent(btnApply, Alignment.TRAILING))
+                    )
                 .addContainerGap())
         );
-        gl_pnlInputMain.setVerticalGroup(
-            gl_pnlInputMain.createParallelGroup(Alignment.LEADING)
-            .addGroup(gl_pnlInputMain.createSequentialGroup()
+        glInputMain.setVerticalGroup(
+            glInputMain.createParallelGroup(Alignment.LEADING)
+            .addGroup(glInputMain.createSequentialGroup()
                 .addContainerGap()
-                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
+                .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
                     .addComponent(fldId, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(lblId)
                     .addComponent(cbBackLogReduce)
@@ -300,25 +307,104 @@ public class MainFrame extends JFrame {
                     .addComponent(fldBackLog)
                 )
                 .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
+                .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
                     .addComponent(lblVideo)
                     .addComponent(fldVideo, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(btnVideo)
                     .addComponent(cbVideoLocal))
                 .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
+                .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
                     .addComponent(lblComment)
                     .addComponent(fldComment, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(btnComment)
                     .addComponent(cbCommentLocal))
                 .addPreferredGap(ComponentPlacement.RELATED)
-                .addGroup(gl_pnlInputMain.createParallelGroup(Alignment.BASELINE)
+                .addGroup(glInputMain.createParallelGroup(Alignment.BASELINE)
                     .addComponent(lblOutput)
                     .addComponent(fldOutput, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                     .addComponent(cbOutputEnable))
-                .addPreferredGap(ComponentPlacement.UNRELATED)
+            )
+        );
+
+        // ffmpeg入力パネル
+        pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(false);
+        pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(false);
+        pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(false);
+        pnlInputFfmpeg.cmbFfmpegOptionFile.addActionListener(new ActionListener() {
+
+            @Override
+            public void actionPerformed(ActionEvent e) {
+                final boolean notFile = !pnlInputFfmpeg.mdlFfmpegOption.isFile();
+                pnlInputFfmpeg.fldFfmpegOptionExtension.setEnabled(notFile);
+                pnlInputFfmpeg.fldFfmpegOptionMain.setEnabled(notFile);
+                pnlInputFfmpeg.fldFfmpegOptionIn.setEnabled(notFile);
+                pnlInputFfmpeg.fldFfmpegOptionOut.setEnabled(notFile);
+                pnlInputFfmpeg.fldFfmpegOptionAv.setEnabled(notFile);
+                pnlInputFfmpeg.cbFfmpegOptionResize.setEnabled(notFile);
+            }
+        });
+        pnlInputFfmpeg.cbFfmpegOptionResize.addItemListener(new ItemListener() {
+
+            @Override
+            public void itemStateChanged(ItemEvent e) {
+                final boolean selected = (e.getStateChange() == ItemEvent.SELECTED);
+                pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(selected);
+                pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(selected);
+                pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(selected);
+            }
+        });
+        pnlInputFfmpeg.cbFfmpegOptionResize.addPropertyChangeListener("enabled", new PropertyChangeListener() {
+
+            @Override
+            public void propertyChange(PropertyChangeEvent evt) {
+                final boolean enabled = ((Boolean) evt.getNewValue()).booleanValue();
+                final boolean fldEnabled = enabled ? pnlInputFfmpeg.cbFfmpegOptionResize.isSelected() : false;
+                pnlInputFfmpeg.fldFfmpegOptionResizeWidth.setEnabled(fldEnabled);
+                pnlInputFfmpeg.fldFfmpegOptionResizeHeight.setEnabled(fldEnabled);
+                pnlInputFfmpeg.cbFfmpegOptionKeepAspect.setEnabled(fldEnabled);
+            }
+        });
+
+
+        tbpInput.add("メイン", pnlInputMain);
+        tbpInput.add("ffmpeg", pnlInputFfmpeg);
+
+        // 入力部のボタンやメッセージ表示部
+        fldInputMessage.setEditable(false);
+        fldInputMessage.setEnabled(false);
+        fldInputMessage.setBorder(BorderFactory.createEmptyBorder());
+
+        final JPanel pnlInputButton = new JPanel();
+        final GroupLayout glInputButton = new GroupLayout(pnlInputButton);
+        pnlInputButton.setLayout(glInputButton);
+        glInputButton.setHorizontalGroup(glInputButton.createSequentialGroup()
+            .addContainerGap()
+            .addComponent(fldInputMessage, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
+            .addPreferredGap(ComponentPlacement.UNRELATED)
+            .addComponent(btnApply)
+            .addContainerGap()
+        );
+        glInputButton.setVerticalGroup(glInputButton.createSequentialGroup()
+            .addContainerGap()
+            .addGroup(glInputButton.createParallelGroup(Alignment.BASELINE)
+                .addComponent(fldInputMessage, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                 .addComponent(btnApply)
-                .addContainerGap(GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+            )
+            .addContainerGap()
+        );
+
+        // 画面下半分の入力部分
+        final JPanel pnlInputAll = new JPanel();
+        pnlInputAll.setBorder(BorderFactory.createBevelBorder(BevelBorder.RAISED));
+        final GroupLayout glInputAll = new GroupLayout(pnlInputAll);
+        pnlInputAll.setLayout(glInputAll);
+        glInputAll.setHorizontalGroup(glInputAll.createParallelGroup()
+            .addComponent(tbpInput)
+            .addComponent(pnlInputButton)
+        );
+        glInputAll.setVerticalGroup(glInputAll.createSequentialGroup()
+            .addComponent(tbpInput)
+            .addComponent(pnlInputButton)
         );
 
         GroupLayout gl_pnlMain = new GroupLayout(pnlMain);
@@ -328,9 +414,10 @@ public class MainFrame extends JFrame {
             .addGroup(Alignment.TRAILING, gl_pnlMain.createSequentialGroup()
                 .addContainerGap()
                 .addGroup(gl_pnlMain.createParallelGroup(Alignment.TRAILING)
-                    .addComponent(pnlInputMain, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                     .addComponent(scrDisplay, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE)
-                    .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
+                    .addComponent(pnlButton, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                    .addComponent(pnlInputAll, Alignment.LEADING, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
+                )
                 .addContainerGap())
         );
         gl_pnlMain.setVerticalGroup(
@@ -341,8 +428,9 @@ public class MainFrame extends JFrame {
                 .addPreferredGap(ComponentPlacement.RELATED)
                 .addComponent(pnlButton, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
                 .addPreferredGap(ComponentPlacement.RELATED)
-                .addComponent(pnlInputMain, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
-                .addGap(24, 24, 24))
+                .addComponent(pnlInputAll, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
+                .addContainerGap()
+            )
         );
 
 
@@ -421,15 +509,6 @@ public class MainFrame extends JFrame {
             }
         }
     }
-    /** This method is called from within the constructor to
-     * initialize the form.
-     * WARNING: Do NOT modify this code. The content of this method is
-     * always regenerated by the Form Editor.
-     */
-    @SuppressWarnings("unchecked")
-    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
-    private void initComponents() {
-    }// </editor-fold>//GEN-END:initComponents
 
     private File searchFileMatchId(final File dir, final String id) {
         // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも
@@ -530,7 +609,7 @@ public class MainFrame extends JFrame {
     private final JButton btnStart = new JButton("開始");
     private final JButton btnStop = new JButton("停止");
     private final JButton btnDeselect = new JButton("選択解除");
-    //入力領域 - 標準
+    // 入力領域 - メイン
     private final JTextField fldId = new JTextField();
     private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
     private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
@@ -543,11 +622,19 @@ public class MainFrame extends JFrame {
     private final JButton btnComment;
     private final JCheckBox cbOutputEnable;
     private final JTextField fldOutput;
+    // 入力領域 - ffmpeg
+    private final FfmpegParamPanel pnlInputFfmpeg = new FfmpegParamPanel();
     // 適用
+    private final JTextField fldInputMessage = new JTextField();
     private final JButton btnApply = new JButton("適用");
     // End of variables declaration//GEN-END:variables
 
     private void initInputPanel() {
+        initMainTab();
+        initFfmpegTab();
+    }
+
+    private void initMainTab() {
         final Config p = Config.INSTANCE;
 
         fldId.setText("");
@@ -572,7 +659,10 @@ public class MainFrame extends JFrame {
         cbOutputEnable.setSelected(convert);
         fldOutput.setEnabled(convert);
         fldOutput.setText(p.getOutputFileNamePattern());
+    }
 
+    private void initFfmpegTab() {
+        pnlInputFfmpeg.init(Config.INSTANCE);
     }
 
     private JMenuBar initMenuBar() {