Statistics
| Revision:

root / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / InfoTransformationsRecentsPanel.java @ 10786

History | View | Annotate | Download (7.47 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.BorderLayout;
44
import java.awt.Dimension;
45
import java.awt.FlowLayout;
46
import java.awt.event.ActionEvent;
47
import java.awt.event.ActionListener;
48
import java.sql.ResultSet;
49
import java.sql.SQLException;
50

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

    
59
import org.gvsig.crs.EpsgConnection;
60
import org.gvsig.crs.Query;
61

    
62
import com.iver.andami.PluginServices;
63
import com.iver.andami.ui.mdiManager.IWindow;
64
import com.iver.andami.ui.mdiManager.WindowInfo;
65
import com.iver.cit.gvsig.gui.TableSorter;
66

    
67
/**
68
 * Panel con la informaci?n de la transformaci?n seleccionada
69
 * @author Jos? Luis G?mez Mart?nez (jolugomar@gmail.com)
70
 * @author Luisa Marina Fern?ndez (luisam.fernandez@uclm.es)
71
 *
72
 */
73
public class InfoTransformationsRecentsPanel extends JPanel implements IWindow, ActionListener{
74

    
75
        private static final long serialVersionUID = 1L;
76

    
77
        private JTable jTable;
78
        public DefaultTableModel dtm = null;
79
        private JScrollPane jScrollPane1 = null;
80
        private JPanel jPanelbuttons;
81
        private JButton jButtonOk;
82
        public TableSorter sorter = null;
83
        String[] data = null;
84
        
85
        //Ancho y alto del panel
86
        private int v_height=200;
87
        private int v_width=420;
88
        
89
        public InfoTransformationsRecentsPanel(String[] data) {
90
                super();
91
                this.data = data;
92
                inicializate();
93
        }
94
        
95
        private void inicializate() {
96
                setLayout(new BorderLayout());
97
                add(getJScrollPane1(), BorderLayout.CENTER);
98
                add(getJPanelButtons(), BorderLayout.SOUTH);
99
                
100
        }
101

    
102
        private JPanel getJPanelButtons() {
103
                if(jPanelbuttons == null) {
104
                        jPanelbuttons = new JPanel();
105
                        jPanelbuttons.setLayout(new FlowLayout(FlowLayout.RIGHT,10,10));
106
                        jPanelbuttons.add(getJButtonOk(),null);
107
                }
108
                return jPanelbuttons;
109
        }
110
        
111
        private JButton getJButtonOk() {
112
                if(jButtonOk == null) {
113
                        jButtonOk = new JButton();
114
                        jButtonOk.setText(PluginServices.getText(this,"ok"));
115
                        jButtonOk.setPreferredSize(new Dimension(100,25));
116
                        jButtonOk.setMnemonic('O');
117
                        jButtonOk.setToolTipText(PluginServices.getText(this,"ok"));
118
                        jButtonOk.addActionListener(this);
119
                }
120
                return jButtonOk;
121
        }
122
                
123
        private JScrollPane getJScrollPane1() {
124
                if(jScrollPane1 == null) {
125
                        jScrollPane1 = new JScrollPane();
126
                        jScrollPane1.setPreferredSize(new Dimension(400,150));        
127
                        jScrollPane1.setBorder(
128
                                    BorderFactory.createCompoundBorder(
129
                                        BorderFactory.createCompoundBorder(
130
                                                        BorderFactory.createTitledBorder(PluginServices.getText(this,"info_transformations")),
131
                                                        BorderFactory.createEmptyBorder(5,5,5,5)),
132
                                                        jScrollPane1.getBorder()));
133
                        jScrollPane1.setViewportView(getJTable());
134
                }
135
                return jScrollPane1;
136
        }
137
        
138
        private JTable getJTable() {
139
                if(jTable == null) {
140
                        String[] columnNames = {PluginServices.getText(this,"nombre")
141
                                        ,PluginServices.getText(this,"valor")};
142
                        Object[][] datos = obtainData();
143
                        dtm = new DefaultTableModel(datos, columnNames)
144
                         {
145
                                private static final long serialVersionUID = 1L;
146

    
147
                                public boolean isCellEditable(int row, int column) {
148
                                        return false;
149
                                }                
150
                        };
151
                        sorter = new TableSorter(dtm);                        
152

    
153
                        jTable = new JTable(sorter);
154

    
155
                        jTable.setCellSelectionEnabled(false);
156
                        jTable.setRowSelectionAllowed(true);
157
                        jTable.setColumnSelectionAllowed(false);
158
                        jTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
159
                        
160
                }
161
                return jTable;
162
        }
163
        
164
        /**
165
         * M?todo que recuperar? la informaci?n a mostrar en el panel
166
         * de las transformaciones recientes
167
         * @return
168
         */
169
        private String[][] obtainData(){        
170
                String[][] valid = null;
171
                String[] transformation = data[0].split(":");
172
                if (transformation[0].equals("EPSG")){
173
                        valid = new String[6][2];
174
                        valid[0][0] = PluginServices.getText(this,"source_crs");
175
                        valid[0][1] = data[2];
176
                        valid[1][0] = PluginServices.getText(this,"target_crs");
177
                        valid[1][1] = data[3];
178
                        EpsgConnection conn = new EpsgConnection();
179
                        conn.setConnectionEPSG();
180
                        String sentence = "SELECT area_of_use_code " +
181
                                                        "FROM epsg_coordoperation " +                        
182
                                                        "WHERE coord_op_code = " + transformation[1] ;
183
                    ResultSet result = Query.select(sentence,conn.getConnection());                   
184
                        try {
185
                                result.next();                                
186
                                valid[2][0] =  PluginServices.getText(this,"transformation_code");
187
                                valid[2][1] = transformation[1];                                
188
                                sentence = "SELECT area_of_use FROM epsg_area " +
189
                                                                "WHERE area_code = "+ Integer.parseInt(result.getString("area_of_use_code"));
190
                                
191
                        } catch (SQLException e) {
192
                                e.printStackTrace();
193
                        }
194
                        valid[3][0] = PluginServices.getText(this,"transformation_name");
195
                        valid[3][1] = data[1];
196
                        valid[4][0] = PluginServices.getText(this,"details");
197
                        result = Query.select(sentence, conn.getConnection());
198
                        try {
199
                                result.next();
200
                                valid[4][1] = result.getString("area_of_use");
201
                        } catch (SQLException e) {
202
                                e.printStackTrace();
203
                        }
204
                }
205
                else if (transformation[0].equals("USR")){
206
                        valid = new String[3][2];
207
                        valid[0][0] = PluginServices.getText(this,"source_crs");
208
                        valid[0][1] = data[2];
209
                        valid[1][0] = PluginServices.getText(this,"target_crs");
210
                        valid[1][1] = data[3];
211
                        valid[2][0] = PluginServices.getText(this,"details");
212
                        valid[2][1] = data[4];                        
213
                } else {
214
                        valid = new String[4][2];
215
                        String[] partes = data[4].split("\\(");
216
                        String nadFile = partes[0];                
217
                        String codigoNad = partes[1].substring(0,partes[1].length()-1);
218
                        valid[0][0] = PluginServices.getText(this,"source_crs");
219
                        valid[0][1] = data[2];
220
                        valid[1][0] =PluginServices.getText(this,"target_crs");
221
                        valid[1][1] = data[3];
222
                        valid[2][0] = PluginServices.getText(this,"nadgrids_file");
223
                        valid[2][1] = nadFile;        
224
                        valid[3][0] = PluginServices.getText(this,"calculated_in");
225
                        valid[3][1] = codigoNad;
226
                }
227
                return valid;
228
        }
229

    
230
        public WindowInfo getWindowInfo() {
231
                WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
232
                   m_viewinfo.setTitle("Info");//PluginServices.getText(this,proj.getCrsWkt().getName()));
233
                   //Define el ancho y el alto del panel
234
                   m_viewinfo.setHeight(v_height);
235
                   m_viewinfo.setWidth(v_width);
236
                return m_viewinfo;
237
        }
238

    
239
        public void actionPerformed(ActionEvent e) {
240
                if (e.getSource() == getJButtonOk()){
241
                        PluginServices.getMDIManager().closeWindow(this);
242
                }
243
        }
244

    
245
}