Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / org / gvsig / app / extension / ZoomToSelectExtension.java @ 38189

History | View | Annotate | Download (4.35 KB)

1
/*
2
 * Created on 31-may-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 org.gvsig.app.extension;
48

    
49
import org.gvsig.andami.PluginServices;
50
import org.gvsig.andami.messages.NotificationManager;
51
import org.gvsig.andami.plugins.Extension;
52
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
53
import org.gvsig.fmap.dal.exception.DataException;
54
import org.gvsig.fmap.geom.primitive.Envelope;
55
import org.gvsig.fmap.mapcontext.MapContext;
56
import org.gvsig.fmap.mapcontext.layers.FLayer;
57
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
58
import org.gvsig.tools.exception.BaseException;
59

    
60

    
61

    
62
/**
63
 * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
64
 * 
65
 * @author Vicente Caballero Navarro
66
 */
67
public class ZoomToSelectExtension extends Extension {
68
        /**
69
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
70
         */
71
        public void execute(String s) {
72
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
73
                         .getActiveWindow();
74
                MapContext mapa = null;
75
                Envelope selectedExtent = null;
76
                if (f instanceof DefaultViewPanel) {
77
                        DefaultViewPanel vista = (DefaultViewPanel)f;
78
                        mapa = vista.getModel().getMapContext();
79
                }
80
                try {
81
                        selectedExtent = mapa.getSelectionBounds();
82
                        mapa.getViewPort().setEnvelope(selectedExtent);
83
                } catch (BaseException e) {
84
                        NotificationManager.addError(e);
85
                }
86

    
87
                //if (selectedExtent != null) {
88
                        //Envelope env=new DefaultEnvelope(2,new double[]{selectedExtent.getX(),selectedExtent.getY()},new double[]{selectedExtent.getMaxX(),selectedExtent.getMaxY()});
89
                        //((ProjectDocument) vista.getModel()).setModified(true);
90

    
91
                //}
92

    
93
        }
94

    
95
        /**
96
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
97
         */
98
        public boolean isVisible() {
99
                org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
100
                if (window != null && window instanceof DefaultViewPanel) {
101
                        MapContext mapa = ((DefaultViewPanel) window).getModel().getMapContext();
102
                        return mapa.getLayers().getLayersCount() > 0;
103
                }
104
                return false;
105
        }
106

    
107
        /**
108
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
109
         */
110
        public boolean isEnabled() {
111
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
112
                         .getActiveWindow();
113
                if (f == null) {
114
                        return false;
115
                }
116
                if (f instanceof DefaultViewPanel) {
117
                        DefaultViewPanel view = (DefaultViewPanel) f;
118
                        FLayer[] selected = view.getModel().getMapContext().getLayers().getActives();
119
                        if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){
120
                                try {
121
                                        if (!((FLyrVect) selected[0]).getFeatureStore()
122
                                                        .getFeatureSelection().isEmpty()) {
123
                                                return true;
124
                                        }
125
                                } catch (DataException e) {
126
                                        NotificationManager.addError(e);
127
                                        return false;
128
                                }
129
                        }
130
        }
131

    
132

    
133
                return false;
134
        }
135

    
136
        /**
137
         * @see org.gvsig.andami.plugins.IExtension#initialize()
138
         */
139
        public void initialize() {
140
                registerIcons();
141
        }
142

    
143
        private void registerIcons(){
144
                PluginServices.getIconTheme().registerDefault(
145
                                "view-zoom-to-seleccion",
146
                                this.getClass().getClassLoader().getResource("images/ZoomSeleccion.png")
147
                        );
148
        }
149
}