svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 6877
History | View | Annotate | Download (7.66 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.FMap; |
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.Encuadrator; |
62 |
import com.iver.cit.gvsig.gui.ExtentListSelectorModel; |
63 |
import com.iver.cit.gvsig.gui.FPanelExtentSelector; |
64 |
import com.iver.cit.gvsig.gui.FPanelLocConfig; |
65 |
import com.iver.cit.gvsig.gui.View; |
66 |
import com.iver.cit.gvsig.gui.preferencespage.ViewPage; |
67 |
import com.iver.cit.gvsig.gui.toc.FPopupMenu; |
68 |
import com.iver.cit.gvsig.project.Project; |
69 |
import com.iver.cit.gvsig.project.ProjectView; |
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().getActiveView(); |
90 |
if (!(view instanceof View)) |
91 |
return;
|
92 |
View vista=(View)view; |
93 |
ProjectView model = vista.getModel(); |
94 |
FMap 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 |
vista.repaintMap(); |
103 |
// mapa.endAtomicEvent();
|
104 |
} catch (DriverException e) {
|
105 |
NotificationManager.addError("Error obteniendo el full extent",
|
106 |
e); |
107 |
} |
108 |
} else if (s.equals("ENCUADRE") ) { |
109 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
110 |
|
111 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class); |
112 |
Project project = p.getProject(); |
113 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
114 |
//ProjectExtent[] extents = project.getExtents();
|
115 |
project.addPropertyChangeListener(modelo); |
116 |
l.setModel(modelo); |
117 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
118 |
PluginServices.getMDIManager().addView(l); |
119 |
} else if (s.equals("CONFIG_LOCATOR") ) { |
120 |
//Set up the map overview
|
121 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
122 |
PluginServices.getMDIManager().addView(m_panelLoc); |
123 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
124 |
} else if (s.equals("PAN") ) { |
125 |
mapCtrl.setTool("pan");
|
126 |
} else if (s.equals("ZOOM_IN") ) { |
127 |
mapCtrl.setTool("zoomIn");
|
128 |
} else if (s.equals("ZOOM_OUT") ) { |
129 |
mapCtrl.setTool("zoomOut");
|
130 |
} else if (s.equals("MEDICION") ) { |
131 |
mapCtrl.setTool("medicion");
|
132 |
} else if (s.equals("AREA") ) { |
133 |
mapCtrl.setTool("area");
|
134 |
} else if (s.equals("CAPAS_VISIBLES") ) { |
135 |
setVisibles(true, mapa);
|
136 |
} else if (s.equals("CAPAS_NOVISIBLES") ) { |
137 |
setVisibles(false, mapa);
|
138 |
} else if (s.equals("CAPAS_ACTIVAS") ) { |
139 |
setActives(true, mapa);
|
140 |
} else if (s.equals("CAPAS_NOACTIVAS") ) { |
141 |
setActives(false, mapa);
|
142 |
} else if (s.equals("SAVERASTER") ) { |
143 |
mapCtrl.setTool("saveRaster");
|
144 |
} else if (s.equals("SELECTIMAGE") ) { |
145 |
mapCtrl.setTool("selectImage");
|
146 |
} else if (s.equals("ACTION_ZOOM_IN") ) { |
147 |
mapCtrl.zoomIn(); |
148 |
} else if (s.equals("ACTION_ZOOM_OUT") ) { |
149 |
mapCtrl.zoomOut(); |
150 |
} else if (s.startsWith("CHANGE_SCALE_")){ |
151 |
String scl=s.replaceAll("CHANGE_SCALE_",""); |
152 |
long scale=Long.parseLong(scl); |
153 |
mapa.setScaleView(scale); |
154 |
} |
155 |
} |
156 |
|
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 |
private void setVisibles(boolean visible, FMap mapa) { |
164 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
165 |
FLayer layer = mapa.getLayers().getLayer(i); |
166 |
layer.setVisible(visible); |
167 |
} |
168 |
} |
169 |
|
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 |
private void setActives(boolean active, FMap mapa) { |
177 |
for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) { |
178 |
FLayer layer = mapa.getLayers().getLayer(i); |
179 |
layer.setActive(active); |
180 |
} |
181 |
} |
182 |
|
183 |
/**
|
184 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
185 |
*/
|
186 |
public boolean isVisible() { |
187 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
188 |
.getActiveView(); |
189 |
|
190 |
if (f == null) { |
191 |
return false; |
192 |
} |
193 |
|
194 |
if (f instanceof View) { |
195 |
View vista = (View) f; |
196 |
ProjectView model = vista.getModel(); |
197 |
FMap mapa = model.getMapContext(); |
198 |
|
199 |
return mapa.getLayers().getLayersCount() > 0; |
200 |
} |
201 |
return false; |
202 |
} |
203 |
|
204 |
/**
|
205 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
206 |
*/
|
207 |
public void initialize() { |
208 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
209 |
|
210 |
|
211 |
if (!extensionPoints.containsKey("View_TocActions")) { |
212 |
extensionPoints.put( |
213 |
new ExtensionPoint(
|
214 |
"View_TocActions",
|
215 |
"Context menu options of the TOC " +
|
216 |
" in the view window "+
|
217 |
"(register instances of " +
|
218 |
"com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
|
219 |
) |
220 |
); |
221 |
} |
222 |
|
223 |
FPopupMenu.registerExtensionPoint(); |
224 |
|
225 |
} |
226 |
|
227 |
/**
|
228 |
* @see com.iver.andami.plugins.IExtension#isEnabled()
|
229 |
*/
|
230 |
public boolean isEnabled() { |
231 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
232 |
.getActiveView(); |
233 |
|
234 |
if (f == null) { |
235 |
return false; |
236 |
} |
237 |
|
238 |
if (f instanceof View) { |
239 |
View vista = (View) f; |
240 |
ProjectView model = vista.getModel(); |
241 |
FMap mapa = model.getMapContext(); |
242 |
|
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 |
} |
251 |
|
252 |
public IPreference getPreferencesPage() {
|
253 |
return viewPropertiesPage;
|
254 |
} |
255 |
} |