root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 8062
History | View | Annotate | Download (7.85 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.messages.NotificationManager; |
||
53 | import com.iver.andami.plugins.Extension; |
||
54 | 6658 | caballero | import com.iver.andami.preferences.IPreference; |
55 | import com.iver.andami.preferences.IPreferenceExtension; |
||
56 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
57 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
58 | 1223 | fernando | import com.iver.cit.gvsig.fmap.MapControl; |
59 | 637 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayer; |
60 | 6778 | jmvivo | import com.iver.cit.gvsig.fmap.layers.FLayers; |
61 | 6658 | caballero | import com.iver.cit.gvsig.gui.preferencespage.ViewPage; |
62 | 1221 | fernando | import com.iver.cit.gvsig.project.Project; |
63 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.Encuadrator; |
64 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
65 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.ExtentListSelectorModel; |
66 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelExtentSelector; |
||
67 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig; |
||
68 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
69 | import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu; |
||
70 | 6673 | jmvivo | import com.iver.utiles.extensionPoints.ExtensionPoint; |
71 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
72 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
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 | 6658 | caballero | private static ViewPage viewPropertiesPage=new ViewPage(); |
85 | 1086 | vcaballero | /**
|
86 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
87 | 1086 | vcaballero | */
|
88 | public void execute(String s) { |
||
89 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
90 | 6658 | caballero | if (!(view instanceof View)) |
91 | return;
|
||
92 | View vista=(View)view; |
||
93 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
94 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
95 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
96 | 1086 | vcaballero | logger.debug("Comand : " + s);
|
97 | 312 | fernando | |
98 | 6239 | caballero | if (s.equals("FULL") ) { |
99 | 1086 | vcaballero | try {
|
100 | 1327 | fjp | // mapa.beginAtomicEvent();
|
101 | 312 | fernando | mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent()); |
102 | 1327 | fjp | vista.repaintMap(); |
103 | // mapa.endAtomicEvent();
|
||
104 | 652 | fernando | } catch (DriverException e) {
|
105 | 1086 | vcaballero | NotificationManager.addError("Error obteniendo el full extent",
|
106 | e); |
||
107 | 312 | fernando | } |
108 | 6239 | caballero | } else if (s.equals("ENCUADRE") ) { |
109 | 1086 | vcaballero | FPanelExtentSelector l = new FPanelExtentSelector();
|
110 | 312 | fernando | |
111 | 1086 | vcaballero | ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
112 | Project project = p.getProject(); |
||
113 | ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
||
114 | 2522 | caballero | //ProjectExtent[] extents = project.getExtents();
|
115 | 1086 | vcaballero | project.addPropertyChangeListener(modelo); |
116 | l.setModel(modelo); |
||
117 | l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
||
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 | 6239 | caballero | } else if (s.equals("PAN") ) { |
125 | 1086 | vcaballero | mapCtrl.setTool("pan");
|
126 | 6239 | caballero | } else if (s.equals("ZOOM_IN") ) { |
127 | 1086 | vcaballero | mapCtrl.setTool("zoomIn");
|
128 | 6239 | caballero | } else if (s.equals("ZOOM_OUT") ) { |
129 | 1086 | vcaballero | mapCtrl.setTool("zoomOut");
|
130 | 6239 | caballero | } else if (s.equals("MEDICION") ) { |
131 | 375 | fjp | mapCtrl.setTool("medicion");
|
132 | 6239 | caballero | } else if (s.equals("AREA") ) { |
133 | 375 | fjp | mapCtrl.setTool("area");
|
134 | 6239 | caballero | } else if (s.equals("CAPAS_VISIBLES") ) { |
135 | 1219 | vcaballero | setVisibles(true, mapa);
|
136 | 6239 | caballero | } else if (s.equals("CAPAS_NOVISIBLES") ) { |
137 | 1219 | vcaballero | setVisibles(false, mapa);
|
138 | 6239 | caballero | } else if (s.equals("CAPAS_ACTIVAS") ) { |
139 | 1219 | vcaballero | setActives(true, mapa);
|
140 | 6239 | caballero | } else if (s.equals("CAPAS_NOACTIVAS") ) { |
141 | 1219 | vcaballero | setActives(false, mapa);
|
142 | 6239 | caballero | } else if (s.equals("SAVERASTER") ) { |
143 | 2183 | fernando | mapCtrl.setTool("saveRaster");
|
144 | 6239 | caballero | } else if (s.equals("SELECTIMAGE") ) { |
145 | 2183 | fernando | mapCtrl.setTool("selectImage");
|
146 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_IN") ) { |
147 | mapCtrl.zoomIn(); |
||
148 | } else if (s.equals("ACTION_ZOOM_OUT") ) { |
||
149 | mapCtrl.zoomOut(); |
||
150 | 6630 | caballero | } else if (s.startsWith("CHANGE_SCALE_")){ |
151 | String scl=s.replaceAll("CHANGE_SCALE_",""); |
||
152 | long scale=Long.parseLong(scl); |
||
153 | mapa.setScaleView(scale); |
||
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 | 1086 | vcaballero | if (f == null) { |
191 | return false; |
||
192 | } |
||
193 | 312 | fernando | |
194 | 5900 | jorpiell | if (f instanceof View) { |
195 | 1086 | vcaballero | View vista = (View) f; |
196 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
197 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
198 | 1219 | vcaballero | |
199 | 1086 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
200 | 6630 | caballero | } |
201 | 1086 | vcaballero | return false; |
202 | } |
||
203 | 596 | fernando | |
204 | /**
|
||
205 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
206 | 596 | fernando | */
|
207 | 5005 | jorpiell | public void initialize() { |
208 | 6673 | jmvivo | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
209 | 6713 | caballero | |
210 | |||
211 | 6673 | jmvivo | if (!extensionPoints.containsKey("View_TocActions")) { |
212 | extensionPoints.put( |
||
213 | new ExtensionPoint(
|
||
214 | "View_TocActions",
|
||
215 | 6713 | caballero | "Context menu options of the TOC " +
|
216 | " in the view window "+
|
||
217 | 6673 | jmvivo | "(register instances of " +
|
218 | "com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
|
||
219 | ) |
||
220 | ); |
||
221 | } |
||
222 | 6713 | caballero | |
223 | FPopupMenu.registerExtensionPoint(); |
||
224 | |||
225 | 596 | fernando | } |
226 | |||
227 | /**
|
||
228 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
229 | 596 | fernando | */
|
230 | public boolean isEnabled() { |
||
231 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
232 | 6880 | cesar | .getActiveWindow(); |
233 | 6778 | jmvivo | |
234 | if (f == null) { |
||
235 | return false; |
||
236 | } |
||
237 | |||
238 | if (f instanceof View) { |
||
239 | View vista = (View) f; |
||
240 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
241 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
242 | 6778 | jmvivo | |
243 | FLayers layers = mapa.getLayers(); |
||
244 | for (int i=0;i<layers.getLayersCount();i++) { |
||
245 | if (layers.getLayer(i).isAvailable()) return true; |
||
246 | } |
||
247 | |||
248 | } |
||
249 | return false; |
||
250 | 596 | fernando | } |
251 | 6658 | caballero | |
252 | public IPreference getPreferencesPage() {
|
||
253 | return viewPropertiesPage;
|
||
254 | } |
||
255 | 312 | fernando | } |