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