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