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