OSDN Git Service

dnd仮実装
[coroid/inqubus.git] / frontend / src / yukihane / inqubuss / model / TargetsTableModel.java
1 package yukihane.inqubuss.model;
2
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.List;
6 import javax.swing.table.AbstractTableModel;
7
8 /**
9  *
10  * @author yuki
11  */
12 public class TargetsTableModel extends AbstractTableModel {
13
14     private final List<Target> targets = new ArrayList<Target>();
15     private final String[] columnNames = new String[]{"動画", "コメント", "投コメ", "状態"};
16     private final Class<?>[] columnClasses = new Class<?>[]{Location.class, Location.class, Location.class, Status.class};
17
18     @Override
19     public int getRowCount() {
20         return targets.size();
21     }
22
23     @Override
24     public int getColumnCount() {
25         return columnNames.length;
26     }
27
28     @Override
29     public String getColumnName(int columnIndex) {
30         return columnNames[columnIndex];
31     }
32
33     @Override
34     public Class<?> getColumnClass(int columnIndex) {
35         return columnClasses[columnIndex];
36     }
37
38     @Override
39     public Object getValueAt(int rowIndex, int columnIndex) {
40         Target t = targets.get(rowIndex);
41         Object res;
42         switch (columnIndex) {
43             case 0:
44                 res = t.getMovie();
45                 break;
46             case 1:
47                 res = t.getComment();
48                 break;
49             case 2:
50                 res = t.getOwnerComment();
51                 break;
52             case 3:
53                 res = t.getStatus();
54                 break;
55             default:
56                 throw new IllegalArgumentException();
57         }
58         return res;
59     }
60
61     @Override
62     public void setValueAt(Object aValue, int rowIndex, int columnIndex) {
63         throw new UnsupportedOperationException("Not supported yet.");
64     }
65
66     public void addTarget(Collection<Target> t) {
67         int before = targets.size();
68         targets.addAll(t);
69         int after = targets.size();
70         if (before < after) {
71             fireTableRowsInserted(before, after - 1);
72         }
73
74     }
75 }