root / org.gvsig.projection.jcrs / trunk / org.gvsig.projection.jcrs / org.gvsig.projection.app.jcrs / org.gvsig.projection.app.jcrs.common / src / main / java / org / gvsig / crs / gui / panels / TransformationRecentsPanel.java @ 320
History | View | Annotate | Download (15.5 KB)
1 |
/* gvSIG. Sistema de Informacin Geogrfica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Ibez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.crs.gui.panels; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.FlowLayout; |
45 |
|
46 |
import javax.swing.BorderFactory; |
47 |
import javax.swing.JButton; |
48 |
import javax.swing.JPanel; |
49 |
import javax.swing.JScrollPane; |
50 |
import javax.swing.JTable; |
51 |
import javax.swing.ListSelectionModel; |
52 |
import javax.swing.table.DefaultTableModel; |
53 |
import javax.swing.table.TableColumn; |
54 |
|
55 |
import org.gvsig.andami.PluginServices; |
56 |
import org.gvsig.app.gui.TableSorter; |
57 |
import org.gvsig.crs.CrsException; |
58 |
import org.gvsig.crs.CrsFactory; |
59 |
import org.gvsig.crs.ICrs; |
60 |
import org.gvsig.crs.ogr.TransEPSG; |
61 |
import org.gvsig.crs.persistence.CompTrData; |
62 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
63 |
import org.gvsig.crs.persistence.RecentTrsPersistence; |
64 |
import org.gvsig.crs.persistence.TrData; |
65 |
|
66 |
|
67 |
import org.slf4j.Logger; |
68 |
import org.slf4j.LoggerFactory; |
69 |
|
70 |
import es.idr.teledeteccion.connection.EpsgConnection; |
71 |
|
72 |
/**
|
73 |
* Panel para la gestin de las transformaciones recientes
|
74 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
|
75 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
76 |
*
|
77 |
*/
|
78 |
public class TransformationRecentsPanel extends JPanel { |
79 |
public static final Logger logger = LoggerFactory.getLogger(TransformationRecentsPanel.class); |
80 |
|
81 |
private static final long serialVersionUID = 1L; |
82 |
int code = 0; |
83 |
private JTable transformationTable; |
84 |
private JScrollPane jScrollPane = null; |
85 |
public DefaultTableModel dtm = null; |
86 |
public TableSorter sorter = null; |
87 |
JButton JButtonInfo = null; |
88 |
public int selectedRowTable = -1; |
89 |
private TrData[] trDataArray; |
90 |
|
91 |
private String cadWKT = ""; |
92 |
private String params =""; |
93 |
public EpsgConnection connect = null; |
94 |
boolean inverseTransformation = false; |
95 |
int trCode;
|
96 |
boolean targetNad = false; |
97 |
String sourceAbrev = null; |
98 |
|
99 |
public TransformationRecentsPanel() {
|
100 |
initialize(); |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Genera el panel contenedor de las transformaciones recientes
|
105 |
* @return
|
106 |
*/
|
107 |
private void initialize(){ |
108 |
connect = new EpsgConnection();
|
109 |
connect.setConnectionEPSG(); |
110 |
//**setLayout(new GridLayout(2,1));
|
111 |
//**setLayout(new FlowLayout(FlowLayout.LEADING,5,10));
|
112 |
//**setPreferredSize(new Dimension(525, 100));
|
113 |
setLayout(new BorderLayout()); |
114 |
setBorder( |
115 |
BorderFactory.createCompoundBorder(
|
116 |
BorderFactory.createCompoundBorder(
|
117 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"recents_transformation")), |
118 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
119 |
getBorder())); |
120 |
JPanel p=new JPanel(); |
121 |
p.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
122 |
p.add(getJButtonInfo()); |
123 |
add(p,BorderLayout.NORTH);
|
124 |
add(getJScrollPane(),BorderLayout.CENTER);
|
125 |
//loadRecents();
|
126 |
} |
127 |
|
128 |
public JTable getJTable() { |
129 |
if (transformationTable == null) { |
130 |
String[] columnNames= {PluginServices.getText(this,"transformation"), |
131 |
PluginServices.getText(this,"name"), |
132 |
PluginServices.getText(this,"source_crs"), |
133 |
PluginServices.getText(this,"target_crs"), |
134 |
PluginServices.getText(this,"detalles"),}; |
135 |
Object[][]data = {}; |
136 |
dtm = new DefaultTableModel(data, columnNames) |
137 |
{ |
138 |
private static final long serialVersionUID = 1L; |
139 |
public boolean isCellEditable(int row, int column) { |
140 |
return false; |
141 |
} |
142 |
/*
|
143 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
144 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
145 |
* actual al seleccionar una fila
|
146 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
147 |
*/
|
148 |
public Class getColumnClass(int column) |
149 |
{ |
150 |
return getValueAt(0, column).getClass(); |
151 |
} |
152 |
}; |
153 |
sorter = new TableSorter(dtm);
|
154 |
|
155 |
transformationTable = new JTable(sorter); |
156 |
sorter.setTableHeader(transformationTable.getTableHeader()); |
157 |
transformationTable.setCellSelectionEnabled(false);
|
158 |
transformationTable.setRowSelectionAllowed(true);
|
159 |
transformationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
160 |
transformationTable.setColumnSelectionAllowed(false);
|
161 |
transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
162 |
TableColumn column = null; |
163 |
for (int i = 0; i < columnNames.length; i++) { |
164 |
column = transformationTable.getColumnModel().getColumn(i); |
165 |
if (i == 0) { |
166 |
column.setPreferredWidth(80);
|
167 |
} |
168 |
else if(i == 4) { |
169 |
column.setPreferredWidth(200);
|
170 |
} |
171 |
else {
|
172 |
column.setPreferredWidth(100);
|
173 |
} |
174 |
} |
175 |
} |
176 |
return transformationTable;
|
177 |
} |
178 |
|
179 |
private JScrollPane getJScrollPane() { |
180 |
if (jScrollPane == null) { |
181 |
jScrollPane = new JScrollPane(); |
182 |
//jScrollPane.setPreferredSize(new Dimension(525,200));
|
183 |
jScrollPane.setBorder( |
184 |
BorderFactory.createCompoundBorder(
|
185 |
BorderFactory.createCompoundBorder(
|
186 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"transformations")), |
187 |
BorderFactory.createEmptyBorder(12,5,70,5)), |
188 |
jScrollPane.getBorder())); |
189 |
jScrollPane.setViewportView(getJTable()); |
190 |
} |
191 |
return jScrollPane;
|
192 |
} |
193 |
|
194 |
public JButton getJButtonInfo() { |
195 |
if(JButtonInfo == null) { |
196 |
JButtonInfo = new JButton(); |
197 |
//Poner: JButtonInfo.setPreferredSize(new Dimension(100,20));
|
198 |
JButtonInfo.setText(PluginServices.getText(this,"info_transformations")); |
199 |
JButtonInfo.setMnemonic('I');
|
200 |
JButtonInfo.setEnabled(false);
|
201 |
} |
202 |
return JButtonInfo;
|
203 |
} |
204 |
|
205 |
/**
|
206 |
* Consigue el crs elegido de las transformaciones
|
207 |
* recientes cuando el se utiliza transformacin EPSG o manual
|
208 |
* @return
|
209 |
*/
|
210 |
public ICrs getProjection() {
|
211 |
ICrs crs = null;
|
212 |
String[] sourceAuthority = getSourceAbrev().split(":"); |
213 |
try {
|
214 |
crs = new CrsFactory().getCRS(sourceAuthority[0]+":"+getCode(),getParams(),null); |
215 |
} catch (CrsException e) {
|
216 |
logger.info("Can't create CRS with authority '"+sourceAuthority[0]+"', code "+getCode()+" and transformation source params '"+getParams()+"'.",e); |
217 |
} |
218 |
return crs;
|
219 |
} |
220 |
|
221 |
/**
|
222 |
* Consigue el crs elegido de las transformaciones recientes compuestas
|
223 |
* cuando se utiliza una transformacion compuesta
|
224 |
* @param info
|
225 |
* @return
|
226 |
*/
|
227 |
public ICrs getProjectionComplex(String details) { |
228 |
ICrs crs = null;
|
229 |
RecentTrsPersistence trPersistence = new RecentTrsPersistence();
|
230 |
TrData crsTrDataArray[] = trPersistence.getArrayOfTrData();
|
231 |
CompTrData comp = null;
|
232 |
String sourceTransformation = null; |
233 |
String targetTransformation = null; |
234 |
for (int iRow = crsTrDataArray.length-1; iRow >= 0; iRow--) { |
235 |
if (details.equals(crsTrDataArray[iRow].getDetails())) {
|
236 |
if (crsTrDataArray[iRow] instanceof CompTrData) { |
237 |
comp = (CompTrData) crsTrDataArray[iRow]; |
238 |
break;
|
239 |
} |
240 |
} |
241 |
} |
242 |
|
243 |
if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "EPSG"))) { |
244 |
TransEPSG epsgParams = new TransEPSG(comp.getFirstTr().getCode(),connect, getInverseTransformation());
|
245 |
setParamsEPGS(epsgParams.getParamValue()); |
246 |
sourceTransformation = getParams(); |
247 |
} else if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "USR"))) { |
248 |
//mirar si funciona y lleva los [ ]
|
249 |
setParamsManual(comp.getFirstTr().getDetails()); |
250 |
sourceTransformation = getParams(); |
251 |
} else if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "NADGR"))) { |
252 |
String info = comp.getFirstTr().getDetails();
|
253 |
String[] partes = info.split("\\("); |
254 |
String nadFile = partes[0]; |
255 |
sourceTransformation = "+nadgrids="+nadFile;
|
256 |
} |
257 |
|
258 |
if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "EPSG"))) { |
259 |
TransEPSG epsgParams = new TransEPSG(comp.getSecondTr().getCode(),connect, getInverseTransformation());
|
260 |
setParamsEPGS(epsgParams.getParamValue()); |
261 |
targetTransformation = getParams(); |
262 |
} else if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "USR"))) { |
263 |
//mirar si funciona y lleva los [ ]
|
264 |
setParamsManual(comp.getSecondTr().getDetails()); |
265 |
targetTransformation = getParams(); |
266 |
} else if (comp.getSecondTr().getAuthority().equals(PluginServices.getText(this, "NADGR"))) { |
267 |
String info = comp.getSecondTr().getDetails();
|
268 |
String[] partes = info.split("\\("); |
269 |
String nadFile = partes[0]; |
270 |
targetTransformation = "+nadgrids="+nadFile;
|
271 |
} |
272 |
|
273 |
try {
|
274 |
crs = new CrsFactory().getCRS(getSourceAbrev(),sourceTransformation,targetTransformation);
|
275 |
return crs;
|
276 |
} catch (org.gvsig.crs.CrsException e) {
|
277 |
logger.info("Can't create CRS with '"+getSourceAbrev()+"' and transformation params source '"+sourceTransformation+" and target'"+targetTransformation+"'.",e); |
278 |
} |
279 |
|
280 |
return crs;
|
281 |
} |
282 |
|
283 |
/**
|
284 |
* Consigue el crs elegido de las transformaciones
|
285 |
* recientes cuando se utiliza transformacin de rejillas
|
286 |
* @param info
|
287 |
* @return
|
288 |
*/
|
289 |
public ICrs getProjectionNad(String info) { |
290 |
String[] partes = info.split("\\("); |
291 |
String nadFile = partes[0]; |
292 |
int codigoNad = Integer.parseInt((partes[1].substring(0,partes[1].length()-1)).split(":")[1]); |
293 |
ICrs crs; |
294 |
String[] sourceAuthority = getSourceAbrev().split(":"); |
295 |
String params = "+nadgrids="+nadFile; |
296 |
|
297 |
if (getCode() == codigoNad){
|
298 |
try {
|
299 |
setNad(false);
|
300 |
crs = new CrsFactory().getCRS(sourceAuthority[0]+":"+getCode(),params,null); |
301 |
return crs;
|
302 |
} catch (org.gvsig.crs.CrsException e) {
|
303 |
logger.info("Can't create CRS with authority '"+sourceAuthority[0]+"', code "+getCode()+" and transformation source params '"+params+" .",e); |
304 |
} |
305 |
return null; |
306 |
} |
307 |
else {
|
308 |
setNad(true);
|
309 |
try {
|
310 |
crs = new CrsFactory().getCRS(sourceAuthority[0]+":"+getCode(),null,params); |
311 |
return crs;
|
312 |
} catch (CrsException e) {
|
313 |
logger.info("Can't create CRS with authority '"+sourceAuthority[0]+"', code "+getCode()+" and transformation target params '"+params+" .",e); |
314 |
} |
315 |
return null; |
316 |
} |
317 |
} |
318 |
|
319 |
/**
|
320 |
*
|
321 |
* @param nadg Define si el fichero rejillas se calcula en el crs fuente o destino
|
322 |
*/
|
323 |
public void setNad(boolean nadg){ |
324 |
targetNad = nadg; |
325 |
} |
326 |
|
327 |
/**
|
328 |
*
|
329 |
* @return Devuelve si el fichero de rejillas se calcula en el crs fuente o destino
|
330 |
*/
|
331 |
public boolean getNad(){ |
332 |
return targetNad;
|
333 |
} |
334 |
|
335 |
/**
|
336 |
*
|
337 |
* @param cod Cdigo del CRS elegido
|
338 |
*/
|
339 |
public void setCode(int cod){ |
340 |
code = cod; |
341 |
} |
342 |
|
343 |
/**
|
344 |
*
|
345 |
* @return Devuelve el cdigo del CRS elegido
|
346 |
*/
|
347 |
public int getCode(){ |
348 |
return code;
|
349 |
} |
350 |
|
351 |
/**
|
352 |
*
|
353 |
* @param cad Cadena wkt del crs fuente
|
354 |
*/
|
355 |
public void setWKT(String cad){ |
356 |
cadWKT = cad; |
357 |
} |
358 |
|
359 |
/**
|
360 |
*
|
361 |
* @return Devuelve la cadena wkt del crs fuente
|
362 |
*/
|
363 |
public String getWKT(){ |
364 |
return cadWKT;
|
365 |
} |
366 |
|
367 |
/**
|
368 |
*
|
369 |
* @param param Hacemos la cadena con los parmetros de la transformacin manual
|
370 |
*/
|
371 |
public void setParamsManual(String param){ |
372 |
params = "+towgs84="+param.substring(1,param.length()-1)+" "; |
373 |
} |
374 |
|
375 |
/**
|
376 |
*
|
377 |
* @param values Hacemos la cadena con los parmetros de la transformacin EPSG
|
378 |
*/
|
379 |
public void setParamsEPGS(String[] values){ |
380 |
params = "+towgs84="+values[0]; |
381 |
for(int i = 1; i < values.length; i++) |
382 |
params +=","+values[i];
|
383 |
params += " ";
|
384 |
} |
385 |
|
386 |
/**
|
387 |
*
|
388 |
* @param nadfile
|
389 |
*/
|
390 |
public void setParamsNads(String nadfile){ |
391 |
|
392 |
} |
393 |
|
394 |
/**
|
395 |
*
|
396 |
* @return Deuelve una cadena con los parmetros de la transformacin
|
397 |
*/
|
398 |
public String getParams(){ |
399 |
return params;
|
400 |
} |
401 |
|
402 |
/**
|
403 |
*
|
404 |
* @param inverse Parmetro que define si la transformacin es directa o inversa
|
405 |
*/
|
406 |
public void setInverseTransformation(boolean inverse){ |
407 |
inverseTransformation = inverse; |
408 |
} |
409 |
|
410 |
/**
|
411 |
*
|
412 |
* @return Devuelve si es una transformacin directa o inversa
|
413 |
*/
|
414 |
public boolean getInverseTransformation(){ |
415 |
return inverseTransformation;
|
416 |
} |
417 |
|
418 |
/**
|
419 |
*
|
420 |
* @param code Cdigo de la transformacin EPGS elegida
|
421 |
*/
|
422 |
public void setTrCode(int code){ |
423 |
trCode = code; |
424 |
} |
425 |
|
426 |
/**
|
427 |
*
|
428 |
* @return Devuelve el cdigo de la transformacin
|
429 |
*/
|
430 |
public int getTrCode(){ |
431 |
return trCode;
|
432 |
} |
433 |
|
434 |
/**
|
435 |
* Carga en la tabla los CRSs leidos del sistema de persistencia.
|
436 |
*/
|
437 |
public void loadRecents(String source, String target){ |
438 |
setSourceAbrev(source); |
439 |
// Eliminar filas en cada nueva bsqueda
|
440 |
int numRow = dtm.getRowCount();
|
441 |
while (numRow != 0) { |
442 |
numRow = numRow - 1;
|
443 |
dtm.removeRow(numRow); |
444 |
} |
445 |
RecentTrsPersistence persistence = new RecentTrsPersistence();
|
446 |
trDataArray = persistence.getArrayOfTrData(); |
447 |
|
448 |
|
449 |
for (int iRow = trDataArray.length-1;iRow>=0;iRow--){ |
450 |
String crsSource = ((String)trDataArray[iRow].getCrsSource()); |
451 |
String crsTarget = ((String)trDataArray[iRow].getCrsTarget()); |
452 |
if(source.equals(crsSource) && target.equals(crsTarget)){
|
453 |
Object row[] ={trDataArray[iRow].getAuthority()+":"+trDataArray[iRow].getCode(),trDataArray[iRow].getName(),trDataArray[iRow].getCrsSource(), |
454 |
trDataArray[iRow].getCrsTarget(),trDataArray[iRow].getDetails()}; |
455 |
dtm.addRow(row); |
456 |
} |
457 |
} |
458 |
|
459 |
/*
|
460 |
/*Seleccionar el primer registro.
|
461 |
*/
|
462 |
int numr = dtm.getRowCount();
|
463 |
if (numr != 0 ) |
464 |
this.getJTable().setRowSelectionInterval(0,0); |
465 |
} |
466 |
|
467 |
/**
|
468 |
* Carga en la tabla los CRSs leidos del sistema de persistencia, para
|
469 |
* las transformaciones compuestas
|
470 |
*/
|
471 |
public void loadRecentsCompuesta(String source){ |
472 |
|
473 |
// Eliminar filas en cada nueva bsqueda
|
474 |
int numRow = dtm.getRowCount();
|
475 |
while (numRow != 0) { |
476 |
numRow = numRow - 1;
|
477 |
dtm.removeRow(numRow); |
478 |
} |
479 |
RecentTrsPersistence persistence = new RecentTrsPersistence();
|
480 |
trDataArray = persistence.getArrayOfTrData(); |
481 |
|
482 |
|
483 |
for (int iRow = trDataArray.length-1;iRow>=0;iRow--){ |
484 |
if (trDataArray[iRow] instanceof CompTrData) { |
485 |
continue;
|
486 |
} else {
|
487 |
String crsSource = ((String)trDataArray[iRow].getCrsSource()); |
488 |
String crsTarget = ((String)trDataArray[iRow].getCrsTarget()); |
489 |
if(source.equals(crsSource) || source.equals(crsTarget)){
|
490 |
Object row[] ={trDataArray[iRow].getAuthority()+":"+trDataArray[iRow].getCode(),trDataArray[iRow].getName(),trDataArray[iRow].getCrsSource(), |
491 |
trDataArray[iRow].getCrsTarget(),trDataArray[iRow].getDetails()}; |
492 |
dtm.addRow(row); |
493 |
} |
494 |
} |
495 |
} |
496 |
|
497 |
/*
|
498 |
/*Seleccionar el primer registro.
|
499 |
*/
|
500 |
int numr = dtm.getRowCount();
|
501 |
if (numr != 0 ) |
502 |
this.getJTable().setRowSelectionInterval(0,0); |
503 |
} |
504 |
|
505 |
public void setSourceAbrev(String source) { |
506 |
sourceAbrev = source; |
507 |
} |
508 |
|
509 |
public String getSourceAbrev() { |
510 |
return sourceAbrev;
|
511 |
} |
512 |
|
513 |
} |