Statistics
| Revision:

root / trunk / libraries / libJCRS / src / org / gvsig / crs / ui / CRSSelectionPanel.java @ 6907

History | View | Annotate | Download (20.2 KB)

1 6813 mgarcia
package org.gvsig.crs.ui;
2
3
import java.awt.Color;
4
import java.awt.Dimension;
5 6855 mgarcia
import java.awt.FlowLayout;
6 6813 mgarcia
import java.awt.GridLayout;
7
import java.awt.event.ActionEvent;
8
import java.awt.event.KeyEvent;
9
import java.awt.event.KeyListener;
10
import java.sql.ResultSet;
11
import java.sql.SQLException;
12
13
import javax.swing.BorderFactory;
14
import javax.swing.JButton;
15
import javax.swing.JLabel;
16
import javax.swing.JOptionPane;
17
import javax.swing.JPanel;
18
import javax.swing.JRadioButton;
19
import javax.swing.JScrollPane;
20
import javax.swing.JTable;
21
import javax.swing.JTextField;
22
import javax.swing.ListSelectionModel;
23
import javax.swing.event.ListSelectionEvent;
24
import javax.swing.event.ListSelectionListener;
25
import javax.swing.table.DefaultTableModel;
26
import javax.swing.table.TableColumn;
27
28
import org.cresques.cts.IProjection;
29
import org.gvsig.crs.CrsException;
30
import org.gvsig.crs.CrsFactory;
31
import org.gvsig.crs.ICrs;
32
import org.gvsig.crs.Query;
33
import org.gvsig.crs.ogr.Epsg2wkt;
34
import org.gvsig.crs.ogr.GetCRSepsg;
35
36 6855 mgarcia
import com.iver.andami.PluginServices;
37 6906 jlgomez
import com.iver.cit.gvsig.gui.View;
38 6813 mgarcia
import com.iver.cit.gvsig.gui.panels.ProjChooserPanel;
39
40 6855 mgarcia
public class CRSSelectionPanel extends JPanel {
41 6813 mgarcia
        /**
42
         *
43
         */
44
        private static final long serialVersionUID = 1L;
45
        JLabel jLabel = null;
46 6820 jlgomez
        JTextField crsTextFld = null;
47 6813 mgarcia
48 6820 jlgomez
        ProjChooserPanel pcp;
49
50 6869 jlgomez
        String cadWKT = "";
51
52 6813 mgarcia
        int transf = 0;
53
        int epsg_code = 0;
54
        boolean source_yn = false;
55
        int source_cod = 0;
56
        int method_code = 0;
57
        int projection_conv_code = 0;
58
        int[] valid_method_code = {9800, 9801, 9802, 9803, 9804, 9805, 9806, 9807, 9808, 9809, 9810,
59
                        9811, 9812, 9813, 9814, 9815, 9816, 9817};
60 6855 mgarcia
        boolean select = false;
61 6813 mgarcia
62
        private JRadioButton codeRadioButton = null;
63
        private JRadioButton nameRadioButton = null;
64
        private JRadioButton areaRadioButton = null;
65
        private JPanel groupRadioButton = null;
66
67 6855 mgarcia
        private JButton infoCrs = null;
68 6813 mgarcia
        private JButton searchButton = null;
69
        private JTextField searchTextField = null;
70
        private JTable jTable = null;
71
        private JScrollPane jScrollPane = null;
72
        public DefaultTableModel dtm = null;
73
        public DefaultTableModel dtm2 = null;
74
        public String key;
75
        public int selectedRowTable = -1;
76
        public int selectedRowTable2 = -1;
77
78
        private int codeCRS = -1;
79
80 6906 jlgomez
        /*
81
         * distinguira entre si es el panel para seleccion solo de CRS o para el de CRS y
82
         * transformacion
83
         */
84
        boolean transfPanel = false;
85
        public static boolean si = false;
86
87
        public CRSSelectionPanel(boolean trans) {
88
                super();
89
                transfPanel = trans;
90 6907 jlgomez
                if (si){
91
                        si= false;
92
                        CrsView.withOutTrans.setEnabled(false);
93
                        CrsView.nadgrids.setEnabled(false);
94
                        CrsView.epsgTrans.setEnabled(false);
95
                        CrsView.manualTrans.setEnabled(false);
96
                        CrsView.next.setVisible(false);
97
                        CrsView.accept.setVisible(true);
98
                }
99 6820 jlgomez
                pcp = new ProjChooserPanel();
100 6813 mgarcia
                initialize();
101
        }
102
103
        private void initialize() {
104
                getJPanel();
105
        }
106
107
        private void getJPanel() {
108
                        this.add(getSearchButton(), null);
109 6855 mgarcia
                        this.add(getSearchTextField(), null);
110
                        this.add(getInfoCrs(), null);
111 6813 mgarcia
                        this.add(getGroupRadioButton(), null);
112
                        this.add(getJScrollPane(), null);
113
        }
114
115
        private void codeRadioButton_actionPerformed(ActionEvent e) {
116
                searchTextField.setText("");
117
                nameRadioButton.setSelected(false);
118
                areaRadioButton.setSelected(false);
119
        }
120
121
        private JRadioButton getCodeRadioButton() {
122
                if (codeRadioButton == null) {
123
                        codeRadioButton = new JRadioButton();
124
                        codeRadioButton.setText("By Code EPSG");
125
                        codeRadioButton.setSelected(true);
126
                        codeRadioButton.addActionListener(new java.awt.event.ActionListener() {
127
                                public void actionPerformed(java.awt.event.ActionEvent e) {
128
                                        codeRadioButton_actionPerformed(e);
129
                                }
130
                        });
131
                }
132
                return codeRadioButton;
133
        }
134
135
        private void nameRadioButton_actionPerformed(ActionEvent e) {
136
                searchTextField.setText("");
137
                codeRadioButton.setSelected(false);
138
                areaRadioButton.setSelected(false);
139
        }
140
141
        private JRadioButton getNameRadioButton() {
142
                if (nameRadioButton == null) {
143
                        nameRadioButton = new JRadioButton();
144
                        nameRadioButton.setText("By CRS Name");
145
                        nameRadioButton.addActionListener(new java.awt.event.ActionListener() {
146
                                public void actionPerformed(java.awt.event.ActionEvent e) {
147
                                        nameRadioButton_actionPerformed(e);
148
                                }
149
                        });
150
                }
151
                return nameRadioButton;
152
        }
153
154
        private void areaRadioButton_actionPerformed(ActionEvent e) {
155
                searchTextField.setText("");
156
                codeRadioButton.setSelected(false);
157
                nameRadioButton.setSelected(false);
158
        }
159
160
        private JRadioButton getAreaRadioButton() {
161
                if (areaRadioButton == null) {
162
                        areaRadioButton = new JRadioButton();
163
                        areaRadioButton.setText("By Area of Use");
164
                        areaRadioButton.addActionListener(new java.awt.event.ActionListener() {
165
                                public void actionPerformed(java.awt.event.ActionEvent e) {
166
                                        areaRadioButton_actionPerformed(e);
167
                                }
168
                        });
169
                }
170
                return areaRadioButton;
171
        }
172
173
        private JPanel getGroupRadioButton() {
174
                if (groupRadioButton == null) {
175
                        groupRadioButton = new JPanel();
176
                        groupRadioButton.setLayout(new GridLayout(1,0));
177
                        groupRadioButton.setPreferredSize(new Dimension(400,50));
178
                        groupRadioButton.add(getCodeRadioButton());
179
                        groupRadioButton.add(getNameRadioButton());
180
                        groupRadioButton.add(getAreaRadioButton());
181
                }
182
                return groupRadioButton;
183
        }
184
185
        private void searchButton_actionPerformed(ActionEvent e) {
186
                searchTextField.setBackground(Color.white);
187
188
                if (searchTextField.getText().equals("")) {
189
                        searchTextField.setBackground(new Color(255,204,204));
190
                        JOptionPane.showMessageDialog(this, "Fill the name of CRS.", "Warning...", JOptionPane.WARNING_MESSAGE);
191
                }
192
193
                else {
194
            //Eliminar filas en cada nueva bsqueda
195
                        int numRow = dtm.getRowCount();
196
                        while (numRow != 0) {
197
                                numRow = numRow - 1;
198
                                dtm.removeRow(numRow);
199
                        }
200
201
                        //Dependiendo de la opcion se realizada una busqueda
202
                        ResultSet result = null;
203
                        ResultSet result2 = null;
204
                        /*
205
                         * variable que indicara si la busqueda se hace primero en epsg_coordinatereferencesystem
206
                         * o en epsg_area; esto es debido a que HSQLDB no soporta la b?squeda simult?nea en ambas
207
                         * tablas, por lo cual hay que separar la b?squeda
208
                         */
209
                        int bus = 2;
210
                        if (codeRadioButton.isSelected()) {
211
                                bus=0;
212
                                key = searchTextField.getText();
213
                                int code = Integer.parseInt(key);
214
                                String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, area_of_use_code, " +
215
                                                                  "source_geogcrs_code, projection_conv_code  " +
216
                                                                  "FROM epsg_coordinatereferencesystem " +
217
                                      "WHERE coord_ref_sys_code = " + code;
218 6820 jlgomez
                                result = Query.select(sentence,pcp.connect.getConnection());
219 6813 mgarcia
                        }
220
221
                        else if (nameRadioButton.isSelected()) {
222
                                bus=0;
223
                                key = searchTextField.getText();
224
                                String key2 = key.substring(0,1);
225
                                String key3 = key.substring(1,key.length());
226
                                key2 = key2.toUpperCase();
227
228
                                String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, coord_ref_sys_kind, " +
229
                                                                        "area_of_use_code, source_geogcrs_code, projection_conv_code " +
230
                                                                          "FROM epsg_coordinatereferencesystem " +
231
                                                                          "WHERE (coord_ref_sys_name LIKE '%" + key + "%') OR (coord_ref_sys_name LIKE '%"+
232
                                                                          key.toUpperCase() +"%') " +
233
                                                                          "OR (coord_ref_sys_name LIKE '%" + key2+key3 +"%')";
234 6820 jlgomez
                                result = Query.select(sentence,pcp.connect.getConnection());
235 6813 mgarcia
                        }
236
237
                        else {
238
                                bus=1;
239
                                key = searchTextField.getText();
240
                                String key2 = key.substring(0,1);
241
                                String key3 = key.substring(1,key.length());
242
                                key2 = key2.toUpperCase();
243
244
                                String sentence = "SELECT area_name, area_of_use, area_code " +
245
                                      "FROM epsg_area " +
246
                                      "WHERE (area_name LIKE '%" + key + "%') OR (area_of_use LIKE '%" + key + "%') "+
247
                                      "OR (area_name LIKE '%" + key.toUpperCase() + "%') OR (area_of_use LIKE '%" + key.toUpperCase() + "%') "+
248
                                      "OR (area_name LIKE '%" + key2+key3 + "%') OR (area_of_use LIKE '%" + key2+key3 + "%') ";
249 6820 jlgomez
                                result = Query.select(sentence,pcp.connect.getConnection());
250 6813 mgarcia
                        }
251
                        String crs_kind = null;
252
                        if (bus==0){
253
                                try {
254
                                        while(result.next()) {
255
                                                Object[]data = new Object[5];
256
                                                data[0] = String.valueOf(result.getInt("coord_ref_sys_code"));
257
                                                data[1] = result.getString("coord_ref_sys_name");
258
                                                crs_kind = result.getString("coord_ref_sys_kind");
259
                                                data[2] = crs_kind;
260
                                                projection_conv_code = result.getInt("projection_conv_code");
261
262
                                                int area_of_use_code = Integer.parseInt(result.getString("area_of_use_code"));
263
264
                                                String sentence = "SELECT area_name, area_of_use FROM epsg_area " +
265
                                                                                "WHERE area_code = "+ area_of_use_code ;
266
267 6820 jlgomez
                                                result2 = Query.select(sentence,pcp.connect.getConnection());
268 6813 mgarcia
                                                while(result2.next()){
269
                                                        data[3] = result2.getString("area_name");
270
                                                        data[4] = result2.getString("area_of_use");
271
                                                }
272
                                                if (data[0]!=null && validCRS(projection_conv_code) && (crs_kind.equals("projected")
273
                                                                || crs_kind.equals("geographic 2D"))){
274
                                                        dtm.addRow(data);
275
                                                }
276
                                        }
277
                                }
278
279
                                catch (SQLException e1) {
280
                                        e1.printStackTrace();
281
                                }
282
                        }
283
                        else if (bus==1){
284
                                try {
285
                                        while(result.next()) {
286
                                                Object[]data = new Object[5];
287
                                                data[3] = result.getString("area_name");
288
                                                data[4] = result.getString("area_of_use");
289
290
                                                int area_of_use_code = Integer.parseInt(result.getString("area_code"));
291
292
                                                String sentence = "SELECT coord_ref_sys_code, coord_ref_sys_name, " +
293
                                                                                "coord_ref_sys_kind, source_geogcrs_code, projection_conv_code " +
294
                                                                                "FROM epsg_coordinatereferencesystem " +
295
                                                                                "WHERE area_of_use_code = "+ area_of_use_code ;
296
297 6820 jlgomez
                                                result2 = Query.select(sentence,pcp.connect.getConnection());
298 6813 mgarcia
                                                while(result2.next()){
299
                                                        data[0] = String.valueOf(result2.getInt("coord_ref_sys_code"));
300
                                                        data[1] = result2.getString("coord_ref_sys_name");
301
                                                        data[2] = result2.getString("coord_ref_sys_kind");
302
                                                        crs_kind = (String)data[2];
303
                                                        projection_conv_code = result2.getInt("projection_conv_code");
304
305
                                                }
306
                                                /*
307
                                                 * Buscaremos solo aquellos CRS cuyas proyecciones esten entre las
308
                                                 * 16 soportadas por proj4 para ello creamos un metodo para validar
309
                                                 * si esta entre estas proyecciones
310
                                                 */
311
                                                if (data[0]!=null && validCRS(projection_conv_code) && (crs_kind.equals("projected")
312
                                                                || crs_kind.equals("geographic 2D"))){
313
                                                        dtm.addRow(data);
314
                                                }
315
                                        }
316
                                }
317
318
                                catch (SQLException e1) {
319
                                        e1.printStackTrace();
320
                                }
321
                        }
322
                        int numr = dtm.getRowCount();
323
                        if (numr == 0 ){
324
                        JOptionPane.showMessageDialog(this, "Not results find.", "Warning...",
325
                                        JOptionPane.WARNING_MESSAGE);
326
                        }
327
                }
328
        }
329
330
        /*
331
         * metodo auxiliar que nos servira para comprobar si la proyeccion del CRS seleccionado
332
         * esta entre las 16 con las que trabaja proj4
333
         */
334
        private boolean validCRS(int projection_conv_code2) {
335
                if (projection_conv_code2 == 0) return true;
336
                String sentence = "SELECT coord_op_method_code " +
337
                                                        "FROM epsg_coordoperation " +
338
                                                        "WHERE coord_op_code = " + projection_conv_code;
339 6820 jlgomez
                ResultSet result = Query.select(sentence,pcp.connect.getConnection());
340 6813 mgarcia
                try {
341
                        while (result.next()){
342
                                method_code = result.getInt("coord_op_method_code");
343
                        }
344
                } catch (SQLException e) {
345
                        e.printStackTrace();
346
                }
347
348
                for (int i = 0; i< valid_method_code.length; i++){
349
                        if (method_code == valid_method_code[i] ){
350
                                return true;
351
                        }
352
                }
353
                return false;
354
        }
355
356
        private JButton getSearchButton() {
357
                if (searchButton == null) {
358
                        searchButton = new JButton();
359
                        searchButton.setPreferredSize(new Dimension(75,20));
360
                        searchButton.setText("Search");
361
                        searchButton.setMnemonic('S');
362
                        searchButton.setToolTipText("Search of a CRS by selected criterion");
363
                        searchButton.addActionListener(new java.awt.event.ActionListener() {
364
                                public void actionPerformed(java.awt.event.ActionEvent e) {
365
                                        searchTextField.setBackground(Color.white);
366
                                        if (searchTextField.getText().equals("")) {
367
                                                searchTextField.setBackground(new Color(255,204,204));
368
                                                JOptionPane.showMessageDialog(CRSSelectionPanel.this,
369
                                                                "Fill the key-word of the search.",
370
                                                                "Warning...", JOptionPane.WARNING_MESSAGE);
371
                                        }
372
                                        else {
373
                                                searchButton_actionPerformed(e);
374
                                        }
375
                                }
376
                        });
377
                }
378
                return searchButton;
379
        }
380
381
        private JTextField getSearchTextField() {
382
                if (searchTextField == null) {
383
                        searchTextField = new JTextField();
384
                        searchTextField.setPreferredSize(new Dimension(300,20));
385
                }
386
                searchTextField.addKeyListener(new KeyListener() {
387
                        public void keyPressed(KeyEvent e) {
388
                                if (e.getKeyCode() == 10) {
389
                                        searchButton_actionPerformed(null);
390
                                }
391
                                if (codeRadioButton.isSelected()){
392
                                        if ((e.getKeyCode() >= 48 && e.getKeyCode() <= 57) || e.getKeyCode() >= 96 && e.getKeyCode() <= 105 ||
393
                                                        (e.getKeyCode() >= 0 && e.getKeyCode()<= 31) || e.getKeyCode() == 127){
394
                                        }
395
                                        else {
396
                                                JOptionPane.showMessageDialog(CRSSelectionPanel.this,
397
                                                                "Only number format.",
398
                                                                "Warning...", JOptionPane.WARNING_MESSAGE);
399
                                                String aux = searchTextField.getText();
400
                                                if (aux.length() == 1){
401
                                                        searchTextField.setText("");
402
                                                }
403
                                                else {
404
                                                        searchTextField.setText(aux.substring(0, aux.length()-1));
405
                                                }
406
                                        }
407
                                }
408
                        }
409
410
                        public void keyReleased(KeyEvent arg0) {
411
                        }
412
413
                        public void keyTyped(KeyEvent arg0) {
414
                        }
415
                });
416
                return searchTextField;
417
        }
418
419
        private JTable getJTable() {
420
                if (jTable == null) {
421
                        String[] columnNames= {"Code of CRS","Name of CRS","Type of CRS","Name of Area","Description of Area"};
422
                        Object[][]data = {};
423
                        dtm = new DefaultTableModel(data, columnNames);
424
                        jTable = new JTable(dtm);
425
                        jTable.setCellSelectionEnabled(false);
426
                        jTable.setRowSelectionAllowed(true);
427
                        jTable.setColumnSelectionAllowed(false);
428
                        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
429
                        TableColumn column = null;
430
                        for (int i = 0; i < 5; i++) {
431
                            column = jTable.getColumnModel().getColumn(i);
432
                            if (i == 0) {
433
                                column.setPreferredWidth(40); //code column is shorter
434
                            }else if (i == 2) {
435
                                    column.setPreferredWidth(80);
436
                            }
437
                            else {
438
                                column.setPreferredWidth(160);
439
                            }
440
                        }
441
                        ListSelectionModel rowSM = jTable.getSelectionModel();
442
                        rowSM.addListSelectionListener(new ListSelectionListener() {
443
                            public void valueChanged(ListSelectionEvent e) {
444 6855 mgarcia
                                    ListSelectionModel lsm = (ListSelectionModel)e.getSource();
445 6813 mgarcia
                                if (lsm.isSelectionEmpty()) {
446
                                        selectedRowTable = -1;
447
                                        setCodeCRS(-1);
448 6907 jlgomez
                                         if (transfPanel){
449
                                                si = false;
450
                                                        CrsView.withOutTrans.setEnabled(false);
451
                                                        CrsView.nadgrids.setEnabled(false);
452
                                                        CrsView.epsgTrans.setEnabled(false);
453
                                                        CrsView.manualTrans.setEnabled(false);
454
                                                        CrsView.next.setVisible(false);
455
                                                        CrsView.accept.setVisible(true);
456
                                         }
457 6813 mgarcia
                                }
458
                                else {
459
                                    selectedRowTable = lsm.getMinSelectionIndex();
460 6872 jlgomez
                                    setCodeCRS(Integer.parseInt((String)dtm.getValueAt(selectedRowTable,0)));
461
                                    setWKT();
462 6906 jlgomez
463
                                    if (transfPanel){
464
                                            compareCRS();
465
                                    }
466 6813 mgarcia
                                }
467 6855 mgarcia
                                infoCrs.setEnabled(true);
468 6813 mgarcia
                            }
469 6906 jlgomez
470
                                private void compareCRS() {
471
                                        int base = getCodeCRS();
472
                                        String datum = "";
473
                                        int datum_code = -1;
474
                                        String sentence = "SELECT source_geogcrs_code " +
475
                                                                        "FROM epsg_coordinatereferencesystem " +
476
                                                                        "WHERE coord_ref_sys_code = "+ base ;
477
                                        ResultSet result = Query.select(sentence,pcp.connect.getConnection());
478
                                        int source = 0;
479
                                        try {
480
                                                result.next();
481
                                                source = result.getInt("source_geogcrs_code");
482
                                        } catch (SQLException e1) {
483
                                                e1.printStackTrace();
484
                                        }
485
486
                                    if (source != 0){
487
                                                    base = source;
488
                                    }
489
490
                                    sentence = "SELECT datum_code " +
491
                                                "FROM epsg_coordinatereferencesystem " +
492
                                                "WHERE coord_ref_sys_code = "+ base ;
493
                                    result = Query.select(sentence,pcp.connect.getConnection());
494
495
                                    try {
496
                                                result.next();
497
                                                datum_code = result.getInt("datum_code");
498
                                        } catch (SQLException e1) {
499
                                                e1.printStackTrace();
500
                                        }
501
502
                                        sentence = "SELECT datum_name " +
503 6907 jlgomez
                                                                "FROM epsg_datum " +
504
                                                                "WHERE datum_code = "+ datum_code ;
505 6906 jlgomez
                                    result = Query.select(sentence,pcp.connect.getConnection());
506
507
                                    try {
508
                                                result.next();
509
                                                datum = result.getString("datum_name");
510
                                        } catch (SQLException e1) {
511
                                                e1.printStackTrace();
512
                                        }
513
514
                                        if (!((ICrs) View.m_MapControl.getProjection()).getCrsWkt().getDatumName().equals(datum.replaceAll(" ",""))){
515
                                                si = true;
516
                                                CrsView.withOutTrans.setEnabled(true);
517
                                                CrsView.nadgrids.setEnabled(true);
518
                                                CrsView.epsgTrans.setEnabled(true);
519
                                                CrsView.manualTrans.setEnabled(true);
520
                                                CrsView.next.setVisible(true);
521
                                                CrsView.accept.setVisible(false);
522
                                                /*
523
                                                 * logica necesaria para comprobar si los crs bases son iguales
524
                                                 * y en ese caso deshabilitar opcion transformacion de
525
                                                 * TransformationEpsgPanel
526
                                                 */
527
                                        }
528
                                        else {
529
                                                si = false;
530
                                                CrsView.withOutTrans.setEnabled(false);
531
                                                CrsView.nadgrids.setEnabled(false);
532
                                                CrsView.epsgTrans.setEnabled(false);
533
                                                CrsView.manualTrans.setEnabled(false);
534
                                                CrsView.next.setVisible(false);
535
                                                CrsView.accept.setVisible(true);
536
                                        }
537
                                }
538 6855 mgarcia
                });
539
        }
540 6813 mgarcia
                return jTable;
541
542
        }
543
544
        private void setCodeCRS(int code) {
545
                codeCRS = code;
546
        }
547
548
        public int getCodeCRS() {
549
                return codeCRS;
550
        }
551
552
        private JScrollPane getJScrollPane() {
553
                if (jScrollPane == null) {
554
                        jScrollPane = new JScrollPane();
555
                        jScrollPane.setPreferredSize(new Dimension(600,250));
556
                        jScrollPane.setBorder(
557
                                    BorderFactory.createCompoundBorder(
558
                                        BorderFactory.createCompoundBorder(
559
                                                        BorderFactory.createTitledBorder("Coordinate Reference Systems"),
560
                                                        BorderFactory.createEmptyBorder(5,5,5,5)),
561
                                                        jScrollPane.getBorder()));
562
                        jScrollPane.setViewportView(getJTable());
563
                }
564
                return jScrollPane;
565
        }
566
567 6855 mgarcia
        private JButton getInfoCrs() {
568
                if(infoCrs == null) {
569
                        infoCrs = new JButton();
570
                        infoCrs.setText("InfoCrs");
571
                        infoCrs.setPreferredSize(new Dimension(75,20));
572
                        infoCrs.setMnemonic('I');
573
                        infoCrs.setEnabled(false);
574
                        infoCrs.setToolTipText("Mostrar la informacion del Crs selecionado");
575
                        infoCrs.addActionListener(new java.awt.event.ActionListener() {
576
                                public void actionPerformed(java.awt.event.ActionEvent e) {
577
                                        infoCrs_actionPerformed(e);
578
                                }
579
                        });
580
                }
581
                return infoCrs;
582
        }
583
584
        private void infoCrs_actionPerformed(ActionEvent e) {
585
                InfoCrs info = new InfoCrs(getCrs());
586
                info.setSize(new Dimension(550,350));
587
                info.setLayout(new GridLayout(0,1));
588
                info.setLayout(new FlowLayout(FlowLayout.LEFT,10,5));
589
                PluginServices.getMDIManager().addView(info);
590
        }
591
592 6813 mgarcia
        public ICrs getProjection() {
593
                return getCrs();
594
        }
595 6872 jlgomez
        public ICrs getCrs() {
596
                try {
597
                        String txt = getWKT();
598
                        ICrs crs = new CrsFactory().getCRS(epsg_code, txt);
599
                        return crs ;
600
                } catch (CrsException e) {
601
                        e.printStackTrace();
602
                }
603
                return null;
604
        }
605
606
        public void setWKT(){
607
                Epsg2wkt wkt = null;
608 6813 mgarcia
609
                epsg_code = getCodeCRS();
610
                if (epsg_code != -1){
611
                        /*
612
                         * ahora que he escogido, recojo toda la informacion que me va a hacer falta
613
                         */
614
                        String sentence = "SELECT source_geogcrs_code, projection_conv_code " +
615
                                                        "FROM epsg_coordinatereferencesystem " +
616
                                                        "WHERE coord_ref_sys_code = "+ epsg_code ;
617 6820 jlgomez
                        ResultSet result = Query.select(sentence,pcp.connect.getConnection());
618 6813 mgarcia
619
                        try {
620
                                result.next();
621
                                source_cod = result.getInt("source_geogcrs_code");
622
                                projection_conv_code = result.getInt("projection_conv_code");
623
                        } catch (SQLException e1) {
624
                                e1.printStackTrace();
625
                        }
626
627
                        if (source_cod != 0){
628
                                source_yn = false;
629
                        }
630
                        else source_yn = true;
631
632 6820 jlgomez
                        GetCRSepsg ep = new GetCRSepsg(epsg_code, source_yn, source_cod, projection_conv_code, pcp);
633 6813 mgarcia
                        ep.Getepsgdata();
634
635
                        if (source_yn){
636
                                wkt = new Epsg2wkt(ep ,0);
637
                        }
638
                        else {
639
                                wkt = new Epsg2wkt(ep);
640
                        }
641
                }
642
                else {
643
                        JOptionPane.showMessageDialog(this,
644
                                        "No CRS selected.",
645
                                        "Warning...", JOptionPane.WARNING_MESSAGE);
646 6872 jlgomez
647 6813 mgarcia
                }
648 6872 jlgomez
                cadWKT = wkt.getWKT();
649 6813 mgarcia
        }
650
651 6869 jlgomez
        public String getWKT(){
652
                return cadWKT;
653
        }
654
655 6813 mgarcia
        public void setProjection(IProjection crs) {
656
                //setCrs((ICrs) crs);
657
        }
658
}