Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / panels / TransformationRecentsPanel.java @ 9240

History | View | Annotate | Download (8.89 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 EPSGTrCode;
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,"tipo"),
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(50);
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(true);
190
                        JButtonInfo.setToolTipText("Mostrar la informacion de la transformacion selecionada");
191
                }
192
                return JButtonInfo;
193
        }
194
        
195
        public ICrs getProjection() {
196
                ICrs crs = null;
197
                try {
198
                        crs = new CrsFactory().getCRS(getCode(),
199
                                        getWKT(),getParams());
200
                } catch (CrsException e) {
201
                        // TODO Auto-generated catch block
202
                        e.printStackTrace();
203
                }
204
                return crs;
205
        }
206
        
207
        public ICrs getProjectionNad(String info) {
208
                String[] partes = info.split("\\(");
209
                String nadFile = partes[0];                
210
                int codigoNad = Integer.parseInt(partes[1].substring(0,partes[1].length()-1));
211
                ICrs crs;
212
                
213
                if (getCode() == codigoNad){
214
                        try {
215
                                setNad(false);
216
                                crs = new CrsFactory().getCRS(getCode(),
217
                                                getWKT());
218
                                crs.setNadGrid("+nadgrids="+nadFile);//nadFile);
219
                                return crs;
220
                        } catch (org.gvsig.crs.CrsException e) {
221
                                e.printStackTrace();
222
                        }
223
                        return null;
224
                }
225
                else {        
226
                        setNad(true);
227
                        try {
228
                                crs = new CrsFactory().getCRS(getCode(),
229
                                                getWKT());
230
                                crs.setNadGrid("+nadgrids="+nadFile);//nadFile);
231
                                crs.setNadInTarget(true);
232
                                
233
                                return crs;
234
                        } catch (CrsException e) {                                
235
                                e.printStackTrace();
236
                        }
237
                        return null;
238
                }        
239
        }
240
        
241
        public void setNad(boolean nadg){
242
                targetNad = nadg;                
243
        }
244
        
245
        public boolean getNad(){
246
                return targetNad;                
247
        }
248
        
249
        public void setCode(int cod){
250
                code = cod;
251
        }
252
        
253
        public int getCode(){
254
                return code;
255
        }
256
        
257
        /**
258
         * 
259
         * @param cad
260
         */
261
        public void setWKT(String cad){
262
                cadWKT = cad;                
263
                //getInfo();
264
        }        
265
        
266
        /**
267
         * 
268
         * @return
269
         */
270
        public String getWKT(){
271
                return cadWKT;
272
        }
273
        
274
        public void setParamsManual(String param){
275
                params = "+towgs84="+param.substring(1,param.length()-1)+" ";
276
        }
277
        
278
        public void setParamsEPGS(String[] values){
279
                params = "+towgs84="+values[0];
280
                for(int i = 1; i < values.length; i++)
281
                        params +=","+values[i];
282
                params += " ";
283
        }
284
        
285
        public void setParamsNads(String nadfile){
286
                
287
        }
288
        
289
        public String getParams(){
290
                return params;
291
        }
292
        
293
        public void setInverseTransformation(boolean inverse){
294
                inverseTransformation = inverse;
295
        }
296
        
297
        public boolean getInverseTransformation(){
298
                return inverseTransformation;
299
        }
300
        
301
        public void setEPSGTrCode(int code){
302
                EPSGTrCode = code;
303
        }
304
        
305
        public int getEPSGTrCode(){
306
                return EPSGTrCode;
307
        }
308
        
309
        /**
310
         * Carga en la tabla los CRSs leidos del sistema de persistencia.
311
         */
312
        public void loadRecents(int source, int target){
313
                RecentTrsPersistence persistence = new RecentTrsPersistence(RecentCRSsPersistence.pluginClassInstance);
314
                trDataArray = persistence.getArrayOfTrData();
315
                
316

    
317
                for (int iRow = trDataArray.length-1;iRow>=0;iRow--){
318
                        if(source == Integer.parseInt(trDataArray[iRow].getCrsSource()) && target == Integer.parseInt(trDataArray[iRow].getCrsTarget())){
319
                                Object row[] ={trDataArray[iRow].getAuthority(),trDataArray[iRow].getName(),trDataArray[iRow].getCrsSource(),
320
                                        trDataArray[iRow].getCrsTarget(),trDataArray[iRow].getDetails()};
321
                                dtm.addRow(row);
322
                        }
323
                }
324
                
325
                /*
326
                /*Seleccionar el primer registro.
327
                 */
328
                int numr = dtm.getRowCount();
329
                if (numr != 0 )
330
                        this.getJTable().setRowSelectionInterval(0,0);
331
        }
332

    
333
}