root / trunk / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / MainPanel.java @ 24986
History | View | Annotate | Download (25.6 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.wizard; |
42 |
|
43 |
import java.awt.BorderLayout; |
44 |
import java.awt.FlowLayout; |
45 |
import java.awt.event.ActionEvent; |
46 |
import java.awt.event.ActionListener; |
47 |
import java.sql.ResultSet; |
48 |
import java.sql.SQLException; |
49 |
import java.text.ParseException; |
50 |
import java.util.ArrayList; |
51 |
|
52 |
import javax.swing.JButton; |
53 |
import javax.swing.JOptionPane; |
54 |
import javax.swing.JPanel; |
55 |
import javax.swing.JTabbedPane; |
56 |
import javax.swing.event.ChangeEvent; |
57 |
import javax.swing.event.ChangeListener; |
58 |
|
59 |
import org.geotools.referencing.wkt.Parser; |
60 |
import org.gvsig.crs.Crs; |
61 |
import org.gvsig.crs.CrsException; |
62 |
import org.gvsig.crs.CrsFactory; |
63 |
import org.gvsig.crs.ICrs; |
64 |
import org.opengis.referencing.crs.CoordinateReferenceSystem; |
65 |
|
66 |
import com.iver.andami.PluginServices; |
67 |
import com.iver.andami.ui.mdiManager.IWindow; |
68 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
69 |
|
70 |
import es.idr.teledeteccion.connection.EpsgConnection; |
71 |
import es.idr.teledeteccion.connection.Query; |
72 |
|
73 |
|
74 |
/**
|
75 |
*
|
76 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
77 |
* @author Jose Luis Gomez Martinez (joseluis.gomez@uclm.es)
|
78 |
*
|
79 |
*/
|
80 |
public class MainPanel extends JPanel implements ActionListener, ChangeListener, IWindow { |
81 |
|
82 |
private static final long serialVersionUID = 1L; |
83 |
private JTabbedPane pCard; |
84 |
private JPanel pSouth; |
85 |
|
86 |
private JButton btnCancelar; |
87 |
private JButton btnSiguiente; |
88 |
private JButton btnAnterior; |
89 |
private JButton btnFinalizar; |
90 |
|
91 |
private DefCrsUsr pCrsUsr;
|
92 |
private DefinirDatum pDatum;
|
93 |
private DefSistCoordenadas pSistCoord;
|
94 |
private ICrs currentCrs;
|
95 |
private String cadWkt = ""; |
96 |
private int newCrsCode = -1; |
97 |
private boolean edit = false; |
98 |
|
99 |
public MainPanel(ICrs crs) {
|
100 |
super();
|
101 |
setCrs(crs); |
102 |
this.setLayout(new BorderLayout()); |
103 |
this.add(getPCard(),BorderLayout.CENTER); |
104 |
this.add(getPSouth(),BorderLayout.SOUTH); |
105 |
getPCrsUsr().getRbCadenaWkt().addActionListener(this);
|
106 |
getPCrsUsr().getRbCrsExistente().addActionListener(this);
|
107 |
getPCrsUsr().getRbNuevoCrs().addActionListener(this);
|
108 |
} |
109 |
/**
|
110 |
* Inicilizar el botn Anterior
|
111 |
* @return
|
112 |
*/
|
113 |
public JButton getBtnAnterior() { |
114 |
if(btnAnterior==null){ |
115 |
btnAnterior=new JButton(); |
116 |
btnAnterior.setText(PluginServices.getText(this,"wz_anterior")); |
117 |
btnAnterior.addActionListener(this);
|
118 |
|
119 |
} |
120 |
return btnAnterior;
|
121 |
} |
122 |
/**
|
123 |
* Inicilizar el botn Cancelar
|
124 |
* @return
|
125 |
*/
|
126 |
public JButton getBtnCancelar() { |
127 |
if(btnCancelar==null){ |
128 |
btnCancelar=new JButton(); |
129 |
btnCancelar.setText(PluginServices.getText(this,"wz_cancel")); |
130 |
btnCancelar.addActionListener(this);
|
131 |
} |
132 |
return btnCancelar;
|
133 |
} |
134 |
/**
|
135 |
* Inicilizar el botn Finalizar
|
136 |
* @return
|
137 |
*/
|
138 |
public JButton getBtnFinalizar() { |
139 |
if(btnFinalizar==null){ |
140 |
btnFinalizar=new JButton(); |
141 |
btnFinalizar.setText(PluginServices.getText(this,"wz_fin")); |
142 |
btnFinalizar.addActionListener(this);
|
143 |
} |
144 |
return btnFinalizar;
|
145 |
} |
146 |
/**
|
147 |
* Inicilizar el botn Siguiente
|
148 |
* @return
|
149 |
*/
|
150 |
public JButton getBtnSiguiente() { |
151 |
if(btnSiguiente==null){ |
152 |
btnSiguiente=new JButton(); |
153 |
btnSiguiente.setText(PluginServices.getText(this,"wz_siguiente")); |
154 |
btnSiguiente.addActionListener(this);
|
155 |
} |
156 |
return btnSiguiente;
|
157 |
} |
158 |
/**
|
159 |
* Inicilizar el panel que maneja los subpaneles del asistente
|
160 |
* @return
|
161 |
*/
|
162 |
public JTabbedPane getPCard() { |
163 |
if(pCard==null){ |
164 |
pCard = new JTabbedPane(); |
165 |
pCard.addTab(PluginServices.getText(this,"crs_usuario"),getPCrsUsr()); |
166 |
pCard.addTab(PluginServices.getText(this,"Dat_nDatum"),getPDatum()); |
167 |
pCard.addTab(PluginServices.getText(this,"SistCoor_titmarco"),getPSistCoord()); |
168 |
//Por defecto se muestra la primera pestaa
|
169 |
pCard.setSelectedIndex(0);
|
170 |
pCard.addChangeListener(this);
|
171 |
} |
172 |
return pCard;
|
173 |
} |
174 |
/**
|
175 |
* Iniciliza el panel que contiene los botones del asistente
|
176 |
* @return
|
177 |
*/
|
178 |
public JPanel getPSouth() { |
179 |
if(pSouth==null){ |
180 |
pSouth=new JPanel(); |
181 |
pSouth.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5)); |
182 |
pSouth.add(getBtnCancelar()); |
183 |
pSouth.add(getBtnAnterior()); |
184 |
pSouth.add(getBtnSiguiente()); |
185 |
pSouth.add(getBtnFinalizar()); |
186 |
getBtnFinalizar().setVisible(false);
|
187 |
getBtnAnterior().setVisible(false);
|
188 |
} |
189 |
return pSouth;
|
190 |
} |
191 |
public DefCrsUsr getPCrsUsr() {
|
192 |
if(pCrsUsr==null){ |
193 |
pCrsUsr=new DefCrsUsr(getCrs());
|
194 |
} |
195 |
return pCrsUsr;
|
196 |
} |
197 |
public DefinirDatum getPDatum() {
|
198 |
if(pDatum==null){ |
199 |
pDatum=new DefinirDatum();
|
200 |
} |
201 |
return pDatum;
|
202 |
} |
203 |
public DefSistCoordenadas getPSistCoord() {
|
204 |
if(pSistCoord==null){ |
205 |
pSistCoord=new DefSistCoordenadas();
|
206 |
} |
207 |
return pSistCoord;
|
208 |
} |
209 |
public void actionPerformed(ActionEvent e) { |
210 |
|
211 |
if(e.getSource().equals(getBtnAnterior())){
|
212 |
|
213 |
//Establecer los botones del Wizard
|
214 |
getBtnFinalizar().setVisible(false);
|
215 |
getBtnSiguiente().setVisible(true);
|
216 |
|
217 |
if (getPSistCoord().isShowing() && isEditing()) {
|
218 |
getBtnAnterior().setVisible(false);
|
219 |
} |
220 |
if(getPDatum().isShowing()){
|
221 |
//Se va a mostrar el primer panel del Wizard
|
222 |
getBtnAnterior().setVisible(false);
|
223 |
if (getPCrsUsr().getRbCadenaWkt().isSelected()) {
|
224 |
getBtnFinalizar().setVisible(true);
|
225 |
} |
226 |
getPCard().setSelectedComponent(getPCrsUsr()); |
227 |
} |
228 |
else if (getPSistCoord().isShowing()) { |
229 |
getPCard().setSelectedComponent(getPDatum()); |
230 |
} |
231 |
|
232 |
}else if(e.getSource().equals(getBtnSiguiente())){ |
233 |
if (getPCrsUsr().isShowing() && getPCrsUsr().getRbCrsExistente().isSelected() ){
|
234 |
getBtnFinalizar().setVisible(false);
|
235 |
ICrs crs = getPCrsUsr().getCrs(); |
236 |
if (crs != null){ |
237 |
fillData(crs); |
238 |
} |
239 |
else fillData(getCrs());
|
240 |
} |
241 |
else if (getPCrsUsr().isShowing() && getPCrsUsr().getRbNuevoCrs().isSelected() ){ |
242 |
getBtnFinalizar().setVisible(false);
|
243 |
cleanData(); |
244 |
} |
245 |
else if (getPCrsUsr().isShowing() && getPCrsUsr().getRbCadenaWkt().isSelected()) { |
246 |
if (getPCrsUsr().getTxtAreaWkt().getText().equals("")) { |
247 |
JOptionPane.showMessageDialog(MainPanel.this,
|
248 |
PluginServices.getText(this,"white_Textbox"), |
249 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
250 |
return;
|
251 |
} else {
|
252 |
CoordinateReferenceSystem crs = null;
|
253 |
String wkt = getPCrsUsr().getTxtAreaWkt().getText();
|
254 |
Parser parser = new Parser(); |
255 |
|
256 |
try {
|
257 |
crs = parser.parseCoordinateReferenceSystem(wkt); |
258 |
} catch (ParseException e1) { |
259 |
//System.out.println("Cadena WKT no ha podido ser parseada");
|
260 |
//e1.printStackTrace();
|
261 |
JOptionPane.showMessageDialog(MainPanel.this,
|
262 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
263 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
264 |
return;
|
265 |
} catch (UnsupportedOperationException e2) { |
266 |
JOptionPane.showMessageDialog(MainPanel.this,
|
267 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
268 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
269 |
return;
|
270 |
} |
271 |
|
272 |
fillData(crs); |
273 |
} |
274 |
} |
275 |
if (getPCrsUsr().isShowing())
|
276 |
getPCard().setSelectedComponent(getPDatum()); |
277 |
else if (getPDatum().isShowing()) |
278 |
getPCard().setSelectedComponent(getPSistCoord()); |
279 |
|
280 |
getBtnAnterior().setVisible(true);
|
281 |
//Si aparece el ultimo panel visualizar el botn finalizar
|
282 |
if (getPDatum().isShowing()){
|
283 |
getBtnFinalizar().setVisible(true);
|
284 |
getBtnSiguiente().setVisible(false);
|
285 |
getBtnAnterior().setVisible(true);
|
286 |
} |
287 |
}else if(e.getSource().equals(getBtnFinalizar())){ |
288 |
if (getPCrsUsr().getRbCadenaWkt().isSelected()) {
|
289 |
CoordinateReferenceSystem crs = null;
|
290 |
String wkt = getPCrsUsr().getTxtAreaWkt().getText();
|
291 |
Parser parser = new Parser(); |
292 |
if (getPCrsUsr().getTxtAreaWkt().getText().equals("")) { |
293 |
JOptionPane.showMessageDialog(MainPanel.this,
|
294 |
PluginServices.getText(this,"white_Textbox"), |
295 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
296 |
return;
|
297 |
} |
298 |
try {
|
299 |
crs = parser.parseCoordinateReferenceSystem(wkt); |
300 |
} catch (ParseException e1) { |
301 |
//System.out.println("Cadena WKT no ha podido ser parseada");
|
302 |
//e1.printStackTrace();
|
303 |
JOptionPane.showMessageDialog(MainPanel.this,
|
304 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
305 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
306 |
return;
|
307 |
} catch (UnsupportedOperationException e2) { |
308 |
JOptionPane.showMessageDialog(MainPanel.this,
|
309 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
310 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
311 |
return;
|
312 |
} |
313 |
|
314 |
fillData(crs); |
315 |
} |
316 |
|
317 |
//Realizar las acciones de fin del Wizard
|
318 |
getDataAndUpdate(); |
319 |
|
320 |
}else if(e.getSource().equals(getBtnCancelar())){ |
321 |
//Cerrar el asistente
|
322 |
PluginServices.getMDIManager().closeWindow(this);
|
323 |
} else if (e.getSource().equals(getPCrsUsr().getRbCadenaWkt())) { |
324 |
getPCrsUsr().habilitarExistente(false);
|
325 |
getPCrsUsr().habilitarWkt(true);
|
326 |
getBtnFinalizar().setVisible(true);
|
327 |
} |
328 |
else if(e.getSource().equals(getPCrsUsr().getRbCrsExistente())){ |
329 |
getPCrsUsr().habilitarExistente(true);
|
330 |
getPCrsUsr().habilitarWkt(false);
|
331 |
getBtnFinalizar().setVisible(false);
|
332 |
}else if(e.getSource().equals(getPCrsUsr().getRbNuevoCrs())){ |
333 |
getPCrsUsr().habilitarExistente(false);
|
334 |
getPCrsUsr().habilitarWkt(false);
|
335 |
getBtnFinalizar().setVisible(false);
|
336 |
} |
337 |
} |
338 |
public WindowInfo getWindowInfo() {
|
339 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
340 |
m_viewinfo.setTitle(PluginServices.getText(this,"wz_titulo")); |
341 |
m_viewinfo.setWidth(560);
|
342 |
//m_viewinfo.setHeight(425);
|
343 |
m_viewinfo.setHeight(400);
|
344 |
return m_viewinfo;
|
345 |
} |
346 |
|
347 |
public ICrs getCrs () {
|
348 |
return currentCrs;
|
349 |
} |
350 |
|
351 |
public void setCrs (ICrs crs) { |
352 |
currentCrs = crs; |
353 |
} |
354 |
|
355 |
public void fillData(ICrs crs) { |
356 |
getPDatum().fillData(crs); |
357 |
getPSistCoord().fillData(crs); |
358 |
} |
359 |
|
360 |
public void fillData(ICrs crs, boolean editing) { |
361 |
getPDatum().fillData(crs, editing); |
362 |
getPSistCoord().fillData(crs); |
363 |
} |
364 |
|
365 |
public void cleanData() { |
366 |
getPDatum().cleanData(); |
367 |
getPSistCoord().cleanData(); |
368 |
} |
369 |
|
370 |
public void fillData(CoordinateReferenceSystem crs) { |
371 |
getPDatum().fillData(crs); |
372 |
getPSistCoord().fillData(crs); |
373 |
} |
374 |
|
375 |
private void getDataAndUpdate() { |
376 |
EpsgConnection conn = new EpsgConnection();
|
377 |
conn.setConnectionUsr(); |
378 |
String codeCrs = ""; |
379 |
String sentence;
|
380 |
ResultSet result;
|
381 |
|
382 |
if (getPDatum().getTxtSemMay().getText().equals("")) { |
383 |
JOptionPane.showMessageDialog(MainPanel.this,
|
384 |
PluginServices.getText(this,"white_Textbox")+": Semieje Mayor", |
385 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
386 |
return;
|
387 |
} |
388 |
|
389 |
if (getPDatum().getTxtLong().getText().equals("")) { |
390 |
JOptionPane.showMessageDialog(MainPanel.this,
|
391 |
PluginServices.getText(this,"white_Textbox")+": Longitud", |
392 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
393 |
return;
|
394 |
} |
395 |
|
396 |
if (getPDatum().getTxtCodigoCrs().getText().equals("")) { |
397 |
JOptionPane.showMessageDialog(MainPanel.this,
|
398 |
PluginServices.getText(this,"white_Textbox")+": Codigo CRS", |
399 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
400 |
return;
|
401 |
} |
402 |
|
403 |
String cadenaNumerica = getPDatum().getTxtSemMay().getText().replaceAll("[^0-9.E-]", ""); |
404 |
|
405 |
if (getPDatum().getTxtSemMay().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
406 |
JOptionPane.showMessageDialog(MainPanel.this,
|
407 |
PluginServices.getText(this,"numeric_format")+": Semieje Mayor", |
408 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
409 |
return;
|
410 |
} |
411 |
|
412 |
cadenaNumerica = getPDatum().getTxtLong().getText().replaceAll("[^0-9.E-]", ""); |
413 |
|
414 |
if (getPDatum().getTxtLong().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
415 |
|
416 |
JOptionPane.showMessageDialog(MainPanel.this,
|
417 |
PluginServices.getText(this,"numeric_format")+": Longitud", |
418 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
419 |
return;
|
420 |
} |
421 |
|
422 |
codeCrs = getPDatum().getTxtCodigoCrs().getText().replaceAll("[^0-9]", ""); |
423 |
|
424 |
if (getPDatum().getTxtCodigoCrs().getText().length() != codeCrs.length()) {
|
425 |
|
426 |
JOptionPane.showMessageDialog(MainPanel.this,
|
427 |
PluginServices.getText(this,"numeric_format")+": Codigo CRS", |
428 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
429 |
return;
|
430 |
} |
431 |
|
432 |
double value = Double.valueOf(getPDatum().getTxtSemMay().getText()).doubleValue(); |
433 |
//Comprobar si es numerico, o quedarnos con la parte numerica...
|
434 |
//searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())
|
435 |
String unit = getPDatum().getLengthUnit(getPDatum().getCbSemMay().getSelectedIndex());
|
436 |
double semMay = getPDatum().convert2Meters(unit, value);
|
437 |
value = Double.valueOf(getPDatum().getTxtLong().getText()).doubleValue();
|
438 |
unit = getPDatum().getAngularUnit(getPDatum().getCbLong().getSelectedIndex()); |
439 |
double longitude = getPDatum().convert2Degree(unit, value);
|
440 |
String spheroidName = getPDatum().getTxtElipsoide().getText();
|
441 |
if (spheroidName.equals("")) |
442 |
spheroidName = PluginServices.getText(this, "no_name"); |
443 |
String[] spheroid = {spheroidName, |
444 |
""+semMay,getPDatum().getTxtInvF().getText()};
|
445 |
String meridianName = getPDatum().getTxtMeridian().getText();
|
446 |
if (meridianName.equals("")) |
447 |
meridianName = PluginServices.getText(this, "no_name"); |
448 |
String[] primem = {meridianName, ""+longitude}; |
449 |
|
450 |
String[] authority = {"\"USR\"", codeCrs}; |
451 |
if (!isEditing()){
|
452 |
sentence = "SELECT usr_code FROM USR WHERE usr_code = " +authority[1]; |
453 |
result = Query.select(sentence, conn.getConnection());
|
454 |
try {
|
455 |
if (result.next()) {
|
456 |
JOptionPane.showMessageDialog(MainPanel.this,
|
457 |
PluginServices.getText(this,"crsRepeat")+": "+authority[1], |
458 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
459 |
return;
|
460 |
} |
461 |
} catch (SQLException e1) { |
462 |
// TODO Auto-generated catch block
|
463 |
e1.printStackTrace(); |
464 |
} |
465 |
} |
466 |
String datum = getPDatum().getTxtDatum().getText();
|
467 |
if (datum.equals("")) |
468 |
datum = PluginServices.getText(this, "no_name"); |
469 |
|
470 |
if (getPSistCoord().getRbGeografico().isSelected()) {
|
471 |
String name = getPDatum().getTxtNombreCrs().getText();
|
472 |
if (name.equals("")) |
473 |
name = PluginServices.getText(this, "no_name"); |
474 |
cadWkt = "GEOGCS[\"" + name + "\", DATUM[\""+ datum + |
475 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
476 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
477 |
"]]";
|
478 |
if (!isEditing()){
|
479 |
sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
480 |
cadWkt +"','','"+name+"','"+datum+"')"; |
481 |
} else {
|
482 |
sentence = "UPDATE USR SET usr_wkt='" +cadWkt +"'," + |
483 |
"usr_proj='',usr_geog='"+getPDatum().getTxtNombreCrs().getText()+"'," + |
484 |
"usr_datum='"+datum+"' " + |
485 |
"WHERE usr_code = " +authority[1]; |
486 |
} |
487 |
|
488 |
} else {
|
489 |
String name = getPDatum().getTxtNombreCrs().getText();
|
490 |
if (name.equals("")) |
491 |
name = PluginServices.getText(this, "no_name"); |
492 |
String projection = getPSistCoord().getTxtNombreProy().getText();
|
493 |
if (projection.equals("")) |
494 |
projection = PluginServices.getText(this, "no_name"); |
495 |
cadWkt = "PROJCS[\""+projection+
|
496 |
"\", GEOGCS[\"" + name + "\", DATUM[\""+ datum + |
497 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
498 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
499 |
"]], PROJECTION[\""+ getPSistCoord().getProjection(getPSistCoord().getCbProyeccion().getSelectedIndex()) + "\"], "; |
500 |
|
501 |
|
502 |
ArrayList maxValues = null; |
503 |
ArrayList minValues = null; |
504 |
int paramPos = 0; |
505 |
try {
|
506 |
maxValues = getPSistCoord().getProj4().getProj4ProjectionParameterMaxValues(getPSistCoord().getPos()); |
507 |
minValues = getPSistCoord().getProj4().getProj4ProjectionParameterMinValues(getPSistCoord().getPos()); |
508 |
|
509 |
} catch (CrsException e) {
|
510 |
e.printStackTrace(); |
511 |
} |
512 |
/*
|
513 |
* falta la parte de los parámetros... metodo para nombres...
|
514 |
*/
|
515 |
int j=0; |
516 |
for (int i= 0; i< getPSistCoord().getTableParametros().getRowCount();i++){ |
517 |
if (((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).equals("")) { |
518 |
getPSistCoord().getTableParametros().setValueAt("0",i,1); |
519 |
} |
520 |
cadenaNumerica = ((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).replaceAll("[^0-9.E-]", ""); |
521 |
|
522 |
if (((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) { |
523 |
|
524 |
JOptionPane.showMessageDialog(MainPanel.this,
|
525 |
PluginServices.getText(this,"numeric_format")+": Parametro "+(String)(getPSistCoord().getTableParametros().getValueAt(i,0)), |
526 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
527 |
return;
|
528 |
} |
529 |
String condition = (String)getPSistCoord().getTableParametros().getValueAt(i, 0); |
530 |
String param = getPSistCoord().getTrueParametersNames(j);
|
531 |
paramPos = findPositionParameter(param); |
532 |
if (paramPos != -1) { |
533 |
value = Double.parseDouble(cadenaNumerica);
|
534 |
if ((PluginServices.getText(this, condition).trim().equals("semi_major") || (PluginServices.getText(this, condition).trim().equals("semi_minor")))) { |
535 |
continue;
|
536 |
} |
537 |
else if (!(param.trim().equals("semi_major") || param.trim().equals("semi_minor"))) { |
538 |
double maxValue = Double.parseDouble((String)maxValues.get(paramPos)); |
539 |
double minValue = Double.parseDouble((String) minValues.get(paramPos)); |
540 |
if (value > maxValue || value < minValue) {
|
541 |
JOptionPane.showMessageDialog(MainPanel.this,
|
542 |
PluginServices.getText(this,"incorrect_domain")+": Parametro "+(String)(getPSistCoord().getTableParametros().getValueAt(i,0)), |
543 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
544 |
return;
|
545 |
} |
546 |
j++; |
547 |
//paramPos ++;
|
548 |
} |
549 |
|
550 |
value = 0;
|
551 |
unit = "";
|
552 |
/**
|
553 |
* Esto está hecho en general, habrá que hacerlo dependiendo del tipo de
|
554 |
* unidad que tenga el parametro
|
555 |
*/
|
556 |
String type = (String) getPSistCoord().getTableParametros().getValueAt(i, 2); |
557 |
value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1)); |
558 |
/*if (type.equals("Meters")) {
|
559 |
value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1));
|
560 |
unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
561 |
value = getPSistCoord().convert2Meters(unit, value);
|
562 |
}
|
563 |
else if (type.equals("Degree")) {
|
564 |
value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1));
|
565 |
unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
566 |
value = getPSistCoord().convert2Degree(unit, value);
|
567 |
}
|
568 |
else if (type.equals("Unitless")) {
|
569 |
value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1));
|
570 |
unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
571 |
value = getPSistCoord().convert2Unitless(unit, value);
|
572 |
}*/
|
573 |
|
574 |
cadWkt += "PARAMETER[\""+getPSistCoord().getTrueParametersNames(i)+"\", " + |
575 |
value+ "], ";
|
576 |
} else {
|
577 |
j++; |
578 |
} |
579 |
} |
580 |
|
581 |
cadWkt += "UNIT[\"Meters\", 1.0]]";
|
582 |
|
583 |
if (!isEditing()) {
|
584 |
sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
585 |
cadWkt +"','"+projection+"','"+name+"','"+datum+"')"; |
586 |
} |
587 |
else {
|
588 |
sentence = "UPDATE USR SET usr_wkt='" + cadWkt +"'," + |
589 |
"usr_proj='"+projection+"'," + |
590 |
"usr_geog='"+name+"'," + |
591 |
"usr_datum='"+datum+"' " + |
592 |
"WHERE usr_code = " +authority[1]; |
593 |
} |
594 |
} |
595 |
try {
|
596 |
conn.update(sentence); |
597 |
conn.shutdown(); |
598 |
} catch (SQLException e) { |
599 |
e.printStackTrace(); |
600 |
} |
601 |
setNewCrsCode(Integer.parseInt(authority[1])); |
602 |
try {
|
603 |
ICrs crs = new CrsFactory().getCRS("USR:"+authority[1]); |
604 |
crs.getProj4String(); |
605 |
} catch (CrsException e1) {
|
606 |
JOptionPane.showMessageDialog(this, PluginServices.getText(this,e1.getMessage()), "Warning...", |
607 |
JOptionPane.WARNING_MESSAGE);
|
608 |
conn.setConnectionUsr(); |
609 |
sentence = "DELETE FROM USR WHERE usr_code =" + authority[1]; |
610 |
result = Query.select(sentence,conn.getConnection());
|
611 |
try {
|
612 |
conn.shutdown(); |
613 |
} catch (SQLException arg0) { |
614 |
// TODO Auto-generated catch block
|
615 |
arg0.printStackTrace(); |
616 |
} |
617 |
return;
|
618 |
} |
619 |
PluginServices.getMDIManager().closeWindow(this);
|
620 |
} |
621 |
|
622 |
private int findPositionParameter(String param) { |
623 |
ArrayList parameters = new ArrayList(); |
624 |
try {
|
625 |
parameters = getPSistCoord().getProj4().getProj4ProjectionParameters(getPSistCoord().getPos()); |
626 |
int pos = -1; |
627 |
int i = 0; |
628 |
do {
|
629 |
pos = getPSistCoord().getProj4().findProjectionParameters(param, parameters.get(i).toString()); |
630 |
i++; |
631 |
if (i==parameters.size()) break; |
632 |
} while (pos == -1); |
633 |
if (pos!=-1) |
634 |
param = getPSistCoord().getProj4().getProj4ProjectionParameterName(pos); |
635 |
} catch (CrsException e) {
|
636 |
// TODO Auto-generated catch block
|
637 |
e.printStackTrace(); |
638 |
} |
639 |
for (int i=0; i< parameters.size(); i++) { |
640 |
String actualParam = ((String)parameters.get(i)).trim(); |
641 |
if (actualParam.equals(param)) return i; |
642 |
} |
643 |
return -1; |
644 |
} |
645 |
|
646 |
public void setNewCrsCode(int code) { |
647 |
newCrsCode = code; |
648 |
} |
649 |
|
650 |
public int getNewCrsCode() { |
651 |
return newCrsCode;
|
652 |
} |
653 |
|
654 |
private boolean notANumber(String cadenaNumerica) { |
655 |
int puntos = 0; |
656 |
int signos = 0; |
657 |
int letras = 0; |
658 |
for (int i = 0; i< cadenaNumerica.length(); i++) { |
659 |
if (cadenaNumerica.charAt(i) == '.') |
660 |
puntos++; |
661 |
else if (cadenaNumerica.charAt(i) == '-') { |
662 |
if (i==0) { |
663 |
signos++; |
664 |
} |
665 |
else if (i!=0 && cadenaNumerica.charAt(i-1) != 'E') { |
666 |
signos = 2;
|
667 |
} |
668 |
} |
669 |
else if (cadenaNumerica.charAt(i) == 'E') { |
670 |
if (i== 0) { |
671 |
letras = 2;
|
672 |
} |
673 |
else letras ++;
|
674 |
} |
675 |
} |
676 |
|
677 |
if ((letras > 1) || (signos > 1) || (puntos > 1)) |
678 |
return true; |
679 |
return false; |
680 |
} |
681 |
|
682 |
public void setEditing(boolean edit) { |
683 |
this.edit = edit;
|
684 |
} |
685 |
|
686 |
public boolean isEditing() { |
687 |
return this.edit; |
688 |
} |
689 |
|
690 |
public void setEditingPanel() { |
691 |
pCard.setSelectedComponent(getPDatum()); |
692 |
pCard.setEnabledAt(0, false); |
693 |
fillData(getCrs(), true);
|
694 |
getPDatum().getTxtCodigoCrs().setEnabled(false);
|
695 |
|
696 |
} |
697 |
public void stateChanged(ChangeEvent e) { |
698 |
if (e.getSource() == getPCard()) {
|
699 |
if (getPCrsUsr().getHasChanged()) {
|
700 |
if (getPCrsUsr().getRbCrsExistente().isSelected()) {
|
701 |
ICrs crs = getPCrsUsr().getCrs(); |
702 |
if (crs != null) fillData(crs); |
703 |
else fillData(getCrs());
|
704 |
getPCrsUsr().setHasChange(false);
|
705 |
} |
706 |
else if (getPCrsUsr().getRbNuevoCrs().isSelected()) { |
707 |
cleanData(); |
708 |
getPCrsUsr().setHasChange(false);
|
709 |
} |
710 |
else if (getPCrsUsr().getRbCadenaWkt().isSelected()) { |
711 |
cleanData(); |
712 |
if (getPCrsUsr().getTxtAreaWkt().getText().equals("")) { |
713 |
JOptionPane.showMessageDialog(MainPanel.this,
|
714 |
PluginServices.getText(this,"white_Textbox"), |
715 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
716 |
getPCrsUsr().setHasChange(false);
|
717 |
getPCard().setSelectedComponent(getPCrsUsr()); |
718 |
return;
|
719 |
} else {
|
720 |
CoordinateReferenceSystem crs = null;
|
721 |
String wkt = getPCrsUsr().getTxtAreaWkt().getText();
|
722 |
Parser parser = new Parser(); |
723 |
Crs crs2 = null;
|
724 |
try {
|
725 |
crs = parser.parseCoordinateReferenceSystem(wkt); |
726 |
} catch (ParseException e1) { |
727 |
//System.out.println("Cadena WKT no ha podido ser parseada");
|
728 |
//e1.printStackTrace();
|
729 |
JOptionPane.showMessageDialog(MainPanel.this,
|
730 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
731 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
732 |
getPCrsUsr().setHasChange(false);
|
733 |
getPCard().setSelectedComponent(getPCrsUsr()); |
734 |
return;
|
735 |
} catch (UnsupportedOperationException e2) { |
736 |
JOptionPane.showMessageDialog(MainPanel.this,
|
737 |
PluginServices.getText(this, "problem_with_wkt_try_manually"), |
738 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
739 |
getPCrsUsr().setHasChange(false);
|
740 |
getPCard().setSelectedComponent(getPCrsUsr()); |
741 |
return;
|
742 |
} |
743 |
fillData(crs); |
744 |
} |
745 |
getPCrsUsr().setHasChange(false);
|
746 |
} |
747 |
} |
748 |
int i = ((JTabbedPane)e.getSource()).getSelectedIndex(); |
749 |
if (i==0){ |
750 |
getBtnAnterior().setVisible(false);
|
751 |
getBtnSiguiente().setVisible(true);
|
752 |
if (getPCrsUsr().getRbCadenaWkt().isSelected()){
|
753 |
getPCrsUsr().setHasChange(true);
|
754 |
getBtnFinalizar().setVisible(true);
|
755 |
} |
756 |
else
|
757 |
getBtnFinalizar().setVisible(false);
|
758 |
} |
759 |
else if (i==1 && !isEditing()) { |
760 |
getBtnAnterior().setVisible(true);
|
761 |
getBtnSiguiente().setVisible(true);
|
762 |
getBtnFinalizar().setVisible(false);
|
763 |
if (getPCrsUsr().getRbCadenaWkt().isSelected()){
|
764 |
//getPCrsUsr().setHasChange(true);
|
765 |
getBtnFinalizar().setVisible(true);
|
766 |
} |
767 |
} |
768 |
else if (i==1 && isEditing()) { |
769 |
getBtnAnterior().setVisible(false);
|
770 |
getBtnSiguiente().setVisible(true);
|
771 |
getBtnFinalizar().setVisible(false);
|
772 |
} |
773 |
else if (i == 2) { |
774 |
getBtnAnterior().setVisible(true);
|
775 |
getBtnSiguiente().setVisible(false);
|
776 |
getBtnFinalizar().setVisible(true);
|
777 |
} |
778 |
} |
779 |
|
780 |
} |
781 |
public Object getWindowProfile() { |
782 |
return WindowInfo.DIALOG_PROFILE;
|
783 |
} |
784 |
} |