Statistics
| Revision:

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

History | View | Annotate | Download (11.5 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

    
64
/**
65
 * @author jaume - jaume.dominguez@iver.es
66
 *
67
 */
68
public class WCSPropsDialog extends JPanel implements View {
69
        JDialog dlg = null;  //  @jve:decl-index=0:visual-constraint="10,20"
70
        private JPanel buttonsPanel = null;
71
        //private FLyrDefault fLayer = null;
72
        private FLayer fLayer = null;
73
        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
        private WCSParamsPanel wcsParamsTabbedPane;
80
    private ComandosListener m_actionListener;
81

    
82
    public WCSPropsDialog(FLayer layer) {
83
                super();
84
                initialize(layer);
85
        }
86
    
87
    
88
        private void initialize(FLayer layer) {
89
                setBounds(0,0,500,333);
90
        setLayout(null);
91

    
92
        setFLayer(layer);
93
        wcsParamsTabbedPane = getParamsPanel(((FLyrWCS) layer).getProperties());
94
        this.add(wcsParamsTabbedPane);
95
                this.add(getButtonsPanel(), null);        
96
        }
97
        
98

    
99
        public void setFLayer(FLayer f) {
100
                fLayer = f;
101
        }
102

    
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
                        URL host = (URL) info.get("host");
132
                        WCSWizardData dataSource = new WCSWizardData();
133
                        dataSource.setHost(host);
134
                        
135
                        WCSParamsPanel toc = new WCSParamsPanel();
136
                        toc.setDataSource(dataSource);
137
                        
138
                        toc.getLstCoverages().setListData(dataSource.getCoverageList());
139
                        
140
                        String coverageName = (String) info.get("name");
141
                        int index = toc.getCoverageIndex( coverageName );
142
                        if (index != -1)
143
                                toc.getLstCoverages().setSelectedIndex(index);
144
                        
145
                        toc.refreshData();
146
                        
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
                                        /*toc.lblInterval.setVisible(true);
168
                                        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
                                        toc.getRadioSingleInterval().setVisible(true);*/
176
                                        toc.getSingleParamValuesList().setEnabled(false);
177
                                        
178
                                        /*String[] pVals = s[1].split("/");
179
                                        String s1 = pVals[0];
180
                                        toc.setIntervalBegin(s1);
181
                                        s1 = pVals[1];
182
                                        
183
                                        toc.setIntervalEnd(s1);
184
                                        toc.getRadioSingleInterval().setSelected(true);*/
185
                                
186
                                } else if (s[1].matches(regexIntervalList)){
187
                                        // Multiple Interval
188
                                        /*toc.getJScrollPane5().setVisible(false);
189
                                        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
                                        */
203
                                } 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
                        }        
220
                        return toc;
221
                } 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
        }
228
        
229
        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
                btnOk = new JButton("Ok");
247
                btnOk.setText(PluginServices.getText(this,"Ok"));
248
                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
                btnApply = new JButton("Apply");
258
                btnApply.setText(PluginServices.getText(this,"Apply"));
259
                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
                btnCancel = new JButton("Cancel");
270
                btnCancel.setText(PluginServices.getText(this,"Cancel"));
271
                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
                        if (e.getActionCommand() == "CANCEL") {
295
                                close();
296
                        } else {
297
                                applied = false;
298
                                
299
                    ((FLyrWCS) fLayer).setCoverageName(wcsParamsTabbedPane.getCurrentCoverageName());
300
                    ((FLyrWCS) fLayer).setName(wcsParamsTabbedPane.getCoverageName());
301
                    ((FLyrWCS) fLayer).setSRS(wcsParamsTabbedPane.getSRS());
302
                    ((FLyrWCS) fLayer).setFormat(wcsParamsTabbedPane.getFormat());
303
                    ((FLyrWCS) fLayer).setFullExtent(wcsParamsTabbedPane.getExtent());
304
                    ((FLyrWCS) fLayer).setTime(wcsParamsTabbedPane.getTime());
305
                    ((FLyrWCS) fLayer).setParameter(wcsParamsTabbedPane.getParameterString());
306
                    
307
                    if (e.getActionCommand() == "APPLY") {
308
                            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
                            applied = true;
312
                            getBtnApply().setEnabled(!applied);
313
                    }
314
                    
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
             }
324
                }
325
    }
326
    
327
        public ViewInfo getViewInfo() {
328
                if (m_ViewInfo==null){
329
                        m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
330
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WCS_layer"));
331
                }
332
                return m_ViewInfo;
333
        }
334
        
335
        public void viewActivated() {
336
        }
337

    
338
        public void openWCSPropertiesDialog() {
339
                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
        public void close() {
355
                PluginServices.getMDIManager().closeView(this);                
356
        }
357

    
358
}