svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / ui / TransformationEpsgPanel.java @ 7020
History | View | Annotate | Download (11.9 KB)
1 |
package org.gvsig.crs.ui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.Component; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.GridLayout; |
8 |
import java.awt.event.ActionEvent; |
9 |
import java.sql.ResultSet; |
10 |
import java.sql.SQLException; |
11 |
import java.util.ArrayList; |
12 |
|
13 |
import javax.swing.BorderFactory; |
14 |
import javax.swing.JButton; |
15 |
import javax.swing.JLabel; |
16 |
import javax.swing.JPanel; |
17 |
import javax.swing.JScrollPane; |
18 |
import javax.swing.JTable; |
19 |
import javax.swing.JTextArea; |
20 |
import javax.swing.ListSelectionModel; |
21 |
import javax.swing.event.ListSelectionEvent; |
22 |
import javax.swing.event.ListSelectionListener; |
23 |
import javax.swing.table.DefaultTableModel; |
24 |
import javax.swing.table.TableColumn; |
25 |
|
26 |
import org.cresques.cts.IProjection; |
27 |
import org.cresques.ui.DefaultDialogPanel; |
28 |
import org.gvsig.crs.CrsFactory; |
29 |
import org.gvsig.crs.ICrs; |
30 |
import org.gvsig.crs.Query; |
31 |
import org.gvsig.crs.ogr.GetTransepsg; |
32 |
|
33 |
import com.iver.andami.PluginServices; |
34 |
import com.iver.andami.ui.mdiManager.IWindow; |
35 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
36 |
import com.iver.cit.gvsig.gui.panels.ProjChooserPanelTransformation; |
37 |
|
38 |
public class TransformationEpsgPanel extends DefaultDialogPanel implements IWindow { |
39 |
|
40 |
|
41 |
/**
|
42 |
*
|
43 |
*/
|
44 |
private static final long serialVersionUID = 1L; |
45 |
|
46 |
private JPanel panel; |
47 |
private IProjection firstProj;
|
48 |
|
49 |
String[] transformations = {"9603", "9606", "9607", "9613", "9615", "9633"}; |
50 |
|
51 |
private int trasnformation_code = -1; |
52 |
private String[] values; |
53 |
private String params = "+towgs84="; |
54 |
|
55 |
private JTable transformationTable; |
56 |
private JScrollPane jScrollPane = null; |
57 |
private JPanel buttonPane; |
58 |
private JButton accept; |
59 |
private JButton cancel; |
60 |
|
61 |
ProjChooserPanelTransformation pcpt; |
62 |
int crs_target = -1; |
63 |
|
64 |
public DefaultTableModel dtm = null; |
65 |
|
66 |
private int codeEpsg; |
67 |
private String cadWKT = ""; |
68 |
private ListSelectionModel lsm2 = null; |
69 |
public int selectedRowTable = -1; |
70 |
boolean tra = false; |
71 |
|
72 |
private JLabel wkt; |
73 |
private JTextArea info; |
74 |
private JScrollPane areaScrollPane; |
75 |
|
76 |
public TransformationEpsgPanel(String cad, int code, int target) { |
77 |
super(false); |
78 |
crs_target = target; |
79 |
pcpt = new ProjChooserPanelTransformation();
|
80 |
cadWKT = cad; |
81 |
init(); |
82 |
codeEpsg = code; |
83 |
callTransformation(code); |
84 |
} |
85 |
|
86 |
private void init() { |
87 |
this.add(getJPanel());
|
88 |
this.add(getJScrollPane());
|
89 |
this.add(getButtonPane());
|
90 |
} |
91 |
|
92 |
private JPanel getJPanel(){ |
93 |
if (panel == null) { |
94 |
panel = new JPanel(); |
95 |
panel.setLayout(new GridLayout(1,2)); |
96 |
panel.setLayout(new FlowLayout(FlowLayout.LEADING,5,10)); |
97 |
panel.setPreferredSize(new Dimension(525, 100)); |
98 |
panel.add(getLabel()); |
99 |
panel.add(getScrollPanelArea(), BorderLayout.NORTH);
|
100 |
} |
101 |
return panel;
|
102 |
} |
103 |
|
104 |
private Component getLabel() { |
105 |
if (wkt == null){ |
106 |
wkt = new JLabel(); |
107 |
wkt.setPreferredSize(new Dimension(90, 80)); |
108 |
wkt.setText("Cadena WKT: ");
|
109 |
} |
110 |
return wkt;
|
111 |
} |
112 |
|
113 |
private Component getInfo() { |
114 |
if (info == null){ |
115 |
info = new JTextArea(); |
116 |
info.setLineWrap(true);
|
117 |
info.setWrapStyleWord(true);
|
118 |
info.setPreferredSize(new Dimension(400, 240)); |
119 |
info.setEditable(false);
|
120 |
info.append(cadWKT); |
121 |
} |
122 |
return info;
|
123 |
} |
124 |
|
125 |
private JScrollPane getScrollPanelArea() { |
126 |
if(areaScrollPane == null) { |
127 |
areaScrollPane = new JScrollPane(getInfo()); |
128 |
areaScrollPane.setVerticalScrollBarPolicy( |
129 |
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
|
130 |
areaScrollPane.setPreferredSize(new Dimension(420, 90)); |
131 |
areaScrollPane.setBorder( |
132 |
BorderFactory.createCompoundBorder(
|
133 |
BorderFactory.createCompoundBorder(
|
134 |
BorderFactory.createTitledBorder("Wkt"), |
135 |
BorderFactory.createEmptyBorder(2,2,2,2)), |
136 |
areaScrollPane.getBorder())); |
137 |
|
138 |
} |
139 |
return areaScrollPane;
|
140 |
} |
141 |
|
142 |
private JTable getJTable() { |
143 |
if (transformationTable == null) { |
144 |
String[] columnNames= {"Code of Transformation","Name of Transformation","Type of Transformation","Source CRS","Target CRS", "Description of Area"}; |
145 |
Object[][]data = {}; |
146 |
dtm = new DefaultTableModel(data, columnNames); |
147 |
transformationTable = new JTable(dtm); |
148 |
transformationTable.setCellSelectionEnabled(false);
|
149 |
transformationTable.setRowSelectionAllowed(true);
|
150 |
transformationTable.setColumnSelectionAllowed(false);
|
151 |
transformationTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
152 |
TableColumn column = null; |
153 |
for (int i = 0; i < columnNames.length; i++) { |
154 |
column = transformationTable.getColumnModel().getColumn(i); |
155 |
if (i == 0 || i == 3 || i == 4) { |
156 |
column.setPreferredWidth(40);
|
157 |
}else if (i == 2) { |
158 |
column.setPreferredWidth(80);
|
159 |
} |
160 |
else {
|
161 |
column.setPreferredWidth(160);
|
162 |
} |
163 |
} |
164 |
ListSelectionModel rowSM2 = transformationTable.getSelectionModel();
|
165 |
rowSM2.addListSelectionListener(new ListSelectionListener() { |
166 |
public void valueChanged(ListSelectionEvent e) { |
167 |
lsm2 = (ListSelectionModel)e.getSource();
|
168 |
if (lsm2.isSelectionEmpty()) {
|
169 |
selectedRowTable = -1;
|
170 |
tra = false;
|
171 |
} |
172 |
else {
|
173 |
selectedRowTable = lsm2.getMinSelectionIndex(); |
174 |
setTrasformation_code(Integer.parseInt((String)dtm.getValueAt(selectedRowTable,0))); |
175 |
} |
176 |
} |
177 |
}); |
178 |
} |
179 |
return transformationTable;
|
180 |
} |
181 |
|
182 |
private JScrollPane getJScrollPane() { |
183 |
if (jScrollPane == null) { |
184 |
jScrollPane = new JScrollPane(); |
185 |
jScrollPane.setPreferredSize(new Dimension(525,200)); |
186 |
jScrollPane.setBorder( |
187 |
BorderFactory.createCompoundBorder(
|
188 |
BorderFactory.createCompoundBorder(
|
189 |
BorderFactory.createTitledBorder("Transformations"), |
190 |
BorderFactory.createEmptyBorder(5,5,5,5)), |
191 |
jScrollPane.getBorder())); |
192 |
jScrollPane.setViewportView(getJTable()); |
193 |
} |
194 |
return jScrollPane;
|
195 |
} |
196 |
|
197 |
private JPanel getButtonPane() { |
198 |
if(buttonPane == null) { |
199 |
buttonPane = new JPanel(); |
200 |
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); |
201 |
buttonPane.setPreferredSize(new Dimension(525,50)); |
202 |
buttonPane.add(getButtonAccept(),null);
|
203 |
buttonPane.add(getButtonCancel(),null);
|
204 |
} |
205 |
return buttonPane;
|
206 |
} |
207 |
|
208 |
private JButton getButtonCancel() { |
209 |
if(cancel == null) { |
210 |
cancel = new JButton(); |
211 |
cancel.setText("Cancelar");
|
212 |
cancel.setPreferredSize(new Dimension(100,25)); |
213 |
cancel.setMnemonic('C');
|
214 |
cancel.setToolTipText("Cancel");
|
215 |
cancel.addActionListener(new java.awt.event.ActionListener() {
|
216 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
217 |
cancelButton_actionPerformed(e); |
218 |
} |
219 |
}); |
220 |
} |
221 |
return cancel;
|
222 |
} |
223 |
|
224 |
public void cancelButton_actionPerformed(ActionEvent e) { |
225 |
PluginServices.getMDIManager().closeWindow(this);
|
226 |
} |
227 |
|
228 |
private JButton getButtonAccept() { |
229 |
if(accept == null) { |
230 |
accept = new JButton(); |
231 |
accept.setText("Ok");
|
232 |
accept.setPreferredSize(new Dimension(100,25)); |
233 |
accept.setMnemonic('A');
|
234 |
accept.setToolTipText("Aceptar");
|
235 |
accept.addActionListener(new java.awt.event.ActionListener() {
|
236 |
public void actionPerformed(java.awt.event.ActionEvent e) { |
237 |
acceptButton_actionPerformed(e); |
238 |
} |
239 |
}); |
240 |
} |
241 |
return accept;
|
242 |
} |
243 |
|
244 |
public void acceptButton_actionPerformed(ActionEvent e) { |
245 |
GetTransepsg epsgParams = new GetTransepsg(trasnformation_code,pcpt);
|
246 |
setValues(epsgParams.getParamValue()); |
247 |
PluginServices.getMDIManager().closeWindow(this);
|
248 |
} |
249 |
|
250 |
private void callTransformation(int crsCode){ |
251 |
int numRow = dtm.getRowCount();
|
252 |
|
253 |
while (numRow != 0) { |
254 |
numRow = numRow - 1;
|
255 |
dtm.removeRow(numRow); |
256 |
} |
257 |
|
258 |
String sentence = "SELECT source_geogcrs_code " + |
259 |
"FROM epsg_coordinatereferencesystem " +
|
260 |
"WHERE coord_ref_sys_code = "+ crsCode ;
|
261 |
ResultSet result = Query.select(sentence,pcpt.connect.getConnection()); |
262 |
int source = 0; |
263 |
try {
|
264 |
result.next(); |
265 |
source = result.getInt("source_geogcrs_code");
|
266 |
} catch (SQLException e1) { |
267 |
e1.printStackTrace(); |
268 |
} |
269 |
|
270 |
ResultSet result2 = null; |
271 |
ResultSet result3 = null; |
272 |
if (source != 0){ |
273 |
crsCode = source; |
274 |
} |
275 |
/*
|
276 |
* Para buscar tambien transformaciones indirectas, tendremos que hacer un metodo
|
277 |
* que nos devuelva la informacion necesaria para printarla en la tabla.
|
278 |
*/
|
279 |
sentence = "SELECT target_crs_code " +
|
280 |
"FROM epsg_coordoperation " +
|
281 |
"WHERE source_crs_code = " + crsCode;
|
282 |
|
283 |
result = Query.select(sentence,pcpt.connect.getConnection());
|
284 |
|
285 |
ArrayList codecs = new ArrayList(); |
286 |
codecs.add(String.valueOf(crsCode));
|
287 |
try {
|
288 |
while(result.next()) {
|
289 |
codecs.add(String.valueOf(result.getInt("target_crs_code"))); |
290 |
} |
291 |
} |
292 |
catch (SQLException e1) { |
293 |
e1.printStackTrace(); |
294 |
} |
295 |
/*
|
296 |
* tendremos que eliminar los codigos repetidos
|
297 |
* para no repetir resultados
|
298 |
*/
|
299 |
codecs = deleteItems(codecs); |
300 |
|
301 |
for (int j=0; j< codecs.size(); j++){ |
302 |
sentence = "SELECT coord_op_code, coord_op_name, coord_op_type, source_crs_code, target_crs_code, area_of_use_code, coord_op_method_code " +
|
303 |
"FROM epsg_coordoperation " +
|
304 |
"WHERE source_crs_code = " + codecs.get(j) + "AND target_crs_code = " + crs_target; |
305 |
|
306 |
result = Query.select(sentence,pcpt.connect.getConnection());
|
307 |
|
308 |
try {
|
309 |
while(result.next()) {
|
310 |
Object[]data = new Object[6]; |
311 |
data[0] = String.valueOf(result.getInt("coord_op_code")); |
312 |
data[1] = result.getString("coord_op_name"); |
313 |
data[2] = result.getString("coord_op_type"); |
314 |
data[3] = String.valueOf(result.getInt("source_crs_code")); |
315 |
data[4] = String.valueOf(result.getInt("target_crs_code")); |
316 |
codecs.add(data[4]);
|
317 |
codecs = deleteItems(codecs); |
318 |
|
319 |
int aouc = Integer.parseInt(result.getString("area_of_use_code")); |
320 |
|
321 |
sentence = "SELECT area_of_use FROM epsg_area " +
|
322 |
"WHERE area_code = "+ aouc ;
|
323 |
|
324 |
result2 = Query.select(sentence,pcpt.connect.getConnection());
|
325 |
while (result2.next())
|
326 |
data[5] = result2.getString("area_of_use"); |
327 |
|
328 |
String coord_op_method = result.getString("coord_op_method_code"); |
329 |
|
330 |
sentence = "SELECT reverse_op FROM epsg_coordoperationmethod "+
|
331 |
"WHERE coord_op_method_code LIKE " + coord_op_method;
|
332 |
result3 = Query.select(sentence,pcpt.connect.getConnection());
|
333 |
|
334 |
while(result3.next()){
|
335 |
if (Integer.parseInt(result3.getString("reverse_op")) == 1){ |
336 |
for (int i=0; i< transformations.length; i++){ |
337 |
if (coord_op_method.equals(transformations[i])){
|
338 |
dtm.addRow(data); |
339 |
} |
340 |
} |
341 |
} |
342 |
} |
343 |
} |
344 |
} |
345 |
catch (SQLException e1) { |
346 |
e1.printStackTrace(); |
347 |
} |
348 |
} |
349 |
} |
350 |
|
351 |
private ArrayList deleteItems(ArrayList codecs) { |
352 |
ArrayList cod = new ArrayList(); |
353 |
boolean equal = false; |
354 |
for (int i = 0; i< codecs.size(); i++){ |
355 |
String c = (String) codecs.get(i); |
356 |
for (int j = 0; j<cod.size(); j++){ |
357 |
if (cod.get(j).equals(c)){
|
358 |
equal = true;
|
359 |
} |
360 |
} |
361 |
if (!equal){
|
362 |
cod.add(c); |
363 |
} |
364 |
equal = false;
|
365 |
} |
366 |
return cod;
|
367 |
} |
368 |
|
369 |
private void setValues(String[] val) { |
370 |
values = val; |
371 |
} |
372 |
|
373 |
public String[] getValues() { |
374 |
return values;
|
375 |
} |
376 |
|
377 |
private void setTrasformation_code(int t_cod) { |
378 |
trasnformation_code = t_cod; |
379 |
} |
380 |
|
381 |
public ICrs getProjection() {
|
382 |
for(int i = 0; i < values.length; i++) |
383 |
params +=values[i]+",";
|
384 |
try {
|
385 |
ICrs crs = new CrsFactory().getCRS(codeEpsg,
|
386 |
cadWKT,params); |
387 |
return crs;
|
388 |
} catch (org.gvsig.crs.CrsException e) {
|
389 |
e.printStackTrace(); |
390 |
} |
391 |
return null; |
392 |
} |
393 |
|
394 |
public void setProjection(IProjection proj) { |
395 |
firstProj = proj; |
396 |
} |
397 |
|
398 |
public WindowInfo getWindowInfo() {
|
399 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
400 |
m_viewinfo.setTitle("Transformation EPSG");
|
401 |
return m_viewinfo;
|
402 |
} |
403 |
|
404 |
} |