Statistics
| Revision:

svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 15673

History | View | Annotate | Download (9.49 KB)

1
/*
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
/* 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
package com.iver.cit.gvsig;
48

    
49
import org.apache.log4j.Logger;
50

    
51
import com.iver.andami.PluginServices;
52
import com.iver.andami.plugins.Extension;
53
import com.iver.andami.preferences.IPreference;
54
import com.iver.andami.preferences.IPreferenceExtension;
55
import com.iver.cit.gvsig.fmap.MapContext;
56
import com.iver.cit.gvsig.fmap.MapControl;
57
import com.iver.cit.gvsig.fmap.layers.FLayer;
58
import com.iver.cit.gvsig.fmap.layers.FLayers;
59
import com.iver.cit.gvsig.gui.preferencespage.ViewPage;
60
import com.iver.cit.gvsig.project.Project;
61
import com.iver.cit.gvsig.project.documents.ProjectDocument;
62
import com.iver.cit.gvsig.project.documents.view.Encuadrator;
63
import com.iver.cit.gvsig.project.documents.view.IProjectView;
64
import com.iver.cit.gvsig.project.documents.view.gui.ExtentListSelectorModel;
65
import com.iver.cit.gvsig.project.documents.view.gui.FPanelExtentSelector;
66
import com.iver.cit.gvsig.project.documents.view.gui.FPanelLocConfig;
67
import com.iver.cit.gvsig.project.documents.view.gui.View;
68
import com.iver.cit.gvsig.project.documents.view.toc.gui.FPopupMenu;
69
import com.iver.utiles.extensionPoints.ExtensionPoint;
70
import com.iver.utiles.extensionPoints.ExtensionPoints;
71
import com.iver.utiles.extensionPoints.ExtensionPointsSingleton;
72

    
73

    
74
//import com.iver.utiles.FPanelExtentSelector;
75

    
76
/**
77
 * Extensi?n que controla las operaciones b?sicas realizadas sobre la vista.
78
 *
79
 * @author vcn
80
 */
81
public class ViewControls extends Extension implements IPreferenceExtension{
82
        private static Logger logger = Logger.getLogger(ViewControls.class.getName());
83
        private static ViewPage viewPropertiesPage = new ViewPage();
84
        /**
85
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
86
         */
87
        public void execute(String s) {
88
                com.iver.andami.ui.mdiManager.IWindow view = PluginServices.getMDIManager().getActiveWindow();
89
                if (!(view instanceof View))
90
                        return;
91
                View vista=(View)view;
92
                IProjectView model = vista.getModel();
93
                MapContext mapa = model.getMapContext();
94
                MapControl mapCtrl = vista.getMapControl();
95
                logger.debug("Comand : " + s);
96

    
97
                if (s.equals("FULL") ) {
98
                        // mapa.beginAtomicEvent();
99
                        mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent());
100
                        mapa.clearAllCachingImageDrawnLayers();
101
                        vista.repaintMap();
102
                        ((ProjectDocument)vista.getModel()).setModified(true);
103
                        // mapa.endAtomicEvent();
104
                } else if (s.equals("ENCUADRE") ) {
105
                        FPanelExtentSelector l = new FPanelExtentSelector();
106

    
107
                        ProjectExtension p = (ProjectExtension) PluginServices.getExtension(com.iver.cit.gvsig.ProjectExtension.class);
108
                        Project project = p.getProject();
109
                        ExtentListSelectorModel modelo = new ExtentListSelectorModel(project);
110
                        //ProjectExtent[] extents = project.getExtents();
111
                        project.addPropertyChangeListener(modelo);
112
                        l.setModel(modelo);
113
                        l.addSelectionListener(new Encuadrator(project, mapa, vista));
114
                        ((ProjectDocument)vista.getModel()).setModified(true);
115
                        PluginServices.getMDIManager().addWindow(l);
116
                } else if (s.equals("CONFIG_LOCATOR") ) {
117
                        //Set up the map overview
118
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
119
                        PluginServices.getMDIManager().addWindow(m_panelLoc);
120
                        m_panelLoc.setPreferredSize(m_panelLoc.getSize());
121
                        ((ProjectDocument)vista.getModel()).setModified(true);
122
                } else if (s.equals("PAN") ) {
123
                        mapCtrl.setTool("pan");
124
                        ((ProjectDocument)vista.getModel()).setModified(true);
125
                } else if (s.equals("ZOOM_IN") ) {
126
                        mapCtrl.setTool("zoomIn");
127
                        ((ProjectDocument)vista.getModel()).setModified(true);
128
                } else if (s.equals("ZOOM_OUT") ) {
129
                        mapCtrl.setTool("zoomOut");
130
                        ((ProjectDocument)vista.getModel()).setModified(true);
131
                } else if (s.equals("CAPAS_VISIBLES") ) {
132
                        setVisibles(true, mapa);
133
                        ((ProjectDocument)vista.getModel()).setModified(true);
134
                } else if (s.equals("CAPAS_NOVISIBLES") ) {
135
                        setVisibles(false, mapa);
136
                        ((ProjectDocument)vista.getModel()).setModified(true);
137
                } else if (s.equals("CAPAS_ACTIVAS") ) {
138
                        setActives(true, mapa);
139
                        ((ProjectDocument)vista.getModel()).setModified(true);
140
                } else if (s.equals("CAPAS_NOACTIVAS") ) {
141
                        setActives(false, mapa);
142
                        ((ProjectDocument)vista.getModel()).setModified(true);
143
                } else if (s.equals("SAVERASTER") ) {
144
                        mapCtrl.setTool("saveRaster");
145
                } else if (s.equals("SELECTIMAGE") ) {
146
                        mapCtrl.setTool("selectImage");
147
                } else if (s.equals("ACTION_ZOOM_IN") ) {
148
                        mapCtrl.zoomIn();
149
                        ((ProjectDocument)vista.getModel()).setModified(true);
150
                } else if (s.equals("ACTION_ZOOM_OUT") ) {
151
                        mapCtrl.zoomOut();
152
                        ((ProjectDocument)vista.getModel()).setModified(true);
153
                } else if (s.startsWith("CHANGE_SCALE_")){
154
                        String scl=s.replaceAll("CHANGE_SCALE_","");
155
                        long scale=Long.parseLong(scl);
156
                        mapa.setScaleView(scale);
157
                        ((ProjectDocument)vista.getModel()).setModified(true);
158
                }
159
        }
160

    
161
        /**
162
         * Pone todas las capas visibles o no visibles.
163
         *
164
         * @param visible true si que quieren poner a visibles.
165
         * @param mapa FMap sobre el que actuar.
166
         */
167
        private void setVisibles(boolean visible, MapContext mapa) {
168
                for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
169
                        FLayer layer = mapa.getLayers().getLayer(i);
170
                        layer.setVisible(visible);
171
                }
172
        }
173

    
174
        /**
175
         * Pone todas las capas activas o no activas.
176
         *
177
         * @param active true si que quieren poner a activas.
178
         * @param mapa FMap sobre el que actuar.
179
         */
180
        private void setActives(boolean active, MapContext mapa) {
181
                for (int i = 0; i < mapa.getLayers().getLayersCount(); i++) {
182
                        FLayer layer = mapa.getLayers().getLayer(i);
183
                        layer.setActive(active);
184
                }
185
        }
186

    
187
        /**
188
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
189
         */
190
        public boolean isVisible() {
191
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
192
                                                                                                                         .getActiveWindow();
193

    
194
                if (f == null) {
195
                        return false;
196
                }
197

    
198
                if (f instanceof View) {
199
                        View vista = (View) f;
200
                        IProjectView model = vista.getModel();
201
                        MapContext mapa = model.getMapContext();
202

    
203
                        return mapa.getLayers().getLayersCount() > 0;
204
                }
205
                        return false;
206
        }
207

    
208
        /**
209
         * @see com.iver.andami.plugins.IExtension#initialize()
210
         */
211
        public void initialize() {
212
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
213

    
214

    
215
                if (!extensionPoints.containsKey("View_TocActions")) {
216
                        extensionPoints.put(
217
                                new ExtensionPoint(
218
                                        "View_TocActions",
219
                                        "Context menu options of the TOC " +
220
                                                " in the view window "+
221
                                                "(register instances of " +
222
                                                "com.iver.cit.gvsig.gui.toc.AbstractTocContextMenuAction)"
223
                                )
224
                        );
225
                }
226

    
227
                FPopupMenu.registerExtensionPoint();
228

    
229
                registerIcons();
230
        }
231

    
232
        private void registerIcons(){
233

    
234
                PluginServices.getIconTheme().registerDefault(
235
                                "view-zoom-in",
236
                                this.getClass().getClassLoader().getResource("images/ZoomIn.png")
237
                        );
238
                PluginServices.getIconTheme().registerDefault(
239
                                "view-zoom-out",
240
                                this.getClass().getClassLoader().getResource("images/ZoomOut.png")
241
                        );
242
                PluginServices.getIconTheme().registerDefault(
243
                                "view-zoom-map-contents",
244
                                this.getClass().getClassLoader().getResource("images/MapContents.png")
245
                        );
246
                PluginServices.getIconTheme().registerDefault(
247
                                "view-zoom-center-in",
248
                                this.getClass().getClassLoader().getResource("images/zoommas.png")
249
                        );
250
                PluginServices.getIconTheme().registerDefault(
251
                                "view-zoom-center-out",
252
                                this.getClass().getClassLoader().getResource("images/zoommenos.png")
253
                        );
254

    
255
                PluginServices.getIconTheme().registerDefault(
256
                                "view-pan",
257
                                this.getClass().getClassLoader().getResource("images/Pan.png")
258
                        );
259

    
260
                PluginServices.getIconTheme().registerDefault(
261
                                "view-zoom-manager",
262
                                this.getClass().getClassLoader().getResource("images/encuadre.png")
263
                        );
264
        }
265

    
266
        /**
267
         * @see com.iver.andami.plugins.IExtension#isEnabled()
268
         */
269
        public boolean isEnabled() {
270
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
271
                .getActiveWindow();
272

    
273
                if (f == null) {
274
                        return false;
275
                }
276

    
277
                if (f instanceof View) {
278
                        View vista = (View) f;
279
                        IProjectView model = vista.getModel();
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()) return true;
285
                        }
286

    
287
                }
288
                return false;
289
        }
290

    
291
        public IPreference[] getPreferencesPages() {
292
                IPreference[] preferences=new IPreference[1];
293
                preferences[0]=viewPropertiesPage;
294
                return preferences;
295
        }
296
}