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 @ 44704
History | View | Annotate | Download (10.8 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 java.util.ArrayList; |
26 |
import java.util.List; |
27 |
import javax.swing.JOptionPane; |
28 |
|
29 |
import org.slf4j.Logger; |
30 |
import org.slf4j.LoggerFactory; |
31 |
|
32 |
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 |
import org.gvsig.app.ApplicationLocator; |
38 |
import org.gvsig.app.ApplicationManager; |
39 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
40 |
import org.gvsig.app.gui.preferencespage.dal.DALPage; |
41 |
import org.gvsig.app.gui.preferencespage.databaseworkspace.DatabaseWorkspacePage; |
42 |
import org.gvsig.app.gui.preferencespage.dialogreminder.DialogReminderPage; |
43 |
import org.gvsig.app.project.Project; |
44 |
import org.gvsig.app.project.ProjectManager; |
45 |
import org.gvsig.app.project.documents.view.Encuadrator; |
46 |
import org.gvsig.app.project.documents.view.ViewDocument; |
47 |
import org.gvsig.app.project.documents.view.ViewManager; |
48 |
import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
49 |
import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
50 |
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
51 |
import org.gvsig.app.project.documents.view.gui.IView; |
52 |
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
53 |
import org.gvsig.fmap.geom.primitive.Envelope; |
54 |
import org.gvsig.fmap.mapcontext.MapContext; |
55 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
56 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
57 |
import org.gvsig.fmap.mapcontrol.MapControl; |
58 |
import org.gvsig.tools.ToolsLocator; |
59 |
import org.gvsig.tools.dataTypes.DataTypes; |
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 |
|
67 |
private static final Logger logger = LoggerFactory |
68 |
.getLogger(ViewInvertSelection.class); |
69 |
|
70 |
private static ViewPage viewPropertiesPage = null; |
71 |
|
72 |
public void execute(String s) { |
73 |
execute(s, null);
|
74 |
} |
75 |
|
76 |
public void execute(String command, Object[] args) { |
77 |
ApplicationManager application = ApplicationLocator.getManager(); |
78 |
|
79 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
80 |
if (view == null) { |
81 |
return;
|
82 |
} |
83 |
ViewDocument document = view.getViewDocument(); |
84 |
|
85 |
MapContext mapa = document.getMapContext(); |
86 |
MapControl mapCtrl = view.getMapControl(); |
87 |
|
88 |
if (command.equalsIgnoreCase("view-navigation-zoom-all")) { |
89 |
Envelope all = mapa.getLayers().getFullEnvelope(); |
90 |
if( all!=null && !all.isEmpty() ) { |
91 |
mapa.getViewPort().setEnvelope(all); |
92 |
document.setModified(true);
|
93 |
} |
94 |
|
95 |
} else if (command.equalsIgnoreCase("view-navigation-frame-manager")) { |
96 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
97 |
|
98 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
99 |
Project project = p.getProject(); |
100 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
101 |
project.addPropertyChangeListener(modelo); |
102 |
l.setModel(modelo); |
103 |
l.addSelectionListener(new Encuadrator(project, mapa, view));
|
104 |
document.setModified(true);
|
105 |
PluginServices.getMDIManager().addWindow(l); |
106 |
|
107 |
} else if (command.equalsIgnoreCase("view-locator-setup")) { |
108 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(view.getMapOverview());
|
109 |
PluginServices.getMDIManager().addCentredWindow(m_panelLoc); |
110 |
document.setModified(true);
|
111 |
|
112 |
} else if (command.equalsIgnoreCase("view-navigation-pan")) { |
113 |
mapCtrl.setTool("pan");
|
114 |
document.setModified(true);
|
115 |
|
116 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint")) { |
117 |
mapCtrl.setTool("zoomIn");
|
118 |
document.setModified(true);
|
119 |
|
120 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint")) { |
121 |
mapCtrl.setTool("zoomOut");
|
122 |
document.setModified(true);
|
123 |
|
124 |
} else if (command.equalsIgnoreCase("layer-set-visible")) { |
125 |
setVisibles(true, mapa.getLayers());
|
126 |
document.setModified(true);
|
127 |
application.refreshMenusAndToolBars(); |
128 |
|
129 |
} else if (command.equalsIgnoreCase("layer-set-hide")) { |
130 |
setVisibles(false, mapa.getLayers());
|
131 |
document.setModified(true);
|
132 |
application.refreshMenusAndToolBars(); |
133 |
|
134 |
} else if (command.equalsIgnoreCase("layer-set-active")) { |
135 |
setActives(true, mapa.getLayers());
|
136 |
document.setModified(true);
|
137 |
application.refreshMenusAndToolBars(); |
138 |
|
139 |
} else if (command.equalsIgnoreCase("layer-set-inactive")) { |
140 |
setActives(false, mapa.getLayers());
|
141 |
document.setModified(true);
|
142 |
application.refreshMenusAndToolBars(); |
143 |
|
144 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-center")) { |
145 |
mapCtrl.zoomIn(); |
146 |
document.setModified(true);
|
147 |
|
148 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-center")) { |
149 |
mapCtrl.zoomOut(); |
150 |
document.setModified(true);
|
151 |
|
152 |
} else if (command.equalsIgnoreCase("view-change-scale")) { |
153 |
try {
|
154 |
Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
155 |
mapa.setScaleView(scale.longValue()); |
156 |
document.setModified(true);
|
157 |
} catch (Throwable ex) { |
158 |
logger.info("Can't change scale of view.", ex);
|
159 |
application.message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
160 |
} |
161 |
} |
162 |
} |
163 |
|
164 |
private ViewPage getViewPropertiesPage() {
|
165 |
if (viewPropertiesPage == null) { |
166 |
viewPropertiesPage = new ViewPage();
|
167 |
} |
168 |
return viewPropertiesPage;
|
169 |
} |
170 |
|
171 |
/**
|
172 |
* Pone todas las capas visibles o no visibles.
|
173 |
*
|
174 |
* @param visible true si que quieren poner a visibles.
|
175 |
* @param mapa FMap sobre el que actuar.
|
176 |
*/
|
177 |
private void setVisibles(boolean visible, FLayers layers) { |
178 |
int layerCount = layers.getLayersCount();
|
179 |
for (int i = 0; i < layerCount; i++) { |
180 |
FLayer layer = layers.getLayer(i); |
181 |
layer.setVisible(visible); |
182 |
if (layer instanceof FLayers) { |
183 |
setVisibles(visible, (FLayers) layer); |
184 |
} |
185 |
} |
186 |
} |
187 |
|
188 |
/**
|
189 |
* Pone todas las capas activas o no activas.
|
190 |
*
|
191 |
* @param active true si que quieren poner a activas.
|
192 |
* @param mapa FMap sobre el que actuar.
|
193 |
*/
|
194 |
private void setActives(boolean active, FLayers layers) { |
195 |
int layerCount = layers.getLayersCount();
|
196 |
for (int i = 0; i < layerCount; i++) { |
197 |
FLayer layer = layers.getLayer(i); |
198 |
layer.setActive(active); |
199 |
if (layer instanceof FLayers) { |
200 |
setActives(active, (FLayers) layer); |
201 |
} |
202 |
} |
203 |
} |
204 |
|
205 |
public boolean isVisible() { |
206 |
ApplicationManager application = ApplicationLocator.getManager(); |
207 |
|
208 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
209 |
if (view == null) { |
210 |
return false; |
211 |
} |
212 |
ViewDocument document = view.getViewDocument(); |
213 |
MapContext mapa = document.getMapContext(); |
214 |
return mapa.getLayers().getLayersCount() > 0; |
215 |
} |
216 |
|
217 |
public void initialize() { |
218 |
registerIcons(); |
219 |
} |
220 |
|
221 |
public void postInitialize() { |
222 |
FPopupMenu.registerExtensionPoint(); |
223 |
ProjectManager projectManager = ApplicationLocator.getProjectManager(); |
224 |
ViewManager viewManager = (ViewManager) projectManager.getDocumentManager(ViewManager.TYPENAME); |
225 |
viewManager.addTOCContextAction("view-layer-add");
|
226 |
} |
227 |
|
228 |
private void registerIcons() { |
229 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this); |
230 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this); |
231 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this); |
232 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this); |
233 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this); |
234 |
IconThemeHelper.registerIcon("action", "view-navigation-pan", this); |
235 |
IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this); |
236 |
|
237 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-modify", this); |
238 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-add", this); |
239 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-delete", this); |
240 |
|
241 |
IconThemeHelper.registerIcon("preferences", "dialog-remember-preferences", this); |
242 |
IconThemeHelper.registerIcon("preferences", "dal-preferences", this); |
243 |
IconThemeHelper.registerIcon("preferences", "databaseworkspace-preferences", this); |
244 |
} |
245 |
|
246 |
public boolean isEnabled() { |
247 |
ApplicationManager application = ApplicationLocator.getManager(); |
248 |
|
249 |
IView view = (IView) application.getActiveComponent(ViewDocument.class); |
250 |
if (view == null) { |
251 |
return false; |
252 |
} |
253 |
ViewDocument document = view.getViewDocument(); |
254 |
MapContext mapa = document.getMapContext(); |
255 |
FLayers layers = mapa.getLayers(); |
256 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
257 |
if (layers.getLayer(i).isAvailable()) {
|
258 |
return true; |
259 |
} |
260 |
} |
261 |
return false; |
262 |
} |
263 |
|
264 |
@Override
|
265 |
public IPreference[] getPreferencesPages() { |
266 |
List<IPreference> prefs = new ArrayList<>(); |
267 |
prefs.add(getViewPropertiesPage()); |
268 |
prefs.add(new DialogReminderPage());
|
269 |
prefs.add(new DALPage());
|
270 |
prefs.add(new DatabaseWorkspacePage());
|
271 |
|
272 |
return prefs.toArray(new IPreference[prefs.size()]); |
273 |
} |
274 |
} |