svn-gvsig-desktop / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / TransformationRecentsPanel.java @ 11814
History | View | Annotate | Download (10.9 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.crs.CrsException; |
56 |
import org.gvsig.crs.CrsFactory; |
57 |
import org.gvsig.crs.ICrs; |
58 |
import org.gvsig.crs.persistence.RecentCRSsPersistence; |
59 |
import org.gvsig.crs.persistence.RecentTrsPersistence; |
60 |
import org.gvsig.crs.persistence.TrData; |
61 |
|
62 |
import com.iver.andami.PluginServices; |
63 |
import com.iver.cit.gvsig.gui.TableSorter; |
64 |
|
65 |
import es.idr.teledeteccion.connection.EpsgConnection; |
66 |
|
67 |
/**
|
68 |
* Panel para la gestin de las transformaciones recientes
|
69 |
* @author Jos Luis Gmez Martnez (jolugomar@gmail.com)
|
70 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
71 |
*
|
72 |
*/
|
73 |
public class TransformationRecentsPanel extends JPanel { |
74 |
|
75 |
private static final long serialVersionUID = 1L; |
76 |
int code = 0; |
77 |
private JTable transformationTable; |
78 |
private JScrollPane jScrollPane = null; |
79 |
public DefaultTableModel dtm = null; |
80 |
public TableSorter sorter = null; |
81 |
JButton JButtonInfo = null; |
82 |
public int selectedRowTable = -1; |
83 |
private TrData[] trDataArray; |
84 |
|
85 |
private String cadWKT = ""; |
86 |
private String params =""; |
87 |
public EpsgConnection connect = null; |
88 |
boolean inverseTransformation = false; |
89 |
int trCode;
|
90 |
boolean targetNad = false; |
91 |
|
92 |
public TransformationRecentsPanel() {
|
93 |
initialize(); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Genera el panel contenedor de las transformaciones recientes
|
98 |
* @return
|
99 |
*/
|
100 |
private void initialize(){ |
101 |
connect = new EpsgConnection();
|
102 |
connect.setConnectionEPSG(); |
103 |
//**setLayout(new GridLayout(2,1));
|
104 |
//**setLayout(new FlowLayout(FlowLayout.LEADING,5,10));
|
105 |
//**setPreferredSize(new Dimension(525, 100));
|
106 |
setLayout(new BorderLayout()); |
107 |
setBorder( |
108 |
BorderFactory.createCompoundBorder(
|
109 |
BorderFactory.createCompoundBorder(
|
110 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"recents_transformation")), |
111 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
112 |
getBorder())); |
113 |
JPanel p=new JPanel(); |
114 |
p.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
115 |
p.add(getJButtonInfo()); |
116 |
add(p,BorderLayout.NORTH);
|
117 |
add(getJScrollPane(),BorderLayout.CENTER);
|
118 |
//loadRecents();
|
119 |
} |
120 |
|
121 |
public JTable getJTable() { |
122 |
if (transformationTable == null) { |
123 |
String[] columnNames= {PluginServices.getText(this,"transformation"), |
124 |
PluginServices.getText(this,"name"), |
125 |
PluginServices.getText(this,"source_crs"), |
126 |
PluginServices.getText(this,"target_crs"), |
127 |
PluginServices.getText(this,"detalles"),}; |
128 |
Object[][]data = {}; |
129 |
dtm = new DefaultTableModel(data, columnNames) |
130 |
{ |
131 |
private static final long serialVersionUID = 1L; |
132 |
public boolean isCellEditable(int row, int column) { |
133 |
return false; |
134 |
} |
135 |
/*
|
136 |
* metodo necesario para cuando utilizamos tablas ordenadas
|
137 |
* ya que sino al ordenar por algun campo no se queda con el orden
|
138 |
* actual al seleccionar una fila
|
139 |
* @see javax.swing.table.TableModel#getColumnClass(int)
|
140 |
*/
|
141 |
public Class getColumnClass(int column) |
142 |
{ |
143 |
return getValueAt(0, column).getClass(); |
144 |
} |
145 |
}; |
146 |
sorter = new TableSorter(dtm);
|
147 |
|
148 |
transformationTable = new JTable(sorter); |
149 |
sorter.setTableHeader(transformationTable.getTableHeader()); |
150 |
transformationTable.setCellSelectionEnabled(false);
|
151 |
transformationTable.setRowSelectionAllowed(true);
|
152 |
transformationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
|
153 |
transformationTable.setColumnSelectionAllowed(false);
|
154 |
transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
155 |
TableColumn column = null; |
156 |
for (int i = 0; i < columnNames.length; i++) { |
157 |
column = transformationTable.getColumnModel().getColumn(i); |
158 |
if (i == 0) { |
159 |
column.setPreferredWidth(80);
|
160 |
} |
161 |
else if(i == 4) { |
162 |
column.setPreferredWidth(200);
|
163 |
} |
164 |
else {
|
165 |
column.setPreferredWidth(100);
|
166 |
} |
167 |
} |
168 |
} |
169 |
return transformationTable;
|
170 |
} |
171 |
|
172 |
private JScrollPane getJScrollPane() { |
173 |
if (jScrollPane == null) { |
174 |
jScrollPane = new JScrollPane(); |
175 |
//jScrollPane.setPreferredSize(new Dimension(525,200));
|
176 |
jScrollPane.setBorder( |
177 |
BorderFactory.createCompoundBorder(
|
178 |
BorderFactory.createCompoundBorder(
|
179 |
BorderFactory.createTitledBorder(PluginServices.getText(this,"transformations")), |
180 |
BorderFactory.createEmptyBorder(12,5,70,5)), |
181 |
jScrollPane.getBorder())); |
182 |
jScrollPane.setViewportView(getJTable()); |
183 |
} |
184 |
return jScrollPane;
|
185 |
} |
186 |
|
187 |
public JButton getJButtonInfo() { |
188 |
if(JButtonInfo == null) { |
189 |
JButtonInfo = new JButton(); |
190 |
//Poner: JButtonInfo.setPreferredSize(new Dimension(100,20));
|
191 |
JButtonInfo.setText(PluginServices.getText(this,"info_transformations")); |
192 |
JButtonInfo.setMnemonic('I');
|
193 |
JButtonInfo.setEnabled(false);
|
194 |
} |
195 |
return JButtonInfo;
|
196 |
} |
197 |
|
198 |
/**
|
199 |
* Consigue el crs elegido de las transformaciones
|
200 |
* recientes cuando el se utiliza transformacin EPSG o manual
|
201 |
* @return
|
202 |
*/
|
203 |
public ICrs getProjection() {
|
204 |
ICrs crs = null;
|
205 |
try {
|
206 |
//crs = new CrsFactory().getCRS(getCode(), getWKT(),getParams());
|
207 |
crs = new CrsFactory().getCRS("EPSG:"+getCode()); |
208 |
crs.setTransformationParams(getParams()); |
209 |
} catch (CrsException e) {
|
210 |
e.printStackTrace(); |
211 |
} |
212 |
return crs;
|
213 |
} |
214 |
|
215 |
/**
|
216 |
* Consigue el crs elegido de las transformaciones
|
217 |
* recientes cuando se utiliza transformacin de rejillas
|
218 |
* @param info
|
219 |
* @return
|
220 |
*/
|
221 |
public ICrs getProjectionNad(String info) { |
222 |
String[] partes = info.split("\\("); |
223 |
String nadFile = partes[0]; |
224 |
int codigoNad = Integer.parseInt((partes[1].substring(0,partes[1].length()-1)).split(":")[1]); |
225 |
ICrs crs; |
226 |
|
227 |
if (getCode() == codigoNad){
|
228 |
try {
|
229 |
setNad(false);
|
230 |
//Siempre EPSG porque solo permitimos transformaciones
|
231 |
//en el caso en que source y target sean de la EPSG
|
232 |
//crs = new CrsFactory().getCRS("EPSG:"+getCode(), getWKT());
|
233 |
crs = new CrsFactory().getCRS("EPSG:"+getCode()); |
234 |
crs.setTransformationParams("+nadgrids="+nadFile);//nadFile); |
235 |
return crs;
|
236 |
} catch (org.gvsig.crs.CrsException e) {
|
237 |
e.printStackTrace(); |
238 |
} |
239 |
return null; |
240 |
} |
241 |
else {
|
242 |
setNad(true);
|
243 |
try {
|
244 |
//crs = new CrsFactory().getCRS("EPSG:"+getCode(), getWKT());
|
245 |
crs = new CrsFactory().getCRS("EPSG:"+getCode()); |
246 |
crs.setTransformationParams("+nadgrids="+nadFile);//nadFile); |
247 |
crs.setParamsInTarget(true);
|
248 |
|
249 |
return crs;
|
250 |
} catch (CrsException e) {
|
251 |
e.printStackTrace(); |
252 |
} |
253 |
return null; |
254 |
} |
255 |
} |
256 |
|
257 |
/**
|
258 |
*
|
259 |
* @param nadg Define si el fichero rejillas se calcula en el crs fuente o destino
|
260 |
*/
|
261 |
public void setNad(boolean nadg){ |
262 |
targetNad = nadg; |
263 |
} |
264 |
|
265 |
/**
|
266 |
*
|
267 |
* @return Devuelve si el fichero de rejillas se calcula en el crs fuente o destino
|
268 |
*/
|
269 |
public boolean getNad(){ |
270 |
return targetNad;
|
271 |
} |
272 |
|
273 |
/**
|
274 |
*
|
275 |
* @param cod Cdigo del CRS elegido
|
276 |
*/
|
277 |
public void setCode(int cod){ |
278 |
code = cod; |
279 |
} |
280 |
|
281 |
/**
|
282 |
*
|
283 |
* @return Devuelve el cdigo del CRS elegido
|
284 |
*/
|
285 |
public int getCode(){ |
286 |
return code;
|
287 |
} |
288 |
|
289 |
/**
|
290 |
*
|
291 |
* @param cad Cadena wkt del crs fuente
|
292 |
*/
|
293 |
public void setWKT(String cad){ |
294 |
cadWKT = cad; |
295 |
} |
296 |
|
297 |
/**
|
298 |
*
|
299 |
* @return Devuelve la cadena wkt del crs fuente
|
300 |
*/
|
301 |
public String getWKT(){ |
302 |
return cadWKT;
|
303 |
} |
304 |
|
305 |
/**
|
306 |
*
|
307 |
* @param param Hacemos la cadena con los parmetros de la transformacin manual
|
308 |
*/
|
309 |
public void setParamsManual(String param){ |
310 |
params = "+towgs84="+param.substring(1,param.length()-1)+" "; |
311 |
} |
312 |
|
313 |
/**
|
314 |
*
|
315 |
* @param values Hacemos la cadena con los parmetros de la transformacin EPSG
|
316 |
*/
|
317 |
public void setParamsEPGS(String[] values){ |
318 |
params = "+towgs84="+values[0]; |
319 |
for(int i = 1; i < values.length; i++) |
320 |
params +=","+values[i];
|
321 |
params += " ";
|
322 |
} |
323 |
|
324 |
/**
|
325 |
*
|
326 |
* @param nadfile
|
327 |
*/
|
328 |
public void setParamsNads(String nadfile){ |
329 |
|
330 |
} |
331 |
|
332 |
/**
|
333 |
*
|
334 |
* @return Deuelve una cadena con los parmetros de la transformacin
|
335 |
*/
|
336 |
public String getParams(){ |
337 |
return params;
|
338 |
} |
339 |
|
340 |
/**
|
341 |
*
|
342 |
* @param inverse Parmetro que define si la transformacin es directa o inversa
|
343 |
*/
|
344 |
public void setInverseTransformation(boolean inverse){ |
345 |
inverseTransformation = inverse; |
346 |
} |
347 |
|
348 |
/**
|
349 |
*
|
350 |
* @return Devuelve si es una transformacin directa o inversa
|
351 |
*/
|
352 |
public boolean getInverseTransformation(){ |
353 |
return inverseTransformation;
|
354 |
} |
355 |
|
356 |
/**
|
357 |
*
|
358 |
* @param code Cdigo de la transformacin EPGS elegida
|
359 |
*/
|
360 |
public void setTrCode(int code){ |
361 |
trCode = code; |
362 |
} |
363 |
|
364 |
/**
|
365 |
*
|
366 |
* @return Devuelve el cdigo de la transformacin
|
367 |
*/
|
368 |
public int getTrCode(){ |
369 |
return trCode;
|
370 |
} |
371 |
|
372 |
/**
|
373 |
* Carga en la tabla los CRSs leidos del sistema de persistencia.
|
374 |
*/
|
375 |
public void loadRecents(int source, int target){ |
376 |
|
377 |
// Eliminar filas en cada nueva bsqueda
|
378 |
int numRow = dtm.getRowCount();
|
379 |
while (numRow != 0) { |
380 |
numRow = numRow - 1;
|
381 |
dtm.removeRow(numRow); |
382 |
} |
383 |
RecentTrsPersistence persistence = new RecentTrsPersistence(RecentCRSsPersistence.pluginClassInstance);
|
384 |
trDataArray = persistence.getArrayOfTrData(); |
385 |
|
386 |
|
387 |
for (int iRow = trDataArray.length-1;iRow>=0;iRow--){ |
388 |
String[] crsSource = ((String)trDataArray[iRow].getCrsSource()).split(":"); |
389 |
String[] crsTarget = ((String)trDataArray[iRow].getCrsTarget()).split(":"); |
390 |
if(source == Integer.parseInt(crsSource[1]) && target == Integer.parseInt(crsTarget[1])){ |
391 |
Object row[] ={trDataArray[iRow].getAuthority()+":"+trDataArray[iRow].getCode(),trDataArray[iRow].getName(),trDataArray[iRow].getCrsSource(), |
392 |
trDataArray[iRow].getCrsTarget(),trDataArray[iRow].getDetails()}; |
393 |
dtm.addRow(row); |
394 |
} |
395 |
} |
396 |
|
397 |
/*
|
398 |
/*Seleccionar el primer registro.
|
399 |
*/
|
400 |
int numr = dtm.getRowCount();
|
401 |
if (numr != 0 ) |
402 |
this.getJTable().setRowSelectionInterval(0,0); |
403 |
} |
404 |
|
405 |
} |