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 @ 40596
History | View | Annotate | Download (9.7 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.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.gui.preferencespage.GridPage; |
38 |
import org.gvsig.app.gui.preferencespage.ViewPage; |
39 |
import org.gvsig.app.project.Project; |
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.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.toc.gui.FPopupMenu; |
47 |
import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
48 |
import org.gvsig.fmap.mapcontext.MapContext; |
49 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
50 |
import org.gvsig.fmap.mapcontext.layers.FLayers; |
51 |
import org.gvsig.fmap.mapcontrol.MapControl; |
52 |
import org.gvsig.tools.ToolsLocator; |
53 |
import org.gvsig.tools.dataTypes.DataTypes; |
54 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
55 |
|
56 |
|
57 |
|
58 |
//import com.iver.utiles.FPanelExtentSelector;
|
59 |
|
60 |
/**
|
61 |
* Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
62 |
*
|
63 |
* @author vcn
|
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 |
// private DefaultViewPanel vista;
|
71 |
/**
|
72 |
* @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
73 |
*/
|
74 |
public void execute(String s) { |
75 |
execute(s,null);
|
76 |
} |
77 |
|
78 |
public void execute(String command, Object[] args) { |
79 |
|
80 |
DefaultViewPanel vista = getView(); |
81 |
if (vista==null) { |
82 |
return;
|
83 |
} |
84 |
|
85 |
|
86 |
ViewDocument document = vista.getViewDocument(); |
87 |
MapContext mapa = document.getMapContext(); |
88 |
MapControl mapCtrl = vista.getMapControl(); |
89 |
|
90 |
if (command.equalsIgnoreCase("view-navigation-zoom-all") ) { |
91 |
// mapa.beginAtomicEvent();
|
92 |
mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
93 |
document.setModified(true);
|
94 |
// mapa.endAtomicEvent();
|
95 |
|
96 |
} else if (command.equalsIgnoreCase("view-navigation-frame-manager") ) { |
97 |
FPanelExtentSelector l = new FPanelExtentSelector();
|
98 |
|
99 |
ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
100 |
Project project = p.getProject(); |
101 |
ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
102 |
//ProjectExtent[] extents = project.getExtents();
|
103 |
project.addPropertyChangeListener(modelo); |
104 |
l.setModel(modelo); |
105 |
l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
106 |
document.setModified(true);
|
107 |
PluginServices.getMDIManager().addWindow(l); |
108 |
|
109 |
} else if (command.equalsIgnoreCase("view-locator-setup") ) { |
110 |
//Set up the map overview
|
111 |
FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
112 |
PluginServices.getMDIManager().addWindow(m_panelLoc); |
113 |
m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
114 |
document.setModified(true);
|
115 |
|
116 |
} else if (command.equalsIgnoreCase("view-navigation-pan") ) { |
117 |
mapCtrl.setTool("pan");
|
118 |
document.setModified(true);
|
119 |
|
120 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint") ) { |
121 |
mapCtrl.setTool("zoomIn");
|
122 |
document.setModified(true);
|
123 |
|
124 |
} else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint") ) { |
125 |
mapCtrl.setTool("zoomOut");
|
126 |
document.setModified(true);
|
127 |
|
128 |
} else if (command.equalsIgnoreCase("layer-set-visible") ) { |
129 |
setVisibles(true, mapa.getLayers());
|
130 |
document.setModified(true);
|
131 |
|
132 |
} else if (command.equalsIgnoreCase("layer-set-hide") ) { |
133 |
setVisibles(false, mapa.getLayers());
|
134 |
document.setModified(true);
|
135 |
|
136 |
} else if (command.equalsIgnoreCase("layer-set-active") ) { |
137 |
setActives(true, mapa.getLayers());
|
138 |
document.setModified(true);
|
139 |
|
140 |
} else if (command.equalsIgnoreCase("layer-set-inactive") ) { |
141 |
setActives(false, mapa.getLayers());
|
142 |
document.setModified(true);
|
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 |
PluginServices.getMainFrame().getStatusBar().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 |
* 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 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
205 |
*/
|
206 |
public boolean isVisible() { |
207 |
|
208 |
DefaultViewPanel vista = getView(); |
209 |
|
210 |
if (vista!=null) { |
211 |
ViewDocument model = vista.getViewDocument(); |
212 |
MapContext mapa = model.getMapContext(); |
213 |
|
214 |
return mapa.getLayers().getLayersCount() > 0; |
215 |
} |
216 |
return false; |
217 |
} |
218 |
|
219 |
private DefaultViewPanel getView() {
|
220 |
|
221 |
|
222 |
org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
223 |
.getActiveWindow(); |
224 |
|
225 |
if (f!=null && f instanceof DefaultViewPanel) { |
226 |
return (DefaultViewPanel) f;
|
227 |
} |
228 |
return null; |
229 |
|
230 |
} |
231 |
|
232 |
/**
|
233 |
* @see org.gvsig.andami.plugins.IExtension#initialize()
|
234 |
*/
|
235 |
public void initialize() { |
236 |
|
237 |
ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
238 |
|
239 |
if (!epManager.has("View_TocActions")) { |
240 |
epManager.add( |
241 |
"View_TocActions",
|
242 |
"Context menu options of the TOC " +
|
243 |
" in the view window "+
|
244 |
"(register instances of " +
|
245 |
"org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
246 |
); |
247 |
} |
248 |
|
249 |
FPopupMenu.registerExtensionPoint(); |
250 |
|
251 |
registerIcons(); |
252 |
Snapping.register(); |
253 |
} |
254 |
|
255 |
private void registerIcons(){ |
256 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this); |
257 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this); |
258 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this); |
259 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this); |
260 |
IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this); |
261 |
IconThemeHelper.registerIcon("action", "view-navigation-pan", this); |
262 |
IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this); |
263 |
|
264 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-modify", this); |
265 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-add", this); |
266 |
IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-delete", this); |
267 |
|
268 |
} |
269 |
|
270 |
/**
|
271 |
* @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
272 |
*/
|
273 |
public boolean isEnabled() { |
274 |
|
275 |
DefaultViewPanel vista = getView(); |
276 |
|
277 |
if (vista != null) { |
278 |
|
279 |
ViewDocument model = vista.getViewDocument(); |
280 |
MapContext mapa = model.getMapContext(); |
281 |
|
282 |
FLayers layers = mapa.getLayers(); |
283 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
284 |
if (layers.getLayer(i).isAvailable()) {
|
285 |
return true; |
286 |
} |
287 |
} |
288 |
} |
289 |
return false; |
290 |
} |
291 |
|
292 |
public IPreference[] getPreferencesPages() { |
293 |
IPreference[] preferences=new IPreference[2]; |
294 |
preferences[0]=getViewPropertiesPage();
|
295 |
GridPage gridPage=new GridPage();
|
296 |
preferences[1]=gridPage;
|
297 |
return preferences;
|
298 |
} |
299 |
} |