Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / extensions / extAddIDEELayers / src / com / iver / gvsig / addIDEElayers / AddIDEELayersExtension.java @ 7506

History | View | Annotate | Download (4.29 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2004 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.gvsig.addIDEElayers;
42

    
43
import java.util.HashMap;
44

    
45
import com.iver.andami.PluginServices;
46
import com.iver.andami.plugins.Extension;
47
import com.iver.andami.ui.mdiManager.IWindow;
48
import com.iver.cit.gvsig.fmap.MapControl;
49
import com.iver.cit.gvsig.fmap.layers.FLyrWMS;
50
import com.iver.cit.gvsig.gui.View;
51

    
52
/**
53
 * Adds all the layers of the IDEE to the current View
54
 * 
55
 * @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
56
 */
57
public class AddIDEELayersExtension extends Extension {
58
    private String sName = "Nuevo_Nombre_Capas";
59
    private String sHost = "http://www.idee.es/wms/IDEE-Base/IDEE-Base";
60
    private String sLayers = "Todas";
61
    private String sSRS = "EPSG:4230"; // Sistema de referencia
62
    private String sFormat = "image/gif";
63

    
64
        /* (non-Javadoc)
65
     * @see com.iver.andami.plugins.Extension#inicializar()
66
     */
67
    public void initialize() {
68
    }
69

    
70
    /* (non-Javadoc)
71
     * @see com.iver.andami.plugins.Extension#execute(java.lang.String)
72
     */
73
    public void execute(String actionCommand) {
74
                View theView = (View) PluginServices.getMDIManager().getActiveWindow();
75
                
76
                this.addIDEELayers(theView.getMapControl());
77
                return;
78
    }
79
    
80
        /**
81
         * Download the IDEE layers and and them to the View
82
         * 
83
         * Returns false if there has been any error, else return true
84
         */        
85
        public boolean addIDEELayers(MapControl mapControl) {
86
                 try
87
                 {
88
                         // Create a hash map for the properties of the layer to load
89
                         HashMap info = new HashMap();
90
                        
91
                         info.put("name", PluginServices.getText(this, sName));
92
                         info.put("selectedLayers", sLayers);
93
                         info.put("host", sHost);
94
                         info.put("srs", sSRS);
95
                         info.put("format", sFormat);
96
                         info.put("layer", sLayers);
97
               
98
                         /* Gets-Download the IDEE WMS layer from IDEE */
99
                         FLyrWMS ideeLayer = new FLyrWMS(info);
100
                        
101
                         /* Adds the layers to the View */
102
                         // To prevent that events that take place(are produced) could be a nuisance to the load of the layers
103
                         mapControl.getMapContext().beginAtomicEvent();
104

    
105
                         int numberOfLayers = mapControl.getMapContext().getLayers().getLayersCount();
106
                         
107
                         // Adds the layers
108
                         mapControl.getMapContext().getLayers().addLayer(ideeLayer);
109
                         
110
                         // Changes the name of the layers into more intuitive other one
111
                         mapControl.getMapContext().getLayers().getLayer(numberOfLayers).setName((String)info.get("name"));
112
                                
113
                         // End To prevent that events that take place(are produced) could be a nuisance to the load of the layers                 
114
                         mapControl.getMapContext().endAtomicEvent();
115
                    
116
                         // Refresh the view
117
                         mapControl.getMapContext().invalidate();        
118
                 } catch(Exception e) {
119
                         e.printStackTrace();
120
                         return false;
121
                 }
122
        
123
      return true;
124
    }
125
   
126
    /* (non-Javadoc)
127
     * @see com.iver.andami.plugins.Extension#isEnabled()
128
     */
129
    public boolean isEnabled() {
130
                return true; // By default is enabled
131
    }
132

    
133
    /* (non-Javadoc)
134
     * @see com.iver.andami.plugins.Extension#isVisible()
135
     */
136
    public boolean isVisible() {
137
                IWindow window = PluginServices.getMDIManager().getActiveWindow();
138

    
139
                if (window == null) {
140
                        return false;
141
                }
142
                
143
                return (window instanceof View);
144
    }
145

    
146
}