Statistics
| Revision:

root / org.gvsig.jcrs / extJCRS / src / org / gvsig / crs / gui / panels / TransformationCapaPanel.java @ 40

History | View | Annotate | Download (14.2 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.CardLayout;
45
import java.awt.Dimension;
46
import java.awt.FlowLayout;
47
import java.awt.GridLayout;
48
import java.awt.event.ActionEvent;
49
import java.awt.event.ActionListener;
50
import java.awt.event.ItemEvent;
51
import java.awt.event.ItemListener;
52

    
53
import javax.swing.JComboBox;
54
import javax.swing.JLabel;
55
import javax.swing.JPanel;
56
import javax.swing.ListSelectionModel;
57

    
58
import org.gvsig.andami.PluginServices;
59
import org.gvsig.crs.gui.CRSMainTrPanel;
60
import org.gvsig.crs.gui.listeners.TransformationCompuestaPanelListener;
61
import org.gvsig.crs.ogr.TransEPSG;
62
import org.gvsig.crs.persistence.CompTrData;
63
import org.gvsig.crs.persistence.RecentTrsPersistence;
64
import org.gvsig.crs.persistence.TrData;
65

    
66

    
67

    
68
/**
69
 * Clase que define la trandformacion de la capa en una transformacion compuesta 
70
 *
71
 * @author Jose Luis Gomez Martinez (JoseLuis.Gomez@uclm.es)
72
 * @author Luisa Marina Fernandez (luisam.fernandez@uclm.es)
73
 *
74
 */
75
public class TransformationCapaPanel extends JPanel implements ActionListener, ItemListener{
76

    
77
        private static final long serialVersionUID = 1L;
78
        private JLabel lblTransCapa=null;
79
        private JComboBox jComboOptions=null;
80
        private JPanel pNorth=null;
81
        private TransformationManualPanel manualTrPanel = null;
82
        private TransformationEpsgPanel epsgTrPanel = null;
83
        private TransformationNadgridsPanel nadsTrPanel = null;
84
        private TransformationRecentsPanel recentsTrPanel = null;
85
        private JPanel pCenter=null;
86
        private JLabel lblCrsCapa = null;
87
        private JLabel lblCrsCapaCode = null;
88
        
89
        String crs_target = null;
90
        String crs_source = null;
91
        String sourceTransformation = null;
92
        CRSMainTrPanel crsMainTrPanel = null;
93
        
94
        boolean recentCompTransformation = false;
95
        
96
        public TransformationCapaPanel(String target, CRSMainTrPanel p) {
97
                super();
98
                crsMainTrPanel = p;
99
                setCrs_target(target);
100
                manualTrPanel = new TransformationManualPanel();
101
                epsgTrPanel = new TransformationEpsgPanel(target);
102
                nadsTrPanel = new TransformationNadgridsPanel(false);
103
                recentsTrPanel = new TransformationRecentsPanel();
104
                        
105
                setListeners();
106
        
107
                this.setLayout(new BorderLayout());
108
                //Aadir al norte el panel que contiene las diferentes opciones de transformacion
109
                this.add(getPNorth(),BorderLayout.NORTH);
110
                this.add(getPCenter(),BorderLayout.CENTER);
111
        }
112
        
113
        public JPanel getPCenter() {
114
                if (pCenter == null) {
115
                        pCenter = new JPanel();
116
                        pCenter.setLayout(new CardLayout());                
117
                
118
                        pCenter.add("recents", recentsTrPanel);
119
                        pCenter.add("manual", manualTrPanel);
120
                        pCenter.add("epsg", epsgTrPanel);
121
                        pCenter.add("nad", nadsTrPanel);
122
                }
123
                
124
                return pCenter;
125
        }
126

    
127
        
128
        public JLabel getLblTransCapa() {
129
                if(lblTransCapa==null){
130
                        lblTransCapa=new JLabel(PluginServices.getText(this,"transformacion_capa"));
131
                }
132
                return lblTransCapa;
133
        }
134
        
135
        public JLabel getLblCrsCapa() {
136
                if(lblCrsCapa==null){
137
                        lblCrsCapa=new JLabel(PluginServices.getText(this,"crs_layer")+":");
138
                }
139
                return lblCrsCapa;
140
        }
141
        
142
        public JLabel getLblCrsCapaCode() {
143
                if(lblCrsCapaCode==null){
144
                        lblCrsCapaCode=new JLabel();
145
                }
146
                return lblCrsCapaCode;
147
        }
148
        /**
149
         * Definicion del panel que contiene el Label y el Combo de 
150
         * las transformaciones de la capa
151
         * @return
152
         */
153
        public JPanel getPNorth() {
154
                if (pNorth==null){
155
                        pNorth=new JPanel();
156
                        pNorth.setLayout(new GridLayout(2,1));
157
                        JPanel p1=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3));
158
                        p1.add(getLblCrsCapa());
159
                        p1.add(getLblCrsCapaCode());
160
                        JPanel p2=new JPanel(new FlowLayout(FlowLayout.LEFT,10,3));
161
                        p2.add(getLblTransCapa());
162
                        p2.add(getJComboOptions());
163
                        
164
                        pNorth.add(p1);
165
                        pNorth.add(p2);
166
                }
167
                return pNorth;
168
        }
169
        /**
170
         * Definicin del ComboBox que contiene las diferentes transformaciones 
171
         * aplicables a la capa
172
         * @return
173
         */
174

    
175
        public JComboBox getJComboOptions() {
176
                if (jComboOptions == null){
177
                        String[] selection = {PluginServices.getText(this, "recents_transformation"),
178
                                        PluginServices.getText(this, "transformacion_epsg"),
179
                                        PluginServices.getText(this, "transformacion_manual"), 
180
                                        PluginServices.getText(this, "nadgrids")}; 
181
                        jComboOptions = new JComboBox(selection);
182
                        jComboOptions.setPreferredSize(new Dimension(180,25));
183
                        jComboOptions.addActionListener(this);
184
                        jComboOptions.addItemListener(this);
185
                        jComboOptions.setSelectedItem(PluginServices.getText(this,"recents_transformation"));
186
                }
187
                
188
                return jComboOptions;
189
        }
190
        
191
        /**
192
         * Mtodo para aplicarle los eventos necesarios en el panel actual. La
193
         * definicin de estos listeners estarn en la clase CRSMainTrPanelListener
194
         *
195
         */
196
        private void setListeners(){
197

    
198
                TransformationCompuestaPanelListener listener = new TransformationCompuestaPanelListener(this, crsMainTrPanel);
199
                
200
                getJComboOptions().addActionListener(listener);
201
                getRecentsTrPanel().getJButtonInfo().addActionListener(listener);
202
                                
203
        ListSelectionModel rowSMEpsgTr = getEpsgTrPanel().getJTable().getSelectionModel();
204
                rowSMEpsgTr.addListSelectionListener(listener);
205
                
206
                ListSelectionModel rowSMRecentsTr = getRecentsTrPanel().getJTable().getSelectionModel();
207
                rowSMRecentsTr.addListSelectionListener(listener);
208
                
209
                getNadsTrPanel().getJComboNadFile().addItemListener(listener);
210
                                
211
                getManualTrPanel().getTx_Translation().addKeyListener(listener);
212
                getManualTrPanel().getTy_Translation().addKeyListener(listener);
213
                getManualTrPanel().getTz_Translation().addKeyListener(listener);
214
                getManualTrPanel().getTx_Rotation().addKeyListener(listener);
215
                getManualTrPanel().getTy_Rotation().addKeyListener(listener);
216
                getManualTrPanel().getTz_Rotation().addKeyListener(listener);
217
                getManualTrPanel().getTscale().addKeyListener(listener);
218
        }
219

    
220
                
221
                
222
        public void actionPerformed(ActionEvent e) {
223
                        
224
        }
225
        
226
        public TransformationEpsgPanel getEpsgTrPanel() {
227
                return epsgTrPanel;
228
        }
229

    
230
        public TransformationManualPanel getManualTrPanel() {
231
                return manualTrPanel;
232
        }
233

    
234
        public TransformationNadgridsPanel getNadsTrPanel() {
235
                return nadsTrPanel;
236
        }
237
        
238
        public TransformationRecentsPanel getRecentsTrPanel() {
239
                return recentsTrPanel;
240
        }
241
        
242
        public void setCrs_target(String cod) {
243
                crs_target = cod;
244
        }
245
        
246
        public String getCrs_target() {
247
                return crs_target;
248
        }
249
        
250
        public void setCrs_source(String authority) {
251
                crs_source = authority;
252
                getLblCrsCapaCode().setText(authority);
253
        }
254
        
255
        public String getCrs_source() {
256
                return crs_source;
257
        }
258
        
259
        public void fillData() {
260
                String[] source = getCrs_source().split(":");
261
                String[] target = getCrs_target().split(":");                
262
                recentsTrPanel.loadRecentsCompuesta(getCrs_source());
263
                epsgTrPanel.setSourceCompuesta(getCrs_source());
264
                nadsTrPanel.setCode(Integer.parseInt(source[1]));
265
                nadsTrPanel.setSourceAbrev(PluginServices.getText(this, source[0]), source[1]);
266
                nadsTrPanel.setTargetAbrev(PluginServices.getText(this, target[0]), target[1]);
267
                nadsTrPanel.getJComboNadFile().setSelectedIndex(0);
268
                manualTrPanel.setCode(Integer.parseInt(source[1]));
269
                manualTrPanel.setSourceAbrev(PluginServices.getText(this, source[0]), source[1]);
270
                manualTrPanel.setTargetAbrev(PluginServices.getText(this, target[0]), target[1]);
271
                getJComboOptions().setSelectedIndex(0);
272
                /*
273
                 * Se dice que no es una transformacion cogida de las recientes compuestas
274
                 * para un correcto funcionamiento de los botones.
275
                 */
276
                setRecentCompTransformation(false);
277
        }
278
                
279
        public void setSourceTransformation(String trans) {
280
                sourceTransformation = trans;
281
        }
282
        
283
        public String getSourceTransformation() {
284
                return sourceTransformation;
285
        }
286
        
287
        public String getParamsEpsg(String [] values) {
288
                String params = "+towgs84=";
289
                params += values[0];
290
                for(int i = 1; i < values.length; i++)
291
                        params +=","+values[i];
292
                return params;
293
        }
294
        
295
        public String getManualParams() {
296
                if(getManualTrPanel().getTx_Translation().getText().equals("")){
297
                        getManualTrPanel().getTx_Translation().setText("0");
298
                }
299
                else if (getManualTrPanel().getTy_Translation().getText().equals("")){
300
                        getManualTrPanel().getTy_Translation().setText("0");
301
                }
302
                else if (getManualTrPanel().getTz_Translation().getText().equals("")){
303
                        getManualTrPanel().getTz_Translation().setText("0");
304
                }
305
                else if (getManualTrPanel().getTx_Rotation().getText().equals("")){
306
                        getManualTrPanel().getTx_Rotation().setText("0");
307
                }
308
                else if (getManualTrPanel().getTy_Rotation().getText().equals("")){
309
                        getManualTrPanel().getTy_Rotation().setText("0");
310
                }
311
                else if (getManualTrPanel().getTz_Rotation().getText().equals("")){
312
                        getManualTrPanel().getTz_Rotation().setText("0");
313
                }
314
                else if (getManualTrPanel().getTscale().getText().equals("")){
315
                        getManualTrPanel().getTscale().setText("0");
316
                }                
317
                String param = "+towgs84="+ getManualTrPanel().getTx_Translation().getText()+","+
318
                                                getManualTrPanel().getTy_Translation().getText()+","+
319
                                                getManualTrPanel().getTz_Translation().getText()+","+
320
                                                getManualTrPanel().getTx_Rotation().getText()+","+
321
                                                getManualTrPanel().getTy_Rotation().getText()+","+
322
                                                getManualTrPanel().getTz_Rotation().getText()+","+
323
                                                getManualTrPanel().getTscale().getText() + " ";
324
                return param;                
325
        }
326
        
327
        public String getNadsParams(String info) {
328
                String[] partes = info.split("\\(");
329
                String nadFile = partes[0];                
330
                return "+nadgrids="+nadFile;
331
        }
332
        
333
        /**
334
         * cuando utilizamos crs+transformacion, cargamos los paneles para que
335
         * el usuario pueda consultar la transformacion utilizada...
336
         * @param details
337
         */
338
        public void fillData(String details) {
339
                RecentTrsPersistence trPersistence = new RecentTrsPersistence();
340
                TrData crsTrDataArray[] = trPersistence.getArrayOfTrData();
341
                CompTrData comp = null;
342
                
343
                for (int iRow = crsTrDataArray.length-1; iRow >= 0; iRow--) {
344
                        if (details.equals(crsTrDataArray[iRow].getAuthority()+":"+crsTrDataArray[iRow].getCode()+" <--> "+crsTrDataArray[iRow].getDetails()) && crsTrDataArray[iRow].getAuthority().equals(PluginServices.getText(this, "COMP"))) {
345
                                comp = (CompTrData) crsTrDataArray[iRow];                                
346
                                break;
347
                        }
348
                }
349
                if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "EPSG"))) {
350
                        getJComboOptions().setSelectedIndex(1);
351
                        int cod = Integer.parseInt(comp.getFirstTr().getCrsSource().split(":")[1]);
352
                        String code = String.valueOf(comp.getFirstTr().getCode());
353
                        //getEpsgTrPanel().setSource(PluginServices.getText(this, "EPSG"), cod);
354
                        for (int i=0; i< getEpsgTrPanel().getJTable().getRowCount(); i++) {
355
                                if (code.equals((String)getEpsgTrPanel().getJTable().getValueAt(i, 0))) {
356
                                        //seleccionarlo                                                
357
                                        getEpsgTrPanel().getJTable().setRowSelectionInterval(i,i);
358
                                        break;                                                
359
                                }
360
                        }
361
                } else if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "USR"))) {
362
                        getJComboOptions().setSelectedIndex(2);
363
                        String data = comp.getFirstTr().getDetails();
364
                        data = data.trim().substring(1, data.length()-1);
365
                        String values[] = data.split(",");
366
                        getManualTrPanel().getTx_Translation().setText(values[0]);
367
                        getManualTrPanel().getTy_Translation().setText(values[1]);
368
                        getManualTrPanel().getTz_Translation().setText(values[2]);
369
                        getManualTrPanel().getTx_Rotation().setText(values[3]);
370
                        getManualTrPanel().getTy_Rotation().setText(values[4]);
371
                        getManualTrPanel().getTz_Rotation().setText(values[5]);
372
                        getManualTrPanel().getTscale().setText(values[6]);
373
                        
374
                } else if (comp.getFirstTr().getAuthority().equals(PluginServices.getText(this, "NADGR"))) {
375
                        getJComboOptions().setSelectedIndex(3);
376
                        String data[] = comp.getFirstTr().getDetails().split(" ");
377
                        String fichero = data[0];
378
                        String[] authority = data[1].substring(1,data[1].length()-1).split(":");
379
                        //Mirar como indicarle el CRS al que se le aplica...                        
380
                        getNadsTrPanel().setSourceAbrev(authority[0], authority[1]);
381
                        
382
                        for (int i = 0; i< getNadsTrPanel().getJComboNadFile().getItemCount(); i++) {
383
                                if (fichero.equals((String)getNadsTrPanel().getJComboNadFile().getItemAt(i))) {
384
                                        getNadsTrPanel().getJComboNadFile().setSelectedIndex(i);
385
                                        break;
386
                                }
387
                        }                        
388
                }
389
                /*
390
                 * Por aquí solo pasa cuando se ha seleccionado una transformación compuesta de recientes.
391
                 * Pondremos el valor de que es un crs compuesto reciente a true para que el botón de siguiente
392
                 * salga habilitado.
393
                 */
394
                setRecentCompTransformation(true);
395
        }
396
        
397
        public void setRecentCompTransformation(boolean state) {
398
                recentCompTransformation = state;
399
        }
400
        
401
        public boolean getRecentCompTransformation() {
402
                return recentCompTransformation;
403
        }
404
        
405
        public void resetData() {
406
                fillData();
407
        }
408
        
409
        public boolean isSthSelected() {
410
                if (getRecentsTrPanel().selectedRowTable == -1)
411
                        return false;
412
                return true;
413
        }
414

    
415
        public void itemStateChanged(ItemEvent e) {
416
                /*
417
                 * Cambio en la seleccion del tipo de transformacion en la capa dentro de una transformacion
418
                 * compuesta. Se podria utilizar para conocer si hay algo seleccionado o no para el correcto
419
                 * funcionamiento del panel de botones... De momento vacio porque funciona bien.
420
                 */                
421
        }
422
        
423
        
424
}