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