1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.xnap.gui.table;
21
22 import java.util.ArrayList;
23
24 import org.xnap.XNap;
25 import org.xnap.peer.Peer;
26
27 /***
28 * Provides a table model for {@link Peer} objects.
29 */
30 public class PeerTableModel extends AbstractColumnTableModel
31 {
32
33
34
35
36
37 protected ArrayList rows = new ArrayList();
38
39
40
41 public PeerTableModel()
42 {
43 Column columns[] = new Column[] {
44 new Column("name", XNap.tr("User"), String.class),
45 new Column("fileCount", XNap.tr("File Count"), Integer.class,
46 new NumberCellRenderer()),
47 new Column("linkSpeed", XNap.tr("Link Speed"), Integer.class,
48 new LinkSpeedCellRenderer()),
49 new Column("status", XNap.tr("Status"), String.class),
50 new Column("downloads", XNap.tr("Downloads"), Integer.class,
51 new NumberCellRenderer()),
52 new Column("uploads", XNap.tr("Uploads"), Integer.class,
53 new NumberCellRenderer()),
54 new Column("client", XNap.tr("Client"), String.class),
55 };
56
57 addColumns(columns);
58 }
59
60
61
62 public void add(Peer u, boolean filterDuplicates)
63 {
64 if (!filterDuplicates || !contains(u)) {
65 rows.add(u);
66 fireTableRowsInserted(rows.size() - 1, rows.size() - 1);
67 }
68 }
69
70 public void add(Peer u)
71 {
72 add(u, true);
73 }
74
75 public void clear()
76 {
77 rows.clear();
78 fireTableDataChanged();
79 }
80
81 public boolean contains(Peer u)
82 {
83 return rows.contains(u);
84 }
85
86 public Peer get(int i)
87 {
88 return (Peer)rows.get(mapToIndex(i));
89 }
90
91 public int getRowCount()
92 {
93 return rows.size();
94 }
95
96 public Object get(int i, int j)
97 {
98 Peer u = (Peer)rows.get(i);
99
100 switch (j) {
101 case 0:
102 return u.getName();
103 case 1:
104 return new Integer(u.getFileCount());
105 case 2:
106 return new Integer(u.getLinkSpeed());
107 case 3:
108 return u.getStatus();
109 case 4:
110 return new Integer(u.getLocalDownloadCount());
111 case 5:
112 return new Integer(u.getLocalUploadCount());
113 case 6:
114 return u.getClientInfo();
115 default:
116 return null;
117 }
118 }
119 public int indexOf(Peer u)
120 {
121 int i = rows.indexOf(u);
122 return i != -1 ? mapToIndex(i) : -1;
123 }
124
125 public void remove(Peer u)
126 {
127 int i = rows.indexOf(u);
128 if (i != -1) {
129 rows.remove(i);
130 fireTableRowsDeleted(i, i);
131 }
132 }
133
134 }
135
136