OSDN Git Service

チェックボックス文字列修正
[coroid/inqubus.git] / frontend / src / yukihane / inqubus / gui / MainFrame.java
index ef44b02..23a2fa0 100644 (file)
@@ -5,8 +5,10 @@
  */
 package yukihane.inqubus.gui;
 
+import java.awt.Dimension;
 import java.awt.Image;
 import java.awt.ItemSelectable;
+import java.awt.Point;
 import java.awt.Toolkit;
 import java.awt.datatransfer.DataFlavor;
 import java.awt.datatransfer.Transferable;
@@ -15,18 +17,23 @@ import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
 import java.awt.event.KeyEvent;
+import java.awt.event.WindowAdapter;
+import java.awt.event.WindowEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
 import java.io.FilenameFilter;
 import java.io.IOException;
 import java.net.URL;
+import java.nio.file.FileSystem;
+import java.nio.file.FileSystems;
+import java.nio.file.Path;
 import java.util.ArrayList;
-import java.util.Collection;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.regex.Matcher;
 import java.util.regex.Pattern;
 import javax.swing.BorderFactory;
 import javax.swing.DropMode;
@@ -51,11 +58,11 @@ import javax.swing.SwingUtilities;
 import javax.swing.TransferHandler;
 import javax.swing.WindowConstants;
 import javax.swing.border.BevelBorder;
+import org.apache.commons.configuration.ConfigurationException;
 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;
@@ -73,6 +80,7 @@ import saccubus.worker.profile.ProxyProfile;
 import saccubus.worker.profile.VideoProfile;
 import yukihane.Util;
 import yukihane.inqubus.Config;
+import yukihane.inqubus.filewatch.FileWatch;
 import yukihane.inqubus.manager.RequestProcess;
 import yukihane.inqubus.manager.TaskKind;
 import yukihane.inqubus.manager.TaskManage;
@@ -99,9 +107,34 @@ public class MainFrame extends JFrame {
             = "ファイル命名規則入力します。";
     private final TargetsTableModel targetModel = new TargetsTableModel();
     private final TaskManage taskManager;
+    private final Thread videoFileWatcherThread;
+    private final FileWatch videoFileWatcher;
 
     /** Creates new form MainFrame */
     public MainFrame() {
+        super();
+        addWindowListener(new MainFrameWindowListener());
+
+        final Config p = Config.INSTANCE;
+
+        // ワーカスレッド生成
+        final int thDownload = p.getSystemDownloadThread();
+        final int secDownload = p.getSystemDownloadWait();
+        final int thConvert = p.getSystemConvertThread();
+        taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener());
+
+        // TODO ディレクトリ監視スレッド生成
+        final List<String> videoSearchDirs = p.getSearchVideoDirs();
+        videoSearchDirs.add(p.getVideoDir());
+        final FileSystem fs = FileSystems.getDefault();
+        final Set<Path> videoPaths = new HashSet<>(videoSearchDirs.size());
+        for (String s : videoSearchDirs) {
+            videoPaths.add(fs.getPath(s));
+        }
+        videoFileWatcher = new FileWatch(videoPaths);
+        this.videoFileWatcherThread = new Thread(videoFileWatcher);
+        this.videoFileWatcherThread.setDaemon(true);
+
         final URL url = MainFrame_AboutBox.class.getResource("icon.png");
         final Image icon1 = Toolkit.getDefaultToolkit().createImage(url);
         final URL url32 = MainFrame_AboutBox.class.getResource("icon32.png");
@@ -116,10 +149,8 @@ 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);
         final JLabel lblVideo = new JLabel();
         cbVideoLocal = new JCheckBox();
         cbVideoLocal.setToolTipText(FILE_LOCALBUTTON_TOOLTIP);
@@ -204,7 +235,10 @@ public class MainFrame extends JFrame {
 
         lblId.setText("ID");
 
-        fldId.addActionListener(applyListener);
+
+        fldId = new IdComboBox(videoFileWatcher);
+        fldId.setToolTipText(ID_FIELD_TOOLTIP);
+        fldId.getEditorComponent().addActionListener(applyListener);
         fldId.addFocusListener(new java.awt.event.FocusAdapter() {
 
             public void focusLost(java.awt.event.FocusEvent evt) {
@@ -436,15 +470,40 @@ public class MainFrame extends JFrame {
         );
 
         pack();
+
+        /*
+         * 画面のサイズや位置を前回終了時のものに設定する
+         */
+        final int windowWidth = p.getSystemWindowWidth();
+        final int windowHeight = p.getSystemWindowHeight();
+        if (windowWidth > 0 && windowHeight > 0) {
+            setSize(windowWidth, windowHeight);
+        }
+
+        final int windowPosX = p.getSystemWindowPosX();
+        final int windowPosY = p.getSystemWindowPosY();
+        if (windowPosX > 0 && windowPosY > 0) {
+            setLocation(windowPosX, windowPosY);
+        } else {
+            setLocationByPlatform(true);
+        }
+
+        final int colId = p.getSystemColumnId();
+        if(colId > 0) {
+            tblDisplay.getColumnModel().getColumn(0).setPreferredWidth(colId);
+        }
+        final int colStatus = p.getSystemColumnStatus();
+        if(colStatus > 0) {
+            tblDisplay.getColumnModel().getColumn(4).setPreferredWidth(colStatus);
+        }
+
         initInputPanel();
         pnlMain.setTransferHandler(new DownloadListTransferHandler());
         tblDisplay.setTransferHandler(new TableTransferHandler());
+    }
 
-        final Config p = Config.INSTANCE;
-        final int thDownload = p.getSystemDownloadThread();
-        final int secDownload = p.getSystemDownloadWait();
-        final int thConvert = p.getSystemConvertThread();
-        taskManager = new TaskManage(thDownload, secDownload,thConvert, new GuiTaskManageListener());
+    public void startWatcher() {
+        videoFileWatcherThread.start();
     }
 
     private class GuiTaskManageListener implements TaskManageListener {
@@ -592,9 +651,11 @@ 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 JTabbedPane tbpInput = new JTabbedPane(JTabbedPane.BOTTOM);
     // 入力領域 - メイン
-    private final JTextField fldId = new JTextField();
-    private final JCheckBox cbBackLogReduce = new JCheckBox("コメ数減少");
+    private final IdComboBox fldId;
+    private final JCheckBox cbBackLogReduce = new JCheckBox("少コメ");
     private final JCheckBox cbBackLog = new JCheckBox("過去ログ");
     private final JTextField fldBackLog = new JTextField();
     private final JCheckBox cbVideoLocal;
@@ -613,6 +674,8 @@ public class MainFrame extends JFrame {
     private void initInputPanel() {
         initMainTab();
         initFfmpegTab();
+        tbpInput.setSelectedIndex(0);
+        fldId.requestFocus();
     }
 
     private void initMainTab() {
@@ -807,6 +870,32 @@ public class MainFrame extends JFrame {
         }
     }
 
+    private class MainFrameWindowListener extends WindowAdapter {
+        @Override
+        public void windowClosing(WindowEvent e) {
+            final Config p = Config.INSTANCE;
+
+            final Dimension size = getSize();
+            p.setSystemWindowWidth(size.width);
+            p.setSystemWindowHeight(size.height);
+
+            final Point pos = getLocation();
+            p.setSystemWindowPosX(pos.x);
+            p.setSystemWindowPosY(pos.y);
+
+            p.setSystemColumnId(tblDisplay.getColumnModel().getColumn(0).getWidth());
+            p.setSystemColumnVideo(tblDisplay.getColumnModel().getColumn(1).getWidth());
+            p.setSystemColumnComment(tblDisplay.getColumnModel().getColumn(2).getWidth());
+            p.setSystemColumnConvert(tblDisplay.getColumnModel().getColumn(3).getWidth());
+            p.setSystemColumnStatus(tblDisplay.getColumnModel().getColumn(4).getWidth());
+            try {
+                p.save();
+            } catch (ConfigurationException ex) {
+                logger.log(Level.SEVERE, "コンフィグ保存失敗", ex);
+            }
+        }
+    }
+
     /*
      * ここからDownloadProfile作成用クラスの定義
      */