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