svn-gvsig-desktop / tags / v2_0_0_Build_2060 / applications / appgvSIG / src / org / gvsig / app / extension / ViewControls.java @ 39341
History | View | Annotate | Download (10.1 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 javax.swing.JOptionPane; |
50 |
|
51 |
import org.slf4j.Logger; |
52 |
import org.slf4j.LoggerFactory; |
53 |
|
54 |
import org.gvsig.andami.IconThemeHelper; |
55 |
import org.gvsig.andami.PluginServices; |
56 |
import org.gvsig.andami.plugins.Extension; |
57 |
import org.gvsig.andami.preferences.IPreference; |
58 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
59 |
import org.gvsig.app.gui.preferencespage.GridPage; |
60 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
61 |
import org.gvsig.app.project.Project; |
62 |
import org.gvsig.app.project.documents.view.Encuadrator; |
63 |
import org.gvsig.app.project.documents.view.ViewDocument; |
64 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
65 |
import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
66 |
import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
67 |
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
68 |
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
69 |
import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
70 |
import org.gvsig.fmap.mapcontext.MapContext; |
71 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
72 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
73 |
import org.gvsig.fmap.mapcontrol.MapControl; |
74 |
import org.gvsig.tools.ToolsLocator; |
75 |
import org.gvsig.tools.dataTypes.DataTypes; |
76 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
77 |
|
78 |
|
79 |
|
80 |
//import com.iver.utiles.FPanelExtentSelector;
|
81 |
|
82 |
/**
|
83 |
* Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
84 |
*
|
85 |
* @author vcn
|
86 |
*/
|
87 |
public class ViewControls extends Extension implements IPreferenceExtension{ |
88 |
private static final Logger logger = LoggerFactory |
89 |
.getLogger(ViewInvertSelection.class); |
90 |
|
91 |
private static ViewPage viewPropertiesPage = null; |
92 |
// private DefaultViewPanel vista;
|
93 |
/**
|
94 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
95 |
*/
|
96 |
public void execute(String s) { |
97 |
execute(s,null);
|
98 |
} |
99 |
|
100 |
public void execute(String command, Object[] args) { |
101 |
|
102 |
DefaultViewPanel vista = getView(); |
103 |
if (vista==null) { |
104 |
return;
|
105 |
} |
106 |
|
107 |
|
108 |
ViewDocument document = vista.getViewDocument(); |
109 |
MapContext mapa = document.getMapContext(); |
110 |
MapControl mapCtrl = vista.getMapControl(); |
111 |
|
112 |
if (command.equalsIgnoreCase("view-navigation-zoom-all") ) { |
113 |
// mapa.beginAtomicEvent();
|
114 |
mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
115 |
document.setModified(true);
|
116 |
// mapa.endAtomicEvent();
|
117 |
|
118 |
} else if (command.equalsIgnoreCase("view-navigation-frame-manager") ) { |
119 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
120 |
|
121 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
122 |
Project project = p.getProject(); |
123 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
124 |
//ProjectExtent[] extents = project.getExtents();
|
125 |
project.addPropertyChangeListener(modelo); |
126 |
l.setModel(modelo); |
127 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
128 |
document.setModified(true);
|
129 |
PluginServices.getMDIManager().addWindow(l); |
130 |
|
131 |
} else if (command.equalsIgnoreCase("view-locator-setup") ) { |
132 |
//Set up the map overview
|
133 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
134 |
PluginServices.getMDIManager().addWindow(m_panelLoc); |
135 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
136 |
document.setModified(true);
|
137 |
|
138 |
} else if (command.equalsIgnoreCase("view-navigation-pan") ) { |
139 |
mapCtrl.setTool("pan");
|
140 |
document.setModified(true);
|
141 |
|
142 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint") ) { |
143 |
mapCtrl.setTool("zoomIn");
|
144 |
document.setModified(true);
|
145 |
|
146 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint") ) { |
147 |
mapCtrl.setTool("zoomOut");
|
148 |
document.setModified(true);
|
149 |
|
150 |
} else if (command.equalsIgnoreCase("layer-set-visible") ) { |
151 |
setVisibles(true, mapa.getLayers());
|
152 |
document.setModified(true);
|
153 |
|
154 |
} else if (command.equalsIgnoreCase("layer-set-hide") ) { |
155 |
setVisibles(false, mapa.getLayers());
|
156 |
document.setModified(true);
|
157 |
|
158 |
} else if (command.equalsIgnoreCase("layer-set-active") ) { |
159 |
setActives(true, mapa.getLayers());
|
160 |
document.setModified(true);
|
161 |
|
162 |
} else if (command.equalsIgnoreCase("layer-set-inactive") ) { |
163 |
setActives(false, mapa.getLayers());
|
164 |
document.setModified(true);
|
165 |
|
166 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-center") ) { |
167 |
mapCtrl.zoomIn(); |
168 |
document.setModified(true);
|
169 |
|
170 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-center") ) { |
171 |
mapCtrl.zoomOut(); |
172 |
document.setModified(true);
|
173 |
|
174 |
} else if (command.equalsIgnoreCase("view-change-scale")) { |
175 |
try {
|
176 |
Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
177 |
mapa.setScaleView(scale.longValue()); |
178 |
document.setModified(true);
|
179 |
} catch(Throwable ex) { |
180 |
logger.info("Can't change scale of view.", ex);
|
181 |
PluginServices.getMainFrame().getStatusBar().message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
182 |
} |
183 |
} |
184 |
} |
185 |
|
186 |
private ViewPage getViewPropertiesPage(){
|
187 |
if(viewPropertiesPage==null){ |
188 |
viewPropertiesPage = new ViewPage();
|
189 |
} |
190 |
return viewPropertiesPage;
|
191 |
} |
192 |
/**
|
193 |
* Pone todas las capas visibles o no visibles.
|
194 |
*
|
195 |
* @param visible true si que quieren poner a visibles.
|
196 |
* @param mapa FMap sobre el que actuar.
|
197 |
*/
|
198 |
private void setVisibles(boolean visible, FLayers layers) { |
199 |
int layerCount=layers.getLayersCount();
|
200 |
for (int i = 0; i < layerCount; i++) { |
201 |
FLayer layer = layers.getLayer(i); |
202 |
layer.setVisible(visible); |
203 |
if (layer instanceof FLayers){ |
204 |
setVisibles(visible,(FLayers)layer); |
205 |
} |
206 |
} |
207 |
} |
208 |
|
209 |
/**
|
210 |
* Pone todas las capas activas o no activas.
|
211 |
*
|
212 |
* @param active true si que quieren poner a activas.
|
213 |
* @param mapa FMap sobre el que actuar.
|
214 |
*/
|
215 |
private void setActives(boolean active, FLayers layers) { |
216 |
int layerCount=layers.getLayersCount();
|
217 |
for (int i = 0; i < layerCount; i++) { |
218 |
FLayer layer = layers.getLayer(i); |
219 |
layer.setActive(active); |
220 |
if (layer instanceof FLayers){ |
221 |
setActives(active,(FLayers)layer); |
222 |
} |
223 |
} |
224 |
} |
225 |
/**
|
226 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
227 |
*/
|
228 |
public boolean isVisible() { |
229 |
|
230 |
DefaultViewPanel vista = getView(); |
231 |
|
232 |
if (vista!=null) { |
233 |
ViewDocument model = vista.getViewDocument(); |
234 |
MapContext mapa = model.getMapContext(); |
235 |
|
236 |
return mapa.getLayers().getLayersCount() > 0; |
237 |
} |
238 |
return false; |
239 |
} |
240 |
|
241 |
private DefaultViewPanel getView() {
|
242 |
|
243 |
|
244 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
245 |
.getActiveWindow(); |
246 |
|
247 |
if (f!=null && f instanceof DefaultViewPanel) { |
248 |
return (DefaultViewPanel) f;
|
249 |
} |
250 |
return null; |
251 |
|
252 |
} |
253 |
|
254 |
/**
|
255 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
256 |
*/
|
257 |
public void initialize() { |
258 |
|
259 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
260 |
|
261 |
if (!epManager.has("View_TocActions")) { |
262 |
epManager.add( |
263 |
"View_TocActions",
|
264 |
"Context menu options of the TOC " +
|
265 |
" in the view window "+
|
266 |
"(register instances of " +
|
267 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
268 |
); |
269 |
} |
270 |
|
271 |
FPopupMenu.registerExtensionPoint(); |
272 |
|
273 |
registerIcons(); |
274 |
Snapping.register(); |
275 |
} |
276 |
|
277 |
private void registerIcons(){ |
278 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this); |
279 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this); |
280 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this); |
281 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this); |
282 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this); |
283 |
IconThemeHelper.registerIcon("action", "view-navigation-pan", this); |
284 |
IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this); |
285 |
|
286 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-modify", this); |
287 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-add", this); |
288 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-delete", this); |
289 |
|
290 |
} |
291 |
|
292 |
/**
|
293 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
294 |
*/
|
295 |
public boolean isEnabled() { |
296 |
|
297 |
DefaultViewPanel vista = getView(); |
298 |
|
299 |
if (vista != null) { |
300 |
|
301 |
ViewDocument model = vista.getViewDocument(); |
302 |
MapContext mapa = model.getMapContext(); |
303 |
|
304 |
FLayers layers = mapa.getLayers(); |
305 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
306 |
if (layers.getLayer(i).isAvailable()) {
|
307 |
return true; |
308 |
} |
309 |
} |
310 |
} |
311 |
return false; |
312 |
} |
313 |
|
314 |
public IPreference[] getPreferencesPages() { |
315 |
IPreference[] preferences=new IPreference[2]; |
316 |
preferences[0]=getViewPropertiesPage();
|
317 |
GridPage gridPage=new GridPage();
|
318 |
preferences[1]=gridPage;
|
319 |
return preferences;
|
320 |
} |
321 |
} |