Statistics
| Revision:

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 @ 40558

History | View | Annotate | Download (11.1 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
 * Created on 20-feb-2004
26
 *
27
 * To change the template for this generated file go to
28
 * Window>Preferences>Java>Code Generation>Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.app.extension;
71

    
72
import javax.swing.JOptionPane;
73

    
74
import org.slf4j.Logger;
75
import org.slf4j.LoggerFactory;
76

    
77
import org.gvsig.andami.IconThemeHelper;
78
import org.gvsig.andami.PluginServices;
79
import org.gvsig.andami.plugins.Extension;
80
import org.gvsig.andami.preferences.IPreference;
81
import org.gvsig.andami.preferences.IPreferenceExtension;
82
import org.gvsig.app.gui.preferencespage.GridPage;
83
import org.gvsig.app.gui.preferencespage.ViewPage;
84
import org.gvsig.app.project.Project;
85
import org.gvsig.app.project.documents.view.Encuadrator;
86
import org.gvsig.app.project.documents.view.ViewDocument;
87
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
88
import org.gvsig.app.project.documents.view.gui.ExtentListSelectorModel;
89
import org.gvsig.app.project.documents.view.gui.FPanelExtentSelector;
90
import org.gvsig.app.project.documents.view.gui.FPanelLocConfig;
91
import org.gvsig.app.project.documents.view.toc.gui.FPopupMenu;
92
import org.gvsig.app.project.documents.view.toolListeners.snapping.Snapping;
93
import org.gvsig.fmap.mapcontext.MapContext;
94
import org.gvsig.fmap.mapcontext.layers.FLayer;
95
import org.gvsig.fmap.mapcontext.layers.FLayers;
96
import org.gvsig.fmap.mapcontrol.MapControl;
97
import org.gvsig.tools.ToolsLocator;
98
import org.gvsig.tools.dataTypes.DataTypes;
99
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
100

    
101

    
102

    
103
//import com.iver.utiles.FPanelExtentSelector;
104

    
105
/**
106
 * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
107
 *
108
 * @author vcn
109
 */
110
public class ViewControls extends Extension implements IPreferenceExtension{
111
    private static final Logger logger = LoggerFactory
112
            .getLogger(ViewInvertSelection.class);
113
    
114
        private static ViewPage viewPropertiesPage = null;
115
        // private DefaultViewPanel vista;
116
        /**
117
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
118
         */
119
        public void execute(String s) {
120
                execute(s,null);
121
        }
122
        
123
        public void execute(String command, Object[] args) {
124
            
125
            DefaultViewPanel vista = getView();
126
            if (vista==null) {
127
                return;
128
            }
129

    
130
            
131
                ViewDocument document = vista.getViewDocument();
132
                MapContext mapa = document.getMapContext();
133
                MapControl mapCtrl = vista.getMapControl();
134

    
135
                if (command.equalsIgnoreCase("view-navigation-zoom-all") ) {
136
                        // mapa.beginAtomicEvent();
137
                        mapa.getViewPort().setEnvelope(mapa.getLayers().getFullEnvelope());
138
                        document.setModified(true);
139
                        // mapa.endAtomicEvent();
140
                        
141
                } else if (command.equalsIgnoreCase("view-navigation-frame-manager") ) {
142
                        FPanelExtentSelector l = new FPanelExtentSelector();
143

    
144
                        ProjectExtension p = (ProjectExtension) PluginServices.getExtension(org.gvsig.app.extension.ProjectExtension.class);
145
                        Project project = p.getProject();
146
                        ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
147
                        //ProjectExtent[] extents = project.getExtents();
148
                        project.addPropertyChangeListener(modelo);
149
                        l.setModel(modelo);
150
                        l.addSelectionListener(new Encuadrator(project, mapa, vista));
151
                        document.setModified(true);
152
                        PluginServices.getMDIManager().addWindow(l);
153
                        
154
                } else if (command.equalsIgnoreCase("view-locator-setup") ) {
155
                        //Set up the map overview
156
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
157
                        PluginServices.getMDIManager().addWindow(m_panelLoc);
158
                        m_panelLoc.setPreferredSize(m_panelLoc.getSize());
159
                        document.setModified(true);
160
                        
161
                } else if (command.equalsIgnoreCase("view-navigation-pan") ) {
162
                        mapCtrl.setTool("pan");
163
                        document.setModified(true);
164
                        
165
                } else if (command.equalsIgnoreCase("view-navigation-zoom-in-topoint") ) {
166
                        mapCtrl.setTool("zoomIn");
167
                        document.setModified(true);
168
                        
169
                } else if (command.equalsIgnoreCase("view-navigation-zoom-out-topoint") ) {
170
                        mapCtrl.setTool("zoomOut");
171
                        document.setModified(true);
172
                        
173
                } else if (command.equalsIgnoreCase("layer-set-visible") ) {
174
                        setVisibles(true, mapa.getLayers());
175
                        document.setModified(true);
176
                        
177
                } else if (command.equalsIgnoreCase("layer-set-hide") ) {
178
                        setVisibles(false, mapa.getLayers());
179
                        document.setModified(true);
180
                        
181
                } else if (command.equalsIgnoreCase("layer-set-active") ) {
182
                        setActives(true, mapa.getLayers());
183
                        document.setModified(true);
184
                        
185
                } else if (command.equalsIgnoreCase("layer-set-inactive") ) {
186
                        setActives(false, mapa.getLayers());
187
                        document.setModified(true);
188
                        
189
                } else if (command.equalsIgnoreCase("view-navigation-zoom-in-center") ) {
190
                        mapCtrl.zoomIn();
191
                        document.setModified(true);
192
                        
193
                } else if (command.equalsIgnoreCase("view-navigation-zoom-out-center") ) {
194
                        mapCtrl.zoomOut();
195
                        document.setModified(true);
196
                        
197
                } else if (command.equalsIgnoreCase("view-change-scale")) {
198
                        try {
199
                                Long scale = (Long) ToolsLocator.getDataTypesManager().coerce(DataTypes.LONG, args[0]);
200
                                mapa.setScaleView(scale.longValue());
201
                                document.setModified(true);
202
                        } catch(Throwable ex) {
203
                                logger.info("Can't change scale of view.", ex);
204
                                PluginServices.getMainFrame().getStatusBar().message("Can't change scale of view.", JOptionPane.ERROR_MESSAGE);
205
                        }
206
                }
207
        }
208

    
209
        private ViewPage getViewPropertiesPage(){
210
                if(viewPropertiesPage==null){
211
                        viewPropertiesPage = new ViewPage();
212
                }
213
                return viewPropertiesPage;
214
        }
215
        /**
216
         * Pone todas las capas visibles o no visibles.
217
         *
218
         * @param visible true si que quieren poner a visibles.
219
         * @param mapa FMap sobre el que actuar.
220
         */
221
        private void setVisibles(boolean visible, FLayers layers) {
222
                int layerCount=layers.getLayersCount();
223
                for (int i = 0; i < layerCount; i++) {
224
                        FLayer layer = layers.getLayer(i);
225
                        layer.setVisible(visible);
226
                        if (layer instanceof FLayers){
227
                                setVisibles(visible,(FLayers)layer);
228
                        }
229
                }
230
        }
231
        
232
        /**
233
         * Pone todas las capas activas o no activas.
234
         *
235
         * @param active true si que quieren poner a activas.
236
         * @param mapa FMap sobre el que actuar.
237
         */
238
        private void setActives(boolean active, FLayers layers) {
239
                int layerCount=layers.getLayersCount();
240
                for (int i = 0; i < layerCount; i++) {
241
                        FLayer layer = layers.getLayer(i);
242
                        layer.setActive(active);
243
                        if (layer instanceof FLayers){
244
                                setActives(active,(FLayers)layer);
245
                        }
246
                }
247
        }
248
        /**
249
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
250
         */
251
        public boolean isVisible() {
252
            
253
            DefaultViewPanel vista = getView();
254
            
255
                if (vista!=null) {
256
                        ViewDocument model = vista.getViewDocument();
257
                        MapContext mapa = model.getMapContext();
258

    
259
                        return mapa.getLayers().getLayersCount() > 0;
260
                }
261
                        return false;
262
        }
263
        
264
        private DefaultViewPanel getView() {
265
            
266

    
267
        org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
268
                                                             .getActiveWindow();
269

    
270
        if (f!=null && f instanceof DefaultViewPanel) {
271
            return (DefaultViewPanel) f;
272
        }
273
        return null;
274
            
275
        }
276

    
277
        /**
278
         * @see org.gvsig.andami.plugins.IExtension#initialize()
279
         */
280
        public void initialize() {
281

    
282
                ExtensionPointManager epManager = ToolsLocator.getExtensionPointManager();
283

    
284
                if (!epManager.has("View_TocActions")) {
285
                        epManager.add(
286
                                        "View_TocActions",
287
                                        "Context menu options of the TOC " +
288
                                                " in the view window "+
289
                                                "(register instances of " +
290
                                                "org.gvsig.app.gui.toc.AbstractTocContextMenuAction)"
291
                        );
292
                }
293

    
294
                FPopupMenu.registerExtensionPoint();
295

    
296
                registerIcons();
297
                Snapping.register();
298
        }
299

    
300
        private void registerIcons(){
301
                IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-topoint", this);
302
                IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-topoint", this);
303
                IconThemeHelper.registerIcon("action", "view-navigation-zoom-all", this);
304
                IconThemeHelper.registerIcon("action", "view-navigation-zoom-in-center", this);
305
                IconThemeHelper.registerIcon("action", "view-navigation-zoom-out-center", this);
306
                IconThemeHelper.registerIcon("action", "view-navigation-pan", this);
307
                IconThemeHelper.registerIcon("action", "view-navigation-frame-manager", this);
308
                
309
                IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-modify", this); 
310
                IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-add", this);
311
                IconThemeHelper.registerIcon("action", "edit-undo-redo-actions-delete", this);
312

    
313
        }
314

    
315
        /**
316
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
317
         */
318
    public boolean isEnabled() {
319

    
320
        DefaultViewPanel vista = getView();
321

    
322
        if (vista != null) {
323

    
324
            ViewDocument model = vista.getViewDocument();
325
            MapContext mapa = model.getMapContext();
326

    
327
            FLayers layers = mapa.getLayers();
328
            for (int i = 0; i < layers.getLayersCount(); i++) {
329
                if (layers.getLayer(i).isAvailable()) {
330
                    return true;
331
                }
332
            }
333
        }
334
        return false;
335
    }
336

    
337
        public IPreference[] getPreferencesPages() {
338
                IPreference[] preferences=new IPreference[2];
339
                preferences[0]=getViewPropertiesPage();
340
                GridPage gridPage=new GridPage();
341
                preferences[1]=gridPage;
342
                return preferences;
343
        }
344
}