Statistics
| Revision:

root / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / dialog / WCSPropsDialog.java @ 24986

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