Statistics
| Revision:

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

History | View | Annotate | Download (6.75 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 com.iver.andami.PluginServices;
50
import com.iver.andami.messages.NotificationManager;
51
import com.iver.andami.plugins.Extension;
52

    
53
import com.iver.cit.gvsig.fmap.DriverException;
54
import com.iver.cit.gvsig.fmap.FMap;
55
import com.iver.cit.gvsig.fmap.MapControl;
56
import com.iver.cit.gvsig.fmap.layers.FLayer;
57
import com.iver.cit.gvsig.gui.Encuadrator;
58
import com.iver.cit.gvsig.gui.ExtentListSelectorModel;
59
import com.iver.cit.gvsig.gui.FPanelExtentSelector;
60
import com.iver.cit.gvsig.gui.FPanelLocConfig;
61
import com.iver.cit.gvsig.gui.View;
62
import com.iver.cit.gvsig.gui.project.ViewProperties;
63
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel;
64
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener;
65
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme;
66
import com.iver.cit.gvsig.project.Project;
67
import com.iver.cit.gvsig.project.ProjectExtent;
68
import com.iver.cit.gvsig.project.ProjectView;
69

    
70
import org.apache.log4j.Logger;
71

    
72

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

    
75
/**
76
 * Extensi?n que controla las operaciones basicas realizadas sobre la vista.
77
 *
78
 * @author vcn
79
 */
80
public class ViewControls implements Extension {
81
        private static Logger logger = Logger.getLogger(ViewControls.class.getName());
82

    
83
        /**
84
         * @see com.iver.mdiApp.plugins.Extension#updateUI(java.lang.String)
85
         */
86
        public void execute(String s) {
87
                View vista = (View) PluginServices.getMDIManager().getActiveView();
88
                ProjectView model = vista.getModel();
89
                FMap mapa = model.getMapContext();
90
                MapControl mapCtrl = vista.getMapControl();
91
                logger.debug("Comand : " + s);
92

    
93
                if (s.compareTo("FULL") == 0) {
94
                        try {
95
                                mapa.getViewPort().setExtent(mapa.getLayers().getFullExtent());
96
                        } catch (DriverException e) {
97
                                NotificationManager.addError("Error obteniendo el full extent",
98
                                        e);
99
                        }
100
                } else if (s.compareTo("SELECTIONBYSHAPE") == 0) {
101
                        SelectionByTheme dlg = new SelectionByTheme();
102
                        FLayer[] layers = mapa.getLayers().getActives();
103
                        int count = 0;
104
                        dlg.setModel(new DefaultSelectionByThemeModel());
105
                        dlg.addSelectionListener(new MySelectionByThemeListener());
106
                        PluginServices.getMDIManager().addView(dlg);
107
                } else if (s.compareTo("ENCUADRE") == 0) {
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.compareTo("INFO") == 0) {
119
                        mapCtrl.setTool("info");
120
                } else if (s.compareTo("CONFIG_LOCATOR") == 0) {
121
                        //Set up the map overview
122
                        FPanelLocConfig m_panelLoc = new FPanelLocConfig(vista.getMapOverview());
123
                        PluginServices.getMDIManager().addView(m_panelLoc);
124
                        m_panelLoc.setPreferredSize(m_panelLoc.getSize());
125
                } else if (s.compareTo("PAN") == 0) {
126
                        mapCtrl.setTool("pan");
127
                } else if (s.compareTo("ZOOM_IN") == 0) {
128
                        mapCtrl.setTool("zoomIn");
129
                } else if (s.compareTo("ZOOM_OUT") == 0) {
130
                        mapCtrl.setTool("zoomOut");
131
                } else if (s.compareTo("MEDICION") == 0) {
132
                        mapCtrl.setTool("medicion");
133
                } else if (s.compareTo("AREA") == 0) {
134
                        mapCtrl.setTool("area");
135
                } else if (s.compareTo("SELRECT") == 0) {
136
                        mapCtrl.setTool("rectSelection");
137
                } else if (s.compareTo("SELPOINT") == 0) {
138
                        mapCtrl.setTool("pointSelection");
139
                } else if (s.compareTo("PROPERTIES") == 0) {
140
                        ViewProperties viewProperties = new ViewProperties(model);
141
                        PluginServices.getMDIManager().addView(viewProperties);
142
                } else if (s.compareTo("TEMAS_VISIBLES") == 0) {
143
                        setVisibles(true, mapa);
144
                } else if (s.compareTo("TEMAS_NOVISIBLES") == 0) {
145
                        setVisibles(false, mapa);
146
                } else if (s.compareTo("TEMAS_ACTIVOS") == 0) {
147
                        setActives(true, mapa);
148
                } else if (s.compareTo("TEMAS_NOACTIVOS") == 0) {
149
                        setActives(false, mapa);
150
                }
151
        }
152

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

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

    
179
        /**
180
         * @see com.iver.mdiApp.plugins.Extension#isVisible()
181
         */
182
        public boolean isVisible() {
183
                com.iver.andami.ui.mdiManager.View f = PluginServices.getMDIManager()
184
                                                                                                                         .getActiveView();
185

    
186
                if (f == null) {
187
                        return false;
188
                }
189

    
190
                if (f.getClass() == View.class) {
191
                        View vista = (View) f;
192
                        ProjectView model = vista.getModel();
193
                        FMap mapa = model.getMapContext();
194

    
195
                        return mapa.getLayers().getLayersCount() > 0;
196
                } else {
197
                        return false;
198
                }
199
        }
200

    
201
        /**
202
         * @see com.iver.andami.plugins.Extension#inicializar()
203
         */
204
        public void inicializar() {
205
        }
206

    
207
        /**
208
         * @see com.iver.andami.plugins.Extension#isEnabled()
209
         */
210
        public boolean isEnabled() {
211
                return true;
212
        }
213
}