OSDN Git Service

動画ファイル名補完
authoryukihane <yukihane.feather@gmail.com>
Fri, 2 Sep 2011 15:57:51 +0000 (00:57 +0900)
committeryukihane <yukihane.feather@gmail.com>
Fri, 9 Sep 2011 11:41:19 +0000 (20:41 +0900)
frontend/src/yukihane/inqubus/filewatch/FileWatchUtil.java
frontend/src/yukihane/inqubus/gui/MainFrame.java

index 7caa07b..3f064c8 100644 (file)
@@ -51,8 +51,13 @@ public final class FileWatchUtil {
         final SortedSet<String> set = new TreeSet<>();
         for (Path p : paths) {
             final String name = FilenameUtils.getBaseName(p.toString());
-            if (name.contains(text)) {
-                set.add(p.toAbsolutePath().toString());
+            final Matcher m = VIDEO_ID_PATTERN.matcher(name);
+            while (m.find()) {
+                final String alt = m.group(1);
+                if (alt.equals(text)) {
+                    set.add(p.toAbsolutePath().toString());
+                    break;
+                }
             }
         }
         return set;
index 6347856..5c4150f 100644 (file)
@@ -32,10 +32,12 @@ import java.util.ArrayList;
 import java.util.HashSet;
 import java.util.List;
 import java.util.Set;
+import java.util.SortedSet;
 import java.util.logging.Level;
 import java.util.logging.Logger;
 import java.util.regex.Pattern;
 import javax.swing.BorderFactory;
+import javax.swing.DefaultComboBoxModel;
 import javax.swing.DropMode;
 import javax.swing.GroupLayout;
 import javax.swing.GroupLayout.Alignment;
@@ -82,6 +84,7 @@ import saccubus.worker.profile.VideoProfile;
 import yukihane.Util;
 import yukihane.inqubus.Config;
 import yukihane.inqubus.filewatch.FileWatch;
+import yukihane.inqubus.filewatch.FileWatchUtil;
 import yukihane.inqubus.manager.RequestProcess;
 import yukihane.inqubus.manager.TaskKind;
 import yukihane.inqubus.manager.TaskManage;
@@ -247,7 +250,7 @@ public class MainFrame extends JFrame {
         cmbId = new IdComboBox(videoFileWatcher);
         cmbId.setToolTipText(ID_FIELD_TOOLTIP);
         cmbId.getEditorComponent().addActionListener(applyListener);
-        cmbId.addFocusListener(new java.awt.event.FocusAdapter() {
+        cmbId.getEditorComponent().addFocusListener(new java.awt.event.FocusAdapter() {
 
             public void focusLost(java.awt.event.FocusEvent evt) {
                 idFieldFocusLost(evt);
@@ -317,9 +320,9 @@ public class MainFrame extends JFrame {
                 )
                 .addPreferredGap(ComponentPlacement.RELATED)
                 .addGroup(glInputMain.createParallelGroup(Alignment.LEADING)
-                    .addComponent(cmbVideo, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
-                    .addComponent(cmbComment, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
-                    .addComponent(fldOutput, GroupLayout.DEFAULT_SIZE, 300, Short.MAX_VALUE)
+                    .addComponent(cmbVideo, 300, 300, Short.MAX_VALUE)
+                    .addComponent(cmbComment, 300, 300, Short.MAX_VALUE)
+                    .addComponent(fldOutput, 300, 300, Short.MAX_VALUE)
                 )
                 .addGroup(glInputMain.createParallelGroup()
                     .addComponent(btnVideo)
@@ -527,6 +530,17 @@ public class MainFrame extends JFrame {
         videoFileWatcherThread.start();
     }
 
+    private static void createFieldInfo( FileComboBox combo,  boolean useLocal,  String text, String pattern,  Set<Path> allFiles) {
+        if (useLocal) {
+            final SortedSet<String> matchFiles = FileWatchUtil.getFileNamesContain(allFiles, text);
+            DefaultComboBoxModel<String> model = new DefaultComboBoxModel<>(matchFiles.toArray(new String[0]));
+            combo.setModel(model);
+        } else {
+            combo.setModel(new DefaultComboBoxModel<String>());
+            combo.getEditorComponent().setText(pattern);
+        }
+    }
+
     private class GuiTaskManageListener implements TaskManageListener {
 
         @Override
@@ -611,36 +625,26 @@ public class MainFrame extends JFrame {
         final ItemSelectable source = evt.getItemSelectable();
 
         JButton button;
-        JTextField field;
-        File dir;
+        FileComboBox combo;
+        Set<Path> allFiles = null;
+        String pattern;
         if (source == cbVideoLocal) {
             button = btnVideo;
-            field = fldVideo;
-            dir = new File(p.getVideoDir());
+            combo = cmbVideo;
+            allFiles = videoFileWatcher.getFiles();
+            pattern = p.getVideoFileNamePattern();
         } else {
             button = btnComment;
-            field = fldComment;
-            dir = new File(p.getCommentDir());
+            combo = cmbComment;
+            pattern = p.getCommentFileNamePattern();
         }
 
         final boolean useLocal = (evt.getStateChange() == ItemEvent.SELECTED);
 
         button.setEnabled(useLocal);
+        createFieldInfo(combo, useLocal, cmbId.getText(), pattern, allFiles);
 
-        String text;
-        if (useLocal) {
-            final File f = searchFileMatchId(dir, cmbId.getText());
-            if (f != null) {
-                text = f.getPath();
-            } else {
-                text = "";
-            }
-        } else {
-            text = p.getVideoFileNamePattern();
-        }
-        field.setText(text);
-
-    }//GEN-LAST:event_useMovieLocalCheckBoxItemStateChanged
+    }
 
     private void outputConvertCheckBoxItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_outputConvertCheckBoxItemStateChanged
         final boolean convert = (evt.getStateChange() == ItemEvent.SELECTED);
@@ -650,17 +654,9 @@ public class MainFrame extends JFrame {
     private void idFieldFocusLost(java.awt.event.FocusEvent evt) {//GEN-FIRST:event_idFieldFocusLost
         final Config p = Config.INSTANCE;
         final String id = cmbId.getText();
-        if (id.isEmpty()) {
-            return;
-        }
 
-        if (cbVideoLocal.isSelected() && fldVideo.getText().isEmpty()) {
-            final File dir = new File(p.getVideoDir());
-            final File file = searchFileMatchId(dir, id);
-            if (file != null) {
-                fldVideo.setText(file.getPath());
-            }
-        }
+        createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles());
+
 
         if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) {
             final File dir = new File(p.getCommentDir());