OSDN Git Service

タスクマネージャからのイベントを受け取りテーブルモデルを更新
authoryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 05:55:47 +0000 (14:55 +0900)
committeryukihane <yukihane.feather@gmail.com>
Mon, 29 Aug 2011 05:55:47 +0000 (14:55 +0900)
frontend/src/yukihane/inqubus/gui/MainFrame.java
frontend/src/yukihane/inqubus/model/Item.java [deleted file]
frontend/src/yukihane/inqubus/model/Location.java [deleted file]
frontend/src/yukihane/inqubus/model/Progress.java [new file with mode: 0644]
frontend/src/yukihane/inqubus/model/Status.java [deleted file]
frontend/src/yukihane/inqubus/model/Target.java
frontend/src/yukihane/inqubus/model/TargetsTableModel.java
frontend/src/yukihane/inqubus/worker/EventManager.java [deleted file]

index 2fd268a..1aa5bf7 100644 (file)
@@ -43,6 +43,7 @@ import javax.swing.JTable;
 import javax.swing.JTextField;
 import javax.swing.KeyStroke;
 import javax.swing.LayoutStyle.ComponentPlacement;
+import javax.swing.SwingUtilities;
 import javax.swing.TransferHandler;
 import javax.swing.WindowConstants;
 import org.apache.commons.lang.StringUtils;
@@ -66,7 +67,10 @@ import saccubus.worker.profile.VideoProfile;
 import yukihane.Util;
 import yukihane.inqubus.Config;
 import yukihane.inqubus.manager.RequestProcess;
+import yukihane.inqubus.manager.TaskKind;
 import yukihane.inqubus.manager.TaskManage;
+import yukihane.inqubus.manager.TaskManageListener;
+import yukihane.inqubus.manager.TaskStatus;
 import yukihane.inqubus.model.Target;
 import yukihane.inqubus.model.TargetsTableModel;
 
@@ -88,8 +92,6 @@ public class MainFrame extends JFrame {
             = "ファイル命名規則入力します。";
     private final TargetsTableModel targetModel = new TargetsTableModel();
     private final TaskManage taskManager;
-    private final DownloadProgressListener downloadProgressListener = new DownloadProgressListener();
-    private final ConvertProgressListener convertProgressListener = new ConvertProgressListener();
 
     /** Creates new form MainFrame */
     public MainFrame() {
@@ -352,8 +354,22 @@ public class MainFrame extends JFrame {
 
         final Config p = Config.INSTANCE;
         // TODO コンフィグからスレッド数
-        taskManager = new TaskManage(1, 1);
+        taskManager = new TaskManage(1, 1, new GuiTaskManageListener());
+    }
+
+    private class GuiTaskManageListener implements TaskManageListener {
 
+        @Override
+        public void process(final int id, final TaskKind kind, final TaskStatus status, final double percentage,
+                final String message) {
+            SwingUtilities.invokeLater(new Runnable() {
+
+                @Override
+                public void run() {
+                    targetModel.setStatus(id, kind, status, percentage, message);
+                }
+            });
+        }
     }
 
     private class ApplyActionListener implements ActionListener {
@@ -365,7 +381,9 @@ public class MainFrame extends JFrame {
             final InqubusConvertProfile convProf = new InqubusConvertProfile();
             logger.log(Level.INFO, downProf.toString());
             logger.log(Level.INFO, convProf.toString());
-            taskManager.add(new RequestProcess(downProf, id, convProf));
+            final RequestProcess rp = new RequestProcess(downProf, id, convProf);
+            taskManager.add(rp);
+            targetModel.addTarget(new Target(rp));
         }
     }
     /** This method is called from within the constructor to
@@ -650,30 +668,32 @@ public class MainFrame extends JFrame {
 
         @Override
         public boolean importData(TransferHandler.TransferSupport support) {
-            try {
-                Transferable transferable = support.getTransferable();
-                if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
-                    @SuppressWarnings("unchecked")
-                    final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
-                    Collection<Target> targets = Target.from(data);
-                    targetModel.addTarget(targets);
-                } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
-                    String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
-                    Matcher matcher = movieIdPattern.matcher(data);
-                    if (matcher.find()) {
-                        String movieId = matcher.group(1);
-                        Target target = Target.fromId(movieId);
-                        targetModel.addTarget(target);
-                    } else {
-                        return false;
-                    }
-
-                }
-                return false;
-            } catch (Exception e) {
-                logger.log(Level.SEVERE, null, e);
-                return false;
-            }
+//            try {
+//                Transferable transferable = support.getTransferable();
+//                if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
+//                    @SuppressWarnings("unchecked")
+//                    final List<File> data = (List<File>) transferable.getTransferData(DataFlavor.javaFileListFlavor);
+//                    Collection<Target> targets = Target.from(data);
+//                    targetModel.addTarget(targets);
+//                } else if (transferable.isDataFlavorSupported(DataFlavor.stringFlavor)) {
+//                    String data = (String) transferable.getTransferData(DataFlavor.stringFlavor);
+//                    Matcher matcher = movieIdPattern.matcher(data);
+//                    if (matcher.find()) {
+//                        String movieId = matcher.group(1);
+//                        Target target = Target.fromId(movieId);
+//                        targetModel.addTarget(target);
+//                    } else {
+//                        return false;
+//                    }
+//
+//                }
+//                return false;
+//            } catch (Exception e) {
+//                logger.log(Level.SEVERE, null, e);
+//                return false;
+//            }
+            // TODO 上記実装見直し(Locationは削除された)
+            return false;
         }
     }
 
diff --git a/frontend/src/yukihane/inqubus/model/Item.java b/frontend/src/yukihane/inqubus/model/Item.java
deleted file mode 100644 (file)
index 6fa8b7d..0000000
+++ /dev/null
@@ -1,28 +0,0 @@
-package yukihane.inqubus.model;
-
-/**
- *
- * @author yuki
- */
-public class Item {
-
-    private final String id;
-    private final boolean useMovieLocal;
-    private final String movieName;
-    private final boolean useCommentLocal;
-    private final String commentName;
-    private final boolean needConvert;
-    private final String ouputName;
-    private Status status = Status.WAITING;
-
-    public Item(String id, boolean useMovieLocal, String movieName, boolean useCommentLocal, String commentName,
-            boolean needConvert, String ouputName) {
-        this.id = id;
-        this.useMovieLocal = useMovieLocal;
-        this.movieName = movieName;
-        this.useCommentLocal = useCommentLocal;
-        this.commentName = commentName;
-        this.needConvert = needConvert;
-        this.ouputName = ouputName;
-    }
-}
diff --git a/frontend/src/yukihane/inqubus/model/Location.java b/frontend/src/yukihane/inqubus/model/Location.java
deleted file mode 100644 (file)
index 8db6690..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package yukihane.inqubus.model;
-
-import java.io.File;
-
-/**
- *
- * @author yuki
- */
-class Location {
-
-    private final String location;
-
-    public Location(String location) {
-        if (location == null) {
-            throw new IllegalArgumentException();
-        }
-        this.location = location;
-    }
-
-    Location(File f) {
-        this.location = f.getPath();
-    }
-
-    @Override
-    public String toString() {
-        return location;
-    }
-
-    @Override
-    public int hashCode() {
-        return location.hashCode();
-
-    }
-
-    @Override
-    public boolean equals(Object obj) {
-        if (obj == null) {
-            return false;
-        }
-        if (getClass() != obj.getClass()) {
-            return false;
-        }
-        final Location other = (Location) obj;
-        if ((this.location == null) ? (other.location != null) : !this.location.equals(other.location)) {
-            return false;
-        }
-        return true;
-    }
-}
diff --git a/frontend/src/yukihane/inqubus/model/Progress.java b/frontend/src/yukihane/inqubus/model/Progress.java
new file mode 100644 (file)
index 0000000..61d6f9b
--- /dev/null
@@ -0,0 +1,32 @@
+package yukihane.inqubus.model;
+
+/**
+ *
+ * @author yuki
+ */
+public class Progress {
+
+    private final double percent;
+    private final String text;
+
+    public Progress(double percent) {
+        this(percent, "");
+    }
+
+    public Progress(String text) {
+        this(100.0, text);
+    }
+
+    public Progress(double percent, String text) {
+        this.percent = percent;
+        this.text = text;
+    }
+
+    public double getPercent() {
+        return percent;
+    }
+
+    public String getText() {
+        return text;
+    }
+}
diff --git a/frontend/src/yukihane/inqubus/model/Status.java b/frontend/src/yukihane/inqubus/model/Status.java
deleted file mode 100644 (file)
index 70f493e..0000000
+++ /dev/null
@@ -1,6 +0,0 @@
-package yukihane.inqubus.model;
-
-public enum Status {
-
-    WAITING, PROCESSING, DONE, FAILED, NOTHING;
-}
index dea376a..c6cc692 100644 (file)
@@ -1,66 +1,63 @@
 package yukihane.inqubus.model;
 
-import java.io.File;
 import java.util.ArrayList;
-import java.util.Collection;
+import java.util.List;
+import yukihane.inqubus.manager.Request;
+import yukihane.inqubus.manager.RequestProcess;
+import yukihane.inqubus.manager.TaskKind;
+import yukihane.inqubus.manager.TaskStatus;
 
 public class Target {
 
-    public static Collection<Target> from(Collection<File> data) {
-        Collection<Target> list = new ArrayList<Target>(data.size());
-        for(File f : data){
-            list.add(new Target(f));
-        }
-        return list;
-    }
-
-    public static Target fromId(String movieId) {
-        return new Target(movieId);
-    }
+    private final RequestProcess requestProcess;
+    private final List<Request> requests = new ArrayList<>(1);
+    private Progress progress;
 
-    private Location movie;
-    private Location comment;
-    private Location ownerComment;
-    private Status status;
-
-    private Target(File f) {
-        movie = new Location(f);
+    public Target(RequestProcess rp) {
+        this.requestProcess = rp;
+        this.requests.add(rp);
     }
 
-    private Target(String movieId) {
-        movie = new Location(movieId);
+    public void add(Request request) {
+        requests.add(request);
     }
 
-    public Location getComment() {
-        return comment;
+    public RequestProcess getRequestProcess() {
+        return requestProcess;
     }
 
-    public void setComment(Location comment) {
-        this.comment = comment;
+    String getVideoId() {
+        return getRequestProcess().getVideoId();
     }
 
-    public Location getMovie() {
-        return movie;
+    boolean isVideoDownload() {
+        return getRequestProcess().getDownloadProfile().getVideoProfile().isDownload();
     }
 
-    public void setMovie(Location movie) {
-        this.movie = movie;
+    boolean isCommentDownload() {
+        return getRequestProcess().getDownloadProfile().getCommentProfile().isDownload();
     }
 
-    public Location getOwnerComment() {
-        return ownerComment;
+    boolean isConvert() {
+        return getRequestProcess().getConvertProfile().isConvert();
     }
 
-    public void setOwnerComment(Location ownerComment) {
-        this.ownerComment = ownerComment;
+    Progress getProgress() {
+        return progress;
     }
 
-    public Status getStatus() {
-        return status;
-    }
+    void setProgress(TaskKind kind, TaskStatus status, double percent, String message) {
+        String text;
+        double p = -1.0;
+        if (status == TaskStatus.READY) {
+            text = status.toString();
+        } else if (status == TaskStatus.DOING || status == TaskStatus.DONE || status == TaskStatus.CANCELLED) {
+            text = kind.toString() + " " + status.toString() + String.format("%.02f", percent) + "%";
+            p = percent;
+        } else {
+            text = message;
+        }
+        progress = new Progress(p, text);
 
-    public void setStatus(Status status) {
-        this.status = status;
     }
-
 }
index 1adf80d..a2cb6f2 100644 (file)
@@ -3,18 +3,24 @@ package yukihane.inqubus.model;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.List;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 import javax.swing.table.AbstractTableModel;
+import yukihane.inqubus.manager.TaskKind;
+import yukihane.inqubus.manager.TaskStatus;
 
 /**
  *
  * @author yuki
  */
 public class TargetsTableModel extends AbstractTableModel {
-    private static final long serialVersionUID = 1L;
 
+    private static final long serialVersionUID = 1L;
+    private static final Logger logger = Logger.getLogger(TargetsTableModel.class.getName());
     private final List<Target> targets = new ArrayList<Target>();
-    private final String[] columnNames = new String[]{"動画", "コメント", "投コメ", "状態"};
-    private final Class<?>[] columnClasses = new Class<?>[]{Location.class, Location.class, Location.class, Status.class};
+    private final String[] columnNames = new String[]{"ID", "動画", "コメ", "変換", "状態"};
+    private final Class<?>[] columnClasses = new Class<?>[]{String.class, Boolean.class, Boolean.class, Boolean.class,
+        Progress.class};
 
     @Override
     public int getRowCount() {
@@ -42,17 +48,19 @@ public class TargetsTableModel extends AbstractTableModel {
         Object res;
         switch (columnIndex) {
             case 0:
-                res = t.getMovie();
+                res = t.getVideoId();
                 break;
             case 1:
-                res = t.getComment();
+                res = Boolean.valueOf(t.isVideoDownload());
                 break;
             case 2:
-                res = t.getOwnerComment();
+                res = Boolean.valueOf(t.isCommentDownload());
                 break;
             case 3:
-                res = t.getStatus();
+                res = Boolean.valueOf(t.isConvert());
                 break;
+            case 4:
+                res = t.getProgress();
             default:
                 throw new IllegalArgumentException();
         }
@@ -78,4 +86,24 @@ public class TargetsTableModel extends AbstractTableModel {
         list.add(t);
         addTarget(list);
     }
+
+    public void setStatus(int id, TaskKind taskKind, TaskStatus taskStatus, double percent, String status) {
+        int pos = -1;
+        for (int i = 0; i < targets.size(); i++) {
+            final Target t = targets.get(i);
+            final int ri = t.getRequestProcess().getRowId();
+            if (id == ri) {
+                pos = i;
+                break;
+            }
+        }
+        if (pos < 0) {
+            logger.log(Level.SEVERE, "本来存在すべきレコードが存在しません id:{0}", id);
+            return;
+        }
+
+        final Target t = targets.get(pos);
+        t.setProgress(taskKind, taskStatus, percent, status);
+
+    }
 }
diff --git a/frontend/src/yukihane/inqubus/worker/EventManager.java b/frontend/src/yukihane/inqubus/worker/EventManager.java
deleted file mode 100644 (file)
index e4260ce..0000000
+++ /dev/null
@@ -1,33 +0,0 @@
-package yukihane.inqubus.worker;
-
-import java.util.ArrayList;
-import java.util.List;
-import java.util.logging.Level;
-import java.util.logging.Logger;
-import yukihane.inqubus.model.Item;
-
-/**
- * いんきゅばすが行う処理を管理します.
- * @author yuki
- */
-public enum EventManager {
-
-    INSTANCE;
-    private static final Logger logger = Logger.getLogger(EventManager.class.getName());
-    private final List<Item> itemList = new ArrayList<Item>();
-
-    /**
-     * 処理対象を追加します.
-     * @param i 処理対象.
-     */
-    public synchronized void addItem(Item i) {
-        itemList.add(i);
-        process();
-    }
-
-    /**
-     * アイテムリストに入っているアイテムを処理します.
-     */
-    private void process() {
-    }
-}