Git

1 import java.util.Hashtable;\r
2 import java.util.Vector;\r
3 import javax.swing.table.*;\r
4 \r
5 public class ServerTableModel extends RefreshAbstractTableModel\r
6 {\r
7 \r
8         Hashtable serverInfos;\r
9         String columns[]={"Number","Host","Users","Files","Connected"};\r
10         DonkeyCore donkeyCore;\r
11         \r
12         public ServerTableModel(Hashtable serverInfos,DonkeyCore donkeyCore)\r
13         {\r
14                 this.donkeyCore=donkeyCore;\r
15                 this.serverInfos=serverInfos;\r
16         }\r
17         \r
18         public int getColumnCount()\r
19         {\r
20                 return columns.length;\r
21         }\r
22         \r
23         public String getColumnName(int col)\r
24         {\r
25                 return columns[col];\r
26         }\r
27 \r
28         public int getRowCount()\r
29         {\r
30                 return serverInfos.size();\r
31         }\r
32         \r
33         public Object getValueAt(int row,int col)\r
34         {\r
35                 if (col==0) return serverInfos.keySet().toArray()[row];\r
36                 return ((Vector)serverInfos.values().toArray()[row]).get(col-1);\r
37         }\r
38 \r
39         public boolean isCellEditable(int row,int col)\r
40         {\r
41                 return col==columns.length-1;\r
42         }\r
43         \r
44         public void setValueAt(Object o,int row,int col)\r
45         {\r
46                 Long id=(Long)getValueAt(row,0);\r
47                 Vector serverInfo=(Vector)serverInfos.get(id);\r
48                 if (((Boolean)serverInfo.elementAt(3)).booleanValue())\r
49                 {\r
50                         //((Vector)searchResult.get(row)).setElementAt(new Boolean(true),col);\r
51                         donkeyCore.disconnectServer((Long)getValueAt(row,0));\r
52                 }\r
53                 else\r
54                 {\r
55                         donkeyCore.connectServer((Long)getValueAt(row,0));\r
56                 }\r
57         }\r
58 \r
59 }