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 @ 44601
History | View | Annotate | Download (10.5 KB)
1 | 40558 | jjdelcerro | /**
|
---|---|---|---|
2 | * gvSIG. Desktop Geographic Information System.
|
||
3 | *
|
||
4 | * Copyright (C) 2007-2013 gvSIG Association.
|
||
5 | *
|
||
6 | 41248 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
11 | 41248 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
16 | 41248 | jjdelcerro | * 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 | 40558 | jjdelcerro | *
|
20 | 41248 | jjdelcerro | * For any additional information, do not hesitate to contact us at info AT
|
21 | * gvsig.com, or visit our website www.gvsig.com.
|
||
22 | 40558 | jjdelcerro | */
|
23 | 40435 | jjdelcerro | package org.gvsig.app.extension; |
24 | |||
25 | 43521 | jjdelcerro | import java.util.ArrayList; |
26 | import java.util.List; |
||
27 | 40435 | jjdelcerro | import javax.swing.JOptionPane; |
28 | |||
29 | 42037 | fdiaz | import org.slf4j.Logger; |
30 | import org.slf4j.LoggerFactory; |
||
31 | |||
32 | 40435 | jjdelcerro | import org.gvsig.andami.IconThemeHelper; |
33 | import org.gvsig.andami.PluginServices; |
||
34 | import org.gvsig.andami.plugins.Extension; |
||
35 | import org.gvsig.andami.preferences.IPreference; |
||
36 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
37 | 41104 | jjdelcerro | import org.gvsig.app.ApplicationLocator; |
38 | import org.gvsig.app.ApplicationManager; |
||
39 | 40435 | jjdelcerro | import org.gvsig.app.gui.preferencespage.ViewPage; |
40 | 43521 | jjdelcerro | import org.gvsig.app.gui.preferencespage.dal.DALPage; |
41 | 43280 | fdiaz | import org.gvsig.app.gui.preferencespage.dialogreminder.DialogReminderPage; |
42 | 40435 | jjdelcerro | import org.gvsig.app.project.Project; |
43 | 41558 | jjdelcerro | import org.gvsig.app.project.ProjectManager; |
44 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.Encuadrator; |
45 | import org.gvsig.app.project.documents.view.ViewDocument; |
||
46 | 41558 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewManager; |
47 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
48 | import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
||
49 | import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
||
50 | 41104 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.IView; |
51 | 40435 | jjdelcerro | import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
52 | 41418 | jjdelcerro | import org.gvsig.fmap.geom.primitive.Envelope; |
53 | 40435 | jjdelcerro | import org.gvsig.fmap.mapcontext.MapContext; |
54 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
55 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
56 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
57 | import org.gvsig.tools.ToolsLocator; |
||
58 | import org.gvsig.tools.dataTypes.DataTypes; |
||
59 | |||
60 | /**
|
||
61 | * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
||
62 | *
|
||
63 | */
|
||
64 | 41248 | jjdelcerro | public class ViewControls extends Extension implements IPreferenceExtension { |
65 | |||
66 | 40435 | jjdelcerro | private static final Logger logger = LoggerFactory |
67 | .getLogger(ViewInvertSelection.class); |
||
68 | |||
69 | 41248 | jjdelcerro | private static ViewPage viewPropertiesPage = null; |
70 | 40435 | jjdelcerro | |
71 | 41248 | jjdelcerro | public void execute(String s) { |
72 | execute(s, null);
|
||
73 | } |
||
74 | 40435 | jjdelcerro | |
75 | 41248 | jjdelcerro | public void execute(String command, Object[] args) { |
76 | ApplicationManager application = ApplicationLocator.getManager(); |
||
77 | 42037 | fdiaz | |
78 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
79 | if (view == null) { |
||
80 | 41248 | jjdelcerro | return;
|
81 | } |
||
82 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
83 | 41248 | jjdelcerro | |
84 | MapContext mapa = document.getMapContext(); |
||
85 | 41264 | jjdelcerro | MapControl mapCtrl = view.getMapControl(); |
86 | 41248 | jjdelcerro | |
87 | if (command.equalsIgnoreCase("view-navigation-zoom-all")) { |
||
88 | 41418 | jjdelcerro | Envelope all = mapa.getLayers().getFullEnvelope(); |
89 | if( all!=null && !all.isEmpty() ) { |
||
90 | mapa.getViewPort().setEnvelope(all); |
||
91 | document.setModified(true);
|
||
92 | } |
||
93 | 41248 | jjdelcerro | |
94 | } else if (command.equalsIgnoreCase("view-navigation-frame-manager")) { |
||
95 | FPanelExtentSelector l = new FPanelExtentSelector();
|
||
96 | |||
97 | ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
||
98 | Project project = p.getProject(); |
||
99 | ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
||
100 | project.addPropertyChangeListener(modelo); |
||
101 | l.setModel(modelo); |
||
102 | 41264 | jjdelcerro | l.addSelectionListener(new Encuadrator(project, mapa, view));
|
103 | 41248 | jjdelcerro | document.setModified(true);
|
104 | PluginServices.getMDIManager().addWindow(l); |
||
105 | |||
106 | } else if (command.equalsIgnoreCase("view-locator-setup")) { |
||
107 | 41264 | jjdelcerro | FPanelLocConfig m_panelLoc = new FPanelLocConfig(view.getMapOverview());
|
108 | 41248 | jjdelcerro | PluginServices.getMDIManager().addCentredWindow(m_panelLoc); |
109 | document.setModified(true);
|
||
110 | |||
111 | } else if (command.equalsIgnoreCase("view-navigation-pan")) { |
||
112 | mapCtrl.setTool("pan");
|
||
113 | document.setModified(true);
|
||
114 | |||
115 | } else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint")) { |
||
116 | mapCtrl.setTool("zoomIn");
|
||
117 | document.setModified(true);
|
||
118 | |||
119 | } else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint")) { |
||
120 | mapCtrl.setTool("zoomOut");
|
||
121 | document.setModified(true);
|
||
122 | |||
123 | } else if (command.equalsIgnoreCase("layer-set-visible")) { |
||
124 | setVisibles(true, mapa.getLayers());
|
||
125 | document.setModified(true);
|
||
126 | 41104 | jjdelcerro | application.refreshMenusAndToolBars(); |
127 | 41248 | jjdelcerro | |
128 | } else if (command.equalsIgnoreCase("layer-set-hide")) { |
||
129 | setVisibles(false, mapa.getLayers());
|
||
130 | document.setModified(true);
|
||
131 | 41104 | jjdelcerro | application.refreshMenusAndToolBars(); |
132 | 41248 | jjdelcerro | |
133 | } else if (command.equalsIgnoreCase("layer-set-active")) { |
||
134 | setActives(true, mapa.getLayers());
|
||
135 | document.setModified(true);
|
||
136 | 41104 | jjdelcerro | application.refreshMenusAndToolBars(); |
137 | 41248 | jjdelcerro | |
138 | } else if (command.equalsIgnoreCase("layer-set-inactive")) { |
||
139 | setActives(false, mapa.getLayers());
|
||
140 | document.setModified(true);
|
||
141 | 41104 | jjdelcerro | application.refreshMenusAndToolBars(); |
142 | 40435 | jjdelcerro | |
143 | 41248 | jjdelcerro | } else if (command.equalsIgnoreCase("view-navigation-zoom-in-center")) { |
144 | mapCtrl.zoomIn(); |
||
145 | document.setModified(true);
|
||
146 | 40435 | jjdelcerro | |
147 | 41248 | jjdelcerro | } else if (command.equalsIgnoreCase("view-navigation-zoom-out-center")) { |
148 | mapCtrl.zoomOut(); |
||
149 | document.setModified(true);
|
||
150 | 40435 | jjdelcerro | |
151 | 41248 | jjdelcerro | } else if (command.equalsIgnoreCase("view-change-scale")) { |
152 | try {
|
||
153 | Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
||
154 | mapa.setScaleView(scale.longValue()); |
||
155 | document.setModified(true);
|
||
156 | } catch (Throwable ex) { |
||
157 | logger.info("Can't change scale of view.", ex);
|
||
158 | application.message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
||
159 | } |
||
160 | } |
||
161 | } |
||
162 | 40435 | jjdelcerro | |
163 | 41248 | jjdelcerro | private ViewPage getViewPropertiesPage() {
|
164 | if (viewPropertiesPage == null) { |
||
165 | viewPropertiesPage = new ViewPage();
|
||
166 | } |
||
167 | return viewPropertiesPage;
|
||
168 | } |
||
169 | |||
170 | /**
|
||
171 | * Pone todas las capas visibles o no visibles.
|
||
172 | *
|
||
173 | * @param visible true si que quieren poner a visibles.
|
||
174 | * @param mapa FMap sobre el que actuar.
|
||
175 | */
|
||
176 | private void setVisibles(boolean visible, FLayers layers) { |
||
177 | int layerCount = layers.getLayersCount();
|
||
178 | for (int i = 0; i < layerCount; i++) { |
||
179 | FLayer layer = layers.getLayer(i); |
||
180 | layer.setVisible(visible); |
||
181 | if (layer instanceof FLayers) { |
||
182 | setVisibles(visible, (FLayers) layer); |
||
183 | } |
||
184 | } |
||
185 | } |
||
186 | |||
187 | /**
|
||
188 | * Pone todas las capas activas o no activas.
|
||
189 | *
|
||
190 | * @param active true si que quieren poner a activas.
|
||
191 | * @param mapa FMap sobre el que actuar.
|
||
192 | */
|
||
193 | private void setActives(boolean active, FLayers layers) { |
||
194 | int layerCount = layers.getLayersCount();
|
||
195 | for (int i = 0; i < layerCount; i++) { |
||
196 | FLayer layer = layers.getLayer(i); |
||
197 | layer.setActive(active); |
||
198 | if (layer instanceof FLayers) { |
||
199 | setActives(active, (FLayers) layer); |
||
200 | } |
||
201 | } |
||
202 | } |
||
203 | |||
204 | public boolean isVisible() { |
||
205 | ApplicationManager application = ApplicationLocator.getManager(); |
||
206 | |||
207 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
208 | if (view == null) { |
||
209 | 41248 | jjdelcerro | return false; |
210 | } |
||
211 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
212 | 41248 | jjdelcerro | MapContext mapa = document.getMapContext(); |
213 | return mapa.getLayers().getLayersCount() > 0; |
||
214 | } |
||
215 | |||
216 | public void initialize() { |
||
217 | registerIcons(); |
||
218 | } |
||
219 | |||
220 | public void postInitialize() { |
||
221 | FPopupMenu.registerExtensionPoint(); |
||
222 | 41558 | jjdelcerro | ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
223 | ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
||
224 | viewManager.addTOCContextAction("view-layer-add");
|
||
225 | 41248 | jjdelcerro | } |
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 | 43167 | jjdelcerro | IconThemeHelper.registerIcon("preferences", "dialog-remember-preferences", this); |
241 | 43521 | jjdelcerro | IconThemeHelper.registerIcon("preferences", "dal-preferences", this); |
242 | 41248 | jjdelcerro | } |
243 | |||
244 | 40435 | jjdelcerro | public boolean isEnabled() { |
245 | 41248 | jjdelcerro | ApplicationManager application = ApplicationLocator.getManager(); |
246 | |||
247 | 41264 | jjdelcerro | IView view = (IView) application.getActiveComponent(ViewDocument.class); |
248 | if (view == null) { |
||
249 | 41248 | jjdelcerro | return false; |
250 | } |
||
251 | 41264 | jjdelcerro | ViewDocument document = view.getViewDocument(); |
252 | 41104 | jjdelcerro | 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 | 40435 | jjdelcerro | } |
258 | } |
||
259 | return false; |
||
260 | } |
||
261 | |||
262 | 43521 | jjdelcerro | @Override
|
263 | 41248 | jjdelcerro | public IPreference[] getPreferencesPages() { |
264 | 43521 | jjdelcerro | List<IPreference> prefs = new ArrayList<>(); |
265 | prefs.add(getViewPropertiesPage()); |
||
266 | prefs.add(new DialogReminderPage());
|
||
267 | prefs.add(new DALPage());
|
||
268 | |||
269 | return prefs.toArray(new IPreference[prefs.size()]); |
||
270 | 41248 | jjdelcerro | } |
271 | 40435 | jjdelcerro | } |