Revision 3044 trunk/extensions/extGeoreferencing/src/com/iver/cit/gvsig/gui/Panels/TablePointsPanel.java
TablePointsPanel.java | ||
---|---|---|
15 | 15 |
import javax.swing.JPanel; |
16 | 16 |
import javax.swing.JScrollPane; |
17 | 17 |
import javax.swing.JTable; |
18 |
import javax.swing.table.AbstractTableModel;
|
|
18 |
import javax.swing.table.DefaultTableModel;
|
|
19 | 19 |
|
20 | 20 |
import com.iver.cit.gvsig.gui.Dialogs.GeoreferencingDialog; |
21 | 21 |
public class TablePointsPanel extends JPanel implements ActionListener{ |
... | ... | |
32 | 32 |
private int widthInfPanel = 375, heightInfPanel = 27; |
33 | 33 |
private int widthTable = 375, heightTable = 110; |
34 | 34 |
|
35 |
final static String[] columnNames = {"N?", |
|
36 |
"X", |
|
37 |
"Y", |
|
38 |
"X'", |
|
39 |
"Y'", |
|
40 |
"Error X", |
|
41 |
"Error Y", |
|
42 |
"RMS"}; |
|
43 |
|
|
35 | 44 |
private PointTable table = null; |
36 | 45 |
|
37 | 46 |
|
... | ... | |
183 | 192 |
|
184 | 193 |
private JTable table = null; |
185 | 194 |
private JScrollPane scrollPane = null; |
186 |
private String[] columnNames = {"N?", |
|
187 |
"X", |
|
188 |
"Y", |
|
189 |
"X'", |
|
190 |
"Y'", |
|
191 |
"Error X", |
|
192 |
"Error Y", |
|
193 |
"RMS"}; |
|
194 |
private Object[][] data = { |
|
195 |
{"", "", "", "", "", "", "", ""} |
|
196 |
}; |
|
195 |
|
|
197 | 196 |
private TableModelPoint tabModel = null; |
198 | 197 |
|
199 | 198 |
public TableModelPoint getTableModel(){ |
... | ... | |
202 | 201 |
|
203 | 202 |
public PointTable(Object[][] d) { |
204 | 203 |
super(new GridLayout(1,0)); |
205 |
/*if(d != null) |
|
206 |
this.data = d; |
|
207 |
|
|
208 |
table = new JTable(data, columnNames);*/ |
|
204 |
|
|
209 | 205 |
tabModel = new TableModelPoint(); |
210 | 206 |
table = new JTable(tabModel); |
211 |
|
|
212 | 207 |
table.setPreferredScrollableViewportSize(new Dimension(500, 70)); |
213 | 208 |
|
214 | 209 |
|
215 | 210 |
table.addMouseListener(new MouseAdapter() { |
216 | 211 |
public void mouseClicked(MouseEvent e) { |
217 |
printDebugData(table); |
|
212 |
|
|
218 | 213 |
} |
219 | 214 |
}); |
220 | 215 |
|
... | ... | |
222 | 217 |
add(scrollPane); |
223 | 218 |
} |
224 | 219 |
|
225 |
private void printDebugData(JTable table) { |
|
226 |
int numRows = table.getRowCount(); |
|
227 |
int numCols = table.getColumnCount(); |
|
228 |
javax.swing.table.TableModel model = table.getModel(); |
|
229 |
|
|
230 |
System.out.println("Value of data: "); |
|
231 |
for (int i=0; i < numRows; i++) { |
|
232 |
System.out.print(" row " + i + ":"); |
|
233 |
for (int j=0; j < numCols; j++) { |
|
234 |
System.out.print(" " + model.getValueAt(i, j)); |
|
235 |
} |
|
236 |
System.out.println(); |
|
220 |
/** |
|
221 |
* TableModel del JTable que contiene los puntos con sus errores |
|
222 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
223 |
* |
|
224 |
*/ |
|
225 |
class TableModelPoint extends DefaultTableModel { |
|
226 |
|
|
227 |
public TableModelPoint(){ |
|
228 |
super(new Object[0][8], columnNames); |
|
237 | 229 |
} |
238 |
System.out.println("--------------------------"); |
|
239 |
} |
|
240 |
|
|
241 |
class TableModelPoint extends AbstractTableModel { |
|
242 |
private String[] columnNames = {"N?", |
|
243 |
"X", |
|
244 |
"Y", |
|
245 |
"X'", |
|
246 |
"Y'", |
|
247 |
"Error X", |
|
248 |
"Error Y", |
|
249 |
"RMS"}; |
|
250 |
private Object[][] data = { |
|
251 |
{"", "", "", "", "", "", "", ""} |
|
252 |
}; |
|
253 |
|
|
254 |
|
|
230 |
|
|
255 | 231 |
public int getColumnCount() { |
256 | 232 |
return columnNames.length; |
257 | 233 |
} |
258 | 234 |
|
259 |
public int getRowCount() { |
|
260 |
return data.length; |
|
261 |
} |
|
262 |
|
|
263 | 235 |
public String getColumnName(int col) { |
264 | 236 |
return columnNames[col]; |
265 | 237 |
} |
266 | 238 |
|
267 |
public Object getValueAt(int row, int col) { |
|
268 |
return data[row][col]; |
|
269 |
} |
|
270 |
|
|
271 |
|
|
272 | 239 |
public Class getColumnClass(int c) { |
273 |
return getValueAt(0, c).getClass();
|
|
240 |
return String.class;
|
|
274 | 241 |
} |
275 | 242 |
|
276 |
|
|
277 |
public boolean isCellEditable(int row, int col) { |
|
278 |
if (col < 2) { |
|
279 |
return false; |
|
280 |
} else { |
|
281 |
return true; |
|
282 |
} |
|
243 |
public void addNew() { |
|
244 |
super.addRow(new Object[] {"", "", "", "", "", "", "", ""}); |
|
283 | 245 |
} |
284 |
|
|
285 |
public void setValueAt(Object value, int row, int col) { |
|
286 |
data = new Object[row + 1][8]; |
|
287 |
data[row][col] = value; |
|
288 |
fireTableCellUpdated(row, col); |
|
246 |
|
|
247 |
public void setValueAt(Object value, int row, int col) { |
|
248 |
super.setValueAt(value, row, col); |
|
289 | 249 |
} |
250 |
|
|
251 |
/** |
|
252 |
* Devuelve true si la celda es editable. Solo son editables |
|
253 |
* las celdas de los puntos. |
|
254 |
*/ |
|
255 |
public boolean isCellEditable(int row, int col){ |
|
256 |
if(col >=1 && col <=4) |
|
257 |
return true; |
|
258 |
return false; |
|
259 |
} |
|
290 | 260 |
|
291 | 261 |
|
292 | 262 |
} |
Also available in: Unified diff