root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ViewControls.java @ 31496
History | View | Annotate | Download (9.6 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 org.gvsig.app.extension; |
48 |
|
49 |
import org.gvsig.andami.PluginServices; |
50 |
import org.gvsig.andami.plugins.Extension; |
51 |
import org.gvsig.andami.preferences.IPreference; |
52 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
53 |
import org.gvsig.app.gui.preferencespage.GridPage; |
54 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
55 |
import org.gvsig.app.project.Project; |
56 |
import org.gvsig.app.project.documents.AbstractDocument; |
57 |
import org.gvsig.app.project.documents.view.Encuadrator; |
58 |
import org.gvsig.app.project.documents.view.ViewDocument; |
59 |
import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
60 |
import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
61 |
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
62 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
63 |
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
64 |
import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
65 |
import org.gvsig.fmap.mapcontext.MapContext; |
66 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
67 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
68 |
import org.gvsig.fmap.mapcontrol.MapControl; |
69 |
import org.gvsig.tools.ToolsLocator; |
70 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
71 |
import org.slf4j.Logger; |
72 |
import org.slf4j.LoggerFactory; |
73 |
|
74 |
|
75 |
|
76 |
//import com.iver.utiles.FPanelExtentSelector;
|
77 |
|
78 |
/**
|
79 |
* Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
80 |
*
|
81 |
* @author vcn
|
82 |
*/
|
83 |
public class ViewControls extends Extension implements IPreferenceExtension{ |
84 |
private static final Logger logger = LoggerFactory |
85 |
.getLogger(ViewInvertSelection.class); |
86 |
|
87 |
private static ViewPage viewPropertiesPage = new ViewPage(); |
88 |
private DefaultViewPanel vista;
|
89 |
/**
|
90 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
91 |
*/
|
92 |
public void execute(String s) { |
93 |
ViewDocument 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 |
// mapa.beginAtomicEvent();
|
100 |
mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
101 |
((AbstractDocument)vista.getModel()).setModified(true); |
102 |
// mapa.endAtomicEvent();
|
103 |
} else if (s.equals("ENCUADRE") ) { |
104 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
105 |
|
106 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
107 |
Project project = p.getProject(); |
108 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
109 |
//ProjectExtent[] extents = project.getExtents();
|
110 |
project.addPropertyChangeListener(modelo); |
111 |
l.setModel(modelo); |
112 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
113 |
((AbstractDocument)vista.getModel()).setModified(true); |
114 |
PluginServices.getMDIManager().addWindow(l); |
115 |
} else if (s.equals("CONFIG_LOCATOR") ) { |
116 |
//Set up the map overview
|
117 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
118 |
PluginServices.getMDIManager().addWindow(m_panelLoc); |
119 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
120 |
((AbstractDocument)vista.getModel()).setModified(true); |
121 |
} else if (s.equals("PAN") ) { |
122 |
mapCtrl.setTool("pan");
|
123 |
((AbstractDocument)vista.getModel()).setModified(true); |
124 |
} else if (s.equals("ZOOM_IN") ) { |
125 |
mapCtrl.setTool("zoomIn");
|
126 |
((AbstractDocument)vista.getModel()).setModified(true); |
127 |
} else if (s.equals("ZOOM_OUT") ) { |
128 |
mapCtrl.setTool("zoomOut");
|
129 |
((AbstractDocument)vista.getModel()).setModified(true); |
130 |
} else if (s.equals("CAPAS_VISIBLES") ) { |
131 |
setVisibles(true, mapa.getLayers());
|
132 |
((AbstractDocument)vista.getModel()).setModified(true); |
133 |
} else if (s.equals("CAPAS_NOVISIBLES") ) { |
134 |
setVisibles(false, mapa.getLayers());
|
135 |
((AbstractDocument)vista.getModel()).setModified(true); |
136 |
} else if (s.equals("CAPAS_ACTIVAS") ) { |
137 |
setActives(true, mapa.getLayers());
|
138 |
((AbstractDocument)vista.getModel()).setModified(true); |
139 |
} else if (s.equals("CAPAS_NOACTIVAS") ) { |
140 |
setActives(false, mapa.getLayers());
|
141 |
((AbstractDocument)vista.getModel()).setModified(true); |
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 |
((AbstractDocument)vista.getModel()).setModified(true); |
149 |
} else if (s.equals("ACTION_ZOOM_OUT") ) { |
150 |
mapCtrl.zoomOut(); |
151 |
((AbstractDocument)vista.getModel()).setModified(true); |
152 |
} else if (s.startsWith("CHANGE_SCALE_")){ |
153 |
String scl=s.replaceAll("CHANGE_SCALE_",""); |
154 |
long scale=Long.parseLong(scl); |
155 |
mapa.setScaleView(scale); |
156 |
((AbstractDocument)vista.getModel()).setModified(true); |
157 |
} |
158 |
} |
159 |
|
160 |
/**
|
161 |
* Pone todas las capas visibles o no visibles.
|
162 |
*
|
163 |
* @param visible true si que quieren poner a visibles.
|
164 |
* @param mapa FMap sobre el que actuar.
|
165 |
*/
|
166 |
private void setVisibles(boolean visible, FLayers layers) { |
167 |
int layerCount=layers.getLayersCount();
|
168 |
for (int i = 0; i < layerCount; i++) { |
169 |
FLayer layer = layers.getLayer(i); |
170 |
layer.setVisible(visible); |
171 |
if (layer instanceof FLayers){ |
172 |
setVisibles(visible,(FLayers)layer); |
173 |
} |
174 |
} |
175 |
} |
176 |
|
177 |
/**
|
178 |
* Pone todas las capas activas o no activas.
|
179 |
*
|
180 |
* @param active true si que quieren poner a activas.
|
181 |
* @param mapa FMap sobre el que actuar.
|
182 |
*/
|
183 |
private void setActives(boolean active, FLayers layers) { |
184 |
int layerCount=layers.getLayersCount();
|
185 |
for (int i = 0; i < layerCount; i++) { |
186 |
FLayer layer = layers.getLayer(i); |
187 |
layer.setActive(active); |
188 |
if (layer instanceof FLayers){ |
189 |
setActives(active,(FLayers)layer); |
190 |
} |
191 |
} |
192 |
} |
193 |
/**
|
194 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
195 |
*/
|
196 |
public boolean isVisible() { |
197 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
198 |
.getActiveWindow(); |
199 |
|
200 |
if (f!=null && f instanceof DefaultViewPanel) { |
201 |
vista = (DefaultViewPanel) f; |
202 |
ViewDocument model = vista.getModel(); |
203 |
MapContext mapa = model.getMapContext(); |
204 |
|
205 |
return mapa.getLayers().getLayersCount() > 0; |
206 |
} |
207 |
return false; |
208 |
} |
209 |
|
210 |
/**
|
211 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
212 |
*/
|
213 |
public void initialize() { |
214 |
|
215 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
216 |
|
217 |
if (!epManager.has("View_TocActions")) { |
218 |
epManager.add( |
219 |
"View_TocActions",
|
220 |
"Context menu options of the TOC " +
|
221 |
" in the view window "+
|
222 |
"(register instances of " +
|
223 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
224 |
); |
225 |
} |
226 |
|
227 |
FPopupMenu.registerExtensionPoint(); |
228 |
|
229 |
registerIcons(); |
230 |
Snapping.register(); |
231 |
} |
232 |
|
233 |
private void registerIcons(){ |
234 |
|
235 |
PluginServices.getIconTheme().registerDefault( |
236 |
"view-zoom-in",
|
237 |
this.getClass().getClassLoader().getResource("images/ZoomIn.png") |
238 |
); |
239 |
PluginServices.getIconTheme().registerDefault( |
240 |
"view-zoom-out",
|
241 |
this.getClass().getClassLoader().getResource("images/ZoomOut.png") |
242 |
); |
243 |
PluginServices.getIconTheme().registerDefault( |
244 |
"view-zoom-map-contents",
|
245 |
this.getClass().getClassLoader().getResource("images/MapContents.png") |
246 |
); |
247 |
PluginServices.getIconTheme().registerDefault( |
248 |
"view-zoom-center-in",
|
249 |
this.getClass().getClassLoader().getResource("images/zoommas.png") |
250 |
); |
251 |
PluginServices.getIconTheme().registerDefault( |
252 |
"view-zoom-center-out",
|
253 |
this.getClass().getClassLoader().getResource("images/zoommenos.png") |
254 |
); |
255 |
|
256 |
PluginServices.getIconTheme().registerDefault( |
257 |
"view-pan",
|
258 |
this.getClass().getClassLoader().getResource("images/Pan.png") |
259 |
); |
260 |
|
261 |
PluginServices.getIconTheme().registerDefault( |
262 |
"view-zoom-manager",
|
263 |
this.getClass().getClassLoader().getResource("images/encuadre.png") |
264 |
); |
265 |
|
266 |
PluginServices.getIconTheme().registerDefault( |
267 |
"toc-layer-group",
|
268 |
this.getClass().getClassLoader().getResource("images/layerGroup.png") |
269 |
); |
270 |
} |
271 |
|
272 |
/**
|
273 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
274 |
*/
|
275 |
public boolean isEnabled() { |
276 |
ViewDocument model = vista.getModel(); |
277 |
MapContext mapa = model.getMapContext(); |
278 |
|
279 |
FLayers layers = mapa.getLayers(); |
280 |
for (int i=0;i<layers.getLayersCount();i++) { |
281 |
if (layers.getLayer(i).isAvailable()) {
|
282 |
return true; |
283 |
} |
284 |
} |
285 |
return false; |
286 |
} |
287 |
|
288 |
public IPreference[] getPreferencesPages() { |
289 |
IPreference[] preferences=new IPreference[2]; |
290 |
preferences[0]=viewPropertiesPage;
|
291 |
GridPage gridPage=new GridPage();
|
292 |
preferences[1]=gridPage;
|
293 |
return preferences;
|
294 |
} |
295 |
} |