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