svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ViewControls.java @ 41104
History | View | Annotate | Download (9.43 KB)
1 |
/**
|
---|---|
2 |
* gvSIG. Desktop Geographic Information System.
|
3 |
*
|
4 |
* Copyright (C) 2007-2013 gvSIG Association.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 3
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
* For any additional information, do not hesitate to contact us
|
22 |
* at info AT gvsig.com, or visit our website www.gvsig.com.
|
23 |
*/
|
24 |
|
25 |
package org.gvsig.app.extension; |
26 |
|
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.gvsig.andami.IconThemeHelper; |
30 |
import org.gvsig.andami.PluginServices; |
31 |
import org.gvsig.andami.plugins.Extension; |
32 |
import org.gvsig.andami.preferences.IPreference; |
33 |
import org.gvsig.andami.preferences.IPreferenceExtension; |
34 |
import org.gvsig.app.ApplicationLocator; |
35 |
import org.gvsig.app.ApplicationManager; |
36 |
import org.gvsig.app.gui.preferencespage.GridPage; |
37 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
38 |
import org.gvsig.app.project.Project; |
39 |
import org.gvsig.app.project.documents.view.Encuadrator; |
40 |
import org.gvsig.app.project.documents.view.ViewDocument; |
41 |
import org.gvsig.app.project.documents.view.ViewManager; |
42 |
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
43 |
import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
44 |
import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
45 |
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
46 |
import org.gvsig.app.project.documents.view.gui.IView; |
47 |
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
48 |
import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
49 |
import org.gvsig.fmap.mapcontext.MapContext; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
51 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
52 |
import org.gvsig.fmap.mapcontrol.MapControl; |
53 |
import org.gvsig.tools.ToolsLocator; |
54 |
import org.gvsig.tools.dataTypes.DataTypes; |
55 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
56 |
import org.slf4j.Logger; |
57 |
import org.slf4j.LoggerFactory; |
58 |
|
59 |
|
60 |
|
61 |
/**
|
62 |
* Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
63 |
*
|
64 |
*/
|
65 |
public class ViewControls extends Extension implements IPreferenceExtension{ |
66 |
private static final Logger logger = LoggerFactory |
67 |
.getLogger(ViewInvertSelection.class); |
68 |
|
69 |
private static ViewPage viewPropertiesPage = null; |
70 |
/**
|
71 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
72 |
*/
|
73 |
public void execute(String s) { |
74 |
execute(s,null);
|
75 |
} |
76 |
|
77 |
public void execute(String command, Object[] args) { |
78 |
ApplicationManager application = ApplicationLocator.getManager(); |
79 |
|
80 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
81 |
if( document == null ) { |
82 |
return;
|
83 |
} |
84 |
|
85 |
IView vista = (IView) document.getMainWindow(); |
86 |
MapContext mapa = document.getMapContext(); |
87 |
MapControl mapCtrl = vista.getMapControl(); |
88 |
|
89 |
if (command.equalsIgnoreCase("view-navigation-zoom-all") ) { |
90 |
mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
91 |
document.setModified(true);
|
92 |
|
93 |
} else if (command.equalsIgnoreCase("view-navigation-frame-manager") ) { |
94 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
95 |
|
96 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
97 |
Project project = p.getProject(); |
98 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
99 |
project.addPropertyChangeListener(modelo); |
100 |
l.setModel(modelo); |
101 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
102 |
document.setModified(true);
|
103 |
PluginServices.getMDIManager().addWindow(l); |
104 |
|
105 |
} else if (command.equalsIgnoreCase("view-locator-setup") ) { |
106 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(((DefaultViewPanel)vista).getMapOverview());
|
107 |
PluginServices.getMDIManager().addCentredWindow(m_panelLoc); |
108 |
document.setModified(true);
|
109 |
|
110 |
} else if (command.equalsIgnoreCase("view-navigation-pan") ) { |
111 |
mapCtrl.setTool("pan");
|
112 |
document.setModified(true);
|
113 |
|
114 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint") ) { |
115 |
mapCtrl.setTool("zoomIn");
|
116 |
document.setModified(true);
|
117 |
|
118 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint") ) { |
119 |
mapCtrl.setTool("zoomOut");
|
120 |
document.setModified(true);
|
121 |
|
122 |
} else if (command.equalsIgnoreCase("layer-set-visible") ) { |
123 |
setVisibles(true, mapa.getLayers());
|
124 |
document.setModified(true);
|
125 |
application.refreshMenusAndToolBars(); |
126 |
|
127 |
} else if (command.equalsIgnoreCase("layer-set-hide") ) { |
128 |
setVisibles(false, mapa.getLayers());
|
129 |
document.setModified(true);
|
130 |
application.refreshMenusAndToolBars(); |
131 |
|
132 |
} else if (command.equalsIgnoreCase("layer-set-active") ) { |
133 |
setActives(true, mapa.getLayers());
|
134 |
document.setModified(true);
|
135 |
application.refreshMenusAndToolBars(); |
136 |
|
137 |
} else if (command.equalsIgnoreCase("layer-set-inactive") ) { |
138 |
setActives(false, mapa.getLayers());
|
139 |
document.setModified(true);
|
140 |
application.refreshMenusAndToolBars(); |
141 |
|
142 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-center") ) { |
143 |
mapCtrl.zoomIn(); |
144 |
document.setModified(true);
|
145 |
|
146 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-center") ) { |
147 |
mapCtrl.zoomOut(); |
148 |
document.setModified(true);
|
149 |
|
150 |
} else if (command.equalsIgnoreCase("view-change-scale")) { |
151 |
try {
|
152 |
Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
153 |
mapa.setScaleView(scale.longValue()); |
154 |
document.setModified(true);
|
155 |
} catch(Throwable ex) { |
156 |
logger.info("Can't change scale of view.", ex);
|
157 |
application.message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
158 |
} |
159 |
} |
160 |
} |
161 |
|
162 |
private ViewPage getViewPropertiesPage(){
|
163 |
if(viewPropertiesPage==null){ |
164 |
viewPropertiesPage = new ViewPage();
|
165 |
} |
166 |
return viewPropertiesPage;
|
167 |
} |
168 |
/**
|
169 |
* Pone todas las capas visibles o no visibles.
|
170 |
*
|
171 |
* @param visible true si que quieren poner a visibles.
|
172 |
* @param mapa FMap sobre el que actuar.
|
173 |
*/
|
174 |
private void setVisibles(boolean visible, FLayers layers) { |
175 |
int layerCount=layers.getLayersCount();
|
176 |
for (int i = 0; i < layerCount; i++) { |
177 |
FLayer layer = layers.getLayer(i); |
178 |
layer.setVisible(visible); |
179 |
if (layer instanceof FLayers){ |
180 |
setVisibles(visible,(FLayers)layer); |
181 |
} |
182 |
} |
183 |
} |
184 |
|
185 |
/**
|
186 |
* Pone todas las capas activas o no activas.
|
187 |
*
|
188 |
* @param active true si que quieren poner a activas.
|
189 |
* @param mapa FMap sobre el que actuar.
|
190 |
*/
|
191 |
private void setActives(boolean active, FLayers layers) { |
192 |
int layerCount=layers.getLayersCount();
|
193 |
for (int i = 0; i < layerCount; i++) { |
194 |
FLayer layer = layers.getLayer(i); |
195 |
layer.setActive(active); |
196 |
if (layer instanceof FLayers){ |
197 |
setActives(active,(FLayers)layer); |
198 |
} |
199 |
} |
200 |
} |
201 |
/**
|
202 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
203 |
*/
|
204 |
public boolean isVisible() { |
205 |
ApplicationManager application = ApplicationLocator.getManager(); |
206 |
|
207 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
208 |
if( document == null ) { |
209 |
return false; |
210 |
} |
211 |
MapContext mapa = document.getMapContext(); |
212 |
return mapa.getLayers().getLayersCount() > 0; |
213 |
} |
214 |
|
215 |
/**
|
216 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
217 |
*/
|
218 |
public void initialize() { |
219 |
registerIcons(); |
220 |
Snapping.register(); |
221 |
} |
222 |
|
223 |
public void postInitialize() { |
224 |
FPopupMenu.registerExtensionPoint(); |
225 |
} |
226 |
|
227 |
private void registerIcons(){ |
228 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this); |
229 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this); |
230 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this); |
231 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this); |
232 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this); |
233 |
IconThemeHelper.registerIcon("action", "view-navigation-pan", this); |
234 |
IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this); |
235 |
|
236 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-modify", this); |
237 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-add", this); |
238 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-delete", this); |
239 |
|
240 |
} |
241 |
|
242 |
/**
|
243 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
244 |
*/
|
245 |
public boolean isEnabled() { |
246 |
ApplicationManager application = ApplicationLocator.getManager(); |
247 |
|
248 |
ViewDocument document = (ViewDocument) application.getActiveDocument(ViewManager.TYPENAME); |
249 |
if( document == null ) { |
250 |
return false; |
251 |
} |
252 |
MapContext mapa = document.getMapContext(); |
253 |
FLayers layers = mapa.getLayers(); |
254 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
255 |
if (layers.getLayer(i).isAvailable()) {
|
256 |
return true; |
257 |
} |
258 |
} |
259 |
return false; |
260 |
} |
261 |
|
262 |
public IPreference[] getPreferencesPages() { |
263 |
IPreference[] preferences=new IPreference[2]; |
264 |
preferences[0]=getViewPropertiesPage();
|
265 |
GridPage gridPage=new GridPage();
|
266 |
preferences[1]=gridPage;
|
267 |
return preferences;
|
268 |
} |
269 |
} |