From 81f2942dcfe590ae53713c63ac6dc984b2f0c09c Mon Sep 17 00:00:00 2001 From: yukihane Date: Sat, 3 Sep 2011 01:07:12 +0900 Subject: [PATCH] =?utf8?q?=E3=82=B3=E3=83=A1=E3=83=B3=E3=83=88=E3=83=95?= =?utf8?q?=E3=82=A1=E3=82=A4=E3=83=AB=E5=90=8D=E8=A3=9C=E5=AE=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- frontend/src/yukihane/inqubus/gui/MainFrame.java | 58 ++++++++---------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/frontend/src/yukihane/inqubus/gui/MainFrame.java b/frontend/src/yukihane/inqubus/gui/MainFrame.java index 5c4150f..5f70895c 100644 --- a/frontend/src/yukihane/inqubus/gui/MainFrame.java +++ b/frontend/src/yukihane/inqubus/gui/MainFrame.java @@ -113,6 +113,9 @@ public class MainFrame extends JFrame { private final TaskManage taskManager; private final Thread videoFileWatcherThread; private final FileWatch videoFileWatcher; + private final Thread commentFileWatcherThread; + private final FileWatch commentFileWatcher; + /** Creates new form MainFrame */ public MainFrame() { @@ -127,10 +130,11 @@ public class MainFrame extends JFrame { final int thConvert = p.getSystemConvertThread(); taskManager = new TaskManage(thDownload, secDownload, thConvert, new GuiTaskManageListener()); - // TODO ディレクトリ監視スレッド生成 + // ディレクトリ監視スレッド生成 + final FileSystem fs = FileSystems.getDefault(); + final List videoSearchDirs = p.getSearchVideoDirs(); videoSearchDirs.add(p.getVideoDir()); - final FileSystem fs = FileSystems.getDefault(); final Set videoPaths = new HashSet<>(videoSearchDirs.size()); for (String s : videoSearchDirs) { videoPaths.add(fs.getPath(s)); @@ -139,6 +143,16 @@ public class MainFrame extends JFrame { this.videoFileWatcherThread = new Thread(videoFileWatcher); this.videoFileWatcherThread.setDaemon(true); + final List commentSearchDirs = p.getSearchCommentDirs(); + commentSearchDirs.add(p.getCommentDir()); + final Set commentPaths = new HashSet<>(commentSearchDirs.size()); + for(String s : commentSearchDirs) { + commentPaths.add(fs.getPath(s)); + } + commentFileWatcher = new FileWatch(commentPaths); + this.commentFileWatcherThread = new Thread(commentFileWatcher); + this.commentFileWatcherThread.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"); @@ -528,6 +542,7 @@ public class MainFrame extends JFrame { public void startWatcher() { videoFileWatcherThread.start(); + commentFileWatcherThread.start(); } private static void createFieldInfo( FileComboBox combo, boolean useLocal, String text, String pattern, Set allFiles) { @@ -591,31 +606,6 @@ public class MainFrame extends JFrame { } } - private File searchFileMatchId(final File dir, final String id) { - // TODO 候補は複数返すようにして、その後の対処は呼び出しもとで行ってもらった方が良いかも - if (id.isEmpty()) { - return null; - } - - final File[] lists = dir.listFiles(new FilenameFilter() { - - final Pattern pattern = Pattern.compile(id + "\\D"); - - @Override - public boolean accept(File dir, String name) { - return pattern.matcher(name).find(); - } - }); - - if (lists.length == 1) { - return lists[0]; - } else if (lists.length > 1) { - throw new UnsupportedOperationException(); - } else { - return null; - } - } - /** * 動画, コメントの"local"チェックボックス更新時の処理. */ @@ -626,7 +616,7 @@ public class MainFrame extends JFrame { JButton button; FileComboBox combo; - Set allFiles = null; + Set allFiles; String pattern; if (source == cbVideoLocal) { button = btnVideo; @@ -636,6 +626,7 @@ public class MainFrame extends JFrame { } else { button = btnComment; combo = cmbComment; + allFiles = commentFileWatcher.getFiles(); pattern = p.getCommentFileNamePattern(); } @@ -656,16 +647,7 @@ public class MainFrame extends JFrame { final String id = cmbId.getText(); createFieldInfo(cmbVideo, cbVideoLocal.isSelected(), id, p.getVideoFileNamePattern(), videoFileWatcher.getFiles()); - - - if (cbCommentLocal.isSelected() && fldComment.getText().isEmpty()) { - final File dir = new File(p.getCommentDir()); - final File file = searchFileMatchId(dir, id); - if (file != null) { - fldComment.setText(file.getPath()); - } - } - + createFieldInfo(cmbComment, cbCommentLocal.isSelected(), id, p.getCommentFileNamePattern(), commentFileWatcher.getFiles()); }//GEN-LAST:event_idFieldFocusLost // Variables declaration - do not modify//GEN-BEGIN:variables private final JTable tblDisplay; -- 2.11.0