root / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / CRSMainTrPanel.java @ 8304
History | View | Annotate | Download (13.2 KB)
1 |
package org.gvsig.crs.gui; |
---|---|
2 |
|
3 |
import java.awt.BorderLayout; |
4 |
import java.awt.CardLayout; |
5 |
import java.awt.Dimension; |
6 |
import java.awt.FlowLayout; |
7 |
import java.awt.GridLayout; |
8 |
import java.sql.ResultSet; |
9 |
import java.sql.SQLException; |
10 |
import javax.swing.JButton; |
11 |
import javax.swing.JComboBox; |
12 |
import javax.swing.JLabel; |
13 |
import javax.swing.JPanel; |
14 |
import javax.swing.ListSelectionModel; |
15 |
import org.cresques.cts.IProjection; |
16 |
import org.gvsig.crs.CrsException; |
17 |
import org.gvsig.crs.CrsFactory; |
18 |
import org.gvsig.crs.CrsWkt; |
19 |
import org.gvsig.crs.EpsgConnection; |
20 |
import org.gvsig.crs.ICrs; |
21 |
import org.gvsig.crs.Query; |
22 |
import org.gvsig.crs.gui.listeners.CRSMainTrPanelListener; |
23 |
import org.gvsig.crs.gui.panels.TransformationEpsgPanel; |
24 |
import org.gvsig.crs.gui.panels.TransformationManualPanel; |
25 |
import org.gvsig.crs.gui.panels.TransformationNadgridsPanel; |
26 |
import com.iver.andami.PluginServices; |
27 |
import com.iver.andami.ui.mdiManager.IWindow; |
28 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
29 |
|
30 |
public class CRSMainTrPanel extends JPanel implements IWindow{ |
31 |
|
32 |
private static final long serialVersionUID = 1L; |
33 |
|
34 |
/*
|
35 |
* Para mostrar los parametros si tenemos seleccionada transformacion
|
36 |
*/
|
37 |
boolean tra = false; |
38 |
boolean inAnApplet = true; |
39 |
private boolean cancelYes = false; |
40 |
private JButton jButtonCancel = null; |
41 |
private JButton jButtonNext = null; |
42 |
private JButton jButtonAccept = null; |
43 |
private JButton jButtonBefore = null; |
44 |
private JPanel jPanelButtons = null; |
45 |
|
46 |
boolean targetNad = false; |
47 |
|
48 |
int crs_target = -1; |
49 |
CrsWkt crsWkt_target = null;
|
50 |
|
51 |
//private EpsgConnection connection = null;
|
52 |
|
53 |
int transformation_code = 0; |
54 |
|
55 |
private JPanel panel = null; |
56 |
CRSMainPanel viewPan = null;
|
57 |
|
58 |
private JPanel jPanelMain = null; |
59 |
private TransformationManualPanel manualTrPanel = null; |
60 |
private boolean manual_tr = false; |
61 |
private TransformationEpsgPanel epsgTrPanel = null; |
62 |
private boolean epsg_tr = false; |
63 |
private TransformationNadgridsPanel nadsTrPanel = null; |
64 |
private boolean nads_tr = false; |
65 |
|
66 |
private boolean sin_tr = false; |
67 |
private JPanel jPanelCombo = null; |
68 |
private JComboBox jComboOptions = null; |
69 |
|
70 |
private IProjection crsfirst;
|
71 |
|
72 |
private CRSMainPanel crsMainPanel;
|
73 |
private String newSelection; |
74 |
String dataSource = ""; |
75 |
ICrs curProj = null;
|
76 |
|
77 |
public CRSMainTrPanel(int target, CrsWkt crsWkttarget, ICrs proj) { |
78 |
curProj = proj; |
79 |
crsMainPanel = new CRSMainPanel(target);
|
80 |
viewPan = crsMainPanel; |
81 |
|
82 |
crs_target = target; |
83 |
crsWkt_target = crsWkttarget; |
84 |
|
85 |
manualTrPanel = new TransformationManualPanel();
|
86 |
epsgTrPanel = new TransformationEpsgPanel(crs_target);
|
87 |
nadsTrPanel = new TransformationNadgridsPanel();
|
88 |
|
89 |
/*
|
90 |
* esta variable contendr? tanto el panel utilizado en CRSViewPanel, como los paneles
|
91 |
* que seran necesarios para realizar las transformaciones
|
92 |
*/
|
93 |
jPanelMain = new JPanel(); |
94 |
jPanelMain.setLayout(new CardLayout()); |
95 |
jPanelMain.add("primero", viewPanel());
|
96 |
jPanelMain.add("manual", manualTrPanel.getJPanel());
|
97 |
jPanelMain.add("epsg", epsgTrPanel.getJPanel());
|
98 |
jPanelMain.add("nad", nadsTrPanel.getJPanel());
|
99 |
|
100 |
this.add(jPanelMain, BorderLayout.CENTER); |
101 |
|
102 |
this.add(getButtons(), BorderLayout.SOUTH); |
103 |
|
104 |
setListeners(); |
105 |
/*
|
106 |
* cargamos en la capa el CRS que hemos fijado en la vista en el primer caso
|
107 |
* o el que pusimos en la ultima eleccion del crs para la capa
|
108 |
*/
|
109 |
|
110 |
/*habra que hacerlo para que lo printe en el primer panel que pongamos
|
111 |
* en nuestro caso seria en el de recientes
|
112 |
*/
|
113 |
/*String sour = curProj.getCrsWkt().getAuthority()[0];
|
114 |
if (sour.equals("EPSG")){
|
115 |
crsMainPanel.getEpsgPanel().loadViewCRS(curProj.getCode());
|
116 |
crsMainPanel.getEpsgPanel().getJTable().setRowSelectionInterval(0,0);
|
117 |
}else if(sour.equals("IAU2000")){
|
118 |
crsMainPanel.getIauPanel().loadViewCRS(curProj.getCode());
|
119 |
crsMainPanel.getIauPanel().getJTable().setRowSelectionInterval(0,0);
|
120 |
}*/
|
121 |
|
122 |
setDataSource(crsMainPanel.getDataSource()); |
123 |
|
124 |
crsMainPanel.getRecentsPanel().loadRecents(); |
125 |
} |
126 |
|
127 |
/*
|
128 |
* Este metodo cargara todo el panel utilizado en el CRSViewPanel y el combobox de
|
129 |
* las transformaciones
|
130 |
*/
|
131 |
private JPanel viewPanel(){ |
132 |
JPanel integro = new JPanel(); |
133 |
integro.setLayout(new GridLayout(0,1)); |
134 |
integro.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
135 |
integro.setPreferredSize(new Dimension(560,300)); |
136 |
|
137 |
integro.add(viewPan.capa(), null);
|
138 |
integro.add(getJPanel(), null);
|
139 |
return integro;
|
140 |
} |
141 |
|
142 |
|
143 |
private JPanel getJPanel() { |
144 |
if (panel == null){ |
145 |
panel = new JPanel(); |
146 |
panel.setPreferredSize(new Dimension(540,80)); |
147 |
panel.setLayout(new GridLayout(0,2)); |
148 |
panel.setLayout(new FlowLayout(FlowLayout.LEFT,10,10)); |
149 |
panel.add(getCombopanel(), null);
|
150 |
} |
151 |
return panel;
|
152 |
} |
153 |
|
154 |
public JPanel getCombopanel(){ |
155 |
if (jPanelCombo == null){ |
156 |
jPanelCombo = new JPanel(); |
157 |
jPanelCombo.setPreferredSize(new Dimension(400,30)); |
158 |
jPanelCombo.add(getJLabelTrans()); |
159 |
jPanelCombo.add(getJComboOptions()); |
160 |
} |
161 |
|
162 |
return jPanelCombo;
|
163 |
} |
164 |
|
165 |
private JLabel getJLabelTrans(){ |
166 |
JLabel jLabelTrans = new JLabel(); |
167 |
jLabelTrans.setPreferredSize(new Dimension(180, 25)); |
168 |
jLabelTrans.setText(PluginServices.getText(this, "seleccione_transformacion")); |
169 |
return jLabelTrans;
|
170 |
} |
171 |
|
172 |
public JComboBox getJComboOptions(){ |
173 |
if (jComboOptions == null){ |
174 |
String[] selection = {PluginServices.getText(this, "sin_transformacion"), |
175 |
PluginServices.getText(this, "transformacion_manual"), |
176 |
"+"+PluginServices.getText(this, "nadgrids"), |
177 |
PluginServices.getText(this, "transformacion_epsg")}; |
178 |
jComboOptions = new JComboBox(selection); |
179 |
jComboOptions.setPreferredSize(new Dimension(150,25)); |
180 |
jComboOptions.setEnabled(false);
|
181 |
jComboOptions.setEditable(false);
|
182 |
jComboOptions.setSelectedIndex(0);
|
183 |
newSelection = (String) jComboOptions.getSelectedItem();
|
184 |
} |
185 |
// jComboOptions.addActionListener(this);
|
186 |
return jComboOptions;
|
187 |
} |
188 |
|
189 |
private JPanel getButtons() { |
190 |
if(jPanelButtons == null) { |
191 |
jPanelButtons = new JPanel(); |
192 |
jPanelButtons.setPreferredSize(new Dimension(550,50)); |
193 |
jPanelButtons.setLayout(new GridLayout(0,1)); |
194 |
jPanelButtons.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5)); |
195 |
jPanelButtons.add(getJButtonCancel(), null);
|
196 |
jPanelButtons.add(getJButtonBefore(), null);
|
197 |
jPanelButtons.add(getJButtonNext(), null);
|
198 |
jPanelButtons.add(getJButtonAccept(), null);
|
199 |
} |
200 |
return jPanelButtons;
|
201 |
} |
202 |
|
203 |
public JButton getJButtonBefore(){ |
204 |
if(jButtonBefore == null) { |
205 |
jButtonBefore = new JButton(); |
206 |
jButtonBefore.setText(PluginServices.getText(this,"anterior")); |
207 |
jButtonBefore.setMnemonic('B');
|
208 |
jButtonBefore.setPreferredSize(new Dimension(100,25)); |
209 |
jButtonBefore.setEnabled(false);
|
210 |
// jButtonBefore.addActionListener(this);
|
211 |
} |
212 |
return jButtonBefore;
|
213 |
} |
214 |
|
215 |
public JButton getJButtonAccept() { |
216 |
if(jButtonAccept == null) { |
217 |
jButtonAccept = new JButton(); |
218 |
jButtonAccept.setText(PluginServices.getText(this,"finalizar")); |
219 |
jButtonAccept.setMnemonic('O');
|
220 |
jButtonAccept.setVisible(true);
|
221 |
jButtonAccept.setPreferredSize(new Dimension(100,25)); |
222 |
// jButtonAccept.addActionListener(this);
|
223 |
} |
224 |
return jButtonAccept;
|
225 |
} |
226 |
|
227 |
public JButton getJButtonNext() { |
228 |
if(jButtonNext == null) { |
229 |
jButtonNext = new JButton(); |
230 |
jButtonNext.setText(PluginServices.getText(this,"siguiente")); |
231 |
jButtonNext.setMnemonic('S');
|
232 |
jButtonNext.setVisible(false);
|
233 |
jButtonNext.setPreferredSize(new Dimension(100,25)); |
234 |
// jButtonNext.addActionListener(this);
|
235 |
} |
236 |
return jButtonNext;
|
237 |
} |
238 |
|
239 |
public JButton getJButtonCancel() { |
240 |
if(jButtonCancel == null) { |
241 |
jButtonCancel = new JButton(); |
242 |
jButtonCancel.setText(PluginServices.getText(this,"cancel")); |
243 |
jButtonCancel.setMnemonic('C');
|
244 |
jButtonCancel.setPreferredSize(new Dimension(100,25)); |
245 |
// jButtonCancel.addActionListener(this);
|
246 |
} |
247 |
return jButtonCancel;
|
248 |
} |
249 |
|
250 |
public void setTargetNad(boolean tarNad){ |
251 |
targetNad = tarNad; |
252 |
} |
253 |
|
254 |
public boolean getTargetNad(){ |
255 |
return targetNad;
|
256 |
} |
257 |
|
258 |
/*
|
259 |
* revisar esta solucion
|
260 |
*/
|
261 |
public ICrs getProjection() {
|
262 |
if (sin_tr) {
|
263 |
ICrs crs; |
264 |
try {
|
265 |
if (getDataSource().equals(PluginServices.getText(this,"EPSG"))){ |
266 |
crs = new CrsFactory().getCRS(crsMainPanel.getEpsgPanel().getCodeCRS(),crsMainPanel.getEpsgPanel().getWKT());
|
267 |
} |
268 |
else if (getDataSource().equals(PluginServices.getText(this,"IAU2000"))){ |
269 |
crs = new CrsFactory().getCRS(crsMainPanel.getIauPanel().getCodeCRS(),crsMainPanel.getIauPanel().getWKT());
|
270 |
} |
271 |
else if (getDataSource().equals(PluginServices.getText(this,"recientes"))){ |
272 |
crs = new CrsFactory().getCRS(crsMainPanel.getRecentsPanel().getCodeCRS(),crsMainPanel.getRecentsPanel().getWKT());
|
273 |
} else {
|
274 |
sin_tr = false;
|
275 |
return null; |
276 |
} |
277 |
sin_tr = false;
|
278 |
return crs;
|
279 |
} catch (CrsException e) {
|
280 |
e.printStackTrace(); |
281 |
} |
282 |
return null; |
283 |
} |
284 |
return (ICrs) crsfirst;
|
285 |
} |
286 |
|
287 |
public void setProjection(IProjection proj) { |
288 |
crsfirst = proj; |
289 |
} |
290 |
|
291 |
private void setListeners(){ |
292 |
|
293 |
CRSMainTrPanelListener listener = new CRSMainTrPanelListener(this); |
294 |
|
295 |
jButtonAccept.addActionListener(listener); |
296 |
jButtonBefore.addActionListener(listener); |
297 |
jButtonCancel.addActionListener(listener); |
298 |
jButtonNext.addActionListener(listener); |
299 |
crsMainPanel.getJComboOptions().addItemListener(listener); |
300 |
getJComboOptions().addActionListener(listener); |
301 |
|
302 |
ListSelectionModel rowSM = crsMainPanel.getEpsgPanel().getJTable().getSelectionModel();
|
303 |
rowSM.addListSelectionListener(listener); |
304 |
|
305 |
ListSelectionModel rowSMiau = crsMainPanel.getIauPanel().getJTable().getSelectionModel();
|
306 |
rowSMiau.addListSelectionListener(listener); |
307 |
|
308 |
ListSelectionModel rowSMrecents = crsMainPanel.getRecentsPanel().getJTable().getSelectionModel();
|
309 |
rowSMrecents.addListSelectionListener(listener); |
310 |
|
311 |
crsMainPanel.getEsriPanel().getJTextOpen().getDocument().addDocumentListener(listener); |
312 |
} |
313 |
|
314 |
public void compareDatum(String wktSource){ |
315 |
CrsWkt crsWkt_source = new CrsWkt(wktSource);
|
316 |
|
317 |
if (!crsWkt_source.getSpheroid()[1].equals(crsWkt_target.getSpheroid()[1])){ |
318 |
jComboOptions.setEnabled(true);
|
319 |
} |
320 |
else if (!crsWkt_source.getSpheroid()[2].equals(crsWkt_target.getSpheroid()[2])){ |
321 |
jComboOptions.setEnabled(true);
|
322 |
} |
323 |
else jComboOptions.setEnabled(false); |
324 |
|
325 |
/*connection = new EpsgConnection();
|
326 |
connection.setConnectionEPSG();
|
327 |
String datum = "";
|
328 |
int datum_code = -1;
|
329 |
String sentence = "SELECT source_geogcrs_code " +
|
330 |
"FROM epsg_coordinatereferencesystem " +
|
331 |
"WHERE coord_ref_sys_code = "+ base ;
|
332 |
ResultSet result = Query.select(sentence,connection.getConnection());
|
333 |
int source = 0;
|
334 |
try {
|
335 |
result.next();
|
336 |
source = result.getInt("source_geogcrs_code");
|
337 |
} catch (SQLException e1) {
|
338 |
e1.printStackTrace();
|
339 |
}
|
340 |
|
341 |
if (source != 0){
|
342 |
base = source;
|
343 |
}
|
344 |
|
345 |
|
346 |
* Recuperamos el Datum del CRS que esta seleccionado de manera provisional
|
347 |
* y realizamos la comparacion para saber si, en caso de elegir el crs que
|
348 |
* tenemos seleccionado, se puede producir una transformacion
|
349 |
|
350 |
sentence = "SELECT datum_code " +
|
351 |
"FROM epsg_coordinatereferencesystem " +
|
352 |
"WHERE coord_ref_sys_code = "+ base ;
|
353 |
result = Query.select(sentence,connection.getConnection());
|
354 |
|
355 |
try {
|
356 |
result.next();
|
357 |
datum_code = result.getInt("datum_code");
|
358 |
} catch (SQLException e1) {
|
359 |
e1.printStackTrace();
|
360 |
}
|
361 |
|
362 |
sentence = "SELECT datum_name " +
|
363 |
"FROM epsg_datum " +
|
364 |
"WHERE datum_code = "+ datum_code ;
|
365 |
result = Query.select(sentence,connection.getConnection());
|
366 |
|
367 |
try {
|
368 |
result.next();
|
369 |
datum = result.getString("datum_name");
|
370 |
} catch (SQLException e1) {
|
371 |
e1.printStackTrace();
|
372 |
}
|
373 |
|
374 |
if (!(crsWkt_target.equals(datum.replaceAll(" ","")))){
|
375 |
jComboOptions.setEnabled(true);
|
376 |
}
|
377 |
else {
|
378 |
jComboOptions.setEnabled(false);
|
379 |
}*/
|
380 |
} |
381 |
|
382 |
|
383 |
|
384 |
public void setDataSource(String sour){ |
385 |
dataSource = sour; |
386 |
} |
387 |
|
388 |
public String getDataSource(){ |
389 |
return crsMainPanel.getDataSource();
|
390 |
} |
391 |
|
392 |
public WindowInfo getWindowInfo() {
|
393 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
394 |
m_viewinfo.setTitle(PluginServices.getText(this,"crsview")); |
395 |
return m_viewinfo;
|
396 |
} |
397 |
|
398 |
|
399 |
|
400 |
|
401 |
|
402 |
|
403 |
|
404 |
|
405 |
|
406 |
|
407 |
|
408 |
|
409 |
|
410 |
public CRSMainPanel getCrsMainPanel() {
|
411 |
return crsMainPanel;
|
412 |
} |
413 |
|
414 |
public TransformationEpsgPanel getEpsgTrPanel() {
|
415 |
return epsgTrPanel;
|
416 |
} |
417 |
|
418 |
public TransformationManualPanel getManualTrPanel() {
|
419 |
return manualTrPanel;
|
420 |
} |
421 |
|
422 |
public TransformationNadgridsPanel getNadsTrPanel() {
|
423 |
return nadsTrPanel;
|
424 |
} |
425 |
|
426 |
public boolean isEpsg_tr() { |
427 |
return epsg_tr;
|
428 |
} |
429 |
|
430 |
public boolean isManual_tr() { |
431 |
return manual_tr;
|
432 |
} |
433 |
|
434 |
public boolean isNads_tr() { |
435 |
return nads_tr;
|
436 |
} |
437 |
|
438 |
public boolean isSin_tr() { |
439 |
return sin_tr;
|
440 |
} |
441 |
|
442 |
public void setEpsg_tr(boolean epsg_tr) { |
443 |
this.epsg_tr = epsg_tr;
|
444 |
} |
445 |
|
446 |
public void setManual_tr(boolean manual_tr) { |
447 |
this.manual_tr = manual_tr;
|
448 |
} |
449 |
|
450 |
public void setNads_tr(boolean nads_tr) { |
451 |
this.nads_tr = nads_tr;
|
452 |
} |
453 |
|
454 |
public void setSin_tr(boolean sin_tr) { |
455 |
this.sin_tr = sin_tr;
|
456 |
} |
457 |
|
458 |
public boolean isCancelYes() { |
459 |
return cancelYes;
|
460 |
} |
461 |
|
462 |
public void setCancelYes(boolean cancelYes) { |
463 |
this.cancelYes = cancelYes;
|
464 |
} |
465 |
|
466 |
public IProjection getCrsfirst() {
|
467 |
return crsfirst;
|
468 |
} |
469 |
|
470 |
public JPanel getJPanelMain() { |
471 |
return jPanelMain;
|
472 |
} |
473 |
|
474 |
public String getNewSelection() { |
475 |
return newSelection;
|
476 |
} |
477 |
|
478 |
public void setNewSelection(String newSelection) { |
479 |
this.newSelection = newSelection;
|
480 |
} |
481 |
|
482 |
/*public EpsgConnection getConnection() {
|
483 |
return connection;
|
484 |
}
|
485 |
|
486 |
public void setConnection(EpsgConnection connect) {
|
487 |
this.connection = connect;
|
488 |
}*/
|
489 |
} |