svn-gvsig-desktop / branches / gvSIG_1.11.0_Mejoras_gvSIG-EIEL / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 35646
History | View | Annotate | Download (9.7 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 20-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | 312 | fernando | package com.iver.cit.gvsig; |
48 | |||
49 | 2522 | caballero | import org.apache.log4j.Logger; |
50 | |||
51 | 596 | fernando | import com.iver.andami.PluginServices; |
52 | import com.iver.andami.plugins.Extension; |
||
53 | 6658 | caballero | import com.iver.andami.preferences.IPreference; |
54 | import com.iver.andami.preferences.IPreferenceExtension; |
||
55 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
56 | 1223 | fernando | import com.iver.cit.gvsig.fmap.MapControl; |
57 | 637 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
58 | 6778 | jmvivo | import com.iver.cit.gvsig.fmap.layers.FLayers; |
59 | 6658 | caballero | import com.iver.cit.gvsig.gui.preferencespage.ViewPage; |
60 | 1221 | fernando | import com.iver.cit.gvsig.project.Project; |
61 | 9532 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
62 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.Encuadrator; |
63 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
64 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.ExtentListSelectorModel; |
65 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelExtentSelector; |
||
66 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig; |
||
67 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
68 | import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu; |
||
69 | 6673 | jmvivo | import com.iver.utiles.extensionPoints.ExtensionPoint; |
70 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
71 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
72 | 1086 | vcaballero | |
73 | |||
74 | 312 | fernando | //import com.iver.utiles.FPanelExtentSelector;
|
75 | |||
76 | /**
|
||
77 | 6630 | caballero | * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
78 | 312 | fernando | *
|
79 | * @author vcn
|
||
80 | */
|
||
81 | 6658 | caballero | public class ViewControls extends Extension implements IPreferenceExtension{ |
82 | 1086 | vcaballero | private static Logger logger = Logger.getLogger(ViewControls.class.getName()); |
83 | 8516 | jaume | private static ViewPage viewPropertiesPage = new ViewPage(); |
84 | 1086 | vcaballero | /**
|
85 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
86 | 1086 | vcaballero | */
|
87 | public void execute(String s) { |
||
88 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
89 | 6658 | caballero | if (!(view instanceof View)) |
90 | return;
|
||
91 | View vista=(View)view; |
||
92 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
93 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
94 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
95 | 1086 | vcaballero | logger.debug("Comand : " + s);
|
96 | 312 | fernando | |
97 | 6239 | caballero | if (s.equals("FULL") ) { |
98 | 10626 | caballero | // mapa.beginAtomicEvent();
|
99 | mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent()); |
||
100 | 24160 | jmvivo | // mapa.clearAllCachingImageDrawnLayers();
|
101 | 10626 | caballero | vista.repaintMap(); |
102 | ((ProjectDocument)vista.getModel()).setModified(true);
|
||
103 | // mapa.endAtomicEvent();
|
||
104 | 6239 | caballero | } else if (s.equals("ENCUADRE") ) { |
105 | 1086 | vcaballero | FPanelExtentSelector l = new FPanelExtentSelector();
|
106 | 312 | fernando | |
107 | 1086 | vcaballero | ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
108 | Project project = p.getProject(); |
||
109 | ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
||
110 | 2522 | caballero | //ProjectExtent[] extents = project.getExtents();
|
111 | 1086 | vcaballero | project.addPropertyChangeListener(modelo); |
112 | l.setModel(modelo); |
||
113 | l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
||
114 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
115 | 6880 | cesar | PluginServices.getMDIManager().addWindow(l); |
116 | 6239 | caballero | } else if (s.equals("CONFIG_LOCATOR") ) { |
117 | 312 | fernando | //Set up the map overview
|
118 | 643 | fjp | FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
119 | 6880 | cesar | PluginServices.getMDIManager().addWindow(m_panelLoc); |
120 | 1086 | vcaballero | m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
121 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
122 | 6239 | caballero | } else if (s.equals("PAN") ) { |
123 | 1086 | vcaballero | mapCtrl.setTool("pan");
|
124 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
125 | 6239 | caballero | } else if (s.equals("ZOOM_IN") ) { |
126 | 1086 | vcaballero | mapCtrl.setTool("zoomIn");
|
127 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
128 | 6239 | caballero | } else if (s.equals("ZOOM_OUT") ) { |
129 | 1086 | vcaballero | mapCtrl.setTool("zoomOut");
|
130 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
131 | 6239 | caballero | } else if (s.equals("CAPAS_VISIBLES") ) { |
132 | 31305 | vcaballero | setVisibles(true, mapa.getLayers());
|
133 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
134 | 6239 | caballero | } else if (s.equals("CAPAS_NOVISIBLES") ) { |
135 | 31305 | vcaballero | setVisibles(false, mapa.getLayers());
|
136 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
137 | 6239 | caballero | } else if (s.equals("CAPAS_ACTIVAS") ) { |
138 | 31305 | vcaballero | setActives(true, mapa.getLayers());
|
139 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
140 | 6239 | caballero | } else if (s.equals("CAPAS_NOACTIVAS") ) { |
141 | 31305 | vcaballero | setActives(false, mapa.getLayers());
|
142 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
143 | 6239 | caballero | } else if (s.equals("SAVERASTER") ) { |
144 | 2183 | fernando | mapCtrl.setTool("saveRaster");
|
145 | 6239 | caballero | } else if (s.equals("SELECTIMAGE") ) { |
146 | 2183 | fernando | mapCtrl.setTool("selectImage");
|
147 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_IN") ) { |
148 | mapCtrl.zoomIn(); |
||
149 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
150 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_OUT") ) { |
151 | mapCtrl.zoomOut(); |
||
152 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
153 | 6630 | caballero | } else if (s.startsWith("CHANGE_SCALE_")){ |
154 | String scl=s.replaceAll("CHANGE_SCALE_",""); |
||
155 | long scale=Long.parseLong(scl); |
||
156 | mapa.setScaleView(scale); |
||
157 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
158 | 1086 | vcaballero | } |
159 | } |
||
160 | 1219 | vcaballero | |
161 | /**
|
||
162 | * Pone todas las capas visibles o no visibles.
|
||
163 | *
|
||
164 | * @param visible true si que quieren poner a visibles.
|
||
165 | * @param mapa FMap sobre el que actuar.
|
||
166 | */
|
||
167 | 31305 | vcaballero | private void setVisibles(boolean visible, FLayers layers) { |
168 | int layerCount=layers.getLayersCount();
|
||
169 | for (int i = 0; i < layerCount; i++) { |
||
170 | FLayer layer = layers.getLayer(i); |
||
171 | 1185 | vcaballero | layer.setVisible(visible); |
172 | 31305 | vcaballero | if (layer instanceof FLayers){ |
173 | setVisibles(visible,(FLayers)layer); |
||
174 | } |
||
175 | 1185 | vcaballero | } |
176 | } |
||
177 | 1219 | vcaballero | |
178 | /**
|
||
179 | * Pone todas las capas activas o no activas.
|
||
180 | *
|
||
181 | * @param active true si que quieren poner a activas.
|
||
182 | * @param mapa FMap sobre el que actuar.
|
||
183 | */
|
||
184 | 31305 | vcaballero | private void setActives(boolean active, FLayers layers) { |
185 | int layerCount=layers.getLayersCount();
|
||
186 | for (int i = 0; i < layerCount; i++) { |
||
187 | FLayer layer = layers.getLayer(i); |
||
188 | 1185 | vcaballero | layer.setActive(active); |
189 | 31305 | vcaballero | if (layer instanceof FLayers){ |
190 | setActives(active,(FLayers)layer); |
||
191 | } |
||
192 | 1185 | vcaballero | } |
193 | } |
||
194 | 1219 | vcaballero | |
195 | 1086 | vcaballero | /**
|
196 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
197 | 1086 | vcaballero | */
|
198 | public boolean isVisible() { |
||
199 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
200 | 6880 | cesar | .getActiveWindow(); |
201 | 312 | fernando | |
202 | 1086 | vcaballero | if (f == null) { |
203 | return false; |
||
204 | } |
||
205 | 312 | fernando | |
206 | 5900 | jorpiell | if (f instanceof View) { |
207 | 1086 | vcaballero | View vista = (View) f; |
208 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
209 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
210 | 1219 | vcaballero | |
211 | 1086 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
212 | 6630 | caballero | } |
213 | 1086 | vcaballero | return false; |
214 | } |
||
215 | 596 | fernando | |
216 | /**
|
||
217 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
218 | 596 | fernando | */
|
219 | 5005 | jorpiell | public void initialize() { |
220 | 6673 | jmvivo | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
221 | 6713 | caballero | |
222 | |||
223 | 6673 | jmvivo | if (!extensionPoints.containsKey("View_TocActions")) { |
224 | extensionPoints.put( |
||
225 | new ExtensionPoint(
|
||
226 | "View_TocActions",
|
||
227 | 6713 | caballero | "Context menu options of the TOC " +
|
228 | " in the view window "+
|
||
229 | 6673 | jmvivo | "(register instances of " +
|
230 | "com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
|
||
231 | ) |
||
232 | ); |
||
233 | } |
||
234 | 6713 | caballero | |
235 | FPopupMenu.registerExtensionPoint(); |
||
236 | |||
237 | 14821 | jmvivo | registerIcons(); |
238 | 596 | fernando | } |
239 | |||
240 | 14821 | jmvivo | private void registerIcons(){ |
241 | |||
242 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
243 | 14821 | jmvivo | "view-zoom-in",
|
244 | this.getClass().getClassLoader().getResource("images/ZoomIn.png") |
||
245 | ); |
||
246 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
247 | 14821 | jmvivo | "view-zoom-out",
|
248 | this.getClass().getClassLoader().getResource("images/ZoomOut.png") |
||
249 | ); |
||
250 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
251 | 14821 | jmvivo | "view-zoom-map-contents",
|
252 | this.getClass().getClassLoader().getResource("images/MapContents.png") |
||
253 | ); |
||
254 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
255 | 14821 | jmvivo | "view-zoom-center-in",
|
256 | this.getClass().getClassLoader().getResource("images/zoommas.png") |
||
257 | ); |
||
258 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
259 | 14821 | jmvivo | "view-zoom-center-out",
|
260 | this.getClass().getClassLoader().getResource("images/zoommenos.png") |
||
261 | ); |
||
262 | |||
263 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
264 | 14821 | jmvivo | "view-pan",
|
265 | this.getClass().getClassLoader().getResource("images/Pan.png") |
||
266 | ); |
||
267 | |||
268 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
269 | 14821 | jmvivo | "view-zoom-manager",
|
270 | this.getClass().getClassLoader().getResource("images/encuadre.png") |
||
271 | ); |
||
272 | } |
||
273 | |||
274 | 596 | fernando | /**
|
275 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
276 | 596 | fernando | */
|
277 | public boolean isEnabled() { |
||
278 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
279 | 6880 | cesar | .getActiveWindow(); |
280 | 8516 | jaume | |
281 | 6778 | jmvivo | if (f == null) { |
282 | return false; |
||
283 | } |
||
284 | 8516 | jaume | |
285 | 6778 | jmvivo | if (f instanceof View) { |
286 | View vista = (View) f; |
||
287 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
288 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
289 | 8516 | jaume | |
290 | 6778 | jmvivo | FLayers layers = mapa.getLayers(); |
291 | for (int i=0;i<layers.getLayersCount();i++) { |
||
292 | if (layers.getLayer(i).isAvailable()) return true; |
||
293 | } |
||
294 | 8516 | jaume | |
295 | 6778 | jmvivo | } |
296 | return false; |
||
297 | 596 | fernando | } |
298 | 6658 | caballero | |
299 | 9634 | caballero | public IPreference[] getPreferencesPages() { |
300 | IPreference[] preferences=new IPreference[1]; |
||
301 | preferences[0]=viewPropertiesPage;
|
||
302 | return preferences;
|
||
303 | 6658 | caballero | } |
304 | 312 | fernando | } |