svn-gvsig-desktop / trunk / libraries / libJCRS / src / org / gvsig / crs / gui / CRSMainTrPanel.java @ 8262
History | View | Annotate | Download (13 KB)
1 | 8130 | dguerrero | 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 | 8262 | jlgomez | import org.gvsig.crs.CrsWkt; |
19 | 8130 | dguerrero | import org.gvsig.crs.EpsgConnection; |
20 | import org.gvsig.crs.ICrs; |
||
21 | import org.gvsig.crs.Query; |
||
22 | 8170 | dguerrero | import org.gvsig.crs.gui.listeners.CRSMainTrPanelListener; |
23 | 8130 | dguerrero | 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 | 8170 | dguerrero | public class CRSMainTrPanel extends JPanel implements IWindow{ |
31 | 8130 | dguerrero | |
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 | 8170 | dguerrero | private boolean cancelYes = false; |
40 | 8130 | dguerrero | private JButton jButtonCancel = null; |
41 | 8170 | dguerrero | private JButton jButtonNext = null; |
42 | private JButton jButtonAccept = null; |
||
43 | private JButton jButtonBefore = null; |
||
44 | 8130 | dguerrero | private JPanel jPanelButtons = null; |
45 | |||
46 | boolean targetNad = false; |
||
47 | |||
48 | int crs_target = -1; |
||
49 | 8262 | jlgomez | CrsWkt crsWkt_target = null;
|
50 | 8130 | dguerrero | |
51 | 8262 | jlgomez | //private EpsgConnection connection = null;
|
52 | 8130 | dguerrero | |
53 | int transformation_code = 0; |
||
54 | |||
55 | private JPanel panel = null; |
||
56 | CRSMainPanel viewPan = null;
|
||
57 | |||
58 | 8170 | dguerrero | 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 | 8130 | dguerrero | |
66 | 8170 | dguerrero | private boolean sin_tr = false; |
67 | 8130 | dguerrero | private JPanel jPanelCombo = null; |
68 | private JComboBox jComboOptions = null; |
||
69 | |||
70 | private IProjection crsfirst;
|
||
71 | |||
72 | 8170 | dguerrero | private CRSMainPanel crsMainPanel;
|
73 | private String newSelection; |
||
74 | 8130 | dguerrero | String dataSource = ""; |
75 | ICrs curProj = null;
|
||
76 | |||
77 | 8262 | jlgomez | public CRSMainTrPanel(int target, CrsWkt crsWkttarget, ICrs proj) { |
78 | 8130 | dguerrero | curProj = proj; |
79 | 8170 | dguerrero | crsMainPanel = new CRSMainPanel(target);
|
80 | viewPan = crsMainPanel; |
||
81 | 8130 | dguerrero | |
82 | crs_target = target; |
||
83 | 8262 | jlgomez | crsWkt_target = crsWkttarget; |
84 | 8130 | dguerrero | |
85 | 8170 | dguerrero | manualTrPanel = new TransformationManualPanel();
|
86 | epsgTrPanel = new TransformationEpsgPanel(crs_target);
|
||
87 | nadsTrPanel = new TransformationNadgridsPanel();
|
||
88 | 8130 | dguerrero | |
89 | /*
|
||
90 | * esta variable contendr? tanto el panel utilizado en CRSViewPanel, como los paneles
|
||
91 | * que seran necesarios para realizar las transformaciones
|
||
92 | */
|
||
93 | 8170 | dguerrero | 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 | 8130 | dguerrero | |
100 | 8170 | dguerrero | this.add(jPanelMain, BorderLayout.CENTER); |
101 | 8130 | dguerrero | |
102 | this.add(getButtons(), BorderLayout.SOUTH); |
||
103 | |||
104 | 8170 | dguerrero | setListeners(); |
105 | 8130 | dguerrero | /*
|
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 | 8171 | jlgomez | /*String sour = curProj.getCrsWkt().getAuthority()[0];
|
114 | 8130 | dguerrero | if (sour.equals("EPSG")){
|
115 | 8170 | dguerrero | crsMainPanel.getEpsgPanel().loadViewCRS(curProj.getCode());
|
116 | crsMainPanel.getEpsgPanel().getJTable().setRowSelectionInterval(0,0);
|
||
117 | 8130 | dguerrero | }else if(sour.equals("IAU2000")){
|
118 | 8170 | dguerrero | crsMainPanel.getIauPanel().loadViewCRS(curProj.getCode());
|
119 | crsMainPanel.getIauPanel().getJTable().setRowSelectionInterval(0,0);
|
||
120 | 8171 | jlgomez | }*/
|
121 | 8130 | dguerrero | |
122 | 8170 | dguerrero | setDataSource(crsMainPanel.getDataSource()); |
123 | 8151 | dguerrero | |
124 | 8170 | dguerrero | crsMainPanel.getRecentsPanel().loadRecents(); |
125 | 8130 | dguerrero | } |
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 Transformaci?n: ")); |
||
169 | return jLabelTrans;
|
||
170 | } |
||
171 | |||
172 | 8170 | dguerrero | public JComboBox getJComboOptions(){ |
173 | 8130 | dguerrero | if (jComboOptions == null){ |
174 | String[] selection = {"Sin transformacion", "Transformacion manual", |
||
175 | "+nadgrids", "Transformacion EPSG"}; |
||
176 | jComboOptions = new JComboBox(selection); |
||
177 | jComboOptions.setPreferredSize(new Dimension(150,25)); |
||
178 | jComboOptions.setEnabled(false);
|
||
179 | jComboOptions.setEditable(false);
|
||
180 | jComboOptions.setSelectedIndex(0);
|
||
181 | newSelection = (String) jComboOptions.getSelectedItem();
|
||
182 | } |
||
183 | 8170 | dguerrero | // jComboOptions.addActionListener(this);
|
184 | 8130 | dguerrero | return jComboOptions;
|
185 | } |
||
186 | |||
187 | private JPanel getButtons() { |
||
188 | if(jPanelButtons == null) { |
||
189 | jPanelButtons = new JPanel(); |
||
190 | jPanelButtons.setPreferredSize(new Dimension(550,50)); |
||
191 | jPanelButtons.setLayout(new GridLayout(0,1)); |
||
192 | jPanelButtons.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5)); |
||
193 | jPanelButtons.add(getJButtonCancel(), null);
|
||
194 | jPanelButtons.add(getJButtonBefore(), null);
|
||
195 | jPanelButtons.add(getJButtonNext(), null);
|
||
196 | jPanelButtons.add(getJButtonAccept(), null);
|
||
197 | } |
||
198 | return jPanelButtons;
|
||
199 | } |
||
200 | |||
201 | 8170 | dguerrero | public JButton getJButtonBefore(){ |
202 | 8130 | dguerrero | if(jButtonBefore == null) { |
203 | jButtonBefore = new JButton(); |
||
204 | jButtonBefore.setText(PluginServices.getText(this,"Anterior")); |
||
205 | jButtonBefore.setMnemonic('B');
|
||
206 | jButtonBefore.setPreferredSize(new Dimension(100,25)); |
||
207 | jButtonBefore.setEnabled(false);
|
||
208 | 8170 | dguerrero | // jButtonBefore.addActionListener(this);
|
209 | 8130 | dguerrero | } |
210 | return jButtonBefore;
|
||
211 | } |
||
212 | |||
213 | 8170 | dguerrero | public JButton getJButtonAccept() { |
214 | 8130 | dguerrero | if(jButtonAccept == null) { |
215 | jButtonAccept = new JButton(); |
||
216 | jButtonAccept.setText(PluginServices.getText(this,"Finalizar")); |
||
217 | jButtonAccept.setMnemonic('O');
|
||
218 | jButtonAccept.setVisible(true);
|
||
219 | jButtonAccept.setPreferredSize(new Dimension(100,25)); |
||
220 | 8170 | dguerrero | // jButtonAccept.addActionListener(this);
|
221 | 8130 | dguerrero | } |
222 | return jButtonAccept;
|
||
223 | } |
||
224 | |||
225 | 8170 | dguerrero | public JButton getJButtonNext() { |
226 | 8130 | dguerrero | if(jButtonNext == null) { |
227 | jButtonNext = new JButton(); |
||
228 | jButtonNext.setText(PluginServices.getText(this,"Siguiente")); |
||
229 | jButtonNext.setMnemonic('S');
|
||
230 | jButtonNext.setVisible(false);
|
||
231 | jButtonNext.setPreferredSize(new Dimension(100,25)); |
||
232 | 8170 | dguerrero | // jButtonNext.addActionListener(this);
|
233 | 8130 | dguerrero | } |
234 | return jButtonNext;
|
||
235 | } |
||
236 | |||
237 | 8170 | dguerrero | public JButton getJButtonCancel() { |
238 | 8130 | dguerrero | if(jButtonCancel == null) { |
239 | jButtonCancel = new JButton(); |
||
240 | jButtonCancel.setText(PluginServices.getText(this,"Cancelar")); |
||
241 | jButtonCancel.setMnemonic('C');
|
||
242 | jButtonCancel.setPreferredSize(new Dimension(100,25)); |
||
243 | 8170 | dguerrero | // jButtonCancel.addActionListener(this);
|
244 | 8130 | dguerrero | } |
245 | return jButtonCancel;
|
||
246 | } |
||
247 | |||
248 | public void setTargetNad(boolean tarNad){ |
||
249 | targetNad = tarNad; |
||
250 | } |
||
251 | |||
252 | public boolean getTargetNad(){ |
||
253 | return targetNad;
|
||
254 | } |
||
255 | |||
256 | /*
|
||
257 | * revisar esta solucion
|
||
258 | */
|
||
259 | public ICrs getProjection() {
|
||
260 | if (sin_tr) {
|
||
261 | ICrs crs; |
||
262 | try {
|
||
263 | if (getDataSource().equals("EPSG")){ |
||
264 | 8170 | dguerrero | crs = new CrsFactory().getCRS(crsMainPanel.getEpsgPanel().getCodeCRS(),crsMainPanel.getEpsgPanel().getWKT());
|
265 | 8130 | dguerrero | } |
266 | else if (getDataSource().equals("IAU2000")){ |
||
267 | 8170 | dguerrero | crs = new CrsFactory().getCRS(crsMainPanel.getIauPanel().getCodeCRS(),crsMainPanel.getIauPanel().getWKT());
|
268 | 8130 | dguerrero | } |
269 | else if (getDataSource().equals("Recientes")){ |
||
270 | 8170 | dguerrero | crs = new CrsFactory().getCRS(crsMainPanel.getRecentsPanel().getCodeCRS(),crsMainPanel.getRecentsPanel().getWKT());
|
271 | 8130 | dguerrero | } else {
|
272 | sin_tr = false;
|
||
273 | return null; |
||
274 | } |
||
275 | sin_tr = false;
|
||
276 | return crs;
|
||
277 | } catch (CrsException e) {
|
||
278 | e.printStackTrace(); |
||
279 | } |
||
280 | return null; |
||
281 | } |
||
282 | return (ICrs) crsfirst;
|
||
283 | } |
||
284 | |||
285 | public void setProjection(IProjection proj) { |
||
286 | crsfirst = proj; |
||
287 | } |
||
288 | |||
289 | 8262 | jlgomez | private void setListeners(){ |
290 | 8170 | dguerrero | |
291 | CRSMainTrPanelListener listener = new CRSMainTrPanelListener(this); |
||
292 | 8136 | dguerrero | |
293 | 8170 | dguerrero | jButtonAccept.addActionListener(listener); |
294 | jButtonBefore.addActionListener(listener); |
||
295 | jButtonCancel.addActionListener(listener); |
||
296 | jButtonNext.addActionListener(listener); |
||
297 | crsMainPanel.getJComboOptions().addItemListener(listener); |
||
298 | 8171 | jlgomez | getJComboOptions().addActionListener(listener); |
299 | 8130 | dguerrero | |
300 | 8170 | dguerrero | ListSelectionModel rowSM = crsMainPanel.getEpsgPanel().getJTable().getSelectionModel();
|
301 | rowSM.addListSelectionListener(listener); |
||
302 | 8130 | dguerrero | |
303 | 8170 | dguerrero | ListSelectionModel rowSMiau = crsMainPanel.getIauPanel().getJTable().getSelectionModel();
|
304 | rowSMiau.addListSelectionListener(listener); |
||
305 | 8135 | dguerrero | |
306 | 8170 | dguerrero | ListSelectionModel rowSMrecents = crsMainPanel.getRecentsPanel().getJTable().getSelectionModel();
|
307 | rowSMrecents.addListSelectionListener(listener); |
||
308 | 8149 | dguerrero | |
309 | 8170 | dguerrero | crsMainPanel.getEsriPanel().getJTextOpen().getDocument().addDocumentListener(listener); |
310 | 8130 | dguerrero | } |
311 | |||
312 | 8262 | jlgomez | public void compareDatum(String wktSource){ |
313 | CrsWkt crsWkt_source = new CrsWkt(wktSource);
|
||
314 | |||
315 | if (!crsWkt_source.getSpheroid()[1].equals(crsWkt_target.getSpheroid()[1])){ |
||
316 | jComboOptions.setEnabled(true);
|
||
317 | } |
||
318 | else if (!crsWkt_source.getSpheroid()[2].equals(crsWkt_target.getSpheroid()[2])){ |
||
319 | jComboOptions.setEnabled(true);
|
||
320 | } |
||
321 | else jComboOptions.setEnabled(false); |
||
322 | |||
323 | /*connection = new EpsgConnection();
|
||
324 | 8171 | jlgomez | connection.setConnectionEPSG();
|
325 | 8130 | dguerrero | String datum = "";
|
326 | int datum_code = -1;
|
||
327 | String sentence = "SELECT source_geogcrs_code " +
|
||
328 | "FROM epsg_coordinatereferencesystem " +
|
||
329 | "WHERE coord_ref_sys_code = "+ base ;
|
||
330 | 8170 | dguerrero | ResultSet result = Query.select(sentence,connection.getConnection());
|
331 | 8130 | dguerrero | int source = 0;
|
332 | try {
|
||
333 | result.next();
|
||
334 | source = result.getInt("source_geogcrs_code");
|
||
335 | } catch (SQLException e1) {
|
||
336 | e1.printStackTrace();
|
||
337 | }
|
||
338 | |||
339 | if (source != 0){
|
||
340 | base = source;
|
||
341 | }
|
||
342 | |||
343 | 8262 | jlgomez | |
344 | 8130 | dguerrero | * Recuperamos el Datum del CRS que esta seleccionado de manera provisional
|
345 | * y realizamos la comparacion para saber si, en caso de elegir el crs que
|
||
346 | * tenemos seleccionado, se puede producir una transformacion
|
||
347 | 8262 | jlgomez | |
348 | 8130 | dguerrero | sentence = "SELECT datum_code " +
|
349 | "FROM epsg_coordinatereferencesystem " +
|
||
350 | "WHERE coord_ref_sys_code = "+ base ;
|
||
351 | 8170 | dguerrero | result = Query.select(sentence,connection.getConnection());
|
352 | 8130 | dguerrero | |
353 | try {
|
||
354 | result.next();
|
||
355 | datum_code = result.getInt("datum_code");
|
||
356 | } catch (SQLException e1) {
|
||
357 | e1.printStackTrace();
|
||
358 | }
|
||
359 | |||
360 | sentence = "SELECT datum_name " +
|
||
361 | "FROM epsg_datum " +
|
||
362 | "WHERE datum_code = "+ datum_code ;
|
||
363 | 8170 | dguerrero | result = Query.select(sentence,connection.getConnection());
|
364 | 8130 | dguerrero | |
365 | try {
|
||
366 | result.next();
|
||
367 | datum = result.getString("datum_name");
|
||
368 | } catch (SQLException e1) {
|
||
369 | e1.printStackTrace();
|
||
370 | }
|
||
371 | |||
372 | 8262 | jlgomez | if (!(crsWkt_target.equals(datum.replaceAll(" ","")))){
|
373 | 8130 | dguerrero | jComboOptions.setEnabled(true);
|
374 | }
|
||
375 | else {
|
||
376 | jComboOptions.setEnabled(false);
|
||
377 | 8262 | jlgomez | }*/
|
378 | 8130 | dguerrero | } |
379 | |||
380 | |||
381 | |||
382 | public void setDataSource(String sour){ |
||
383 | dataSource = sour; |
||
384 | } |
||
385 | |||
386 | public String getDataSource(){ |
||
387 | 8170 | dguerrero | return crsMainPanel.getDataSource();
|
388 | 8130 | dguerrero | } |
389 | |||
390 | public WindowInfo getWindowInfo() {
|
||
391 | WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
||
392 | m_viewinfo.setTitle(PluginServices.getText(this,"CrsView")); |
||
393 | return m_viewinfo;
|
||
394 | } |
||
395 | |||
396 | |||
397 | 8170 | dguerrero | |
398 | |||
399 | |||
400 | |||
401 | |||
402 | |||
403 | |||
404 | |||
405 | |||
406 | |||
407 | |||
408 | public CRSMainPanel getCrsMainPanel() {
|
||
409 | return crsMainPanel;
|
||
410 | 8130 | dguerrero | } |
411 | 8135 | dguerrero | |
412 | 8170 | dguerrero | public TransformationEpsgPanel getEpsgTrPanel() {
|
413 | return epsgTrPanel;
|
||
414 | 8135 | dguerrero | } |
415 | 8149 | dguerrero | |
416 | 8170 | dguerrero | public TransformationManualPanel getManualTrPanel() {
|
417 | return manualTrPanel;
|
||
418 | 8149 | dguerrero | } |
419 | |||
420 | 8170 | dguerrero | public TransformationNadgridsPanel getNadsTrPanel() {
|
421 | return nadsTrPanel;
|
||
422 | 8149 | dguerrero | } |
423 | |||
424 | 8170 | dguerrero | public boolean isEpsg_tr() { |
425 | return epsg_tr;
|
||
426 | 8149 | dguerrero | } |
427 | |||
428 | 8170 | dguerrero | public boolean isManual_tr() { |
429 | return manual_tr;
|
||
430 | 8149 | dguerrero | } |
431 | 8170 | dguerrero | |
432 | public boolean isNads_tr() { |
||
433 | return nads_tr;
|
||
434 | } |
||
435 | |||
436 | public boolean isSin_tr() { |
||
437 | return sin_tr;
|
||
438 | } |
||
439 | |||
440 | public void setEpsg_tr(boolean epsg_tr) { |
||
441 | this.epsg_tr = epsg_tr;
|
||
442 | } |
||
443 | |||
444 | public void setManual_tr(boolean manual_tr) { |
||
445 | this.manual_tr = manual_tr;
|
||
446 | } |
||
447 | |||
448 | public void setNads_tr(boolean nads_tr) { |
||
449 | this.nads_tr = nads_tr;
|
||
450 | } |
||
451 | |||
452 | public void setSin_tr(boolean sin_tr) { |
||
453 | this.sin_tr = sin_tr;
|
||
454 | } |
||
455 | |||
456 | public boolean isCancelYes() { |
||
457 | return cancelYes;
|
||
458 | } |
||
459 | |||
460 | public void setCancelYes(boolean cancelYes) { |
||
461 | this.cancelYes = cancelYes;
|
||
462 | } |
||
463 | |||
464 | public IProjection getCrsfirst() {
|
||
465 | return crsfirst;
|
||
466 | } |
||
467 | |||
468 | public JPanel getJPanelMain() { |
||
469 | return jPanelMain;
|
||
470 | } |
||
471 | |||
472 | public String getNewSelection() { |
||
473 | return newSelection;
|
||
474 | } |
||
475 | |||
476 | public void setNewSelection(String newSelection) { |
||
477 | this.newSelection = newSelection;
|
||
478 | } |
||
479 | |||
480 | 8262 | jlgomez | /*public EpsgConnection getConnection() {
|
481 | 8170 | dguerrero | return connection;
|
482 | }
|
||
483 | |||
484 | public void setConnection(EpsgConnection connect) {
|
||
485 | this.connection = connect;
|
||
486 | 8262 | jlgomez | }*/
|
487 | 8130 | dguerrero | } |