root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ViewControls.java @ 38564
History | View | Annotate | Download (9.36 KB)
1 | 312 | fernando | /*
|
---|---|---|---|
2 | * Created on 20-feb-2004
|
||
3 | *
|
||
4 | * To change the template for this generated file go to
|
||
5 | * Window>Preferences>Java>Code Generation>Code and Comments
|
||
6 | */
|
||
7 | 1103 | fjp | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 | *
|
||
9 | * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
||
10 | *
|
||
11 | * This program is free software; you can redistribute it and/or
|
||
12 | * modify it under the terms of the GNU General Public License
|
||
13 | * as published by the Free Software Foundation; either version 2
|
||
14 | * of the License, or (at your option) any later version.
|
||
15 | *
|
||
16 | * This program is distributed in the hope that it will be useful,
|
||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
19 | * GNU General Public License for more details.
|
||
20 | *
|
||
21 | * You should have received a copy of the GNU General Public License
|
||
22 | * along with this program; if not, write to the Free Software
|
||
23 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
24 | *
|
||
25 | * For more information, contact:
|
||
26 | *
|
||
27 | * Generalitat Valenciana
|
||
28 | * Conselleria d'Infraestructures i Transport
|
||
29 | * Av. Blasco Ib??ez, 50
|
||
30 | * 46010 VALENCIA
|
||
31 | * SPAIN
|
||
32 | *
|
||
33 | * +34 963862235
|
||
34 | * gvsig@gva.es
|
||
35 | * www.gvsig.gva.es
|
||
36 | *
|
||
37 | * or
|
||
38 | *
|
||
39 | * IVER T.I. S.A
|
||
40 | * Salamanca 50
|
||
41 | * 46005 Valencia
|
||
42 | * Spain
|
||
43 | *
|
||
44 | * +34 963163400
|
||
45 | * dac@iver.es
|
||
46 | */
|
||
47 | 29596 | jpiera | package org.gvsig.app.extension; |
48 | 312 | fernando | |
49 | 38564 | jjdelcerro | import javax.swing.JOptionPane; |
50 | |||
51 | import org.gvsig.andami.IconThemeHelper; |
||
52 | 29596 | jpiera | import org.gvsig.andami.PluginServices; |
53 | import org.gvsig.andami.plugins.Extension; |
||
54 | import org.gvsig.andami.preferences.IPreference; |
||
55 | import org.gvsig.andami.preferences.IPreferenceExtension; |
||
56 | import org.gvsig.app.gui.preferencespage.GridPage; |
||
57 | import org.gvsig.app.gui.preferencespage.ViewPage; |
||
58 | import org.gvsig.app.project.Project; |
||
59 | import org.gvsig.app.project.documents.view.Encuadrator; |
||
60 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.ViewDocument; |
61 | 38564 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
62 | 31306 | vcaballero | import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel; |
63 | import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector; |
||
64 | import org.gvsig.app.project.documents.view.gui.FPanelLocConfig; |
||
65 | 29596 | jpiera | import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu; |
66 | import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping; |
||
67 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
68 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
69 | import org.gvsig.fmap.mapcontext.layers.FLayers; |
||
70 | import org.gvsig.fmap.mapcontrol.MapControl; |
||
71 | 24953 | jmvivo | import org.gvsig.tools.ToolsLocator; |
72 | 38564 | jjdelcerro | import org.gvsig.tools.dataTypes.DataTypes; |
73 | 24953 | jmvivo | import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
74 | 28033 | cordinyana | import org.slf4j.Logger; |
75 | import org.slf4j.LoggerFactory; |
||
76 | 2522 | caballero | |
77 | 1086 | vcaballero | |
78 | |||
79 | 312 | fernando | //import com.iver.utiles.FPanelExtentSelector;
|
80 | |||
81 | /**
|
||
82 | 6630 | caballero | * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
|
83 | 312 | fernando | *
|
84 | * @author vcn
|
||
85 | */
|
||
86 | 6658 | caballero | public class ViewControls extends Extension implements IPreferenceExtension{ |
87 | 28033 | cordinyana | private static final Logger logger = LoggerFactory |
88 | .getLogger(ViewInvertSelection.class); |
||
89 | |||
90 | 36641 | fdiaz | private static ViewPage viewPropertiesPage = null; |
91 | 31496 | jjdelcerro | private DefaultViewPanel vista;
|
92 | 1086 | vcaballero | /**
|
93 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
94 | 1086 | vcaballero | */
|
95 | public void execute(String s) { |
||
96 | 38564 | jjdelcerro | execute(s,null);
|
97 | } |
||
98 | |||
99 | public void execute(String command, Object[] args) { |
||
100 | ViewDocument document = vista.getViewDocument(); |
||
101 | MapContext mapa = document.getMapContext(); |
||
102 | 1223 | fernando | MapControl mapCtrl = vista.getMapControl(); |
103 | 312 | fernando | |
104 | 38564 | jjdelcerro | if (command.equalsIgnoreCase("view-navigation-zoom-all") ) { |
105 | 10626 | caballero | // mapa.beginAtomicEvent();
|
106 | 21501 | vcaballero | mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope()); |
107 | 38564 | jjdelcerro | document.setModified(true);
|
108 | 10626 | caballero | // mapa.endAtomicEvent();
|
109 | 38564 | jjdelcerro | |
110 | } else if (command.equalsIgnoreCase("view-navigation-frame-manager") ) { |
||
111 | 1086 | vcaballero | FPanelExtentSelector l = new FPanelExtentSelector();
|
112 | 312 | fernando | |
113 | 29596 | jpiera | ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class); |
114 | 1086 | vcaballero | Project project = p.getProject(); |
115 | ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
|
||
116 | 2522 | caballero | //ProjectExtent[] extents = project.getExtents();
|
117 | 1086 | vcaballero | project.addPropertyChangeListener(modelo); |
118 | l.setModel(modelo); |
||
119 | l.addSelectionListener(new Encuadrator(project, mapa, vista));
|
||
120 | 38564 | jjdelcerro | document.setModified(true);
|
121 | 6880 | cesar | PluginServices.getMDIManager().addWindow(l); |
122 | 38564 | jjdelcerro | |
123 | } else if (command.equalsIgnoreCase("view-locator-setup") ) { |
||
124 | 312 | fernando | //Set up the map overview
|
125 | 643 | fjp | FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
|
126 | 6880 | cesar | PluginServices.getMDIManager().addWindow(m_panelLoc); |
127 | 1086 | vcaballero | m_panelLoc.setPreferredSize(m_panelLoc.getSize()); |
128 | 38564 | jjdelcerro | document.setModified(true);
|
129 | |||
130 | } else if (command.equalsIgnoreCase("view-navigation-pan") ) { |
||
131 | 1086 | vcaballero | mapCtrl.setTool("pan");
|
132 | 38564 | jjdelcerro | document.setModified(true);
|
133 | |||
134 | } else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint") ) { |
||
135 | 1086 | vcaballero | mapCtrl.setTool("zoomIn");
|
136 | 38564 | jjdelcerro | document.setModified(true);
|
137 | |||
138 | } else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint") ) { |
||
139 | 1086 | vcaballero | mapCtrl.setTool("zoomOut");
|
140 | 38564 | jjdelcerro | document.setModified(true);
|
141 | |||
142 | } else if (command.equalsIgnoreCase("layer-set-visible") ) { |
||
143 | 31306 | vcaballero | setVisibles(true, mapa.getLayers());
|
144 | 38564 | jjdelcerro | document.setModified(true);
|
145 | |||
146 | } else if (command.equalsIgnoreCase("layer-set-hide") ) { |
||
147 | 31306 | vcaballero | setVisibles(false, mapa.getLayers());
|
148 | 38564 | jjdelcerro | document.setModified(true);
|
149 | |||
150 | } else if (command.equalsIgnoreCase("layer-set-active") ) { |
||
151 | 31306 | vcaballero | setActives(true, mapa.getLayers());
|
152 | 38564 | jjdelcerro | document.setModified(true);
|
153 | |||
154 | } else if (command.equalsIgnoreCase("layer-set-inactive") ) { |
||
155 | 31306 | vcaballero | setActives(false, mapa.getLayers());
|
156 | 38564 | jjdelcerro | document.setModified(true);
|
157 | |||
158 | } else if (command.equalsIgnoreCase("view-navigation-zoom-in-center") ) { |
||
159 | 6239 | caballero | mapCtrl.zoomIn(); |
160 | 38564 | jjdelcerro | document.setModified(true);
|
161 | |||
162 | } else if (command.equalsIgnoreCase("view-navigation-zoom-out-center") ) { |
||
163 | 6239 | caballero | mapCtrl.zoomOut(); |
164 | 38564 | jjdelcerro | document.setModified(true);
|
165 | |||
166 | } else if (command.equalsIgnoreCase("view-change-scale")) { |
||
167 | try {
|
||
168 | Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]); |
||
169 | mapa.setScaleView(scale.longValue()); |
||
170 | document.setModified(true);
|
||
171 | } catch(Throwable ex) { |
||
172 | logger.info("Can't change scale of view.", ex);
|
||
173 | PluginServices.getMainFrame().getStatusBar().message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE); |
||
174 | } |
||
175 | 1086 | vcaballero | } |
176 | } |
||
177 | 1219 | vcaballero | |
178 | 36641 | fdiaz | private ViewPage getViewPropertiesPage(){
|
179 | if(viewPropertiesPage==null){ |
||
180 | viewPropertiesPage = new ViewPage();
|
||
181 | } |
||
182 | return viewPropertiesPage;
|
||
183 | } |
||
184 | 1219 | vcaballero | /**
|
185 | * Pone todas las capas visibles o no visibles.
|
||
186 | *
|
||
187 | * @param visible true si que quieren poner a visibles.
|
||
188 | * @param mapa FMap sobre el que actuar.
|
||
189 | */
|
||
190 | 31306 | vcaballero | private void setVisibles(boolean visible, FLayers layers) { |
191 | int layerCount=layers.getLayersCount();
|
||
192 | for (int i = 0; i < layerCount; i++) { |
||
193 | FLayer layer = layers.getLayer(i); |
||
194 | 1185 | vcaballero | layer.setVisible(visible); |
195 | 31306 | vcaballero | if (layer instanceof FLayers){ |
196 | setVisibles(visible,(FLayers)layer); |
||
197 | } |
||
198 | 1185 | vcaballero | } |
199 | } |
||
200 | 31306 | vcaballero | |
201 | 1219 | vcaballero | /**
|
202 | * Pone todas las capas activas o no activas.
|
||
203 | *
|
||
204 | * @param active true si que quieren poner a activas.
|
||
205 | * @param mapa FMap sobre el que actuar.
|
||
206 | */
|
||
207 | 31306 | vcaballero | private void setActives(boolean active, FLayers layers) { |
208 | int layerCount=layers.getLayersCount();
|
||
209 | for (int i = 0; i < layerCount; i++) { |
||
210 | FLayer layer = layers.getLayer(i); |
||
211 | 1185 | vcaballero | layer.setActive(active); |
212 | 31306 | vcaballero | if (layer instanceof FLayers){ |
213 | setActives(active,(FLayers)layer); |
||
214 | } |
||
215 | 1185 | vcaballero | } |
216 | } |
||
217 | 1086 | vcaballero | /**
|
218 | 5005 | jorpiell | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
219 | 1086 | vcaballero | */
|
220 | public boolean isVisible() { |
||
221 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
222 | 6880 | cesar | .getActiveWindow(); |
223 | 312 | fernando | |
224 | 31496 | jjdelcerro | if (f!=null && f instanceof DefaultViewPanel) { |
225 | vista = (DefaultViewPanel) f; |
||
226 | 38564 | jjdelcerro | ViewDocument model = vista.getViewDocument(); |
227 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
228 | 1219 | vcaballero | |
229 | 1086 | vcaballero | return mapa.getLayers().getLayersCount() > 0; |
230 | 6630 | caballero | } |
231 | 1086 | vcaballero | return false; |
232 | } |
||
233 | 596 | fernando | |
234 | /**
|
||
235 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
236 | 596 | fernando | */
|
237 | 5005 | jorpiell | public void initialize() { |
238 | 6713 | caballero | |
239 | 24953 | jmvivo | ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager(); |
240 | 6713 | caballero | |
241 | 24953 | jmvivo | if (!epManager.has("View_TocActions")) { |
242 | epManager.add( |
||
243 | 6673 | jmvivo | "View_TocActions",
|
244 | 6713 | caballero | "Context menu options of the TOC " +
|
245 | " in the view window "+
|
||
246 | 6673 | jmvivo | "(register instances of " +
|
247 | 29596 | jpiera | "org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
|
248 | 6673 | jmvivo | ); |
249 | } |
||
250 | 6713 | caballero | |
251 | FPopupMenu.registerExtensionPoint(); |
||
252 | |||
253 | 14821 | jmvivo | registerIcons(); |
254 | 23642 | vcaballero | Snapping.register(); |
255 | 596 | fernando | } |
256 | |||
257 | 14821 | jmvivo | private void registerIcons(){ |
258 | 38564 | jjdelcerro | IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this); |
259 | IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this); |
||
260 | IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this); |
||
261 | IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this); |
||
262 | IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this); |
||
263 | IconThemeHelper.registerIcon("action", "view-navigation-pan", this); |
||
264 | IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this); |
||
265 | 14821 | jmvivo | } |
266 | |||
267 | 596 | fernando | /**
|
268 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
269 | 596 | fernando | */
|
270 | public boolean isEnabled() { |
||
271 | 38564 | jjdelcerro | ViewDocument model = vista.getViewDocument(); |
272 | 26053 | vcaballero | MapContext mapa = model.getMapContext(); |
273 | 8516 | jaume | |
274 | 26053 | vcaballero | FLayers layers = mapa.getLayers(); |
275 | for (int i=0;i<layers.getLayersCount();i++) { |
||
276 | if (layers.getLayer(i).isAvailable()) {
|
||
277 | return true; |
||
278 | 6778 | jmvivo | } |
279 | } |
||
280 | return false; |
||
281 | 596 | fernando | } |
282 | 6658 | caballero | |
283 | 9634 | caballero | public IPreference[] getPreferencesPages() { |
284 | 23642 | vcaballero | IPreference[] preferences=new IPreference[2]; |
285 | 36641 | fdiaz | preferences[0]=getViewPropertiesPage();
|
286 | 23642 | vcaballero | GridPage gridPage=new GridPage();
|
287 | preferences[1]=gridPage;
|
||
288 | 9634 | caballero | return preferences;
|
289 | 6658 | caballero | } |
290 | 312 | fernando | } |