Statistics
| Revision:

root / trunk / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSPropsDialog.java @ 4962

History | View | Annotate | Download (12.6 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.dialogs;
42

    
43
import java.awt.Component;
44
import java.awt.Dimension;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import java.net.URL;
48
import java.util.HashMap;
49
import java.util.Vector;
50

    
51
import javax.swing.JButton;
52
import javax.swing.JDialog;
53
import javax.swing.JOptionPane;
54
import javax.swing.JPanel;
55
import javax.swing.tree.TreePath;
56

    
57
import org.gvsig.gui.beans.controls.dnd.JDnDListModel;
58

    
59
import com.iver.andami.PluginServices;
60
import com.iver.andami.ui.mdiManager.View;
61
import com.iver.andami.ui.mdiManager.ViewInfo;
62
import com.iver.cit.gvsig.fmap.DriverException;
63
import com.iver.cit.gvsig.fmap.MapControl;
64
import com.iver.cit.gvsig.fmap.exceptions.CannotReprojectException;
65
import com.iver.cit.gvsig.fmap.layers.FLayer;
66
import com.iver.cit.gvsig.fmap.layers.FLyrWMS;
67
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
68
import com.iver.cit.gvsig.gui.panels.WMSParamsPanel;
69
import com.iver.cit.gvsig.gui.wizards.LayerTreeModel;
70
import com.iver.cit.gvsig.gui.wizards.WMSWizardData;
71
import com.iver.cit.gvsig.gui.wizards.WizardListener;
72
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
73

    
74
/**
75
 * The TOC WMS properties panel container.
76
 * 
77
 * @author jaume - jaume.dominguez@iver.es
78
 *
79
 */
80
public class WMSPropsDialog extends JPanel implements View {
81
        JDialog dlg = null;  //  @jve:decl-index=0:visual-constraint="10,20"
82
        private JPanel buttonsPanel = null;
83
        //private FLyrDefault fLayer = null;
84
        private FLayer fLayer = null;
85
        boolean applied;
86
        private ViewInfo m_ViewInfo = null;
87
        
88
        private JButton btnApply = null;
89
        private JButton btnOk = null;
90
        private JButton btnCancel = null;
91
        private WMSParamsPanel wmsParamsTabbedPane;
92
    private CommandListener m_actionListener;
93

    
94
    public WMSPropsDialog(FLayer layer) {
95
                super();
96
                initialize(layer);
97
        }
98
    
99
    
100
        private void initialize(FLayer layer) {
101
                setLayout(null);
102

    
103
        setFLayer(layer);
104
        wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties());
105
        wmsParamsTabbedPane.addWizardListener(new WizardListener(){
106
                        public void wizardStateChanged(boolean finishable) {
107
                                getBtnOk().setEnabled(finishable);
108
                                getBtnApply().setEnabled(finishable);
109
                        }
110

    
111
                        public void error(Exception e) {
112
                        }
113
                
114
        })  ;     
115
        this.add(wmsParamsTabbedPane);
116
        this.add(getButtonsPanel(), null);
117
        
118
        }
119
        
120

    
121
        public void setFLayer(FLayer f) {
122
                fLayer = f;
123
        }
124

    
125
        /**
126
         * With getParamsPanel we have access to the map config TabbedPane.
127
         * If this panel doesn't exist yet (which can occur when an existing project is
128
         * recovered) it is been automatically constructed by connecting to the server,
129
         * reloading the necessary data, filling up the content and setting the selected
130
         * values that were selected when the projet was saved.
131
         * 
132
         * 
133
         * Since a connection to the server is needed when rebuiliding the panel, this
134
         * causes a delay for the panel's showing up or a nullPointer error if there is
135
         * no path to the server.
136
         * 
137
         * 
138
         * Con getParamsPanel tenemos acceso a juego de pesta?as de configuraci?n
139
         * del mapa. Si este panel todav?a no existe (como puede ser cuando
140
         * recuperamos un proyecto guardado) ?ste se crea autom?ticamente conectando
141
         * al servidor, recuperando los datos necesarios, rellenando el contenido y
142
         * dejando seleccionados los valores que estaban seleccionados cuando se
143
         * guard? el proyecto.
144
         * 
145
         * 
146
         * Como para reconstruirse requiere una conexi?n con el servidor esto causa
147
         * un retardo en la aparici?n en el toc o un error de nullPointer si no
148
         * hay conexi?n hasta el servidor.
149
         * 
150
         * 
151
         * @return WCSParamsPanel
152
         */
153
        public WMSParamsPanel getParamsPanel(HashMap info) {
154
            if (info!=null){
155
                try {
156
                    
157
                        // host
158
                URL host = (URL) info.get("host");
159
                WMSWizardData dataSource = new WMSWizardData();
160
                dataSource.setHost(host, false);
161
                
162
                // name
163
                    WMSParamsPanel toc = new WMSParamsPanel();                    
164
                    toc.setLayerName((String)info.get("name")); 
165
                    toc.setWizardData(dataSource);
166
                    
167
                    toc.setVisible(true);
168
                    toc.setListenerSupport(new WizardListenerSupport());
169
                    
170
                WMSLayerNode[] selectedLayers = (WMSLayerNode[]) ((Vector) info.get("selectedLayers")).toArray(new WMSLayerNode[0]);
171
                boolean any = false;
172

    
173
                // selected layers
174
                    for (int i = 0; i < selectedLayers.length; i++) {
175
                    //  Se a?ade a la lista de layers seleccionados
176
                            
177
                            TreePath path = new TreePath(((LayerTreeModel)toc.getJustTreeLayer()
178
                                                                    .getModel()).getNodeByName(selectedLayers[i].getName()));
179
                            toc.getJustTreeLayer().addSelectionPath(path);
180
                            toc.addLayer();
181
                            
182
//                    JDnDListModel modelo = (JDnDListModel) toc.getLstSelectedLayers().getModel();                    
183
//                    if (modelo.addElement(0, selectedLayers[i])) {
184
//                        any = true;
185
//                    }
186
                }
187
//                if (any) {
188
//                    toc.refreshData();
189
//                }
190
                                
191
                // srs
192
                String srs = (String) info.get("srs");
193
                int index = toc.getSRSIndex( srs );
194
                    if (index != -1)
195
                        toc.getLstSRSs().setSelectedIndex(index);
196
                    
197
                // format
198
                    String format = (String) info.get("format");
199
                    index = toc.getFormatIndex(format);
200
                    if (index != -1)
201
                        toc.getLstFormats().setSelectedIndex(index);
202
                    
203
                    // transparency
204
                toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue());
205
                
206
                // styles
207
                Vector v = (Vector) info.get("styles");
208
                if (v != null)
209
                        toc.setStyleSelections(v);
210
                
211
                // dimensions
212
                v = (Vector) info.get("dimensions");
213
                if (v != null) toc.setDimensions(v);
214
                             
215
                // fixed sizes
216
                Dimension sz = (Dimension) info.get("fixedSize");
217
                if (sz != null) toc.setFixedSize(sz);
218
                toc.refreshInfo();
219
                applied = false;
220
                    return toc;
221
                } catch (DriverException ioe){
222
                    JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
223
                } catch (Exception e) {
224
                    e.printStackTrace();
225
                }
226
            }
227
            return null;        
228
        }
229
        
230

    
231
        public JPanel getButtonsPanel() {
232
                if (buttonsPanel == null) {
233
                        m_actionListener = new CommandListener(this);
234
                        buttonsPanel = new JPanel();
235
                buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40);
236
                        buttonsPanel.setLayout(null);     
237
                        buttonsPanel.setName("buttonPanel");
238
                        
239
                buttonsPanel.add(getBtnOk(), null);
240
                buttonsPanel.add(getBtnApply(), null);
241
                buttonsPanel.add(getBtnCancel(), null);
242
                }
243
                return buttonsPanel;
244
        }
245
        
246
        public JButton getBtnOk() {
247
                if (btnOk == null) {
248
                btnOk = new JButton("ok");
249
                btnOk.setText(PluginServices.getText(this,"ok"));
250
                btnOk.setActionCommand("OK");
251
                btnOk.addActionListener(m_actionListener);
252
                btnOk.setBounds(367, 9, 90, 25);
253
                }
254
                return btnOk;
255
        }
256
        
257
        public JButton getBtnApply() {
258
                if (btnApply == null) {
259
                btnApply = new JButton("apply");
260
                btnApply.setText(PluginServices.getText(this,"apply"));
261
                btnApply.setEnabled(false);
262
                btnApply.setActionCommand("APPLY");
263
                btnApply.addActionListener(m_actionListener);
264
                btnApply.setBounds(267, 9, 90, 25);
265
                }
266
                return btnApply;
267
        }
268
        
269
        public JButton getBtnCancel() {
270
                if (btnCancel == null) {
271
                btnCancel = new JButton("cancel");
272
                btnCancel.setText(PluginServices.getText(this,"cancel"));
273
                btnCancel.setActionCommand("CANCEL");
274
                btnCancel.addActionListener(m_actionListener);
275
                btnCancel.setBounds(137, 9, 90, 25);
276
                }
277
                return btnCancel;
278
        }
279
        
280
    private class CommandListener implements ActionListener {
281
        
282
        /**
283
         * Creates a new ComandosListener object.
284
         *
285
         * @param lg DOCUMENT ME!
286
         */
287
        public CommandListener(WMSPropsDialog tp) {
288
            //m_tp = tp;
289
        }
290

    
291
                /* (non-Javadoc)
292
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
293
                 */
294
                public void actionPerformed(ActionEvent e) {
295
            if (e.getActionCommand() == "CANCEL")
296
                close();
297
            else{
298
                    applied = false;
299
                    //Commented by Laura
300
//                    try {
301
//                                        ((FLyrWMS) fLayer).setFullExtent(wmsParamsTabbedPane.getLayersRectangle());
302
//                                } catch (CannotReprojectException ex) {
303
//                                        ex.printStackTrace();
304
//                                JOptionPane.showMessageDialog((Component)PluginServices.getMainFrame(), ex.getMessage());
305
//                                return;
306
//                                }                                
307
//                ((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat());
308
//                ((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery());
309
//                ((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery());
310
//                ((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS());
311
//                ((FLyrWMS) fLayer).setName(wmsParamsTabbedPane.getLayerName());
312
//                ((FLyrWMS) fLayer).setWmsTransparency(wmsParamsTabbedPane.getTransparency());
313
//                ((FLyrWMS) fLayer).setStyles(wmsParamsTabbedPane.getStyles());
314
//                ((FLyrWMS) fLayer).setDimensions(wmsParamsTabbedPane.getDimensions());
315
//                ((FLyrWMS) fLayer).setFixedSize(wmsParamsTabbedPane.getFixedSize());
316
                
317
                    fLayer = wmsParamsTabbedPane.getLayer();  
318
                if (e.getActionCommand() == "APPLY"){
319
                    com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
320
                    MapControl mapCtrl = vista.getMapControl();
321
                    //int index = mapCtrl.getMapContext().getLayers().ge
322
                    mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), fLayer);
323
                    
324
                    mapCtrl.getMapContext().invalidate();
325
                    applied = true;
326
                    getBtnApply().setEnabled(!applied); 
327
                }
328
                
329
                if (e.getActionCommand() == "OK") {
330
                    if (!applied) {
331
                        com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
332
                        MapControl mapCtrl = vista.getMapControl();
333
                        mapCtrl.getMapContext().getLayers().replaceLayer(fLayer.getName(), fLayer);
334
                        mapCtrl.getMapContext().invalidate();
335
                    }
336
                    close();
337
                }
338
            }
339
                }
340
    }
341
    
342
        public ViewInfo getViewInfo() {
343
                if (m_ViewInfo==null){
344
                        m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
345
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer"));
346
                m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
347
                m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
348

    
349
                }
350
                return m_ViewInfo;
351
        }
352
                
353
        public void close() {
354
                PluginServices.getMDIManager().closeView(this);                
355
        }
356

    
357
}  //  @jve:decl-index=0:visual-constraint="10,10"