root / trunk / extensions / extAddIDEELayers / src / com / iver / gvsig / addIDEElayers / AddIDEELayersExtension.java @ 10763
History | View | Annotate | Download (4.62 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 javax.swing.JOptionPane; |
46 |
|
47 |
import com.iver.andami.PluginServices; |
48 |
import com.iver.andami.plugins.Extension; |
49 |
import com.iver.andami.ui.mdiManager.IWindow; |
50 |
import com.iver.cit.gvsig.fmap.MapControl; |
51 |
import com.iver.cit.gvsig.fmap.drivers.DriverIOException; |
52 |
import com.iver.cit.gvsig.fmap.layers.FLyrWMS; |
53 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
54 |
|
55 |
/**
|
56 |
* Adds all the layers of the IDEE to the current active View
|
57 |
*
|
58 |
* @author Pablo Piqueras Bartolom? (p_queras@hotmail.com)
|
59 |
*/
|
60 |
public class AddIDEELayersExtension extends Extension { |
61 |
private String sName = "Nuevo_Nombre_Capas"; |
62 |
private String sHost = "http://www.idee.es/wms/IDEE-Base/IDEE-Base"; |
63 |
private String sLayers = "Todas"; |
64 |
private String sSRS = "EPSG:4230"; // Sistema de referencia |
65 |
private String sFormat = "image/gif"; |
66 |
|
67 |
/* (non-Javadoc)
|
68 |
* @see com.iver.andami.plugins.Extension#inicializar()
|
69 |
*/
|
70 |
public void initialize() { |
71 |
} |
72 |
|
73 |
/* (non-Javadoc)
|
74 |
* @see com.iver.andami.plugins.Extension#execute(java.lang.String)
|
75 |
*/
|
76 |
public void execute(String actionCommand) { |
77 |
View theView = (View) PluginServices.getMDIManager().getActiveWindow(); |
78 |
|
79 |
this.addIDEELayers(theView.getMapControl());
|
80 |
return;
|
81 |
} |
82 |
|
83 |
/**
|
84 |
* Downloads the IDEE layers and adds them to the View
|
85 |
*
|
86 |
* Returns false if there has been any error, else return true
|
87 |
*/
|
88 |
public boolean addIDEELayers(MapControl mapControl) { |
89 |
try
|
90 |
{ |
91 |
// Create a hash map for the properties of the layer to load
|
92 |
HashMap info = new HashMap(); |
93 |
|
94 |
info.put("name", PluginServices.getText(this, sName)); |
95 |
info.put("selectedLayers", sLayers);
|
96 |
info.put("host", sHost);
|
97 |
info.put("SRS", sSRS);
|
98 |
info.put("Format", sFormat);
|
99 |
info.put("layer", sLayers);
|
100 |
|
101 |
/* Gets-Download the IDEE WMS layer from IDEE */
|
102 |
FLyrWMS ideeLayer = new FLyrWMS(info);
|
103 |
|
104 |
/* Adds the layers to the View */
|
105 |
// To prevent that events that take place (are produced) could be a nuisance to the load of the layers
|
106 |
mapControl.getMapContext().beginAtomicEvent(); |
107 |
|
108 |
int numberOfLayers = mapControl.getMapContext().getLayers().getLayersCount();
|
109 |
|
110 |
// Adds the layers
|
111 |
mapControl.getMapContext().getLayers().addLayer(ideeLayer); |
112 |
|
113 |
// Changes the name of the layers into more intuitive other one
|
114 |
mapControl.getMapContext().getLayers().getLayer(numberOfLayers).setName((String)info.get("name")); |
115 |
|
116 |
// End To prevent that events that take place(are produced) could be a nuisance to the load of the layers
|
117 |
mapControl.getMapContext().endAtomicEvent(); |
118 |
|
119 |
// Refresh the view
|
120 |
mapControl.getMapContext().invalidate(); |
121 |
|
122 |
} catch (Exception ex) { |
123 |
// Notify the problem to the user
|
124 |
ex.printStackTrace(); |
125 |
JOptionPane.showMessageDialog(null, PluginServices.getText(null, "error") + ":\n" + ex.getMessage(), PluginServices.getText(null, "error"), JOptionPane.ERROR_MESSAGE); |
126 |
return false; |
127 |
} |
128 |
|
129 |
return true; |
130 |
} |
131 |
|
132 |
/* (non-Javadoc)
|
133 |
* @see com.iver.andami.plugins.Extension#isEnabled()
|
134 |
*/
|
135 |
public boolean isEnabled() { |
136 |
return true; // By default is enabled |
137 |
} |
138 |
|
139 |
/* (non-Javadoc)
|
140 |
* @see com.iver.andami.plugins.Extension#isVisible()
|
141 |
*/
|
142 |
public boolean isVisible() { |
143 |
IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
144 |
|
145 |
if (window == null) { |
146 |
return false; |
147 |
} |
148 |
|
149 |
return (window instanceof View); |
150 |
} |
151 |
|
152 |
} |