Statistics
| Revision:

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

History | View | Annotate | Download (4.26 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.IconThemeHelper;
50
import org.gvsig.andami.PluginServices;
51
import org.gvsig.andami.messages.NotificationManager;
52
import org.gvsig.andami.plugins.Extension;
53
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
54
import org.gvsig.fmap.dal.exception.DataException;
55
import org.gvsig.fmap.geom.primitive.Envelope;
56
import org.gvsig.fmap.mapcontext.MapContext;
57
import org.gvsig.fmap.mapcontext.layers.FLayer;
58
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
59
import org.gvsig.tools.exception.BaseException;
60

    
61

    
62

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

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

    
92
                //}
93

    
94
        }
95

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

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

    
133

    
134
                return false;
135
        }
136

    
137
        /**
138
         * @see org.gvsig.andami.plugins.IExtension#initialize()
139
         */
140
        public void initialize() {
141
                   IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this);
142
        }
143
}