svn-gvsig-desktop / branches / F2 / extensions / extJCRS / src / org / gvsig / crs / gui / panels / wizard / MainPanel.java @ 11699
History | View | Annotate | Download (8.4 KB)
1 |
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 |
import java.sql.ResultSet; |
9 |
import java.sql.SQLException; |
10 |
|
11 |
import javax.swing.JButton; |
12 |
import javax.swing.JOptionPane; |
13 |
import javax.swing.JPanel; |
14 |
|
15 |
import org.gvsig.crs.ICrs; |
16 |
import org.gvsig.crs.gui.panels.EPSGpanel; |
17 |
|
18 |
import com.iver.andami.PluginServices; |
19 |
import com.iver.andami.ui.mdiManager.IWindow; |
20 |
import com.iver.andami.ui.mdiManager.WindowInfo; |
21 |
|
22 |
import es.idr.teledeteccion.connection.EpsgConnection; |
23 |
import es.idr.teledeteccion.connection.Query; |
24 |
|
25 |
|
26 |
/**
|
27 |
*
|
28 |
* @author Luisa Marina Fernndez (luisam.fernandez@uclm.es)
|
29 |
*
|
30 |
*/
|
31 |
public class MainPanel extends JPanel implements ActionListener,IWindow { |
32 |
|
33 |
private static final long serialVersionUID = 1L; |
34 |
private JPanel pCard; |
35 |
private JPanel pSouth; |
36 |
|
37 |
private JButton btnCancelar; |
38 |
private JButton btnSiguiente; |
39 |
private JButton btnAnterior; |
40 |
private JButton btnFinalizar; |
41 |
|
42 |
private DefCrsUsr pCrsUsr;
|
43 |
private DefinirDatum pDatum;
|
44 |
private DefSistCoordenadas pSistCoord;
|
45 |
|
46 |
final static String CRSUSUARIOPANEL = "CrsUsuario"; |
47 |
final static String DEFINIRDATUMPANEL = "DefinirDatum"; |
48 |
final static String SISTEMACOORDENADASPANEL = "SistemaCoordenadas"; |
49 |
|
50 |
private ICrs currentCrs;
|
51 |
private String cadWkt = ""; |
52 |
private int newCrsCode = -1; |
53 |
|
54 |
public MainPanel(ICrs crs) {
|
55 |
super();
|
56 |
setCrs(crs); |
57 |
this.setLayout(new BorderLayout()); |
58 |
this.add(getPCard(),BorderLayout.CENTER); |
59 |
this.add(getPSouth(),BorderLayout.SOUTH); |
60 |
} |
61 |
/**
|
62 |
* Inicilizar el botn Anterior
|
63 |
* @return
|
64 |
*/
|
65 |
public JButton getBtnAnterior() { |
66 |
if(btnAnterior==null){ |
67 |
btnAnterior=new JButton(); |
68 |
btnAnterior.setText(PluginServices.getText(this,"wz_anterior")); |
69 |
btnAnterior.addActionListener(this);
|
70 |
|
71 |
} |
72 |
return btnAnterior;
|
73 |
} |
74 |
/**
|
75 |
* Inicilizar el botn Cancelar
|
76 |
* @return
|
77 |
*/
|
78 |
public JButton getBtnCancelar() { |
79 |
if(btnCancelar==null){ |
80 |
btnCancelar=new JButton(); |
81 |
btnCancelar.setText(PluginServices.getText(this,"wz_cancel")); |
82 |
btnCancelar.addActionListener(this);
|
83 |
} |
84 |
return btnCancelar;
|
85 |
} |
86 |
/**
|
87 |
* Inicilizar el botn Finalizar
|
88 |
* @return
|
89 |
*/
|
90 |
public JButton getBtnFinalizar() { |
91 |
if(btnFinalizar==null){ |
92 |
btnFinalizar=new JButton(); |
93 |
btnFinalizar.setText(PluginServices.getText(this,"wz_fin")); |
94 |
btnFinalizar.addActionListener(this);
|
95 |
} |
96 |
return btnFinalizar;
|
97 |
} |
98 |
/**
|
99 |
* Inicilizar el botn Siguiente
|
100 |
* @return
|
101 |
*/
|
102 |
public JButton getBtnSiguiente() { |
103 |
if(btnSiguiente==null){ |
104 |
btnSiguiente=new JButton(); |
105 |
btnSiguiente.setText(PluginServices.getText(this,"wz_siguiente")); |
106 |
btnSiguiente.addActionListener(this);
|
107 |
} |
108 |
return btnSiguiente;
|
109 |
} |
110 |
/**
|
111 |
* Inicilizar el panel que maneja los subpaneles del asistente
|
112 |
* @return
|
113 |
*/
|
114 |
public JPanel getPCard() { |
115 |
if(pCard==null){ |
116 |
pCard=new JPanel(); |
117 |
pCard.setLayout(new CardLayout()); |
118 |
|
119 |
pCard.add(CRSUSUARIOPANEL,getPCrsUsr()); |
120 |
pCard.add(DEFINIRDATUMPANEL,getPDatum()); |
121 |
pCard.add(SISTEMACOORDENADASPANEL,getPSistCoord()); |
122 |
|
123 |
} |
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 |
getBtnAnterior().setVisible(false);
|
140 |
} |
141 |
return pSouth;
|
142 |
} |
143 |
public DefCrsUsr getPCrsUsr() {
|
144 |
if(pCrsUsr==null){ |
145 |
pCrsUsr=new DefCrsUsr(getCrs());
|
146 |
} |
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 |
public void actionPerformed(ActionEvent e) { |
162 |
|
163 |
CardLayout cl = (CardLayout)(pCard.getLayout()); |
164 |
|
165 |
if(e.getSource().equals(getBtnAnterior())){
|
166 |
|
167 |
if(getPDatum().isShowing()){
|
168 |
//Se va a mostrar el primer panel del Wizard
|
169 |
getBtnAnterior().setVisible(false);
|
170 |
} |
171 |
//Mostrar el panel anterior
|
172 |
cl.previous(pCard); |
173 |
//Establecer los botones del Wizard
|
174 |
getBtnFinalizar().setVisible(false);
|
175 |
getBtnSiguiente().setVisible(true);
|
176 |
|
177 |
}else if(e.getSource().equals(getBtnSiguiente())){ |
178 |
if (getPCrsUsr().isShowing() && getPCrsUsr().getRbCrsExistente().isSelected() ){
|
179 |
ICrs crs = getPCrsUsr().getCrs(); |
180 |
if (crs != null){ |
181 |
fillData(crs); |
182 |
} |
183 |
else fillData(getCrs());
|
184 |
} |
185 |
else if (getPCrsUsr().isShowing() && getPCrsUsr().getRbNuevoCrs().isSelected() ){ |
186 |
cleanData(); |
187 |
} |
188 |
cl.next(pCard); |
189 |
getBtnAnterior().setVisible(true);
|
190 |
//Si aparece el ultimo panel visualizar el botn finalizar
|
191 |
if (getPSistCoord().isShowing()){
|
192 |
getBtnFinalizar().setVisible(true);
|
193 |
getBtnSiguiente().setVisible(false);
|
194 |
getBtnAnterior().setVisible(true);
|
195 |
} |
196 |
|
197 |
|
198 |
}else if(e.getSource().equals(getBtnFinalizar())){ |
199 |
//Realizar las acciones de fin del Wizard
|
200 |
getDataAndUpdate(); |
201 |
}else if(e.getSource().equals(getBtnCancelar())){ |
202 |
//Cerrar el asistente
|
203 |
PluginServices.getMDIManager().closeWindow(this);
|
204 |
} |
205 |
} |
206 |
public WindowInfo getWindowInfo() {
|
207 |
WindowInfo m_viewinfo=new WindowInfo(WindowInfo.MODALDIALOG);
|
208 |
m_viewinfo.setTitle(PluginServices.getText(this,"wz_titulo")); |
209 |
m_viewinfo.setWidth(444);
|
210 |
//m_viewinfo.setHeight(425);
|
211 |
m_viewinfo.setHeight(390);
|
212 |
return m_viewinfo;
|
213 |
} |
214 |
|
215 |
public ICrs getCrs () {
|
216 |
return currentCrs;
|
217 |
} |
218 |
|
219 |
public void setCrs (ICrs crs) { |
220 |
currentCrs = crs; |
221 |
} |
222 |
|
223 |
|
224 |
|
225 |
private void fillData(ICrs crs) { |
226 |
getPDatum().fillData(crs); |
227 |
getPSistCoord().fillData(crs); |
228 |
} |
229 |
|
230 |
private void cleanData() { |
231 |
getPDatum().cleanData(); |
232 |
getPSistCoord().cleanData(); |
233 |
} |
234 |
|
235 |
private void getDataAndUpdate() { |
236 |
EpsgConnection conn = new EpsgConnection();
|
237 |
conn.setConnectionUsr(); |
238 |
String[] spheroid = {getPDatum().getTxtElipsoide().getText(), |
239 |
getPDatum().getTxtSemMay().getText(), |
240 |
getPDatum().getTxtInvF().getText()}; |
241 |
String[] primem = {getPDatum().getTxtMeridian().getText(), |
242 |
getPDatum().getTxtLong().getText()}; |
243 |
|
244 |
String[] authority = {"\"USR\"", "2001"}; |
245 |
String sentence = "SELECT usr_code FROM USR WHERE usr_code = " +authority[1]; |
246 |
ResultSet result = Query.select(sentence, conn.getConnection()); |
247 |
try {
|
248 |
if (result.next()) {
|
249 |
JOptionPane.showMessageDialog(MainPanel.this,
|
250 |
PluginServices.getText(this,"crsRepeat")+": "+authority[1], |
251 |
"Warning...", JOptionPane.WARNING_MESSAGE); |
252 |
return;
|
253 |
} |
254 |
} catch (SQLException e1) { |
255 |
// TODO Auto-generated catch block
|
256 |
e1.printStackTrace(); |
257 |
} |
258 |
String datum = getPDatum().getTxtDatum().getText();
|
259 |
|
260 |
|
261 |
if (getPSistCoord().getRbGeografico().isSelected()) {
|
262 |
cadWkt = "GEOGCS[\"" + "Nombre crs usuario" + "\", DATUM[\""+ datum + |
263 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
264 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
265 |
"]]";
|
266 |
|
267 |
sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
268 |
cadWkt +"','','Nombre crs usuario','"+datum+"')"; |
269 |
|
270 |
} else {
|
271 |
|
272 |
cadWkt = "PROJCS[\""+ "crs proyectado usuario"/*A cambiar cuando arreglemos paneles*/+ |
273 |
"\", GEOGCS[\"" + "Nombre crs usuario" + "\", DATUM[\""+ datum + |
274 |
"\", SPHEROID[\""+ spheroid[0] + "\", "+ spheroid[1] + ", "+ spheroid[2] +"]], " + |
275 |
"PRIMEM[\""+ primem[0] + "\", "+ primem[1] +"], UNIT[\"Degree\", " + (Math.PI/180) + |
276 |
"]], PROJECTION[\""+ getPSistCoord().getCbProyeccion().getSelectedItem().toString() + "\"], "; |
277 |
|
278 |
/*
|
279 |
* falta la parte de los parĂ¡metros... metodo para nombres...
|
280 |
*/
|
281 |
for (int i= 0; i< getPSistCoord().getTableParametros().getRowCount();i++){ |
282 |
cadWkt += "PARAMETER[\""+getPSistCoord().getTableParametros().getValueAt(i, 0)+"\", " + |
283 |
getPSistCoord().getTableParametros().getValueAt(i, 1)+ "], "; |
284 |
} |
285 |
|
286 |
cadWkt += "UNIT[\"Meters\", 1.0]]";
|
287 |
|
288 |
|
289 |
sentence = "INSERT INTO USR VALUES("+authority[1]+",'" + |
290 |
cadWkt +"','crs proyectado usuario','Nombre crs usuario','"+datum+"')"; |
291 |
|
292 |
} |
293 |
|
294 |
try {
|
295 |
conn.update(sentence); |
296 |
conn.shutdown(); |
297 |
} catch (SQLException e) { |
298 |
// TODO Auto-generated catch block
|
299 |
e.printStackTrace(); |
300 |
} |
301 |
setNewCrsCode(Integer.parseInt(authority[1])); |
302 |
PluginServices.getMDIManager().closeWindow(this);
|
303 |
} |
304 |
|
305 |
public void setNewCrsCode(int code) { |
306 |
newCrsCode = code; |
307 |
} |
308 |
|
309 |
public int getNewCrsCode() { |
310 |
return newCrsCode;
|
311 |
} |
312 |
|
313 |
} |