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;
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;
= "ファイル命名規則入力します。";
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() {
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 {
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
@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;
}
}
+++ /dev/null
-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;
- }
-}
+++ /dev/null
-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;
- }
-}
--- /dev/null
+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;
+ }
+}
+++ /dev/null
-package yukihane.inqubus.model;
-
-public enum Status {
-
- WAITING, PROCESSING, DONE, FAILED, NOTHING;
-}
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;
}
-
}
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() {
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();
}
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);
+
+ }
}
+++ /dev/null
-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() {
- }
-}