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