root / trunk / extensions / extGeoreferencing / src / org / gvsig / georeferencing / ui / table / GCPTablePanel.java @ 31518
History | View | Annotate | Download (26.8 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.georeferencing.ui.table; |
20 |
|
21 |
import java.awt.BorderLayout; |
22 |
import java.awt.Color; |
23 |
import java.awt.Component; |
24 |
import java.awt.Dimension; |
25 |
import java.awt.GridBagConstraints; |
26 |
import java.awt.GridBagLayout; |
27 |
import java.awt.event.ComponentEvent; |
28 |
import java.awt.event.ComponentListener; |
29 |
import java.awt.geom.Point2D; |
30 |
import java.util.ArrayList; |
31 |
|
32 |
import javax.swing.JButton; |
33 |
import javax.swing.JPanel; |
34 |
import javax.swing.JTable; |
35 |
import javax.swing.JToggleButton; |
36 |
import javax.swing.table.DefaultTableCellRenderer; |
37 |
import javax.swing.table.DefaultTableModel; |
38 |
import javax.swing.table.TableColumn; |
39 |
|
40 |
import org.gvsig.georeferencing.main.ApplicationControlsListener; |
41 |
import org.gvsig.georeferencing.main.Georeferencing; |
42 |
import org.gvsig.georeferencing.process.geotransform.GeoTransformDataResult; |
43 |
import org.gvsig.georeferencing.process.geotransform.GeoTransformProcess; |
44 |
import org.gvsig.gui.beans.datainput.DataInputContainer; |
45 |
import org.gvsig.gui.beans.table.TableContainer; |
46 |
import org.gvsig.gui.beans.table.exceptions.NotInitializeException; |
47 |
import org.gvsig.gui.beans.table.models.GCPModel; |
48 |
import org.gvsig.raster.datastruct.GeoPoint; |
49 |
import org.gvsig.raster.datastruct.GeoPointList; |
50 |
import org.gvsig.raster.util.RasterToolsUtil; |
51 |
|
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.ui.mdiManager.IWindow; |
54 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
55 |
|
56 |
/**
|
57 |
* Panel que contiene la tabla de puntos de control
|
58 |
*
|
59 |
* 22/12/2007
|
60 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
61 |
*/
|
62 |
public class GCPTablePanel extends JPanel implements IWindow, ComponentListener { |
63 |
private static final long serialVersionUID = 1L; |
64 |
private String[] columnNames = {"-", |
65 |
RasterToolsUtil.getText(this, "num"), |
66 |
RasterToolsUtil.getText(this, "worldx"), |
67 |
RasterToolsUtil.getText(this, "worldy"), |
68 |
RasterToolsUtil.getText(this, "imagex"), |
69 |
RasterToolsUtil.getText(this, "imagey"), |
70 |
"Error X", "Error Y", "RMS", "-"}; |
71 |
private int[] columnWidths = {25, 25, 90, 90, 90, 90, 50, 50, 50, 0}; |
72 |
private TableContainer table = null; |
73 |
|
74 |
private JPanel buttonsPanel = null; |
75 |
private ApplicationControlsListener buttonsListener = null; |
76 |
private JButton bSaveToXml = null; |
77 |
private JButton bLoadFromXml = null; |
78 |
private JButton bSaveToAscii = null; |
79 |
private JButton bLoadFromAscii = null; |
80 |
private JButton bOptions = null; |
81 |
private JButton bTest = null; |
82 |
private JButton bEndTest = null; |
83 |
private JButton bEndGeoref = null; |
84 |
private JButton bCenterView = null; |
85 |
private JToggleButton bAddPoint = null; |
86 |
private DataInputContainer error = null; |
87 |
|
88 |
private int w = 640; |
89 |
private int h = 100; |
90 |
private int posX = 0; |
91 |
private int posY = 0; |
92 |
private GeoTransformProcess process = null; |
93 |
private Georeferencing appMain = null; |
94 |
|
95 |
/**
|
96 |
* Constructor.
|
97 |
* Crea la composici?n de controles de zoom.
|
98 |
*/
|
99 |
public GCPTablePanel(int posX, int posY, int w, int h, Georeferencing appMain) { |
100 |
setPosition(posX, posY); |
101 |
setWindowsSize(w, h); |
102 |
this.appMain = appMain;
|
103 |
} |
104 |
|
105 |
/**
|
106 |
* Obtiene el objeto gestor de la georreferenciaci?n.
|
107 |
* @return
|
108 |
*/
|
109 |
public Georeferencing getAppMain() {
|
110 |
return appMain;
|
111 |
} |
112 |
|
113 |
/**
|
114 |
* Asigna el listener para los botones
|
115 |
* @param listener
|
116 |
*/
|
117 |
public void initialize(ApplicationControlsListener listener) { |
118 |
this.buttonsListener = listener;
|
119 |
process = new GeoTransformProcess();
|
120 |
this.addComponentListener(this); |
121 |
try {
|
122 |
init(); |
123 |
} catch (NotInitializeException e) {
|
124 |
RasterToolsUtil.messageBoxError(RasterToolsUtil.getText(this, "table_not_initialize"), this); |
125 |
} |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Asigna la posici?n de la ventana
|
130 |
* @param posX Posici?n en X
|
131 |
* @param posY Posici?n en Y
|
132 |
*/
|
133 |
public void setPosition(int posX, int posY) { |
134 |
this.posX = posX;
|
135 |
this.posY = posY;
|
136 |
} |
137 |
|
138 |
/**
|
139 |
* Asigna la posici?n de la ventana
|
140 |
* @param posX Posici?n en X
|
141 |
* @param posY Posici?n en Y
|
142 |
*/
|
143 |
public void setWindowsSize(int w, int h) { |
144 |
this.w = w;
|
145 |
this.h = h;
|
146 |
} |
147 |
|
148 |
/**
|
149 |
* Inicializaci?n de los componentes gr?ficos
|
150 |
*/
|
151 |
private void init() throws NotInitializeException { |
152 |
setLayout(new BorderLayout()); |
153 |
setSize(new java.awt.Dimension(w, h));
|
154 |
|
155 |
GridBagConstraints gb = new GridBagConstraints(); |
156 |
gb.insets = new java.awt.Insets(0, 0, 0, 0); |
157 |
gb.gridy = 0;
|
158 |
gb.gridx = 0;
|
159 |
gb.weightx = 1D; //El espacio sobrante se distribuye horizontalmente |
160 |
gb.weighty = 1D; //El espacio sobrante se distribuye verticalmente |
161 |
gb.fill = GridBagConstraints.BOTH; //El componente se hace tan ancho como espacio disponible tiene |
162 |
gb.anchor = GridBagConstraints.NORTH; //Alineamos las cajas arriba |
163 |
add(getTable(), BorderLayout.CENTER);
|
164 |
|
165 |
gb.gridx = 1;
|
166 |
add(getButtonsPanel(), BorderLayout.EAST);
|
167 |
} |
168 |
|
169 |
/**
|
170 |
* Obtiene la tabla de puntos de control
|
171 |
* @return TableContainer
|
172 |
*/
|
173 |
public TableContainer getTable() throws NotInitializeException { |
174 |
if(table == null) { |
175 |
ArrayList listeners = new ArrayList(); |
176 |
listeners.add(buttonsListener); |
177 |
table = new TableContainer(columnNames, columnWidths, listeners);
|
178 |
table.setModel("GCPModel");
|
179 |
table.initialize(); |
180 |
table.setControlVisible(true);
|
181 |
table.setMoveRowsButtonsVisible(true);
|
182 |
table.setEditable(true);
|
183 |
table.getTable().getJTable().getColumnModel().getColumn(columnNames.length - 1).setMinWidth(0); |
184 |
table.getTable().getJTable().getColumnModel().getColumn(columnNames.length - 1).setMaxWidth(0); |
185 |
table.getTable().getJTable().getColumnModel().getColumn(0).setMinWidth(26); |
186 |
table.getTable().getJTable().getColumnModel().getColumn(0).setMaxWidth(26); |
187 |
table.getTable().getJTable().getColumnModel().getColumn(1).setMinWidth(26); |
188 |
table.getTable().getJTable().getColumnModel().getColumn(1).setMaxWidth(26); |
189 |
table.getModel().addTableModelListener(buttonsListener); |
190 |
} |
191 |
return table;
|
192 |
} |
193 |
|
194 |
/**
|
195 |
* Obtiene el panel de botones
|
196 |
* @return JPanel
|
197 |
*/
|
198 |
public JPanel getButtonsPanel() { |
199 |
if(buttonsPanel == null) { |
200 |
buttonsPanel = new JPanel(); |
201 |
buttonsPanel.setLayout(new GridBagLayout()); |
202 |
|
203 |
GridBagConstraints gb = new GridBagConstraints(); |
204 |
gb.insets = new java.awt.Insets(0, 0, 1, 1); |
205 |
gb.gridy = 0;
|
206 |
gb.gridx = 0;
|
207 |
buttonsPanel.add(getSaveToXMLButton(), gb); |
208 |
|
209 |
gb.gridy = 0;
|
210 |
gb.gridx = 1;
|
211 |
buttonsPanel.add(getLoadFromXMLButton(), gb); |
212 |
|
213 |
gb.gridy = 0;
|
214 |
gb.gridx = 2;
|
215 |
buttonsPanel.add(getExporToCSVButton(), gb); |
216 |
|
217 |
gb.gridy = 0;
|
218 |
gb.gridx = 3;
|
219 |
buttonsPanel.add(getLoadFromCSVButton(), gb); |
220 |
|
221 |
gb.gridy = 1;
|
222 |
gb.gridx = 0;
|
223 |
buttonsPanel.add(getOptionsButton(), gb); |
224 |
|
225 |
gb.gridy = 1;
|
226 |
gb.gridx = 1;
|
227 |
buttonsPanel.add(getCenterButton(), gb); |
228 |
|
229 |
gb.gridy = 1;
|
230 |
gb.gridx = 2;
|
231 |
buttonsPanel.add(getToolSelectPointButton(), gb); |
232 |
|
233 |
gb.gridy = 1;
|
234 |
gb.gridx = 3;
|
235 |
buttonsPanel.add(getEndGeorefButton(), gb); |
236 |
|
237 |
gb.gridy = 2;
|
238 |
gb.gridx = 0;
|
239 |
buttonsPanel.add(getTestButton(), gb); |
240 |
|
241 |
gb.gridy = 2;
|
242 |
gb.gridx = 1;
|
243 |
buttonsPanel.add(getEndTestButton(), gb); |
244 |
|
245 |
gb.gridy = 3;
|
246 |
gb.gridx = 0;
|
247 |
gb.gridwidth = 4;
|
248 |
buttonsPanel.add(getError(), gb); |
249 |
} |
250 |
return buttonsPanel;
|
251 |
} |
252 |
|
253 |
/**
|
254 |
* Obtiene el objeto con el error total
|
255 |
* @return
|
256 |
*/
|
257 |
public DataInputContainer getError() {
|
258 |
if(error == null) { |
259 |
error = new DataInputContainer();
|
260 |
error.setLabelText("RMS");
|
261 |
error.setPreferredSize(new Dimension(90, 35)); |
262 |
} |
263 |
return error;
|
264 |
} |
265 |
|
266 |
/**
|
267 |
* Obtiene el bot?n de finalizar georreferenciaci?n. Si no existe se crea.
|
268 |
* @return JButton
|
269 |
*/
|
270 |
public JButton getEndGeorefButton() { |
271 |
if(bEndGeoref == null) { |
272 |
bEndGeoref = new JButton(); |
273 |
bEndGeoref.setPreferredSize(new Dimension(22, 19)); |
274 |
bEndGeoref.setIcon(RasterToolsUtil.getIcon("exit-icon"));
|
275 |
bEndGeoref.setToolTipText(RasterToolsUtil.getText(this, "end_georef")); |
276 |
bEndGeoref.addActionListener(buttonsListener); |
277 |
} |
278 |
return bEndGeoref;
|
279 |
} |
280 |
|
281 |
/**
|
282 |
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
283 |
* @return JButton
|
284 |
*/
|
285 |
public JButton getTestButton() { |
286 |
if(bTest == null) { |
287 |
bTest = new JButton(); |
288 |
bTest.setPreferredSize(new Dimension(22, 19)); |
289 |
bTest.setToolTipText(RasterToolsUtil.getText(this, "test_georef")); |
290 |
bTest.addActionListener(buttonsListener); |
291 |
bTest.setIcon(RasterToolsUtil.getIcon("process-icon"));
|
292 |
} |
293 |
return bTest;
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* Obtiene el bot?n de terminar el test de georreferenciaci?n. Si no existe se crea.
|
298 |
* @return JButton
|
299 |
*/
|
300 |
public JButton getEndTestButton() { |
301 |
if(bEndTest == null) { |
302 |
bEndTest = new JButton(); |
303 |
bEndTest.setPreferredSize(new Dimension(22, 19)); |
304 |
bEndTest.setToolTipText(RasterToolsUtil.getText(this, "end_test_georef")); |
305 |
bEndTest.addActionListener(buttonsListener); |
306 |
bEndTest.setIcon(RasterToolsUtil.getIcon("endprocess-icon"));
|
307 |
} |
308 |
return bEndTest;
|
309 |
} |
310 |
|
311 |
/**
|
312 |
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
313 |
* @return JButton
|
314 |
*/
|
315 |
public JButton getLoadFromCSVButton() { |
316 |
if(bLoadFromAscii == null) { |
317 |
bLoadFromAscii = new JButton(); |
318 |
bLoadFromAscii.setPreferredSize(new Dimension(22, 19)); |
319 |
bLoadFromAscii.setToolTipText(RasterToolsUtil.getText(this, "load_from_ascii")); |
320 |
bLoadFromAscii.addActionListener(buttonsListener); |
321 |
bLoadFromAscii.setIcon(RasterToolsUtil.getIcon("importfromcsv-icon"));
|
322 |
} |
323 |
return bLoadFromAscii;
|
324 |
} |
325 |
|
326 |
/**
|
327 |
* Obtiene el bot?n de exportar a Ascii. Si no existe se crea.
|
328 |
* @return JButton
|
329 |
*/
|
330 |
public JButton getExporToCSVButton() { |
331 |
if(bSaveToAscii == null) { |
332 |
bSaveToAscii = new JButton(); |
333 |
bSaveToAscii.setPreferredSize(new Dimension(22, 19)); |
334 |
bSaveToAscii.setToolTipText(RasterToolsUtil.getText(this, "save_to_ascii")); |
335 |
bSaveToAscii.addActionListener(buttonsListener); |
336 |
bSaveToAscii.setIcon(RasterToolsUtil.getIcon("exporttocsv-icon"));
|
337 |
} |
338 |
return bSaveToAscii;
|
339 |
} |
340 |
|
341 |
/**
|
342 |
* Obtiene el bot?n de cargar desde XML. Si no existe se crea.
|
343 |
* @return JButton
|
344 |
*/
|
345 |
public JButton getLoadFromXMLButton() { |
346 |
if(bLoadFromXml == null) { |
347 |
bLoadFromXml = new JButton(); |
348 |
bLoadFromXml.setPreferredSize(new Dimension(22, 19)); |
349 |
bLoadFromXml.setToolTipText(RasterToolsUtil.getText(this, "load_from_xml")); |
350 |
bLoadFromXml.addActionListener(buttonsListener); |
351 |
bLoadFromXml.setIcon(RasterToolsUtil.getIcon("tfwload-icon"));
|
352 |
} |
353 |
return bLoadFromXml;
|
354 |
} |
355 |
|
356 |
/**
|
357 |
* Obtiene el bot?n de salvar a XML. Si no existe se crea.
|
358 |
* @return JButton
|
359 |
*/
|
360 |
public JButton getSaveToXMLButton() { |
361 |
if(bSaveToXml == null) { |
362 |
bSaveToXml = new JButton(); |
363 |
bSaveToXml.setPreferredSize(new Dimension(22, 19)); |
364 |
bSaveToXml.setToolTipText(RasterToolsUtil.getText(this, "save_gcp_to_xml")); |
365 |
bSaveToXml.addActionListener(buttonsListener); |
366 |
bSaveToXml.setIcon(RasterToolsUtil.getIcon("save-icon"));
|
367 |
} |
368 |
return bSaveToXml;
|
369 |
} |
370 |
|
371 |
/**
|
372 |
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
373 |
* @return JButton
|
374 |
*/
|
375 |
public JButton getOptionsButton() { |
376 |
if(bOptions == null) { |
377 |
bOptions = new JButton(); |
378 |
bOptions.setPreferredSize(new Dimension(22, 19)); |
379 |
bOptions.setToolTipText(RasterToolsUtil.getText(this, "options")); |
380 |
bOptions.addActionListener(buttonsListener); |
381 |
bOptions.setIcon(RasterToolsUtil.getIcon("options-icon"));
|
382 |
} |
383 |
return bOptions;
|
384 |
} |
385 |
|
386 |
/**
|
387 |
* Obtiene el bot?n de asignar el punto de control seleccionado en la tabla sobre
|
388 |
* una posici?n de la vista. Si no existe se crea.
|
389 |
* @return JButton
|
390 |
*/
|
391 |
public JToggleButton getToolSelectPointButton() { |
392 |
if(bAddPoint == null) { |
393 |
bAddPoint = new JToggleButton(); |
394 |
bAddPoint.setPreferredSize(new Dimension(22, 19)); |
395 |
bAddPoint.setToolTipText(RasterToolsUtil.getText(this, "move-point")); |
396 |
bAddPoint.addActionListener(buttonsListener); |
397 |
bAddPoint.setIcon(RasterToolsUtil.getIcon("add-icon"));
|
398 |
} |
399 |
return bAddPoint;
|
400 |
} |
401 |
|
402 |
/**
|
403 |
* Obtiene el bot?n de procesar georreferenciaci?n. Si no existe se crea.
|
404 |
* @return JButton
|
405 |
*/
|
406 |
public JButton getCenterButton() { |
407 |
if(bCenterView == null) { |
408 |
bCenterView = new JButton(); |
409 |
bCenterView.setPreferredSize(new Dimension(22, 19)); |
410 |
bCenterView.setToolTipText(RasterToolsUtil.getText(this, "center_view")); |
411 |
bCenterView.addActionListener(buttonsListener); |
412 |
bCenterView.setIcon(RasterToolsUtil.getIcon("centerpoint-icon"));
|
413 |
} |
414 |
return bCenterView;
|
415 |
} |
416 |
|
417 |
public void componentHidden(ComponentEvent e) { |
418 |
} |
419 |
|
420 |
public void componentMoved(ComponentEvent e) { |
421 |
} |
422 |
|
423 |
public void componentShown(ComponentEvent e) { |
424 |
} |
425 |
|
426 |
/**
|
427 |
* Cuando la tabla tiene un tama?o mayor de 800 pixeles de ancho se muestran las
|
428 |
* columnas de error en X e Y que cuando est? minimizada no aparecen.
|
429 |
*/
|
430 |
public void componentResized(ComponentEvent e) { |
431 |
try {
|
432 |
Dimension dim = ((GCPTablePanel)e.getSource()).getSize();
|
433 |
if(dim.getWidth() <= 800) { |
434 |
TableColumn col = getTable().getTable().getJTable().getColumnModel().getColumn(6); |
435 |
col.setMinWidth(0);
|
436 |
col.setMaxWidth(0);
|
437 |
col = getTable().getTable().getJTable().getColumnModel().getColumn(7);
|
438 |
col.setMinWidth(0);
|
439 |
col.setMaxWidth(0);
|
440 |
} else {
|
441 |
TableColumn col = getTable().getTable().getJTable().getColumnModel().getColumn(6); |
442 |
col.setMaxWidth(110);
|
443 |
col.setMinWidth(110);
|
444 |
col = getTable().getTable().getJTable().getColumnModel().getColumn(7);
|
445 |
col.setMaxWidth(110);
|
446 |
col.setMinWidth(110);
|
447 |
} |
448 |
getTable().getTable().invalidate(); |
449 |
} catch (NotInitializeException ex) {
|
450 |
return;
|
451 |
} |
452 |
} |
453 |
|
454 |
/*
|
455 |
* (non-Javadoc)
|
456 |
* @see com.iver.andami.ui.mdiManager.IWindow#getWindowInfo()
|
457 |
*/
|
458 |
public WindowInfo getWindowInfo() {
|
459 |
WindowInfo m_viewinfo = new WindowInfo(WindowInfo.MODELESSDIALOG | WindowInfo.RESIZABLE | WindowInfo.MAXIMIZABLE | WindowInfo.NOTCLOSABLE);
|
460 |
//if (getClippingPanel().getFLayer() != null)
|
461 |
//m_viewinfo.setAdditionalInfo(getClippingPanel().getFLayer().getName());
|
462 |
m_viewinfo.setTitle(PluginServices.getText(this, "points_panel")); |
463 |
m_viewinfo.setX(posX); |
464 |
m_viewinfo.setY(posY); |
465 |
m_viewinfo.setHeight(h); |
466 |
m_viewinfo.setWidth(w); |
467 |
return m_viewinfo;
|
468 |
} |
469 |
|
470 |
public Object getWindowProfile(){ |
471 |
return WindowInfo.TOOL_PROFILE;
|
472 |
} |
473 |
|
474 |
//****************************************************
|
475 |
//Acceso a los datos de la tabla
|
476 |
|
477 |
/**
|
478 |
* Obtiene las coordenadas de una fila
|
479 |
* @param row Fila de la que se quieren obtener las coordenadas
|
480 |
* @return Array con 4 valores coordenadas real X, coordenada real Y, coordenadas raster X y coordenada raste Y
|
481 |
*/
|
482 |
public double[] getCoordinates(int row) { |
483 |
double xMap = 0, yMap = 0, xRaster = 0, yRaster = 0; |
484 |
boolean numberFormatException = false; |
485 |
try {
|
486 |
Object value = getTable().getModel().getValueAt(row, 2); |
487 |
try {
|
488 |
if(value instanceof Double) |
489 |
xMap = ((Double)value).doubleValue();
|
490 |
else if(value instanceof String) |
491 |
xMap = Double.valueOf(((String)value)).doubleValue(); |
492 |
} catch (NumberFormatException ex1) { |
493 |
numberFormatException = true;
|
494 |
} |
495 |
|
496 |
value = getTable().getModel().getValueAt(row, 3);
|
497 |
try {
|
498 |
if(value instanceof Double) |
499 |
yMap = ((Double)value).doubleValue();
|
500 |
else if(value instanceof String) |
501 |
yMap = Double.valueOf(((String)value)).doubleValue(); |
502 |
} catch (NumberFormatException ex1) { |
503 |
numberFormatException = true;
|
504 |
} |
505 |
|
506 |
try {
|
507 |
value = getTable().getModel().getValueAt(row, 4);
|
508 |
if(value instanceof Double) |
509 |
xRaster = ((Double)value).doubleValue();
|
510 |
else if(value instanceof String) |
511 |
xRaster = Double.valueOf(((String)value)).doubleValue(); |
512 |
} catch (NumberFormatException ex1) { |
513 |
numberFormatException = true;
|
514 |
} |
515 |
|
516 |
try {
|
517 |
value = getTable().getModel().getValueAt(row, 5);
|
518 |
if(value instanceof Double) |
519 |
yRaster = ((Double)value).doubleValue();
|
520 |
else if(value instanceof String) |
521 |
yRaster = Double.valueOf(((String)value)).doubleValue(); |
522 |
} catch (NumberFormatException ex1) { |
523 |
numberFormatException = true;
|
524 |
} |
525 |
|
526 |
//Esto es necesario porque aunque se produzca una excepci?n en la lectura
|
527 |
//de un valor deben leerse los dem?s campos antes de terminar.
|
528 |
if(numberFormatException) {
|
529 |
RasterToolsUtil.messageBoxError("value_not_valid", table);
|
530 |
try {
|
531 |
getTable().getModel().setValueAt(new String(xMap + ""), row, 2); |
532 |
getTable().getModel().setValueAt(new String(yMap + ""), row, 3); |
533 |
getTable().getModel().setValueAt(new String(xRaster + ""), row, 4); |
534 |
getTable().getModel().setValueAt(new String(yRaster + ""), row, 5); |
535 |
} catch (NotInitializeException e) {
|
536 |
//Si est? inicializada sino habr?a entrado en la excepci?n de nivel mayor
|
537 |
} |
538 |
} |
539 |
|
540 |
//return new double[]{xMap, yMap, xRaster, yRaster};
|
541 |
} catch (NotInitializeException ex) {
|
542 |
RasterToolsUtil.messageBoxError("table_not_initialize", table);
|
543 |
} |
544 |
return new double[]{xMap, yMap, xRaster, yRaster}; |
545 |
} |
546 |
|
547 |
/**
|
548 |
*
|
549 |
* @param row
|
550 |
* @return
|
551 |
*/
|
552 |
public boolean getChecked(int row) { |
553 |
try {
|
554 |
Object value = getTable().getModel().getValueAt(row, 0); |
555 |
if(value != null && value instanceof Boolean) |
556 |
return ((Boolean)value).booleanValue(); |
557 |
}catch (NotInitializeException ex) {
|
558 |
RasterToolsUtil.messageBoxYesOrNot("table_not_initialize", table);
|
559 |
} |
560 |
return false; |
561 |
} |
562 |
|
563 |
/**
|
564 |
* A?ade una fila de datos al final de la tabla
|
565 |
* @param checked
|
566 |
* @param mX
|
567 |
* @param mY
|
568 |
* @param pX
|
569 |
* @param pY
|
570 |
* @param z
|
571 |
* @param eX
|
572 |
* @param eY
|
573 |
* @param rms
|
574 |
*/
|
575 |
public void addRow(boolean checked, Point2D map, Point2D pixel, double z, double eX, double eY, double rms, long id) { |
576 |
try {
|
577 |
int rowCount = getTable().getRowCount();
|
578 |
DefaultTableModel model = getTable().getModel();
|
579 |
if(model instanceof GCPModel) { |
580 |
Object[] rowData = ((GCPModel)model).getNewLine(); |
581 |
rowData[0] = new Boolean(checked); |
582 |
rowData[1] = rowCount + ""; |
583 |
rowData[2] = map.getX() + ""; |
584 |
rowData[3] = map.getY() + ""; |
585 |
rowData[4] = pixel.getX() + ""; |
586 |
rowData[5] = pixel.getY() + ""; |
587 |
rowData[rowData.length - 1] = new Long(id); |
588 |
getTable().addRow(rowData); |
589 |
} |
590 |
} catch (NotInitializeException e) {
|
591 |
RasterToolsUtil.messageBoxYesOrNot("table_not_initialize", table);
|
592 |
} |
593 |
} |
594 |
|
595 |
/**
|
596 |
* Elimina todos los puntos de la tabla
|
597 |
*/
|
598 |
public void removeAllPoints() { |
599 |
try {
|
600 |
getTable().removeAllRows(); |
601 |
} catch (NotInitializeException e) {
|
602 |
RasterToolsUtil.messageBoxYesOrNot("table_not_initialize", table);
|
603 |
} |
604 |
} |
605 |
|
606 |
/**
|
607 |
* Asigna una valor a una celda de la tabla
|
608 |
* @param value Valor a asignar
|
609 |
* @param row Fila
|
610 |
* @param col Columna
|
611 |
*/
|
612 |
public void setValueAt(Object value, int row, int col) { |
613 |
try {
|
614 |
getTable().setValueAt(value, row, col); |
615 |
} catch (NotInitializeException e) {
|
616 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
617 |
} |
618 |
} |
619 |
|
620 |
/**
|
621 |
* Asigna un valor al punto en coordenadas raster de la tabla. Es recomendable gastar este y no
|
622 |
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
623 |
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
624 |
* @param valueX Valor en X
|
625 |
* @param valueY Valor en Y
|
626 |
* @param row Fila a actualizar
|
627 |
* @param col Columna a actualizar
|
628 |
*/
|
629 |
public void updateRasterPoint(Object valueX, Object valueY, int row) { |
630 |
try {
|
631 |
getTable().setValueAt(valueX, row, 4);
|
632 |
getTable().setValueAt(valueY, row, 5);
|
633 |
updateErrors(); |
634 |
} catch (NotInitializeException e) {
|
635 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
636 |
} |
637 |
} |
638 |
|
639 |
/**
|
640 |
* Asigna un valor al punto en coordenadas del mundo de la tabla. Es recomendable gastar este y no
|
641 |
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
642 |
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
643 |
* @param valueX Valor en X
|
644 |
* @param valueY Valor en Y
|
645 |
* @param row Fila a actualizar
|
646 |
* @param col Columna a actualizar
|
647 |
*/
|
648 |
public void updateMapPoint(Object valueX, Object valueY, int row) { |
649 |
try {
|
650 |
getTable().setValueAt(valueX, row, 2);
|
651 |
getTable().setValueAt(valueY, row, 3);
|
652 |
updateErrors(); |
653 |
} catch (NotInitializeException e) {
|
654 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
655 |
} |
656 |
} |
657 |
|
658 |
/**
|
659 |
* Asigna un valor al punto de la tabla. Es recomendable gastar este y no
|
660 |
* setValueAt para evitar que se recalculen los errores en cada inserci?n de cada celda. De esta
|
661 |
* forma al actualiza ambas coordenadas a la vez solo se calcular? el error una vez.
|
662 |
* @param mapX Valor en X en coordenadas del mundo
|
663 |
* @param mapY Valor en Y en coordenadas del mundo
|
664 |
* @param pixelX Valor en X en coordenadas del raster
|
665 |
* @param pixelY Valor en Y en coordenadas del raster
|
666 |
* @param row Fila a actualizar
|
667 |
* @param col Columna a actualizar
|
668 |
*/
|
669 |
public void updatePoint(Object mapX, Object mapY, Object pixelX, Object pixelY, int row) { |
670 |
try {
|
671 |
getTable().setValueAt(mapX, row, 2);
|
672 |
getTable().setValueAt(mapY, row, 3);
|
673 |
getTable().setValueAt(pixelX, row, 4);
|
674 |
getTable().setValueAt(pixelY, row, 5);
|
675 |
updateErrors(); |
676 |
} catch (NotInitializeException e) {
|
677 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
678 |
} |
679 |
} |
680 |
|
681 |
/**
|
682 |
* Actualiza los errores de toda la tabla. Esta funci?n debe ser llamada cuando ha
|
683 |
* habido alg?n cambio en los valores de los puntos.
|
684 |
* @throws NotInitializeException
|
685 |
*/
|
686 |
public void updateErrors() { |
687 |
GeoPointList gpList = appMain.getLayerPointManager().getGeoPoints(); |
688 |
process.addParam("gpcs", gpList);
|
689 |
int degree = 1; |
690 |
if(appMain.getOptions().getAlgorithm() == Georeferencing.POLYNOMIAL)
|
691 |
degree = appMain.getOptions().getDegree(); |
692 |
process.addParam("orden", new Integer(degree)); |
693 |
try {
|
694 |
process.execute(); |
695 |
} catch (InterruptedException e) { |
696 |
return;
|
697 |
} catch(RuntimeException e) { |
698 |
//Matriz singular
|
699 |
return;
|
700 |
} |
701 |
GeoTransformDataResult result = (GeoTransformDataResult)process.getResult(); |
702 |
if(result == null) |
703 |
return;
|
704 |
|
705 |
//Actualizamos los errores de toda la tabla
|
706 |
try {
|
707 |
ColorColumnRenderer cr = new ColorColumnRenderer();
|
708 |
for (int i = 0; i < gpList.size(); i++) { |
709 |
GeoPoint point = gpList.get(i); |
710 |
getTable().setValueAt(new Double(point.getErrorX()), point.number, 6); |
711 |
getTable().setValueAt(new Double(point.getErrorY()), point.number, 7); |
712 |
getTable().setValueAt(new Double(point.getRms()), point.number, 8); |
713 |
if (point.getRms() > appMain.getOptions().getThreshold())
|
714 |
cr.addRowToColor1(point.number); |
715 |
else
|
716 |
cr.addRowToColor2(point.number); |
717 |
} |
718 |
getTable().getTable().getJTable().getColumnModel().getColumn(8).setCellRenderer(cr);
|
719 |
getError().setValue(result.getRmsTotal() + "");
|
720 |
} catch (NotInitializeException e) {
|
721 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
722 |
} |
723 |
} |
724 |
|
725 |
/**
|
726 |
* Obtiene el resultado de aplicar el algoritmo de transformaci?n
|
727 |
* @return
|
728 |
*/
|
729 |
public GeoTransformDataResult getGeoTransformDataResult() {
|
730 |
if(process != null) |
731 |
return (GeoTransformDataResult)process.getResult();
|
732 |
return null; |
733 |
} |
734 |
|
735 |
/**
|
736 |
* Obtiene una valor de una celda de la tabla
|
737 |
* @param row Fila
|
738 |
* @param col Columna
|
739 |
* @return Valor obtenido
|
740 |
*/
|
741 |
public Object getValueAt(int row, int col) { |
742 |
try {
|
743 |
return getTable().getModel().getValueAt(row, col);
|
744 |
} catch (NotInitializeException e) {
|
745 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
746 |
} |
747 |
return null; |
748 |
} |
749 |
|
750 |
/**
|
751 |
* Obtiene el n?mero de filas de la tabla
|
752 |
* @return Entero que representa el n?mero de filas de la tabla
|
753 |
*/
|
754 |
public int getRowCount() { |
755 |
try {
|
756 |
return getTable().getRowCount();
|
757 |
} catch (NotInitializeException e) {
|
758 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
759 |
} |
760 |
return 0; |
761 |
} |
762 |
|
763 |
/**
|
764 |
* Obtiene el n?mero de columnas de la tabla
|
765 |
* @return Entero que representa el n?mero de columnas de la tabla
|
766 |
*/
|
767 |
public int getColumnCount() { |
768 |
try {
|
769 |
return getTable().getModel().getColumnCount();
|
770 |
} catch (NotInitializeException e) {
|
771 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
772 |
} |
773 |
return 0; |
774 |
} |
775 |
|
776 |
/**
|
777 |
* Inicializa una fila de la tabla con los valores a 0, el n?mero de punto
|
778 |
* y el identificador. Esto es util para la inserci?n de un nuevo punto antes
|
779 |
* de introducir sus coordenadas.
|
780 |
* @param row Fila a inicializar
|
781 |
* @param id Identificador
|
782 |
*/
|
783 |
public void initializeRow(int row, long id) { |
784 |
try {
|
785 |
getTable().setValueAt(new Integer(row), row, 1); |
786 |
for (int i = 2; i <= 9; i++) |
787 |
getTable().setValueAt(new Double(0), row, i); |
788 |
getTable().setValueAt(new Long(id), row, getColumnCount() - 1); |
789 |
} catch (NotInitializeException e) {
|
790 |
RasterToolsUtil.messageBoxError("table_not_initialize", this, e); |
791 |
} |
792 |
} |
793 |
|
794 |
|
795 |
/**
|
796 |
* Renderer para cambiar el color a la columna de la tabla
|
797 |
* 06/02/2008
|
798 |
* @author Nacho Brodin nachobrodin@gmail.com
|
799 |
*/
|
800 |
public class ColorColumnRenderer extends DefaultTableCellRenderer { |
801 |
private static final long serialVersionUID = 1L; |
802 |
private Color back = Color.red; |
803 |
private Color fore = Color.white; |
804 |
private Color back2 = Color.white; |
805 |
private Color fore2 = Color.black; |
806 |
private ArrayList color1 = null; |
807 |
private ArrayList color2 = null; |
808 |
|
809 |
public ColorColumnRenderer() {
|
810 |
super();
|
811 |
color1 = new ArrayList(); |
812 |
color2 = new ArrayList(); |
813 |
} |
814 |
|
815 |
/**
|
816 |
* A?ade una fila al tipo de color 1
|
817 |
* @param row
|
818 |
*/
|
819 |
public void addRowToColor1(int row) { |
820 |
color1.add(new Integer(row)); |
821 |
} |
822 |
|
823 |
/**
|
824 |
* A?ade una fila al tipo de color 2
|
825 |
* @param row
|
826 |
*/
|
827 |
public void addRowToColor2(int row) { |
828 |
color2.add(new Integer(row)); |
829 |
} |
830 |
|
831 |
public Component getTableCellRendererComponent (JTable table, Object value, boolean isSelected, |
832 |
boolean hasFocus, int row, int column) { |
833 |
Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); |
834 |
for (int i = 0; i < color1.size(); i++) { |
835 |
if(((Integer)color1.get(i)).intValue() == row) { |
836 |
cell.setBackground(back); |
837 |
cell.setForeground(fore); |
838 |
} |
839 |
} |
840 |
for (int i = 0; i < color2.size(); i++) { |
841 |
if(((Integer)color2.get(i)).intValue() == row) { |
842 |
cell.setBackground(back2); |
843 |
cell.setForeground(fore2); |
844 |
} |
845 |
} |
846 |
return cell;
|
847 |
} |
848 |
} |
849 |
|
850 |
} |
851 |
|