Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extWCS / src / com / iver / cit / gvsig / gui / dialog / WCSPropsDialog.java @ 10626

History | View | Annotate | Download (11.1 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.hardcode.gdbms.driver.exceptions.ReadDriverException;
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.ui.mdiManager.IWindow;
57
import com.iver.andami.ui.mdiManager.WindowInfo;
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
 *  The TOC WCS properties panel container.
68
 *
69
 * @author jaume - jaume.dominguez@iver.es
70
 *
71
 */
72
public class WCSPropsDialog extends JPanel implements IWindow {
73
        JDialog dlg = null;  //  @jve:decl-index=0:visual-constraint="10,20"
74
        private JPanel buttonsPanel = null;
75
        //private FLyrDefault fLayer = null;
76
        private FLayer fLayer = null;
77
        boolean applied;
78
        private WindowInfo m_ViewInfo = null;
79

    
80
        private JButton btnApply = null;
81
        private JButton btnOk = null;
82
        private JButton btnCancel = null;
83
        private WCSParamsPanel wcsParamsTabbedPane;
84
    private ComandosListener m_actionListener;
85

    
86
    /**
87
     * Creates a new instance of WCSPropsDialog
88
     * @param layer,
89
     */
90
    public WCSPropsDialog(FLyrWCS layer) {
91
                super();
92
                initialize(layer);
93
        }
94

    
95

    
96
        private void initialize(FLyrWCS layer) {
97
                setBounds(0,0,500,333);
98
        setLayout(null);
99

    
100
        setFLayer(layer);
101
        wcsParamsTabbedPane = getParamsPanel(((FLyrWCS) layer).getProperties());
102
        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

    
112
        })  ;
113

    
114
        this.add(wcsParamsTabbedPane);
115
                this.add(getButtonsPanel(), null);
116
        }
117

    
118

    
119
        public void setFLayer(FLayer f) {
120
                fLayer = f;
121
        }
122

    
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
         *
130
         * 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
         *
134
         *
135
         * 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
         *
142
         * 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
         *
146
         * @return WCSParamsPanel
147
         */
148
        public WCSParamsPanel getParamsPanel(Hashtable info) {
149
                try {
150

    
151
                        URL host = (URL) info.get("host");
152
                        WCSWizardData dataSource = new WCSWizardData();
153
                        dataSource.setHost(host, false);
154

    
155
                        WCSParamsPanel toc = new WCSParamsPanel();
156
                        toc.setVisible(true);
157
                        toc.setListenerSupport(new WizardListenerSupport());
158

    
159
                        toc.setDataSource(dataSource);
160

    
161
                        toc.getLstCoverages().setListData(dataSource.getCoverageList());
162

    
163
                        String coverageName = (String) info.get("name");
164
                        int index = toc.getCoverageIndex( coverageName );
165
                        if (index != -1)
166
                                toc.getLstCoverages().setSelectedIndex(index);
167

    
168
                        toc.refreshData();
169

    
170
                        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
                                toc.getLstSelectedTimes().setListData(time.split(","));
179
                        String parameter = (String) info.get("parameter");
180
                        if (!parameter.equals("")){
181
                                String[] s = parameter.split("=");
182
                                String pName = s[0];
183

    
184
                                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

    
192

    
193
                                } else if (s[1].matches(regexIntervalList)){
194
                                        // Multiple Interval
195

    
196
                                } else {
197
                                        // Single values
198
                                        toc.getJScrollPane5().setVisible(true);
199
                                        toc.getSingleParamValuesList().setEnabled(true);
200

    
201
                                        String[] pVals = s[1].split(",");
202
                                        index = toc.getParamIndex(pName);
203
                                        toc.getCmbParam().setSelectedIndex(index);
204
                                        //toc.refreshParamValues( coverageName );
205
                                        int[] indexes = new int[pVals.length];
206
                                        for (int i = 0; i < pVals.length; i++) {
207
                                                indexes[i] = toc.getValueIndex(pVals[i]);
208
                                        }
209

    
210
                                        toc.getSingleParamValuesList().setSelectedIndices(indexes);
211
                                }
212
                        }
213
                        toc.refreshInfo();
214
                        return toc;
215
                } catch (ReadDriverException soe) {
216
                        JOptionPane.showMessageDialog(null, "servidor_wcs_no_responde", "Error", JOptionPane.ERROR_MESSAGE);
217
                } catch (Exception e) {
218
                        e.printStackTrace();
219
                }
220
                return null;
221
        }
222

    
223
        public JPanel getButtonsPanel() {
224
                if (buttonsPanel == null) {
225
                        m_actionListener = new ComandosListener(this);
226
                        buttonsPanel = new JPanel();
227
                buttonsPanel.setBounds(5, wcsParamsTabbedPane.getHeight(), 471, 40);
228
                        buttonsPanel.setLayout(null);
229
                        buttonsPanel.setName("buttonPanel");
230

    
231
                buttonsPanel.add(getBtnOk(), null);
232
                buttonsPanel.add(getBtnApply(), null);
233
                buttonsPanel.add(getBtnCancel(), null);
234
                }
235
                return buttonsPanel;
236
        }
237

    
238
        public JButton getBtnOk() {
239
                if (btnOk == null) {
240
                btnOk = new JButton("Ok");
241
                btnOk.setText(PluginServices.getText(this,"Ok"));
242
                btnOk.setActionCommand("OK");
243
                btnOk.addActionListener(m_actionListener);
244
                btnOk.setBounds(367, 9, 90, 25);
245
                }
246
                return btnOk;
247
        }
248

    
249
        public JButton getBtnApply() {
250
                if (btnApply == null) {
251
                btnApply = new JButton("Apply");
252
                btnApply.setText(PluginServices.getText(this,"Apply"));
253
                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

    
261
        public JButton getBtnCancel() {
262
                if (btnCancel == null) {
263
                btnCancel = new JButton("Cancel");
264
                btnCancel.setText(PluginServices.getText(this,"Cancel"));
265
                btnCancel.setActionCommand("CANCEL");
266
                btnCancel.addActionListener(m_actionListener);
267
                btnCancel.setBounds(137, 9, 90, 25);
268
                }
269
                return btnCancel;
270
        }
271

    
272
    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
                        if (e.getActionCommand() == "CANCEL") {
289
                                close();
290
                        } else {
291
                                applied = false;
292

    
293
                    ((FLyrWCS) fLayer).setCoverageName(wcsParamsTabbedPane.getCurrentCoverageName());
294
                    ((FLyrWCS) fLayer).setName(wcsParamsTabbedPane.getCoverageName());
295
                    ((FLyrWCS) fLayer).setSRS(wcsParamsTabbedPane.getSRS());
296
                    ((FLyrWCS) fLayer).setFormat(wcsParamsTabbedPane.getFormat());
297
                    ((FLyrWCS) fLayer).setFullExtent(wcsParamsTabbedPane.getExtent());
298
                    ((FLyrWCS) fLayer).setTime(wcsParamsTabbedPane.getTime());
299
                    ((FLyrWCS) fLayer).setParameter(wcsParamsTabbedPane.getParameterString());
300

    
301
                    if (e.getActionCommand() == "APPLY") {
302
                            com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) PluginServices.getMDIManager().getActiveWindow();
303
                            MapControl mapCtrl = vista.getMapControl();
304
                            mapCtrl.getMapContext().invalidate();
305
                            applied = true;
306
                            getBtnApply().setEnabled(!applied);
307
                    }
308

    
309
                    if (e.getActionCommand() == "OK") {
310
                            if (!applied) {
311
                                    com.iver.cit.gvsig.project.documents.view.gui.View vista = (com.iver.cit.gvsig.project.documents.view.gui.View) PluginServices.getMDIManager().getActiveWindow();
312
                        MapControl mapCtrl = vista.getMapControl();
313
                        mapCtrl.getMapContext().invalidate();
314
                            }
315
                    close();
316
                    }
317
             }
318
                }
319
    }
320

    
321
        public WindowInfo getWindowInfo() {
322
                if (m_ViewInfo==null){
323
                        m_ViewInfo=new WindowInfo(WindowInfo.MODALDIALOG);
324
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WCS_layer"));
325
                        m_ViewInfo.setWidth(wcsParamsTabbedPane.getWidth()+10);
326
                m_ViewInfo.setHeight(wcsParamsTabbedPane.getHeight()+40);
327
                }
328
                return m_ViewInfo;
329
        }
330

    
331
        public void viewActivated() {
332
        }
333

    
334
        public void openWCSPropertiesDialog() {
335
                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
                        dlg.setModal(true);
344
                        dlg.pack();
345
                        dlg.show();
346
                } else
347
                        PluginServices.getMDIManager().addWindow(this);
348
        }
349

    
350
        public void close() {
351
                PluginServices.getMDIManager().closeWindow(this);
352
        }
353

    
354
}