svn-gvsig-desktop / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / MainPanel.java @ 11812
History | View | Annotate | Download (16.5 KB)
1 | 10603 | lmfernandez | package org.gvsig.crs.gui.panels.wizard; |
---|---|---|---|
2 | |||
3 | import java.awt.BorderLayout; |
||
4 | import java.awt.CardLayout; |
||
5 | import java.awt.FlowLayout; |
||
6 | import java.awt.event.ActionEvent; |
||
7 | import java.awt.event.ActionListener; |
||
8 | 11699 | jlgomez | import java.sql.ResultSet; |
9 | 11581 | jlgomez | import java.sql.SQLException; |
10 | 11736 | jlgomez | import java.util.ArrayList; |
11 | 10603 | lmfernandez | |
12 | import javax.swing.JButton; |
||
13 | 11699 | jlgomez | import javax.swing.JOptionPane; |
14 | 10603 | lmfernandez | import javax.swing.JPanel; |
15 | 11764 | lmfernandez | import javax.swing.JTabbedPane; |
16 | 11790 | jlgomez | import javax.swing.event.ChangeEvent; |
17 | import javax.swing.event.ChangeListener; |
||
18 | 10603 | lmfernandez | |
19 | 11736 | jlgomez | import org.gvsig.crs.CrsException; |
20 | 11570 | jlgomez | import org.gvsig.crs.ICrs; |
21 | |||
22 | 10786 | lmfernandez | import com.iver.andami.PluginServices; |
23 | import com.iver.andami.ui.mdiManager.IWindow; |
||
24 | import com.iver.andami.ui.mdiManager.WindowInfo; |
||
25 | 10603 | lmfernandez | |
26 | 11581 | jlgomez | import es.idr.teledeteccion.connection.EpsgConnection; |
27 | 11699 | jlgomez | import es.idr.teledeteccion.connection.Query; |
28 | 10786 | lmfernandez | |
29 | 11581 | jlgomez | |
30 | 10603 | lmfernandez | /**
|
31 | *
|
||
32 | 11570 | jlgomez | * @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
33 | 10603 | lmfernandez | *
|
34 | */
|
||
35 | 11790 | jlgomez | public class MainPanel extends JPanel implements ActionListener, ChangeListener, IWindow { |
36 | 10603 | lmfernandez | |
37 | 10604 | lmfernandez | private static final long serialVersionUID = 1L; |
38 | 11764 | lmfernandez | private JTabbedPane pCard; |
39 | 10603 | lmfernandez | private JPanel pSouth; |
40 | |||
41 | private JButton btnCancelar; |
||
42 | private JButton btnSiguiente; |
||
43 | private JButton btnAnterior; |
||
44 | private JButton btnFinalizar; |
||
45 | |||
46 | private DefCrsUsr pCrsUsr;
|
||
47 | private DefinirDatum pDatum;
|
||
48 | private DefSistCoordenadas pSistCoord;
|
||
49 | 11570 | jlgomez | private ICrs currentCrs;
|
50 | 11629 | jlgomez | private String cadWkt = ""; |
51 | private int newCrsCode = -1; |
||
52 | 11765 | jlgomez | private boolean edit = false; |
53 | 10603 | lmfernandez | |
54 | 11570 | jlgomez | public MainPanel(ICrs crs) {
|
55 | 10603 | lmfernandez | super();
|
56 | 11570 | jlgomez | setCrs(crs); |
57 | 10603 | lmfernandez | this.setLayout(new BorderLayout()); |
58 | this.add(getPCard(),BorderLayout.CENTER); |
||
59 | this.add(getPSouth(),BorderLayout.SOUTH); |
||
60 | } |
||
61 | /**
|
||
62 | 11570 | jlgomez | * Inicilizar el botn Anterior
|
63 | 10603 | lmfernandez | * @return
|
64 | */
|
||
65 | public JButton getBtnAnterior() { |
||
66 | if(btnAnterior==null){ |
||
67 | btnAnterior=new JButton(); |
||
68 | 10787 | lmfernandez | btnAnterior.setText(PluginServices.getText(this,"wz_anterior")); |
69 | 10603 | lmfernandez | btnAnterior.addActionListener(this);
|
70 | |||
71 | } |
||
72 | return btnAnterior;
|
||
73 | } |
||
74 | /**
|
||
75 | 11570 | jlgomez | * Inicilizar el botn Cancelar
|
76 | 10603 | lmfernandez | * @return
|
77 | */
|
||
78 | public JButton getBtnCancelar() { |
||
79 | if(btnCancelar==null){ |
||
80 | btnCancelar=new JButton(); |
||
81 | 10787 | lmfernandez | btnCancelar.setText(PluginServices.getText(this,"wz_cancel")); |
82 | 10603 | lmfernandez | btnCancelar.addActionListener(this);
|
83 | } |
||
84 | return btnCancelar;
|
||
85 | } |
||
86 | /**
|
||
87 | 11570 | jlgomez | * Inicilizar el botn Finalizar
|
88 | 10603 | lmfernandez | * @return
|
89 | */
|
||
90 | public JButton getBtnFinalizar() { |
||
91 | if(btnFinalizar==null){ |
||
92 | btnFinalizar=new JButton(); |
||
93 | 10787 | lmfernandez | btnFinalizar.setText(PluginServices.getText(this,"wz_fin")); |
94 | 10603 | lmfernandez | btnFinalizar.addActionListener(this);
|
95 | } |
||
96 | return btnFinalizar;
|
||
97 | } |
||
98 | /**
|
||
99 | 11570 | jlgomez | * Inicilizar el botn Siguiente
|
100 | 10603 | lmfernandez | * @return
|
101 | */
|
||
102 | public JButton getBtnSiguiente() { |
||
103 | if(btnSiguiente==null){ |
||
104 | btnSiguiente=new JButton(); |
||
105 | 10787 | lmfernandez | btnSiguiente.setText(PluginServices.getText(this,"wz_siguiente")); |
106 | 10603 | lmfernandez | btnSiguiente.addActionListener(this);
|
107 | } |
||
108 | return btnSiguiente;
|
||
109 | } |
||
110 | /**
|
||
111 | * Inicilizar el panel que maneja los subpaneles del asistente
|
||
112 | * @return
|
||
113 | */
|
||
114 | 11764 | lmfernandez | public JTabbedPane getPCard() { |
115 | 10603 | lmfernandez | if(pCard==null){ |
116 | 11769 | lmfernandez | pCard = new JTabbedPane(); |
117 | pCard.addTab(PluginServices.getText(this,"crs_usuario"),getPCrsUsr()); |
||
118 | pCard.addTab(PluginServices.getText(this,"Dat_nDatum"),getPDatum()); |
||
119 | pCard.addTab(PluginServices.getText(this,"SistCoor_titmarco"),getPSistCoord()); |
||
120 | 11765 | jlgomez | //Por defecto se muestra la primera pestaa
|
121 | 11764 | lmfernandez | pCard.setSelectedIndex(0);
|
122 | 11790 | jlgomez | pCard.addChangeListener(this);
|
123 | 10603 | lmfernandez | } |
124 | return pCard;
|
||
125 | } |
||
126 | /**
|
||
127 | * Iniciliza el panel que contiene los botones del asistente
|
||
128 | * @return
|
||
129 | */
|
||
130 | public JPanel getPSouth() { |
||
131 | if(pSouth==null){ |
||
132 | pSouth=new JPanel(); |
||
133 | pSouth.setLayout(new FlowLayout(FlowLayout.RIGHT,5,5)); |
||
134 | pSouth.add(getBtnCancelar()); |
||
135 | pSouth.add(getBtnAnterior()); |
||
136 | pSouth.add(getBtnSiguiente()); |
||
137 | pSouth.add(getBtnFinalizar()); |
||
138 | getBtnFinalizar().setVisible(false);
|
||
139 | 10786 | lmfernandez | getBtnAnterior().setVisible(false);
|
140 | 10603 | lmfernandez | } |
141 | return pSouth;
|
||
142 | } |
||
143 | 10609 | lmfernandez | public DefCrsUsr getPCrsUsr() {
|
144 | if(pCrsUsr==null){ |
||
145 | 11570 | jlgomez | pCrsUsr=new DefCrsUsr(getCrs());
|
146 | 10609 | lmfernandez | } |
147 | return pCrsUsr;
|
||
148 | } |
||
149 | public DefinirDatum getPDatum() {
|
||
150 | if(pDatum==null){ |
||
151 | pDatum=new DefinirDatum();
|
||
152 | } |
||
153 | return pDatum;
|
||
154 | } |
||
155 | public DefSistCoordenadas getPSistCoord() {
|
||
156 | if(pSistCoord==null){ |
||
157 | pSistCoord=new DefSistCoordenadas();
|
||
158 | } |
||
159 | return pSistCoord;
|
||
160 | } |
||
161 | 10603 | lmfernandez | public void actionPerformed(ActionEvent e) { |
162 | 11769 | lmfernandez | |
163 | 10603 | lmfernandez | if(e.getSource().equals(getBtnAnterior())){
|
164 | 11765 | jlgomez | if (getPSistCoord().isShowing() && isEditing()) {
|
165 | getBtnAnterior().setVisible(false);
|
||
166 | } |
||
167 | 11581 | jlgomez | if(getPDatum().isShowing()){
|
168 | //Se va a mostrar el primer panel del Wizard
|
||
169 | 11570 | jlgomez | getBtnAnterior().setVisible(false);
|
170 | 11775 | jlgomez | getPCard().setSelectedComponent(getPCrsUsr()); |
171 | 10603 | lmfernandez | } |
172 | 11775 | jlgomez | else if (getPSistCoord().isShowing()) { |
173 | getPCard().setSelectedComponent(getPDatum()); |
||
174 | } |
||
175 | |||
176 | 11581 | jlgomez | //Establecer los botones del Wizard
|
177 | getBtnFinalizar().setVisible(false);
|
||
178 | getBtnSiguiente().setVisible(true);
|
||
179 | |||
180 | 10603 | lmfernandez | }else if(e.getSource().equals(getBtnSiguiente())){ |
181 | 11570 | jlgomez | if (getPCrsUsr().isShowing() && getPCrsUsr().getRbCrsExistente().isSelected() ){
|
182 | 11669 | jlgomez | ICrs crs = getPCrsUsr().getCrs(); |
183 | if (crs != null){ |
||
184 | fillData(crs); |
||
185 | } |
||
186 | else fillData(getCrs());
|
||
187 | 11570 | jlgomez | } |
188 | 11699 | jlgomez | else if (getPCrsUsr().isShowing() && getPCrsUsr().getRbNuevoCrs().isSelected() ){ |
189 | cleanData(); |
||
190 | } |
||
191 | 11775 | jlgomez | if (getPCrsUsr().isShowing())
|
192 | getPCard().setSelectedComponent(getPDatum()); |
||
193 | else if (getPDatum().isShowing()) |
||
194 | getPCard().setSelectedComponent(getPSistCoord()); |
||
195 | 11764 | lmfernandez | |
196 | 11570 | jlgomez | getBtnAnterior().setVisible(true);
|
197 | //Si aparece el ultimo panel visualizar el botn finalizar
|
||
198 | 11775 | jlgomez | if (getPDatum().isShowing()){
|
199 | 11570 | jlgomez | getBtnFinalizar().setVisible(true);
|
200 | getBtnSiguiente().setVisible(false);
|
||
201 | 10786 | lmfernandez | getBtnAnterior().setVisible(true);
|
202 | 10603 | lmfernandez | } |
203 | }else if(e.getSource().equals(getBtnFinalizar())){ |
||
204 | //Realizar las acciones de fin del Wizard
|
||
205 | 11699 | jlgomez | getDataAndUpdate(); |
206 | 10603 | lmfernandez | }else if(e.getSource().equals(getBtnCancelar())){ |
207 | //Cerrar el asistente
|
||
208 | 10786 | lmfernandez | PluginServices.getMDIManager().closeWindow(this);
|
209 | 10603 | lmfernandez | } |
210 | } |
||
211 | 10786 | lmfernandez | public WindowInfo getWindowInfo() {
|
212 | WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
||
213 | 10787 | lmfernandez | m_viewinfo.setTitle(PluginServices.getText(this,"wz_titulo")); |
214 | 11770 | jlgomez | m_viewinfo.setWidth(560);
|
215 | 10786 | lmfernandez | //m_viewinfo.setHeight(425);
|
216 | 11736 | jlgomez | m_viewinfo.setHeight(400);
|
217 | 10786 | lmfernandez | return m_viewinfo;
|
218 | } |
||
219 | 11570 | jlgomez | |
220 | public ICrs getCrs () {
|
||
221 | return currentCrs;
|
||
222 | } |
||
223 | |||
224 | public void setCrs (ICrs crs) { |
||
225 | currentCrs = crs; |
||
226 | } |
||
227 | |||
228 | |||
229 | |||
230 | 11775 | jlgomez | public void fillData(ICrs crs) { |
231 | 11669 | jlgomez | getPDatum().fillData(crs); |
232 | getPSistCoord().fillData(crs); |
||
233 | 11570 | jlgomez | } |
234 | 11581 | jlgomez | |
235 | 11775 | jlgomez | public void cleanData() { |
236 | 11699 | jlgomez | getPDatum().cleanData(); |
237 | getPSistCoord().cleanData(); |
||
238 | } |
||
239 | |||
240 | 11581 | jlgomez | private void getDataAndUpdate() { |
241 | 11699 | jlgomez | EpsgConnection conn = new EpsgConnection();
|
242 | conn.setConnectionUsr(); |
||
243 | 11752 | jlgomez | String codeCrs = ""; |
244 | 11765 | jlgomez | String sentence;
|
245 | ResultSet result;
|
||
246 | 11752 | jlgomez | |
247 | if (getPDatum().getTxtSemMay().getText().equals("")) { |
||
248 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
249 | PluginServices.getText(this,"white_Textbox")+": Semieje Mayor", |
||
250 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
251 | return;
|
||
252 | 11723 | jlgomez | } |
253 | 11752 | jlgomez | |
254 | if (getPDatum().getTxtLong().getText().equals("")) { |
||
255 | 11709 | jlgomez | JOptionPane.showMessageDialog(MainPanel.this,
|
256 | 11752 | jlgomez | PluginServices.getText(this,"white_Textbox")+": Longitud", |
257 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
258 | return;
|
||
259 | } |
||
260 | |||
261 | if (getPDatum().getTxtCodigoCrs().getText().equals("")) { |
||
262 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
263 | PluginServices.getText(this,"white_Textbox")+": Codigo CRS", |
||
264 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
265 | return;
|
||
266 | } |
||
267 | |||
268 | String cadenaNumerica = getPDatum().getTxtSemMay().getText().replaceAll("[^0-9.E-]", ""); |
||
269 | |||
270 | if (getPDatum().getTxtSemMay().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
||
271 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
272 | 11723 | jlgomez | PluginServices.getText(this,"numeric_format")+": Semieje Mayor", |
273 | 11709 | jlgomez | "Warning...", JOptionPane.WARNING_MESSAGE); |
274 | return;
|
||
275 | 11723 | jlgomez | } |
276 | 11709 | jlgomez | |
277 | 11752 | jlgomez | cadenaNumerica = getPDatum().getTxtLong().getText().replaceAll("[^0-9.E-]", ""); |
278 | |||
279 | if (getPDatum().getTxtLong().getText().length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) {
|
||
280 | |||
281 | 11709 | jlgomez | JOptionPane.showMessageDialog(MainPanel.this,
|
282 | 11723 | jlgomez | PluginServices.getText(this,"numeric_format")+": Longitud", |
283 | 11709 | jlgomez | "Warning...", JOptionPane.WARNING_MESSAGE); |
284 | return;
|
||
285 | } |
||
286 | 11752 | jlgomez | |
287 | codeCrs = getPDatum().getTxtCodigoCrs().getText().replaceAll("[^0-9]", ""); |
||
288 | |||
289 | if (getPDatum().getTxtCodigoCrs().getText().length() != codeCrs.length()) {
|
||
290 | |||
291 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
292 | PluginServices.getText(this,"numeric_format")+": Codigo CRS", |
||
293 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
294 | return;
|
||
295 | } |
||
296 | |||
297 | 11709 | jlgomez | double value = Double.valueOf(getPDatum().getTxtSemMay().getText()).doubleValue(); |
298 | //Comprobar si es numerico, o quedarnos con la parte numerica...
|
||
299 | //searchTextField.getText().length()!=searchTextField.getText().replaceAll("[^0-9]", "").length())
|
||
300 | String unit = (String)getPDatum().getCbSemMay().getSelectedItem(); |
||
301 | double semMay = getPDatum().convert2Meters(unit, value);
|
||
302 | value = Double.valueOf(getPDatum().getTxtLong().getText()).doubleValue();
|
||
303 | unit = (String)getPDatum().getCbLong().getSelectedItem();
|
||
304 | double longitude = getPDatum().convert2Meters(unit, value);
|
||
305 | |||
306 | 11581 | jlgomez | String[] spheroid = {getPDatum().getTxtElipsoide().getText(), |
307 | 11709 | jlgomez | ""+semMay,getPDatum().getTxtInvF().getText()};
|
308 | String[] primem = {getPDatum().getTxtMeridian().getText(), ""+longitude}; |
||
309 | 11581 | jlgomez | |
310 | 11752 | jlgomez | String[] authority = {"\"USR\"", codeCrs}; |
311 | 11765 | jlgomez | if (!isEditing()){
|
312 | sentence = "SELECT usr_code FROM USR WHERE usr_code = " +authority[1]; |
||
313 | result = Query.select(sentence, conn.getConnection());
|
||
314 | try {
|
||
315 | if (result.next()) {
|
||
316 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
317 | PluginServices.getText(this,"crsRepeat")+": "+authority[1], |
||
318 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
319 | return;
|
||
320 | } |
||
321 | } catch (SQLException e1) { |
||
322 | // TODO Auto-generated catch block
|
||
323 | e1.printStackTrace(); |
||
324 | } |
||
325 | 11699 | jlgomez | } |
326 | 11581 | jlgomez | String datum = getPDatum().getTxtDatum().getText();
|
327 | |||
328 | 11699 | jlgomez | |
329 | 11581 | jlgomez | if (getPSistCoord().getRbGeografico().isSelected()) {
|
330 | 11752 | jlgomez | cadWkt = "GEOGCS[\"" + getPDatum().getTxtNombreCrs().getText() + "\", DATUM[\""+ datum + |
331 | 11581 | jlgomez | "\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
332 | "PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
||
333 | "]]";
|
||
334 | 11765 | jlgomez | if (!isEditing()){
|
335 | sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
||
336 | cadWkt +"','','"+getPDatum().getTxtNombreCrs().getText()+"','"+datum+"')"; |
||
337 | } else {
|
||
338 | sentence = "UPDATE USR SET usr_wkt='" +cadWkt +"'," + |
||
339 | "usr_proj='',usr_geog='"+getPDatum().getTxtNombreCrs().getText()+"'," + |
||
340 | "usr_datum='"+datum+"' " + |
||
341 | "WHERE usr_code = " +authority[1]; |
||
342 | } |
||
343 | 11581 | jlgomez | |
344 | } else {
|
||
345 | |||
346 | 11812 | jlgomez | cadWkt = "PROJCS[\""+getPSistCoord().getTxtNombreProy().getText()+
|
347 | 11752 | jlgomez | "\", GEOGCS[\"" + getPDatum().getTxtNombreCrs().getText() + "\", DATUM[\""+ datum + |
348 | 11581 | jlgomez | "\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
349 | "PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
||
350 | "]], PROJECTION[\""+ getPSistCoord().getCbProyeccion().getSelectedItem().toString() + "\"], "; |
||
351 | |||
352 | 11736 | jlgomez | |
353 | ArrayList maxValues = null; |
||
354 | ArrayList minValues = null; |
||
355 | int paramPos = 0; |
||
356 | try {
|
||
357 | maxValues = getPSistCoord().getProj4().getProj4ProjectionParameterMaxValues(getPSistCoord().getPos()); |
||
358 | minValues = getPSistCoord().getProj4().getProj4ProjectionParameterMinValues(getPSistCoord().getPos()); |
||
359 | |||
360 | } catch (CrsException e) {
|
||
361 | e.printStackTrace(); |
||
362 | } |
||
363 | 11581 | jlgomez | /*
|
364 | * falta la parte de los parámetros... metodo para nombres...
|
||
365 | */
|
||
366 | for (int i= 0; i< getPSistCoord().getTableParametros().getRowCount();i++){ |
||
367 | 11752 | jlgomez | if (((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).equals("")) { |
368 | getPSistCoord().getTableParametros().setValueAt("0",i,1); |
||
369 | 11723 | jlgomez | } |
370 | 11752 | jlgomez | cadenaNumerica = ((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).replaceAll("[^0-9.E-]", ""); |
371 | |||
372 | if (((String)(getPSistCoord().getTableParametros().getValueAt(i,1))).length() != cadenaNumerica.length() || notANumber(cadenaNumerica)) { |
||
373 | 11723 | jlgomez | |
374 | 11736 | jlgomez | JOptionPane.showMessageDialog(MainPanel.this,
|
375 | PluginServices.getText(this,"numeric_format")+": Parametro "+(String)(getPSistCoord().getTableParametros().getValueAt(i,0)), |
||
376 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
377 | return;
|
||
378 | 11723 | jlgomez | } |
379 | 11736 | jlgomez | String param = (String)getPSistCoord().getTableParametros().getValueAt(i, 0); |
380 | value = Double.parseDouble(cadenaNumerica);
|
||
381 | if (!(param.trim().equals("semi_major") || param.trim().equals("semi_minor"))) { |
||
382 | double maxValue = Double.parseDouble((String)maxValues.get(paramPos)); |
||
383 | double minValue = Double.parseDouble((String) minValues.get(paramPos)); |
||
384 | if (value > maxValue || value < minValue) {
|
||
385 | JOptionPane.showMessageDialog(MainPanel.this,
|
||
386 | PluginServices.getText(this,"incorrect_domain")+": Parametro "+(String)(getPSistCoord().getTableParametros().getValueAt(i,0)), |
||
387 | "Warning...", JOptionPane.WARNING_MESSAGE); |
||
388 | return;
|
||
389 | } |
||
390 | paramPos ++; |
||
391 | } |
||
392 | 11765 | jlgomez | |
393 | 11709 | jlgomez | value = 0;
|
394 | unit = "";
|
||
395 | /**
|
||
396 | * Esto está hecho en general, habrá que hacerlo dependiendo del tipo de
|
||
397 | * unidad que tenga el parametro
|
||
398 | */
|
||
399 | String type = (String) getPSistCoord().getTableParametros().getValueAt(i, 2); |
||
400 | if (type.equals("Meters")) { |
||
401 | value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1)); |
||
402 | unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
||
403 | value = getPSistCoord().convert2Meters(unit, value); |
||
404 | } |
||
405 | else if (type.equals("Degree")) { |
||
406 | value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1)); |
||
407 | unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
||
408 | value = getPSistCoord().convert2Degree(unit, value); |
||
409 | } |
||
410 | else if (type.equals("Unitless")) { |
||
411 | value = Double.parseDouble((String)getPSistCoord().getTableParametros().getValueAt(i, 1)); |
||
412 | unit = (String)getPSistCoord().getCbUnits().getSelectedItem();
|
||
413 | value = getPSistCoord().convert2Unitless(unit, value); |
||
414 | } |
||
415 | 11581 | jlgomez | cadWkt += "PARAMETER[\""+getPSistCoord().getTableParametros().getValueAt(i, 0)+"\", " + |
416 | 11709 | jlgomez | value+ "], ";
|
417 | 11581 | jlgomez | } |
418 | |||
419 | cadWkt += "UNIT[\"Meters\", 1.0]]";
|
||
420 | |||
421 | 11765 | jlgomez | if (!isEditing()) {
|
422 | sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
||
423 | 11812 | jlgomez | cadWkt +"','"+getPSistCoord().getTxtNombreProy().getText()+"','"+getPDatum().getTxtNombreCrs().getText()+"','"+datum+"')"; |
424 | 11765 | jlgomez | } |
425 | else {
|
||
426 | sentence = "UPDATE USR SET usr_wkt='" + cadWkt +"'," + |
||
427 | 11812 | jlgomez | "usr_proj='"+getPSistCoord().getTxtNombreProy().getText()+"'," + |
428 | 11765 | jlgomez | "usr_geog='"+getPDatum().getTxtNombreCrs().getText()+"'," + |
429 | "usr_datum='"+datum+"' " + |
||
430 | "WHERE usr_code = " +authority[1]; |
||
431 | } |
||
432 | 11699 | jlgomez | } |
433 | 11581 | jlgomez | |
434 | try {
|
||
435 | conn.update(sentence); |
||
436 | conn.shutdown(); |
||
437 | } catch (SQLException e) { |
||
438 | e.printStackTrace(); |
||
439 | 11699 | jlgomez | } |
440 | 11581 | jlgomez | setNewCrsCode(Integer.parseInt(authority[1])); |
441 | 11699 | jlgomez | PluginServices.getMDIManager().closeWindow(this);
|
442 | 11581 | jlgomez | } |
443 | |||
444 | public void setNewCrsCode(int code) { |
||
445 | newCrsCode = code; |
||
446 | } |
||
447 | |||
448 | public int getNewCrsCode() { |
||
449 | return newCrsCode;
|
||
450 | } |
||
451 | |||
452 | 11752 | jlgomez | private boolean notANumber(String cadenaNumerica) { |
453 | int puntos = 0; |
||
454 | int signos = 0; |
||
455 | int letras = 0; |
||
456 | for (int i = 0; i< cadenaNumerica.length(); i++) { |
||
457 | if (cadenaNumerica.charAt(i) == '.') |
||
458 | puntos++; |
||
459 | else if (cadenaNumerica.charAt(i) == '-') { |
||
460 | if (i==0) { |
||
461 | signos++; |
||
462 | } |
||
463 | else if (i!=0 && cadenaNumerica.charAt(i-1) != 'E') { |
||
464 | signos = 2;
|
||
465 | } |
||
466 | } |
||
467 | else if (cadenaNumerica.charAt(i) == 'E') { |
||
468 | if (i== 0) { |
||
469 | letras = 2;
|
||
470 | } |
||
471 | else letras ++;
|
||
472 | } |
||
473 | } |
||
474 | |||
475 | if ((letras > 1) || (signos > 1) || (puntos > 1)) |
||
476 | return true; |
||
477 | return false; |
||
478 | } |
||
479 | |||
480 | 11765 | jlgomez | public void setEditing(boolean edit) { |
481 | this.edit = edit;
|
||
482 | } |
||
483 | |||
484 | public boolean isEditing() { |
||
485 | return this.edit; |
||
486 | } |
||
487 | |||
488 | public void setEditingPanel() { |
||
489 | 11775 | jlgomez | pCard.setSelectedComponent(getPDatum()); |
490 | pCard.setEnabledAt(0, false); |
||
491 | 11765 | jlgomez | fillData(getCrs()); |
492 | getPDatum().getTxtCodigoCrs().setEnabled(false);
|
||
493 | 11775 | jlgomez | |
494 | 11765 | jlgomez | } |
495 | 11790 | jlgomez | public void stateChanged(ChangeEvent e) { |
496 | if (e.getSource() == getPCard()) {
|
||
497 | 11812 | jlgomez | if (getPCrsUsr().getHasChanged()) {
|
498 | if (getPCrsUsr().getRbCrsExistente().isSelected()) {
|
||
499 | ICrs crs = getPCrsUsr().getCrs(); |
||
500 | if (crs != null) fillData(crs); |
||
501 | else fillData(getCrs());
|
||
502 | getPCrsUsr().setHasChange(false);
|
||
503 | } |
||
504 | else if (getPCrsUsr().getRbNuevoCrs().isSelected()) { |
||
505 | cleanData(); |
||
506 | getPCrsUsr().setHasChange(false);
|
||
507 | } |
||
508 | } |
||
509 | 11790 | jlgomez | int i = ((JTabbedPane)e.getSource()).getSelectedIndex(); |
510 | if (i==0){ |
||
511 | getBtnAnterior().setVisible(false);
|
||
512 | getBtnSiguiente().setVisible(true);
|
||
513 | getBtnFinalizar().setVisible(false);
|
||
514 | } |
||
515 | 11812 | jlgomez | else if (i==1 && !isEditing()) { |
516 | 11790 | jlgomez | getBtnAnterior().setVisible(true);
|
517 | getBtnSiguiente().setVisible(true);
|
||
518 | getBtnFinalizar().setVisible(false);
|
||
519 | } |
||
520 | 11812 | jlgomez | else if (i==1 && isEditing()) { |
521 | getBtnAnterior().setVisible(false);
|
||
522 | getBtnSiguiente().setVisible(true);
|
||
523 | getBtnFinalizar().setVisible(false);
|
||
524 | } |
||
525 | 11790 | jlgomez | else if (i == 2) { |
526 | getBtnAnterior().setVisible(true);
|
||
527 | getBtnSiguiente().setVisible(false);
|
||
528 | getBtnFinalizar().setVisible(true);
|
||
529 | } |
||
530 | } |
||
531 | |||
532 | } |
||
533 | 11765 | jlgomez | |
534 | 10603 | lmfernandez | } |