Line | Hits | Source |
---|---|---|
1 | /******************************************************************************* | |
2 | * InternetCafe is a software solution that helps the management of Cybercafes | |
3 | * according with the ITALIAN DECREE LAW ON ANTI-TERROR MEASURES, 27 JULY 2005. | |
4 | * Copyright (C) 2006 Guido Angelo Ingenito | |
5 | ||
6 | * This program is free software; you can redistribute it and/or | |
7 | * modify it under the terms of the GNU General Public License | |
8 | * as published by the Free Software Foundation; either version 2 | |
9 | * of the License, or (at your option) any later version. | |
10 | ||
11 | * This program is distributed in the hope that it will be useful, | |
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | * GNU General Public License for more details. | |
15 | * | |
16 | * You should have received a copy of the GNU General Public License | |
17 | * along with this program; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |
19 | *******************************************************************************/ | |
20 | package ui.table.model; | |
21 | ||
22 | import java.net.InetAddress; | |
23 | import java.util.Observable; | |
24 | import java.util.Observer; | |
25 | ||
26 | import javax.swing.table.AbstractTableModel; | |
27 | ||
28 | import ui.Messages; | |
29 | import base.network.NetworkManager; | |
30 | import base.network.Workstation; | |
31 | ||
32 | @SuppressWarnings("serial") //$NON-NLS-1$ | |
33 | public class ClientWorkstationTableModel extends AbstractTableModel implements | |
34 | Observer { | |
35 | /* | |
36 | * private String name; private String description; private WorkstationType | |
37 | * type; private InetAddress address; private boolean inUse = false; | |
38 | 0 | */ |
39 | 0 | private String[] columnNames = { Messages.getString("common.id"), Messages.getString("common.name"), Messages.getString("common.location"), Messages.getString("common.description"), //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
40 | 0 | Messages.getString("common.type"), Messages.getString("common.address"), Messages.getString("common.port"), Messages.getString("common.inuse") }; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ |
41 | 0 | |
42 | public static final int WORKSTATION_ID_COLUMN = 0; | |
43 | ||
44 | public static final int WORKSTATION_NAME_COLUMN = 1; | |
45 | ||
46 | public static final int WORKSTATION_LOCATION_COLUMN = 2; | |
47 | ||
48 | public static final int WORKSTATION_DESCRIPTION_COLUMN = 3; | |
49 | ||
50 | public static final int WORKSTATION_TYPE_COLUMN = 4; | |
51 | ||
52 | public static final int WORKSTATION_ADDRESS_COLUMN = 5; | |
53 | ||
54 | public static final int WORKSTATION_PORT_COLUMN = 6; | |
55 | ||
56 | public static final int WORKSTATION_IN_USE_COLUMN = 7; | |
57 | ||
58 | 0 | public ClientWorkstationTableModel() { |
59 | 0 | super(); |
60 | 0 | NetworkManager.getInstance().addObserver(this); |
61 | 0 | } |
62 | 0 | |
63 | 0 | public int getColumnCount() { |
64 | 0 | return columnNames.length; |
65 | 0 | } |
66 | ||
67 | 0 | public int getRowCount() { |
68 | 0 | return NetworkManager.getInstance().getNetwork().getClient().length; |
69 | 0 | } |
70 | ||
71 | 0 | public String getColumnName(int column) { |
72 | 0 | return columnNames[column]; |
73 | 0 | } |
74 | ||
75 | 0 | public Object getValueAt(int row, int column) { |
76 | 0 | if (row < 0 || column < 0) |
77 | 0 | return null; |
78 | 0 | Workstation[] client = NetworkManager.getInstance().getNetwork() |
79 | 0 | .getClient(); |
80 | 0 | Object result = null; |
81 | 0 | switch (column) { |
82 | 0 | case WORKSTATION_ID_COLUMN: |
83 | 0 | result = client[row].getId(); |
84 | 0 | break; |
85 | 0 | case WORKSTATION_NAME_COLUMN: |
86 | 0 | result = client[row].getName(); |
87 | 0 | break; |
88 | 0 | case WORKSTATION_LOCATION_COLUMN: |
89 | 0 | result = client[row].getLocation(); |
90 | 0 | break; |
91 | 0 | case WORKSTATION_DESCRIPTION_COLUMN: |
92 | 0 | result = client[row].getDescription(); |
93 | 0 | break; |
94 | 0 | case WORKSTATION_TYPE_COLUMN: |
95 | 0 | result = client[row].getType(); |
96 | 0 | break; |
97 | 0 | case WORKSTATION_ADDRESS_COLUMN: |
98 | 0 | result = client[row].getAddress().getHostAddress(); |
99 | 0 | break; |
100 | 0 | case WORKSTATION_PORT_COLUMN: |
101 | 0 | result = client[row].getPort(); |
102 | 0 | break; |
103 | 0 | case WORKSTATION_IN_USE_COLUMN: |
104 | 0 | result = client[row].isInUse(); |
105 | 0 | break; |
106 | 0 | } |
107 | 0 | return result; |
108 | 0 | } |
109 | ||
110 | @SuppressWarnings("unchecked") //$NON-NLS-1$ | |
111 | 0 | public Class getColumnClass(int column) { |
112 | 0 | Class result = null; |
113 | 0 | switch (column) { |
114 | 0 | case WORKSTATION_ID_COLUMN: |
115 | 0 | result = Integer.class; |
116 | 0 | break; |
117 | 0 | case WORKSTATION_NAME_COLUMN: |
118 | 0 | result = String.class; |
119 | 0 | break; |
120 | 0 | case WORKSTATION_LOCATION_COLUMN: |
121 | 0 | result = String.class; |
122 | 0 | break; |
123 | 0 | case WORKSTATION_DESCRIPTION_COLUMN: |
124 | 0 | result = String.class; |
125 | 0 | break; |
126 | 0 | case WORKSTATION_TYPE_COLUMN: |
127 | 0 | result = String.class; |
128 | 0 | break; |
129 | 0 | case WORKSTATION_ADDRESS_COLUMN: |
130 | 0 | result = InetAddress.class; |
131 | 0 | break; |
132 | 0 | case WORKSTATION_PORT_COLUMN: |
133 | 0 | result = Integer.class; |
134 | 0 | break; |
135 | 0 | case WORKSTATION_IN_USE_COLUMN: |
136 | 0 | result = Boolean.class; |
137 | 0 | break; |
138 | 0 | } |
139 | 0 | return result; |
140 | 0 | } |
141 | ||
142 | /* | |
143 | * Don't need to implement this method unless your table's editable. | |
144 | */ | |
145 | 0 | public boolean isCellEditable(int row, int column) { |
146 | 0 | if (row < 0 || column < 0) |
147 | 0 | return false; |
148 | 0 | // Note that the data/cell address is constant, |
149 | 0 | // no matter where the cell appears onscreen. |
150 | 0 | boolean result = false; |
151 | 0 | switch (column) { |
152 | 0 | case WORKSTATION_ID_COLUMN: |
153 | 0 | result = false; |
154 | 0 | break; |
155 | 0 | case WORKSTATION_NAME_COLUMN: |
156 | 0 | result = true; |
157 | 0 | break; |
158 | 0 | case WORKSTATION_LOCATION_COLUMN: |
159 | 0 | result = true; |
160 | 0 | break; |
161 | 0 | case WORKSTATION_DESCRIPTION_COLUMN: |
162 | 0 | result = true; |
163 | 0 | break; |
164 | 0 | case WORKSTATION_TYPE_COLUMN: |
165 | 0 | result = true; |
166 | 0 | break; |
167 | 0 | case WORKSTATION_ADDRESS_COLUMN: |
168 | 0 | result = false; |
169 | 0 | break; |
170 | 0 | case WORKSTATION_PORT_COLUMN: |
171 | 0 | result = true; |
172 | 0 | break; |
173 | 0 | case WORKSTATION_IN_USE_COLUMN: |
174 | 0 | result = false; |
175 | 0 | break; |
176 | 0 | } |
177 | 0 | return result; |
178 | 0 | } |
179 | ||
180 | /* | |
181 | * Don't need to implement this method unless your table's data can change. | |
182 | */ | |
183 | 0 | public void setValueAt(Object value, int row, int column) { |
184 | 0 | if (row < 0 || column < 0) |
185 | 0 | return; |
186 | 0 | Workstation[] client = NetworkManager.getInstance().getNetwork() |
187 | 0 | .getClient(); |
188 | 0 | switch (column) { |
189 | 0 | case WORKSTATION_ID_COLUMN: |
190 | 0 | break; |
191 | 0 | case WORKSTATION_NAME_COLUMN: |
192 | 0 | client[row].setName(value.toString()); |
193 | 0 | break; |
194 | 0 | case WORKSTATION_LOCATION_COLUMN: |
195 | 0 | client[row].setLocation(value.toString()); |
196 | 0 | break; |
197 | 0 | case WORKSTATION_DESCRIPTION_COLUMN: |
198 | 0 | client[row].setDescription(value.toString()); |
199 | 0 | break; |
200 | 0 | case WORKSTATION_TYPE_COLUMN: |
201 | 0 | client[row].setType(value.toString()); |
202 | 0 | break; |
203 | 0 | case WORKSTATION_ADDRESS_COLUMN: |
204 | 0 | break; |
205 | 0 | case WORKSTATION_PORT_COLUMN: |
206 | 0 | client[row].setPort(Integer.parseInt(value.toString())); |
207 | 0 | break; |
208 | 0 | case WORKSTATION_IN_USE_COLUMN: |
209 | break; | |
210 | 0 | } |
211 | 0 | fireTableCellUpdated(row, column); |
212 | 0 | } |
213 | 0 | |
214 | /* | |
215 | * (non-Javadoc) | |
216 | * | |
217 | * @see java.util.Observer#update(java.util.Observable, java.lang.Object) | |
218 | */ | |
219 | 0 | public void update(Observable observable, Object changedObject) { |
220 | 0 | if (changedObject instanceof Workstation) |
221 | 0 | this.fireTableDataChanged(); |
222 | 0 | } |
223 | 0 | |
224 | } |
this report was generated by version 1.0.5 of jcoverage. |
copyright © 2003, jcoverage ltd. all rights reserved. |