root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 24444
History | View | Annotate | Download (7.72 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 | 652 | fernando | import com.iver.cit.gvsig.fmap.DriverException; |
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 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.Encuadrator; |
62 | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
||
63 | import com.iver.cit.gvsig.project.documents.view.gui.ExtentListSelectorModel; |
||
64 | import com.iver.cit.gvsig.project.documents.view.gui.FPanelExtentSelector; |
||
65 | 11091 | jaume | import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig; |
66 | 8765 | jjdelcerro | import com.iver.cit.gvsig.project.documents.view.gui.View; |
67 | import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu; |
||
68 | 6673 | jmvivo | import com.iver.utiles.extensionPoints.ExtensionPoint; |
69 | import com.iver.utiles.extensionPoints.ExtensionPoints; |
||
70 | import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
||
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 | 22283 | vcaballero | public class ViewControls extends Extension { |
81 | 1086 | vcaballero | private static Logger logger = Logger.getLogger(ViewControls.class.getName()); |
82 | 8765 | jjdelcerro | private static ViewPage viewPropertiesPage = new ViewPage(); |
83 | 1086 | vcaballero | /**
|
84 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
85 | 1086 | vcaballero | */
|
86 | public void execute(String s) { |
||
87 | 6880 | cesar | com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
88 | 6658 | caballero | if (!(view instanceof View)) |
89 | return;
|
||
90 | View vista=(View)view; |
||
91 | 8765 | jjdelcerro | IProjectView model = vista.getModel(); |
92 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
93 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
94 | 1086 | vcaballero | logger.debug("Comand : " + s);
|
95 | 312 | fernando | |
96 | 6239 | caballero | if (s.equals("FULL") ) { |
97 | 1086 | vcaballero | try {
|
98 | 1327 | fjp | // mapa.beginAtomicEvent();
|
99 | 312 | fernando | mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent()); |
100 | 10752 | caballero | mapa.clearAllCachingImageDrawnLayers(); |
101 | 1327 | fjp | vista.repaintMap(); |
102 | // mapa.endAtomicEvent();
|
||
103 | 652 | fernando | } catch (DriverException e) {
|
104 | 1086 | vcaballero | NotificationManager.addError("Error obteniendo el full extent",
|
105 | e); |
||
106 | 312 | fernando | } |
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 | 6880 | cesar | PluginServices.getMDIManager().addWindow(l); |
118 | 6239 | caballero | } else if (s.equals("CONFIG_LOCATOR") ) { |
119 | 312 | fernando | //Set up the map overview
|
120 | 11091 | jaume | FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
121 | 6880 | cesar | PluginServices.getMDIManager().addWindow(m_panelLoc); |
122 | 1086 | vcaballero | m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
123 | 6239 | caballero | } else if (s.equals("PAN") ) { |
124 | 1086 | vcaballero | mapCtrl.setTool("pan");
|
125 | 6239 | caballero | } else if (s.equals("ZOOM_IN") ) { |
126 | 1086 | vcaballero | mapCtrl.setTool("zoomIn");
|
127 | 6239 | caballero | } else if (s.equals("ZOOM_OUT") ) { |
128 | 1086 | vcaballero | mapCtrl.setTool("zoomOut");
|
129 | 6239 | caballero | } else if (s.equals("CAPAS_VISIBLES") ) { |
130 | 1219 | vcaballero | setVisibles(true, mapa);
|
131 | 6239 | caballero | } else if (s.equals("CAPAS_NOVISIBLES") ) { |
132 | 1219 | vcaballero | setVisibles(false, mapa);
|
133 | 6239 | caballero | } else if (s.equals("CAPAS_ACTIVAS") ) { |
134 | 1219 | vcaballero | setActives(true, mapa);
|
135 | 6239 | caballero | } else if (s.equals("CAPAS_NOACTIVAS") ) { |
136 | 1219 | vcaballero | setActives(false, mapa);
|
137 | 6239 | caballero | } else if (s.equals("SAVERASTER") ) { |
138 | 2183 | fernando | mapCtrl.setTool("saveRaster");
|
139 | 6239 | caballero | } else if (s.equals("SELECTIMAGE") ) { |
140 | 2183 | fernando | mapCtrl.setTool("selectImage");
|
141 | 6239 | caballero | } else if (s.equals("ACTION_ZOOM_IN") ) { |
142 | mapCtrl.zoomIn(); |
||
143 | } else if (s.equals("ACTION_ZOOM_OUT") ) { |
||
144 | mapCtrl.zoomOut(); |
||
145 | 6630 | caballero | } else if (s.startsWith("CHANGE_SCALE_")){ |
146 | String scl=s.replaceAll("CHANGE_SCALE_",""); |
||
147 | long scale=Long.parseLong(scl); |
||
148 | mapa.setScaleView(scale); |
||
149 | 1086 | vcaballero | } |
150 | } |
||
151 | 1219 | vcaballero | |
152 | /**
|
||
153 | * Pone todas las capas visibles o no visibles.
|
||
154 | *
|
||
155 | * @param visible true si que quieren poner a visibles.
|
||
156 | * @param mapa FMap sobre el que actuar.
|
||
157 | */
|
||
158 | 6878 | cesar | private void setVisibles(boolean visible, MapContext mapa) { |
159 | 1219 | vcaballero | for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
160 | FLayer layer = mapa.getLayers().getLayer(i); |
||
161 | 1185 | vcaballero | layer.setVisible(visible); |
162 | } |
||
163 | } |
||
164 | 1219 | vcaballero | |
165 | /**
|
||
166 | * Pone todas las capas activas o no activas.
|
||
167 | *
|
||
168 | * @param active true si que quieren poner a activas.
|
||
169 | * @param mapa FMap sobre el que actuar.
|
||
170 | */
|
||
171 | 6878 | cesar | private void setActives(boolean active, MapContext mapa) { |
172 | 1219 | vcaballero | for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
173 | FLayer layer = mapa.getLayers().getLayer(i); |
||
174 | 1185 | vcaballero | layer.setActive(active); |
175 | } |
||
176 | } |
||
177 | 1219 | vcaballero | |
178 | 1086 | vcaballero | /**
|
179 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
180 | 1086 | vcaballero | */
|
181 | public boolean isVisible() { |
||
182 | 6877 | cesar | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
183 | 6880 | cesar | .getActiveWindow(); |
184 | 312 | fernando | |
185 | 1086 | vcaballero | if (f == null) { |
186 | return false; |
||
187 | } |
||
188 | 312 | fernando | |
189 | 5900 | jorpiell | if (f instanceof View) { |
190 | 1086 | vcaballero | View vista = (View) f; |
191 | 8765 | jjdelcerro | IProjectView model = vista.getModel(); |
192 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
193 | 1219 | vcaballero | |
194 | 1086 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
195 | 6630 | caballero | } |
196 | 1086 | vcaballero | return false; |
197 | } |
||
198 | 596 | fernando | |
199 | /**
|
||
200 | 5005 | jorpiell | * @see com.iver.andami.plugins.IExtension#initialize()
|
201 | 596 | fernando | */
|
202 | 5005 | jorpiell | public void initialize() { |
203 | 6673 | jmvivo | ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
204 | 6713 | caballero | |
205 | |||
206 | 6673 | jmvivo | if (!extensionPoints.containsKey("View_TocActions")) { |
207 | extensionPoints.put( |
||
208 | new ExtensionPoint(
|
||
209 | "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 | } |
||
217 | 6713 | caballero | |
218 | FPopupMenu.registerExtensionPoint(); |
||
219 | 22283 | vcaballero | registerPrefPage(); |
220 | } |
||
221 | 6713 | caballero | |
222 | 22283 | vcaballero | private void registerPrefPage() { |
223 | ExtensionPointsSingleton.getInstance().add("AplicationPreferences",
|
||
224 | ViewPage.class.getName(), new ViewPage());
|
||
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 | 8765 | jjdelcerro | |
234 | 6778 | jmvivo | if (f == null) { |
235 | return false; |
||
236 | } |
||
237 | 8765 | jjdelcerro | |
238 | 6778 | jmvivo | if (f instanceof View) { |
239 | View vista = (View) f; |
||
240 | 8765 | jjdelcerro | IProjectView model = vista.getModel(); |
241 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
242 | 8765 | jjdelcerro | |
243 | 6778 | jmvivo | FLayers layers = mapa.getLayers(); |
244 | for (int i=0;i<layers.getLayersCount();i++) { |
||
245 | if (layers.getLayer(i).isAvailable()) return true; |
||
246 | } |
||
247 | 8765 | jjdelcerro | |
248 | 6778 | jmvivo | } |
249 | return false; |
||
250 | 596 | fernando | } |
251 | 6658 | caballero | |
252 | 312 | fernando | } |