Statistics
| Revision:

root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewControls.java @ 6728

History | View | Annotate | Download (7.18 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.messages.NotificationManager;
53
import com.iver.andami.plugins.Extension;
54
import com.iver.andami.preferences.IPreference;
55
import com.iver.andami.preferences.IPreferenceExtension;
56
import com.iver.cit.gvsig.fmap.DriverException;
57
import com.iver.cit.gvsig.fmap.FMap;
58
import com.iver.cit.gvsig.fmap.MapControl;
59
import com.iver.cit.gvsig.fmap.layers.FLayer;
60
import com.iver.cit.gvsig.gui.Encuadrator;
61
import com.iver.cit.gvsig.gui.ExtentListSelectorModel;
62
import com.iver.cit.gvsig.gui.FPanelExtentSelector;
63
import com.iver.cit.gvsig.gui.FPanelLocConfig;
64
import com.iver.cit.gvsig.gui.View;
65
import com.iver.cit.gvsig.gui.preferencespage.ViewPage;
66
import com.iver.cit.gvsig.gui.toc.FPopupMenu;
67
import com.iver.cit.gvsig.project.Project;
68
import com.iver.cit.gvsig.project.ProjectView;
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.View view = PluginServices.getMDIManager().getActiveView();
89
                if (!(view instanceof View))
90
                        return;
91
                View vista=(View)view;
92
                ProjectView model = vista.getModel();
93
                FMap mapa = model.getMapContext();
94
                MapControl mapCtrl = vista.getMapControl();
95
                logger.debug("Comand : " + s);
96

    
97
                if (s.equals("FULL") ) {
98
                        try {
99
                            // mapa.beginAtomicEvent();
100
                                mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent());
101
                                vista.repaintMap();
102
                                // mapa.endAtomicEvent();
103
                        } catch (DriverException e) {
104
                                NotificationManager.addError("Error obteniendo el full extent",
105
                                        e);
106
                        }
107
                } else if (s.equals("ENCUADRE") ) {
108
                        FPanelExtentSelector l = new FPanelExtentSelector();
109

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

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

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

    
182
        /**
183
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
184
         */
185
        public boolean isVisible() {
186
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
187
                                                                                                                         .getActiveView();
188

    
189
                if (f == null) {
190
                        return false;
191
                }
192

    
193
                if (f instanceof View) {
194
                        View vista = (View) f;
195
                        ProjectView model = vista.getModel();
196
                        FMap mapa = model.getMapContext();
197

    
198
                        return mapa.getLayers().getLayersCount() > 0;
199
                }
200
                        return false;
201
        }
202

    
203
        /**
204
         * @see com.iver.andami.plugins.IExtension#initialize()
205
         */
206
        public void initialize() {
207
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
208

    
209

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

    
222
                FPopupMenu.registerExtensionPoint();
223

    
224
        }
225

    
226
        /**
227
         * @see com.iver.andami.plugins.IExtension#isEnabled()
228
         */
229
        public boolean isEnabled() {
230
                return true;
231
        }
232

    
233
        public IPreference getPreferencesPage() {
234
                return viewPropertiesPage;
235
        }
236
}