root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 24963
History | View | Annotate | Download (9.61 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 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
51 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
52 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
53 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
54 | 24953 | jmvivo | import org.gvsig.tools.ToolsLocator; |
55 | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
||
56 | 2522 | caballero | |
57 | 596 | fernando | import com.iver.andami.PluginServices; |
58 | import com.iver.andami.plugins.Extension; |
||
59 | 6658 | caballero | import com.iver.andami.preferences.IPreference; |
60 | import com.iver.andami.preferences.IPreferenceExtension; |
||
61 | 23642 | vcaballero | import com.iver.cit.gvsig.gui.preferencespage.GridPage; |
62 | 6658 | caballero | import com.iver.cit.gvsig.gui.preferencespage.ViewPage; |
63 | 1221 | fernando | import com.iver.cit.gvsig.project.Project; |
64 | 9532 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
65 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.Encuadrator; |
66 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
67 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.ExtentListSelectorModel; |
68 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelExtentSelector; |
||
69 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig; |
||
70 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
71 | import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu; |
||
72 | 23642 | vcaballero | import com.iver.cit.gvsig.project.documents.view.toolListeners.snapping.Snapping; |
73 | 1086 | vcaballero | |
74 | |||
75 | 312 | fernando | //import com.iver.utiles.FPanelExtentSelector;
|
76 | |||
77 | /**
|
||
78 | 6630 | caballero | * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
79 | 312 | fernando | *
|
80 | * @author vcn
|
||
81 | */
|
||
82 | 6658 | caballero | public class ViewControls extends Extension implements IPreferenceExtension{ |
83 | 1086 | vcaballero | private static Logger logger = Logger.getLogger(ViewControls.class.getName()); |
84 | 8516 | jaume | private static ViewPage viewPropertiesPage = new ViewPage(); |
85 | 23642 | vcaballero | |
86 | 1086 | vcaballero | /**
|
87 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
88 | 1086 | vcaballero | */
|
89 | public void execute(String s) { |
||
90 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
91 | 24953 | jmvivo | if (!(view instanceof View)) { |
92 | 6658 | caballero | return;
|
93 | 24953 | jmvivo | } |
94 | 6658 | caballero | View vista=(View)view; |
95 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
96 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
97 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
98 | 1086 | vcaballero | logger.debug("Comand : " + s);
|
99 | 312 | fernando | |
100 | 6239 | caballero | if (s.equals("FULL") ) { |
101 | 10626 | caballero | // mapa.beginAtomicEvent();
|
102 | 21501 | vcaballero | mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
103 | 10839 | caballero | mapa.clearAllCachingImageDrawnLayers(); |
104 | 10626 | caballero | vista.repaintMap(); |
105 | ((ProjectDocument)vista.getModel()).setModified(true);
|
||
106 | // mapa.endAtomicEvent();
|
||
107 | 6239 | caballero | } else if (s.equals("ENCUADRE") ) { |
108 | 1086 | vcaballero | FPanelExtentSelector l = new FPanelExtentSelector();
|
109 | 312 | fernando | |
110 | 1086 | vcaballero | ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
111 | Project project = p.getProject(); |
||
112 | ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
||
113 | 2522 | caballero | //ProjectExtent[] extents = project.getExtents();
|
114 | 1086 | vcaballero | project.addPropertyChangeListener(modelo); |
115 | l.setModel(modelo); |
||
116 | l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
||
117 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
118 | 6880 | cesar | PluginServices.getMDIManager().addWindow(l); |
119 | 6239 | caballero | } else if (s.equals("CONFIG_LOCATOR") ) { |
120 | 312 | fernando | //Set up the map overview
|
121 | 643 | fjp | FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
122 | 6880 | cesar | PluginServices.getMDIManager().addWindow(m_panelLoc); |
123 | 1086 | vcaballero | m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
124 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
125 | 6239 | caballero | } else if (s.equals("PAN") ) { |
126 | 1086 | vcaballero | mapCtrl.setTool("pan");
|
127 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
128 | 6239 | caballero | } else if (s.equals("ZOOM_IN") ) { |
129 | 1086 | vcaballero | mapCtrl.setTool("zoomIn");
|
130 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
131 | 6239 | caballero | } else if (s.equals("ZOOM_OUT") ) { |
132 | 1086 | vcaballero | mapCtrl.setTool("zoomOut");
|
133 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
134 | 6239 | caballero | } else if (s.equals("CAPAS_VISIBLES") ) { |
135 | 1219 | vcaballero | setVisibles(true, mapa);
|
136 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
137 | 6239 | caballero | } else if (s.equals("CAPAS_NOVISIBLES") ) { |
138 | 1219 | vcaballero | setVisibles(false, mapa);
|
139 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
140 | 6239 | caballero | } else if (s.equals("CAPAS_ACTIVAS") ) { |
141 | 1219 | vcaballero | setActives(true, mapa);
|
142 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
143 | 6239 | caballero | } else if (s.equals("CAPAS_NOACTIVAS") ) { |
144 | 1219 | vcaballero | setActives(false, mapa);
|
145 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
146 | 6239 | caballero | } else if (s.equals("SAVERASTER") ) { |
147 | 2183 | fernando | mapCtrl.setTool("saveRaster");
|
148 | 6239 | caballero | } else if (s.equals("SELECTIMAGE") ) { |
149 | 2183 | fernando | mapCtrl.setTool("selectImage");
|
150 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_IN") ) { |
151 | mapCtrl.zoomIn(); |
||
152 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
153 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_OUT") ) { |
154 | mapCtrl.zoomOut(); |
||
155 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
156 | 6630 | caballero | } else if (s.startsWith("CHANGE_SCALE_")){ |
157 | String scl=s.replaceAll("CHANGE_SCALE_",""); |
||
158 | long scale=Long.parseLong(scl); |
||
159 | mapa.setScaleView(scale); |
||
160 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
161 | 1086 | vcaballero | } |
162 | } |
||
163 | 1219 | vcaballero | |
164 | /**
|
||
165 | * Pone todas las capas visibles o no visibles.
|
||
166 | *
|
||
167 | * @param visible true si que quieren poner a visibles.
|
||
168 | * @param mapa FMap sobre el que actuar.
|
||
169 | */
|
||
170 | 6878 | cesar | private void setVisibles(boolean visible, MapContext mapa) { |
171 | 1219 | vcaballero | for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
172 | FLayer layer = mapa.getLayers().getLayer(i); |
||
173 | 1185 | vcaballero | layer.setVisible(visible); |
174 | } |
||
175 | } |
||
176 | 1219 | vcaballero | |
177 | /**
|
||
178 | * Pone todas las capas activas o no activas.
|
||
179 | *
|
||
180 | * @param active true si que quieren poner a activas.
|
||
181 | * @param mapa FMap sobre el que actuar.
|
||
182 | */
|
||
183 | 6878 | cesar | private void setActives(boolean active, MapContext mapa) { |
184 | 1219 | vcaballero | for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
185 | FLayer layer = mapa.getLayers().getLayer(i); |
||
186 | 1185 | vcaballero | layer.setActive(active); |
187 | } |
||
188 | } |
||
189 | 1219 | vcaballero | |
190 | 1086 | vcaballero | /**
|
191 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
192 | 1086 | vcaballero | */
|
193 | public boolean isVisible() { |
||
194 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
195 | 6880 | cesar | .getActiveWindow(); |
196 | 312 | fernando | |
197 | 1086 | vcaballero | if (f == null) { |
198 | return false; |
||
199 | } |
||
200 | 312 | fernando | |
201 | 5900 | jorpiell | if (f instanceof View) { |
202 | 1086 | vcaballero | View vista = (View) f; |
203 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
204 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
205 | 1219 | vcaballero | |
206 | 1086 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
207 | 6630 | caballero | } |
208 | 1086 | vcaballero | return false; |
209 | } |
||
210 | 596 | fernando | |
211 | /**
|
||
212 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
213 | 596 | fernando | */
|
214 | 5005 | jorpiell | public void initialize() { |
215 | 6713 | caballero | |
216 | 24953 | jmvivo | ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
217 | 6713 | caballero | |
218 | 24953 | jmvivo | if (!epManager.has("View_TocActions")) { |
219 | epManager.add( |
||
220 | 6673 | jmvivo | "View_TocActions",
|
221 | 6713 | caballero | "Context menu options of the TOC " +
|
222 | " in the view window "+
|
||
223 | 6673 | jmvivo | "(register instances of " +
|
224 | "com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
|
||
225 | ); |
||
226 | } |
||
227 | 6713 | caballero | |
228 | FPopupMenu.registerExtensionPoint(); |
||
229 | |||
230 | 14821 | jmvivo | registerIcons(); |
231 | 23642 | vcaballero | Snapping.register(); |
232 | 596 | fernando | } |
233 | |||
234 | 14821 | jmvivo | private void registerIcons(){ |
235 | |||
236 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
237 | 14821 | jmvivo | "view-zoom-in",
|
238 | this.getClass().getClassLoader().getResource("images/ZoomIn.png") |
||
239 | ); |
||
240 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
241 | 14821 | jmvivo | "view-zoom-out",
|
242 | this.getClass().getClassLoader().getResource("images/ZoomOut.png") |
||
243 | ); |
||
244 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
245 | 14821 | jmvivo | "view-zoom-map-contents",
|
246 | this.getClass().getClassLoader().getResource("images/MapContents.png") |
||
247 | ); |
||
248 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
249 | 14821 | jmvivo | "view-zoom-center-in",
|
250 | this.getClass().getClassLoader().getResource("images/zoommas.png") |
||
251 | ); |
||
252 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
253 | 14821 | jmvivo | "view-zoom-center-out",
|
254 | this.getClass().getClassLoader().getResource("images/zoommenos.png") |
||
255 | ); |
||
256 | |||
257 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
258 | 14821 | jmvivo | "view-pan",
|
259 | this.getClass().getClassLoader().getResource("images/Pan.png") |
||
260 | ); |
||
261 | |||
262 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
263 | 14821 | jmvivo | "view-zoom-manager",
|
264 | this.getClass().getClassLoader().getResource("images/encuadre.png") |
||
265 | ); |
||
266 | } |
||
267 | |||
268 | 596 | fernando | /**
|
269 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
270 | 596 | fernando | */
|
271 | public boolean isEnabled() { |
||
272 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
273 | 6880 | cesar | .getActiveWindow(); |
274 | 8516 | jaume | |
275 | 6778 | jmvivo | if (f == null) { |
276 | return false; |
||
277 | } |
||
278 | 8516 | jaume | |
279 | 6778 | jmvivo | if (f instanceof View) { |
280 | View vista = (View) f; |
||
281 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
282 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
283 | 8516 | jaume | |
284 | 6778 | jmvivo | FLayers layers = mapa.getLayers(); |
285 | for (int i=0;i<layers.getLayersCount();i++) { |
||
286 | 24953 | jmvivo | if (layers.getLayer(i).isAvailable()) {
|
287 | return true; |
||
288 | } |
||
289 | 6778 | jmvivo | } |
290 | 8516 | jaume | |
291 | 6778 | jmvivo | } |
292 | return false; |
||
293 | 596 | fernando | } |
294 | 6658 | caballero | |
295 | 9634 | caballero | public IPreference[] getPreferencesPages() { |
296 | 23642 | vcaballero | IPreference[] preferences=new IPreference[2]; |
297 | 9634 | caballero | preferences[0]=viewPropertiesPage;
|
298 | 23642 | vcaballero | GridPage gridPage=new GridPage();
|
299 | preferences[1]=gridPage;
|
||
300 | 9634 | caballero | return preferences;
|
301 | 6658 | caballero | } |
302 | 312 | fernando | } |