svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 9532
History | View | Annotate | Download (8.68 KB)
1 |
/*
|
---|---|
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 |
/* 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 |
package com.iver.cit.gvsig; |
48 |
|
49 |
import org.apache.log4j.Logger; |
50 |
|
51 |
import com.iver.andami.PluginServices; |
52 |
import com.iver.andami.messages.NotificationManager; |
53 |
import com.iver.andami.plugins.Extension; |
54 |
import com.iver.andami.preferences.IPreference; |
55 |
import com.iver.andami.preferences.IPreferenceExtension; |
56 |
import com.iver.andami.ui.mdiManager.IWindow; |
57 |
import com.iver.cit.gvsig.fmap.DriverException; |
58 |
import com.iver.cit.gvsig.fmap.MapContext; |
59 |
import com.iver.cit.gvsig.fmap.MapControl; |
60 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
61 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
62 |
import com.iver.cit.gvsig.gui.preferencespage.ViewPage; |
63 |
import com.iver.cit.gvsig.project.Project; |
64 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
65 |
import com.iver.cit.gvsig.project.documents.view.Encuadrator; |
66 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
67 |
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 |
import com.iver.utiles.extensionPoints.ExtensionPoint; |
73 |
import com.iver.utiles.extensionPoints.ExtensionPoints; |
74 |
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton; |
75 |
|
76 |
|
77 |
//import com.iver.utiles.FPanelExtentSelector;
|
78 |
|
79 |
/**
|
80 |
* Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
81 |
*
|
82 |
* @author vcn
|
83 |
*/
|
84 |
public class ViewControls extends Extension implements IPreferenceExtension{ |
85 |
private static Logger logger = Logger.getLogger(ViewControls.class.getName()); |
86 |
private static ViewPage viewPropertiesPage = new ViewPage(); |
87 |
/**
|
88 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
89 |
*/
|
90 |
public void execute(String s) { |
91 |
com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow(); |
92 |
if (!(view instanceof View)) |
93 |
return;
|
94 |
View vista=(View)view; |
95 |
IProjectView model = vista.getModel(); |
96 |
MapContext mapa = model.getMapContext(); |
97 |
MapControl mapCtrl = vista.getMapControl(); |
98 |
logger.debug("Comand : " + s);
|
99 |
|
100 |
if (s.equals("FULL") ) { |
101 |
try {
|
102 |
// mapa.beginAtomicEvent();
|
103 |
mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent()); |
104 |
vista.repaintMap(); |
105 |
((ProjectDocument)vista.getModel()).setModified(true);
|
106 |
// mapa.endAtomicEvent();
|
107 |
} catch (DriverException e) {
|
108 |
NotificationManager.addError("Error obteniendo el full extent",
|
109 |
e); |
110 |
} |
111 |
} else if (s.equals("ENCUADRE") ) { |
112 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
113 |
|
114 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
115 |
Project project = p.getProject(); |
116 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
117 |
//ProjectExtent[] extents = project.getExtents();
|
118 |
project.addPropertyChangeListener(modelo); |
119 |
l.setModel(modelo); |
120 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
121 |
((ProjectDocument)vista.getModel()).setModified(true);
|
122 |
PluginServices.getMDIManager().addWindow(l); |
123 |
} else if (s.equals("CONFIG_LOCATOR") ) { |
124 |
//Set up the map overview
|
125 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
126 |
PluginServices.getMDIManager().addWindow(m_panelLoc); |
127 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
128 |
((ProjectDocument)vista.getModel()).setModified(true);
|
129 |
} else if (s.equals("PAN") ) { |
130 |
mapCtrl.setTool("pan");
|
131 |
((ProjectDocument)vista.getModel()).setModified(true);
|
132 |
} else if (s.equals("ZOOM_IN") ) { |
133 |
mapCtrl.setTool("zoomIn");
|
134 |
((ProjectDocument)vista.getModel()).setModified(true);
|
135 |
} else if (s.equals("ZOOM_OUT") ) { |
136 |
mapCtrl.setTool("zoomOut");
|
137 |
((ProjectDocument)vista.getModel()).setModified(true);
|
138 |
} else if (s.equals("MEDICION") ) { |
139 |
mapCtrl.setTool("medicion");
|
140 |
} else if (s.equals("AREA") ) { |
141 |
mapCtrl.setTool("area");
|
142 |
} else if (s.equals("CAPAS_VISIBLES") ) { |
143 |
setVisibles(true, mapa);
|
144 |
((ProjectDocument)vista.getModel()).setModified(true);
|
145 |
} else if (s.equals("CAPAS_NOVISIBLES") ) { |
146 |
setVisibles(false, mapa);
|
147 |
((ProjectDocument)vista.getModel()).setModified(true);
|
148 |
} else if (s.equals("CAPAS_ACTIVAS") ) { |
149 |
setActives(true, mapa);
|
150 |
((ProjectDocument)vista.getModel()).setModified(true);
|
151 |
} else if (s.equals("CAPAS_NOACTIVAS") ) { |
152 |
setActives(false, mapa);
|
153 |
((ProjectDocument)vista.getModel()).setModified(true);
|
154 |
} else if (s.equals("SAVERASTER") ) { |
155 |
mapCtrl.setTool("saveRaster");
|
156 |
} else if (s.equals("SELECTIMAGE") ) { |
157 |
mapCtrl.setTool("selectImage");
|
158 |
} else if (s.equals("ACTION_ZOOM_IN") ) { |
159 |
mapCtrl.zoomIn(); |
160 |
((ProjectDocument)vista.getModel()).setModified(true);
|
161 |
} else if (s.equals("ACTION_ZOOM_OUT") ) { |
162 |
mapCtrl.zoomOut(); |
163 |
((ProjectDocument)vista.getModel()).setModified(true);
|
164 |
} else if (s.startsWith("CHANGE_SCALE_")){ |
165 |
String scl=s.replaceAll("CHANGE_SCALE_",""); |
166 |
long scale=Long.parseLong(scl); |
167 |
mapa.setScaleView(scale); |
168 |
((ProjectDocument)vista.getModel()).setModified(true);
|
169 |
} |
170 |
} |
171 |
|
172 |
/**
|
173 |
* Pone todas las capas visibles o no visibles.
|
174 |
*
|
175 |
* @param visible true si que quieren poner a visibles.
|
176 |
* @param mapa FMap sobre el que actuar.
|
177 |
*/
|
178 |
private void setVisibles(boolean visible, MapContext mapa) { |
179 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
180 |
FLayer layer = mapa.getLayers().getLayer(i); |
181 |
layer.setVisible(visible); |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Pone todas las capas activas o no activas.
|
187 |
*
|
188 |
* @param active true si que quieren poner a activas.
|
189 |
* @param mapa FMap sobre el que actuar.
|
190 |
*/
|
191 |
private void setActives(boolean active, MapContext mapa) { |
192 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
193 |
FLayer layer = mapa.getLayers().getLayer(i); |
194 |
layer.setActive(active); |
195 |
} |
196 |
} |
197 |
|
198 |
/**
|
199 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
200 |
*/
|
201 |
public boolean isVisible() { |
202 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
203 |
.getActiveWindow(); |
204 |
|
205 |
if (f == null) { |
206 |
return false; |
207 |
} |
208 |
|
209 |
if (f instanceof View) { |
210 |
View vista = (View) f; |
211 |
IProjectView model = vista.getModel(); |
212 |
MapContext mapa = model.getMapContext(); |
213 |
|
214 |
return mapa.getLayers().getLayersCount() > 0; |
215 |
} |
216 |
return false; |
217 |
} |
218 |
|
219 |
/**
|
220 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
221 |
*/
|
222 |
public void initialize() { |
223 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
224 |
|
225 |
|
226 |
if (!extensionPoints.containsKey("View_TocActions")) { |
227 |
extensionPoints.put( |
228 |
new ExtensionPoint(
|
229 |
"View_TocActions",
|
230 |
"Context menu options of the TOC " +
|
231 |
" in the view window "+
|
232 |
"(register instances of " +
|
233 |
"com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
|
234 |
) |
235 |
); |
236 |
} |
237 |
|
238 |
FPopupMenu.registerExtensionPoint(); |
239 |
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
244 |
*/
|
245 |
public boolean isEnabled() { |
246 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
247 |
.getActiveWindow(); |
248 |
|
249 |
if (f == null) { |
250 |
return false; |
251 |
} |
252 |
|
253 |
if (f instanceof View) { |
254 |
View vista = (View) f; |
255 |
IProjectView model = vista.getModel(); |
256 |
MapContext mapa = model.getMapContext(); |
257 |
|
258 |
FLayers layers = mapa.getLayers(); |
259 |
for (int i=0;i<layers.getLayersCount();i++) { |
260 |
if (layers.getLayer(i).isAvailable()) return true; |
261 |
} |
262 |
|
263 |
} |
264 |
return false; |
265 |
} |
266 |
|
267 |
public IPreference getPreferencesPage() {
|
268 |
return viewPropertiesPage;
|
269 |
} |
270 |
} |