Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libJCRS / src / org / gvsig / crs / gui / panels / TransformationRecentsPanel.java @ 11544

History | View | Annotate | Download (10.5 KB)

1
/* 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
import java.awt.Dimension;
44
import java.awt.FlowLayout;
45
import java.awt.GridLayout;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48

    
49
import javax.swing.BorderFactory;
50
import javax.swing.JButton;
51
import javax.swing.JPanel;
52
import javax.swing.JScrollPane;
53
import javax.swing.JTable;
54
import javax.swing.ListSelectionModel;
55
import javax.swing.table.DefaultTableModel;
56
import javax.swing.table.TableColumn;
57

    
58
import org.gvsig.crs.CrsException;
59
import org.gvsig.crs.CrsFactory;
60
import org.gvsig.crs.CrsWkt;
61
import org.gvsig.crs.EpsgConnection;
62
import org.gvsig.crs.ICrs;
63
import org.gvsig.crs.persistence.RecentCRSsPersistence;
64
import org.gvsig.crs.persistence.RecentTrsPersistence;
65
import org.gvsig.crs.persistence.TrData;
66

    
67
import com.iver.andami.PluginServices;
68
import com.iver.cit.gvsig.gui.TableSorter;
69

    
70
/**
71
 * Panel para la gesti?n de las transformaciones recientes
72
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
73
 *
74
 */
75
public class TransformationRecentsPanel extends JPanel {
76
        
77
        int code = 0;
78
        private JTable transformationTable;        
79
        private JScrollPane jScrollPane = null;
80
        public DefaultTableModel dtm = null;
81
        public TableSorter sorter = null;
82
        JButton JButtonInfo = null;
83
        public int selectedRowTable = -1;
84
        private TrData[] trDataArray;
85
        
86
        private String cadWKT = "";
87
        private String params ="";
88
        public EpsgConnection connect = null;
89
        boolean inverseTransformation = false;
90
        int trCode;
91
        boolean targetNad = false;
92

    
93
        public TransformationRecentsPanel() {
94
                initialize();
95
        }
96
        
97
        /**
98
         * Genera el panel contenedor de las transformaciones recientes
99
         * @return
100
         */
101
        private void initialize(){
102
                connect = new EpsgConnection();
103
                connect.setConnectionEPSG();
104
                        setLayout(new GridLayout(2,1));
105
                        setLayout(new FlowLayout(FlowLayout.LEADING,5,10));
106
                        setPreferredSize(new Dimension(525, 100));
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
                        add(getJButtonInfo());
114
                        add(getJScrollPane());        
115
                        //loadRecents();
116
        }
117
        
118
        public JTable getJTable() {
119
                if (transformationTable == null) {
120
                        String[] columnNames= {PluginServices.getText(this,"transformation"),
121
                                        PluginServices.getText(this,"name"),
122
                                        PluginServices.getText(this,"source_crs"),
123
                                        PluginServices.getText(this,"target_crs"),
124
                                        PluginServices.getText(this,"detalles"),};                                        
125
                        Object[][]data = {};
126
                        dtm = new DefaultTableModel(data, columnNames)
127
                        {
128
                                public boolean isCellEditable(int row, int column) {
129
                                        return false;
130
                                }
131
                                /*
132
                                 * metodo necesario para cuando utilizamos tablas ordenadas
133
                                 * ya que sino al ordenar por algun campo no se queda con el orden
134
                                 * actual al seleccionar una fila
135
                                 * @see javax.swing.table.TableModel#getColumnClass(int)
136
                                 */
137
                                public Class getColumnClass(int column)
138
                                {
139
                                        return getValueAt(0, column).getClass();
140
                                }
141
                        };
142
                        sorter = new TableSorter(dtm);                        
143

    
144
                        transformationTable = new JTable(sorter);
145
                        sorter.setTableHeader(transformationTable.getTableHeader());        
146
                        transformationTable.setCellSelectionEnabled(false);
147
                        transformationTable.setRowSelectionAllowed(true);
148
                        transformationTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
149
                        transformationTable.setColumnSelectionAllowed(false);
150
                        transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
151
                        TableColumn column = null;
152
                        for (int i = 0; i < columnNames.length; i++) {
153
                            column = transformationTable.getColumnModel().getColumn(i);
154
                            if (i == 0) {
155
                                    column.setPreferredWidth(80);
156
                            }
157
                            else if(i == 4) {
158
                                    column.setPreferredWidth(200);
159
                            }
160
                            else {                            
161
                                column.setPreferredWidth(100);
162
                            }
163
                        }                        
164
                }
165
                return transformationTable;
166
        }
167
        
168
        private JScrollPane getJScrollPane() {
169
                if (jScrollPane == null) {
170
                        jScrollPane = new JScrollPane();
171
                        jScrollPane.setPreferredSize(new Dimension(525,200));
172
                        jScrollPane.setBorder(
173
                                    BorderFactory.createCompoundBorder(
174
                                        BorderFactory.createCompoundBorder(
175
                                                        BorderFactory.createTitledBorder(PluginServices.getText(this,"transformations")),
176
                                                        BorderFactory.createEmptyBorder(5,5,5,5)),
177
                                                        jScrollPane.getBorder()));
178
                        jScrollPane.setViewportView(getJTable());
179
                }
180
                return jScrollPane;
181
        }
182
        
183
        public JButton getJButtonInfo() {
184
                if(JButtonInfo == null) {
185
                        JButtonInfo = new JButton();
186
                        JButtonInfo.setPreferredSize(new Dimension(200,20));                        
187
                        JButtonInfo.setText(PluginServices.getText(this,"info_transformations"));                        
188
                        JButtonInfo.setMnemonic('I');
189
                        JButtonInfo.setEnabled(false);                        
190
                }
191
                return JButtonInfo;
192
        }
193
        
194
        /**
195
         * Consigue el crs elegido de las transformaciones
196
         * recientes cuando el se utiliza transformaci?n EPSG o manual
197
         * @return
198
         */
199
        public ICrs getProjection() {
200
                ICrs crs = null;
201
                try {
202
                        //crs = new CrsFactory().getCRS(getCode(),getWKT(),getParams());
203
                        crs = new CrsFactory().getCRS(getCode(),getWKT());
204
                        crs.setTransParam(getParams());
205
                        crs.setTransInTarget(false);
206
                } catch (CrsException e) {
207
                        // TODO Auto-generated catch block
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.setTransParam("+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.setTransParam("+nadgrids="+nadFile);
243
                                crs.setTransInTarget(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
                
373
//                Eliminar filas en cada nueva busqueda
374
                int numRow = dtm.getRowCount();
375
                while (numRow != 0) {
376
                        numRow = numRow - 1;
377
                        dtm.removeRow(numRow);
378
                }
379
                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
}