svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / dialog / WCSPropsDialog.java @ 4615
History | View | Annotate | Download (10.9 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. 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 |
* IVER T.I. S.A
|
34 |
* Salamanca 50
|
35 |
* 46005 Valencia
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 963163400
|
39 |
* dac@iver.es
|
40 |
*/
|
41 |
package com.iver.cit.gvsig.gui.dialog; |
42 |
|
43 |
import java.awt.Rectangle; |
44 |
import java.awt.event.ActionEvent; |
45 |
import java.awt.event.ActionListener; |
46 |
import java.net.URL; |
47 |
import java.util.Hashtable; |
48 |
|
49 |
import javax.swing.JButton; |
50 |
import javax.swing.JDialog; |
51 |
import javax.swing.JOptionPane; |
52 |
import javax.swing.JPanel; |
53 |
|
54 |
import com.iver.andami.PluginServices; |
55 |
import com.iver.andami.ui.mdiManager.View; |
56 |
import com.iver.andami.ui.mdiManager.ViewInfo; |
57 |
import com.iver.cit.gvsig.fmap.DriverException; |
58 |
import com.iver.cit.gvsig.fmap.MapControl; |
59 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLyrWCS; |
61 |
import com.iver.cit.gvsig.gui.panels.WCSParamsPanel; |
62 |
import com.iver.cit.gvsig.gui.wcs.WCSWizardData; |
63 |
import com.iver.cit.gvsig.gui.wizards.WizardListener; |
64 |
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport; |
65 |
|
66 |
/**
|
67 |
* @author jaume - jaume.dominguez@iver.es
|
68 |
*
|
69 |
*/
|
70 |
public class WCSPropsDialog extends JPanel implements View { |
71 |
JDialog dlg = null; // @jve:decl-index=0:visual-constraint="10,20" |
72 |
private JPanel buttonsPanel = null; |
73 |
//private FLyrDefault fLayer = null;
|
74 |
private FLayer fLayer = null; |
75 |
boolean applied;
|
76 |
private ViewInfo m_ViewInfo = null; |
77 |
|
78 |
private JButton btnApply = null; |
79 |
private JButton btnOk = null; |
80 |
private JButton btnCancel = null; |
81 |
private WCSParamsPanel wcsParamsTabbedPane;
|
82 |
private ComandosListener m_actionListener;
|
83 |
|
84 |
public WCSPropsDialog(FLayer layer) {
|
85 |
super();
|
86 |
initialize(layer); |
87 |
} |
88 |
|
89 |
|
90 |
private void initialize(FLayer layer) { |
91 |
setBounds(0,0,500,333); |
92 |
setLayout(null);
|
93 |
|
94 |
setFLayer(layer); |
95 |
wcsParamsTabbedPane = getParamsPanel(((FLyrWCS) layer).getProperties()); |
96 |
wcsParamsTabbedPane.addWizardListener(new WizardListener(){
|
97 |
|
98 |
public void wizardStateChanged(boolean finishable) { |
99 |
getBtnOk().setEnabled(finishable); |
100 |
getBtnApply().setEnabled(finishable); |
101 |
} |
102 |
|
103 |
public void error(Exception e) { |
104 |
} |
105 |
|
106 |
}) ; |
107 |
|
108 |
this.add(wcsParamsTabbedPane);
|
109 |
this.add(getButtonsPanel(), null); |
110 |
} |
111 |
|
112 |
|
113 |
public void setFLayer(FLayer f) { |
114 |
fLayer = f; |
115 |
} |
116 |
|
117 |
/**
|
118 |
* With getParamsPanel we have access to the coverage config TabbedPane.
|
119 |
* If this panel doesn't exist yet (which can occur when an existing project is
|
120 |
* recovered) it is been automatically constructed by connecting to the server,
|
121 |
* reloading the necessary data, filling up the content and setting the selected
|
122 |
* values that were selected when the projet was saved.
|
123 |
*
|
124 |
* Since a connection to the server is needed when rebuiliding the panel, this
|
125 |
* causes a delay for the panel's showing up or a nullPointer error if there is
|
126 |
* no path to the server.
|
127 |
*
|
128 |
*
|
129 |
* Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
|
130 |
* de la cobertura. Si este panel todav?a no existe (como puede ser cuando
|
131 |
* recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
|
132 |
* al servidor, recuperando los datos necesarios, rellenando el contenido y
|
133 |
* dejando seleccionados los valores que estaban seleccionados cuando se
|
134 |
* guard? el proyecto.
|
135 |
*
|
136 |
* Como para reconstruirse requiere una conexi?n con el servidor esto causa
|
137 |
* un retardo en la aparici?n en el toc o un error de nullPointer si no
|
138 |
* hay conexi?n hasta el servidor.
|
139 |
*
|
140 |
* @return WCSParamsPanel
|
141 |
*/
|
142 |
public WCSParamsPanel getParamsPanel(Hashtable info) { |
143 |
try {
|
144 |
|
145 |
URL host = (URL) info.get("host"); |
146 |
WCSWizardData dataSource = new WCSWizardData();
|
147 |
dataSource.setHost(host); |
148 |
|
149 |
WCSParamsPanel toc = new WCSParamsPanel();
|
150 |
toc.setVisible(true);
|
151 |
toc.setListenerSupport(new WizardListenerSupport());
|
152 |
|
153 |
toc.setDataSource(dataSource); |
154 |
|
155 |
toc.getLstCoverages().setListData(dataSource.getCoverageList()); |
156 |
|
157 |
String coverageName = (String) info.get("name"); |
158 |
int index = toc.getCoverageIndex( coverageName );
|
159 |
if (index != -1) |
160 |
toc.getLstCoverages().setSelectedIndex(index); |
161 |
|
162 |
toc.refreshData(); |
163 |
|
164 |
index = toc.getSRSIndex((String) info.get("crs") ); |
165 |
if (index != -1) |
166 |
toc.getLstCRSs().setSelectedIndex(index); |
167 |
index = toc.getFormatIndex((String) info.get("format")); |
168 |
if (index != -1) |
169 |
toc.getLstFormats().setSelectedIndex(index); |
170 |
String time = (String) info.get("time"); |
171 |
if (!time.equals("")) |
172 |
toc.getLstSelectedTimes().setListData(time.split("=")[1].split(",")); |
173 |
String parameter = (String) info.get("parameter"); |
174 |
if (!parameter.equals("")){ |
175 |
String[] s = parameter.split("="); |
176 |
String pName = s[0]; |
177 |
|
178 |
String regexDouble = "-?[0-9]+(\\.[0-9]+)?"; |
179 |
String regexInterval = regexDouble+"/"+regexDouble; |
180 |
String regexIntervalList = regexInterval+"(,"+regexInterval+")*"; |
181 |
if (s[1].matches(regexInterval)){ |
182 |
// Single Interval
|
183 |
toc.getJScrollPane5().setVisible(false);
|
184 |
toc.getSingleParamValuesList().setEnabled(false);
|
185 |
|
186 |
|
187 |
} else if (s[1].matches(regexIntervalList)){ |
188 |
// Multiple Interval
|
189 |
|
190 |
} else {
|
191 |
// Single values
|
192 |
toc.getJScrollPane5().setVisible(true);
|
193 |
toc.getSingleParamValuesList().setEnabled(true);
|
194 |
|
195 |
String[] pVals = s[1].split(","); |
196 |
index = toc.getParamIndex(pName); |
197 |
toc.getCmbParam().setSelectedIndex(index); |
198 |
//toc.refreshParamValues( coverageName );
|
199 |
int[] indexes = new int[pVals.length]; |
200 |
for (int i = 0; i < pVals.length; i++) { |
201 |
indexes[i] = toc.getValueIndex(pVals[i]); |
202 |
} |
203 |
|
204 |
toc.getSingleParamValuesList().setSelectedIndices(indexes); |
205 |
} |
206 |
} |
207 |
toc.refreshInfo(); |
208 |
return toc;
|
209 |
} catch (DriverException soe) {
|
210 |
JOptionPane.showMessageDialog(null, "servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE); |
211 |
} catch (Exception e) { |
212 |
e.printStackTrace(); |
213 |
} |
214 |
return null; |
215 |
} |
216 |
|
217 |
public JPanel getButtonsPanel() { |
218 |
if (buttonsPanel == null) { |
219 |
m_actionListener = new ComandosListener(this); |
220 |
buttonsPanel = new JPanel(); |
221 |
buttonsPanel.setBounds(5, wcsParamsTabbedPane.getHeight(), 471, 40); |
222 |
buttonsPanel.setLayout(null);
|
223 |
buttonsPanel.setName("buttonPanel");
|
224 |
|
225 |
buttonsPanel.add(getBtnOk(), null);
|
226 |
buttonsPanel.add(getBtnApply(), null);
|
227 |
buttonsPanel.add(getBtnCancel(), null);
|
228 |
} |
229 |
return buttonsPanel;
|
230 |
} |
231 |
|
232 |
public JButton getBtnOk() { |
233 |
if (btnOk == null) { |
234 |
btnOk = new JButton("Ok"); |
235 |
btnOk.setText(PluginServices.getText(this,"Ok")); |
236 |
btnOk.setActionCommand("OK");
|
237 |
btnOk.addActionListener(m_actionListener); |
238 |
btnOk.setBounds(367, 9, 90, 25); |
239 |
} |
240 |
return btnOk;
|
241 |
} |
242 |
|
243 |
public JButton getBtnApply() { |
244 |
if (btnApply == null) { |
245 |
btnApply = new JButton("Apply"); |
246 |
btnApply.setText(PluginServices.getText(this,"Apply")); |
247 |
btnApply.setEnabled(false);
|
248 |
btnApply.setActionCommand("APPLY");
|
249 |
btnApply.addActionListener(m_actionListener); |
250 |
btnApply.setBounds(267, 9, 90, 25); |
251 |
} |
252 |
return btnApply;
|
253 |
} |
254 |
|
255 |
public JButton getBtnCancel() { |
256 |
if (btnCancel == null) { |
257 |
btnCancel = new JButton("Cancel"); |
258 |
btnCancel.setText(PluginServices.getText(this,"Cancel")); |
259 |
btnCancel.setActionCommand("CANCEL");
|
260 |
btnCancel.addActionListener(m_actionListener); |
261 |
btnCancel.setBounds(137, 9, 90, 25); |
262 |
} |
263 |
return btnCancel;
|
264 |
} |
265 |
|
266 |
private class ComandosListener implements ActionListener { |
267 |
private WCSPropsDialog m_tp;
|
268 |
|
269 |
/**
|
270 |
* Creates a new ComandosListener object.
|
271 |
*
|
272 |
* @param lg DOCUMENT ME!
|
273 |
*/
|
274 |
public ComandosListener(WCSPropsDialog tp) {
|
275 |
m_tp = tp; |
276 |
} |
277 |
|
278 |
/* (non-Javadoc)
|
279 |
* @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
|
280 |
*/
|
281 |
public void actionPerformed(ActionEvent e) { |
282 |
if (e.getActionCommand() == "CANCEL") { |
283 |
close(); |
284 |
} else {
|
285 |
applied = false;
|
286 |
|
287 |
((FLyrWCS) fLayer).setCoverageName(wcsParamsTabbedPane.getCurrentCoverageName()); |
288 |
((FLyrWCS) fLayer).setName(wcsParamsTabbedPane.getCoverageName()); |
289 |
((FLyrWCS) fLayer).setSRS(wcsParamsTabbedPane.getSRS()); |
290 |
((FLyrWCS) fLayer).setFormat(wcsParamsTabbedPane.getFormat()); |
291 |
((FLyrWCS) fLayer).setFullExtent(wcsParamsTabbedPane.getExtent()); |
292 |
((FLyrWCS) fLayer).setTime(wcsParamsTabbedPane.getTime()); |
293 |
((FLyrWCS) fLayer).setParameter(wcsParamsTabbedPane.getParameterString()); |
294 |
|
295 |
if (e.getActionCommand() == "APPLY") { |
296 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
297 |
MapControl mapCtrl = vista.getMapControl(); |
298 |
mapCtrl.getMapContext().invalidate(); |
299 |
applied = true;
|
300 |
getBtnApply().setEnabled(!applied); |
301 |
} |
302 |
|
303 |
if (e.getActionCommand() == "OK") { |
304 |
if (!applied) {
|
305 |
com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView(); |
306 |
MapControl mapCtrl = vista.getMapControl(); |
307 |
mapCtrl.getMapContext().invalidate(); |
308 |
} |
309 |
close(); |
310 |
} |
311 |
} |
312 |
} |
313 |
} |
314 |
|
315 |
public ViewInfo getViewInfo() {
|
316 |
if (m_ViewInfo==null){ |
317 |
m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
|
318 |
m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WCS_layer")); |
319 |
m_ViewInfo.setWidth(wcsParamsTabbedPane.getWidth()+10);
|
320 |
m_ViewInfo.setHeight(wcsParamsTabbedPane.getHeight()+40);
|
321 |
} |
322 |
return m_ViewInfo;
|
323 |
} |
324 |
|
325 |
public void viewActivated() { |
326 |
} |
327 |
|
328 |
public void openWCSPropertiesDialog() { |
329 |
if (PluginServices.getMainFrame() == null) { |
330 |
dlg = new JDialog(); |
331 |
Rectangle bnds = getBounds();
|
332 |
bnds.width += 10;
|
333 |
bnds.height += 33;
|
334 |
dlg.setBounds(bnds); |
335 |
dlg.setSize(getSize()); |
336 |
dlg.getContentPane().add(this);
|
337 |
dlg.setModal(true);
|
338 |
dlg.pack(); |
339 |
dlg.show(); |
340 |
} else
|
341 |
PluginServices.getMDIManager().addView(this);
|
342 |
} |
343 |
|
344 |
public void close() { |
345 |
PluginServices.getMDIManager().closeView(this);
|
346 |
} |
347 |
|
348 |
} |