1 package yukihane.inqubus.model;
3 import java.util.ArrayList;
4 import java.util.Collection;
6 import java.util.logging.Level;
7 import java.util.logging.Logger;
8 import javax.swing.table.AbstractTableModel;
9 import yukihane.inqubus.manager.TaskKind;
10 import yukihane.inqubus.manager.TaskStatus;
16 public class TargetsTableModel extends AbstractTableModel {
18 private static final long serialVersionUID = 1L;
19 private static final Logger logger = Logger.getLogger(TargetsTableModel.class.getName());
20 private final List<Target> targets = new ArrayList<>();
21 private static final int STATUS_CLOMN = 4;
22 private final String[] columnNames = new String[]{"ID", "動画", "コメ", "変換", "状態"};
23 private final Class<?>[] columnClasses = new Class<?>[]{String.class, Boolean.class, Boolean.class, Boolean.class,
27 public int getRowCount() {
28 return targets.size();
32 public int getColumnCount() {
33 return columnNames.length;
37 public String getColumnName(int columnIndex) {
38 return columnNames[columnIndex];
42 public Class<?> getColumnClass(int columnIndex) {
43 return columnClasses[columnIndex];
47 public Object getValueAt(int rowIndex, int columnIndex) {
48 Target t = targets.get(rowIndex);
50 switch (columnIndex) {
55 res = Boolean.valueOf(t.isVideoDownload());
58 res = Boolean.valueOf(t.isCommentDownload());
61 res = Boolean.valueOf(t.isConvert());
64 res = t.getProgress();
67 throw new IllegalArgumentException();
72 public void addTarget(Collection<Target> t) {
73 int before = targets.size();
75 int after = targets.size();
77 fireTableRowsInserted(before, after - 1);
81 public void addTarget(Target t) {
82 List<Target> list = new ArrayList<>(1);
87 public Target getTarget(int rowIndex) {
88 return targets.get(rowIndex);
91 public void setStatus(int id, TaskKind taskKind, TaskStatus taskStatus, double percent, String status) {
93 for (int i = 0; i < targets.size(); i++) {
94 final Target t = targets.get(i);
95 final int ri = t.getRowId();
102 logger.log(Level.SEVERE, "本来存在すべきレコードが存在しません id:{0}", id);
106 final Target t = targets.get(pos);
107 t.setProgress(taskKind, taskStatus, percent, status);
108 fireTableCellUpdated(pos, STATUS_CLOMN);