Statistics
| Revision:

svn-gvsig-desktop / branches / v05 / extensions / extWMS / src / com / iver / cit / gvsig / gui / dialogs / WMSPropsDialog.java @ 3855

History | View | Annotate | Download (10.9 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.event.ActionEvent;
44
import java.awt.event.ActionListener;
45
import java.net.URL;
46
import java.util.ArrayList;
47
import java.util.HashMap;
48
import java.util.Vector;
49

    
50
import javax.swing.JButton;
51
import javax.swing.JDialog;
52
import javax.swing.JOptionPane;
53
import javax.swing.JPanel;
54

    
55
import com.iver.andami.PluginServices;
56
import com.iver.andami.ui.mdiManager.View;
57
import com.iver.andami.ui.mdiManager.ViewInfo;
58
import com.iver.cit.gvsig.fmap.DriverException;
59
import com.iver.cit.gvsig.fmap.MapControl;
60
import com.iver.cit.gvsig.fmap.layers.FLayer;
61
import com.iver.cit.gvsig.fmap.layers.FLyrWMS;
62
import com.iver.cit.gvsig.fmap.layers.WMSLayerNode;
63
import com.iver.cit.gvsig.gui.beans.controls.dnd.JDnDListModel;
64
import com.iver.cit.gvsig.gui.panels.WMSParamsPanel;
65
import com.iver.cit.gvsig.gui.wizards.WMSWizardData;
66
import com.iver.cit.gvsig.gui.wizards.WizardListener;
67
import com.iver.cit.gvsig.gui.wizards.WizardListenerSupport;
68

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

    
89
    public WMSPropsDialog(FLayer layer) {
90
                super();
91
                initialize(layer);
92
        }
93
    
94
    
95
        private void initialize(FLayer layer) {
96
                setLayout(null);
97

    
98
        setFLayer(layer);
99
        wmsParamsTabbedPane = getParamsPanel(((FLyrWMS) layer).getProperties());
100
        wmsParamsTabbedPane.addWizardListener(new WizardListener(){
101

    
102
                        public void wizardStateChanged(boolean finishable) {
103
                                getBtnOk().setEnabled(finishable);
104
                                getBtnApply().setEnabled(finishable);
105
                        }
106

    
107
                        public void error(Exception e) {
108
                        }
109
                
110
        })  ;     
111
        this.add(wmsParamsTabbedPane);
112
        this.add(getButtonsPanel(), null);
113
        
114
        }
115
        
116

    
117
        public void setFLayer(FLayer f) {
118
                fLayer = f;
119
        }
120

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

    
167
                    for (int i = 0; i < selectedLayers.length; i++) {
168
                        //  Se a?ade a la lista de layers seleccionados
169
                    JDnDListModel modelo = (JDnDListModel) toc.getLstSelectedLayers().getModel();
170
                    if (modelo.addElement(0, selectedLayers[i])) {
171
                        any = true;
172
                    }
173
                }
174
                if (any) {
175
                    toc.refreshData();
176
                }
177
                String srs = (String) info.get("srs");
178
                    String format = (String) info.get("format");
179
                    
180
                    int index = toc.getSRSIndex( srs );
181
                    if (index != -1)
182
                        toc.getLstSRSs().setSelectedIndex(index);
183
                    index = toc.getFormatIndex(format);
184
                    if (index != -1)
185
                        toc.getLstFormats().setSelectedIndex(index);
186
                    
187
                toc.setTransparent(((Boolean) info.get("wmsTransparency")).booleanValue());
188
                Vector v = (Vector) info.get("styles");
189
                
190
                if (v != null)
191
                        toc.setStyleSelections(selectedLayers, v);
192
                v = (Vector) info.get("dimensions");
193
                if (v != null) toc.setDimensions(v);
194
                              
195
                toc.refreshInfo();
196
                    return toc;
197
                } catch (DriverException ioe){
198
                    JOptionPane.showMessageDialog(null, "error_comunicacion_servidor", "Error", JOptionPane.ERROR_MESSAGE);
199
                } catch (Exception e) {
200
                    e.printStackTrace();
201
                }
202
            }
203
            return null;        
204
        }
205
        
206

    
207
        public JPanel getButtonsPanel() {
208
                if (buttonsPanel == null) {
209
                        m_actionListener = new CommandListener(this);
210
                        buttonsPanel = new JPanel();
211
                buttonsPanel.setBounds(5, wmsParamsTabbedPane.getHeight(), 471, 40);
212
                        buttonsPanel.setLayout(null);     
213
                        buttonsPanel.setName("buttonPanel");
214
                        
215
                buttonsPanel.add(getBtnOk(), null);
216
                buttonsPanel.add(getBtnApply(), null);
217
                buttonsPanel.add(getBtnCancel(), null);
218
                }
219
                return buttonsPanel;
220
        }
221
        
222
        public JButton getBtnOk() {
223
                if (btnOk == null) {
224
                btnOk = new JButton("aceptar");
225
                btnOk.setText(PluginServices.getText(this,"aceptar"));
226
                btnOk.setActionCommand("OK");
227
                btnOk.addActionListener(m_actionListener);
228
                btnOk.setBounds(367, 9, 90, 25);
229
                }
230
                return btnOk;
231
        }
232
        
233
        public JButton getBtnApply() {
234
                if (btnApply == null) {
235
                btnApply = new JButton("apply");
236
                btnApply.setText(PluginServices.getText(this,"aplicar"));
237
                btnApply.setEnabled(false);
238
                btnApply.setActionCommand("APPLY");
239
                btnApply.addActionListener(m_actionListener);
240
                btnApply.setBounds(267, 9, 90, 25);
241
                }
242
                return btnApply;
243
        }
244
        
245
        public JButton getBtnCancel() {
246
                if (btnCancel == null) {
247
                btnCancel = new JButton("cancelar");
248
                btnCancel.setText(PluginServices.getText(this,"cancelar"));
249
                btnCancel.setActionCommand("CANCEL");
250
                btnCancel.addActionListener(m_actionListener);
251
                btnCancel.setBounds(137, 9, 90, 25);
252
                }
253
                return btnCancel;
254
        }
255
        
256
    private class CommandListener implements ActionListener {
257
        
258
        /**
259
         * Creates a new ComandosListener object.
260
         *
261
         * @param lg DOCUMENT ME!
262
         */
263
        public CommandListener(WMSPropsDialog tp) {
264
            //m_tp = tp;
265
        }
266

    
267
                /* (non-Javadoc)
268
                 * @see java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
269
                 */
270
                public void actionPerformed(ActionEvent e) {
271
            if (e.getActionCommand() == "CANCEL")
272
                close();
273
            else{
274
                ((FLyrWMS) fLayer).setFormat(wmsParamsTabbedPane.getFormat());
275
                ((FLyrWMS) fLayer).setLayerQuery(wmsParamsTabbedPane.getLayersQuery());
276
                ((FLyrWMS) fLayer).setInfoLayerQuery(wmsParamsTabbedPane.getQueryableLayerQuery());
277
                ((FLyrWMS) fLayer).setSRS(wmsParamsTabbedPane.getSRS());
278
                ((FLyrWMS) fLayer).setName(wmsParamsTabbedPane.getLayerName());
279
                ((FLyrWMS) fLayer).setWmsTransparency(wmsParamsTabbedPane.getTransparency());
280
                ((FLyrWMS) fLayer).setStyles(wmsParamsTabbedPane.getStyles());
281
                ((FLyrWMS) fLayer).setDimensions(wmsParamsTabbedPane.getDimensions());
282
                
283
                if (e.getActionCommand() == "APPLY"){
284
                    com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
285
                    MapControl mapCtrl = vista.getMapControl();
286
                    mapCtrl.getMapContext().invalidate();
287
                    applied = true;
288
                    getBtnApply().setEnabled(!applied); 
289
                }
290
                
291
                if (e.getActionCommand() == "OK") {
292
                    if (!applied) {
293
                        com.iver.cit.gvsig.gui.View vista = (com.iver.cit.gvsig.gui.View) PluginServices.getMDIManager().getActiveView();
294
                        MapControl mapCtrl = vista.getMapControl();
295
                        mapCtrl.getMapContext().invalidate();
296
                    }
297
                    close();
298
                }
299
            }
300
                }
301
    }
302
    
303
        public ViewInfo getViewInfo() {
304
                if (m_ViewInfo==null){
305
                        m_ViewInfo=new ViewInfo(ViewInfo.MODALDIALOG);
306
                        m_ViewInfo.setTitle(PluginServices.getText(this,"fit_WMS_layer"));
307
                m_ViewInfo.setWidth(wmsParamsTabbedPane.getWidth()+10);
308
                m_ViewInfo.setHeight(wmsParamsTabbedPane.getHeight()+40);
309

    
310
                }
311
                return m_ViewInfo;
312
        }
313
                
314
        public void close() {
315
                PluginServices.getMDIManager().closeView(this);                
316
        }
317

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