Statistics
| Revision:

svn-gvsig-desktop / trunk / org.gvsig.desktop / org.gvsig.desktop.plugin / org.gvsig.app / org.gvsig.app.mainplugin / src / main / java / org / gvsig / app / extension / ZoomToSelectExtension.java @ 40558

History | View | Annotate | Download (5.2 KB)

1
/**
2
 * gvSIG. Desktop Geographic Information System.
3
 *
4
 * Copyright (C) 2007-2013 gvSIG Association.
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 3
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 * For any additional information, do not hesitate to contact us
22
 * at info AT gvsig.com, or visit our website www.gvsig.com.
23
 */
24
/*
25
 * Created on 31-may-2004
26
 *
27
 * To change the template for this generated file go to
28
 * Window>Preferences>Java>Code Generation>Code and Comments
29
 */
30
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
31
 *
32
 * Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
33
 *
34
 * This program is free software; you can redistribute it and/or
35
 * modify it under the terms of the GNU General Public License
36
 * as published by the Free Software Foundation; either version 2
37
 * of the License, or (at your option) any later version.
38
 *
39
 * This program is distributed in the hope that it will be useful,
40
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
41
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
42
 * GNU General Public License for more details.
43
 *
44
 * You should have received a copy of the GNU General Public License
45
 * along with this program; if not, write to the Free Software
46
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
47
 *
48
 * For more information, contact:
49
 *
50
 *  Generalitat Valenciana
51
 *   Conselleria d'Infraestructures i Transport
52
 *   Av. Blasco Ib??ez, 50
53
 *   46010 VALENCIA
54
 *   SPAIN
55
 *
56
 *      +34 963862235
57
 *   gvsig@gva.es
58
 *      www.gvsig.gva.es
59
 *
60
 *    or
61
 *
62
 *   IVER T.I. S.A
63
 *   Salamanca 50
64
 *   46005 Valencia
65
 *   Spain
66
 *
67
 *   +34 963163400
68
 *   dac@iver.es
69
 */
70
package org.gvsig.app.extension;
71

    
72
import org.gvsig.andami.IconThemeHelper;
73
import org.gvsig.andami.PluginServices;
74
import org.gvsig.andami.messages.NotificationManager;
75
import org.gvsig.andami.plugins.Extension;
76
import org.gvsig.app.project.documents.view.gui.DefaultViewPanel;
77
import org.gvsig.fmap.dal.exception.DataException;
78
import org.gvsig.fmap.geom.primitive.Envelope;
79
import org.gvsig.fmap.mapcontext.MapContext;
80
import org.gvsig.fmap.mapcontext.layers.FLayer;
81
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
82
import org.gvsig.tools.exception.BaseException;
83

    
84

    
85

    
86
/**
87
 * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista.
88
 * 
89
 * @author Vicente Caballero Navarro
90
 */
91
public class ZoomToSelectExtension extends Extension {
92
        /**
93
         * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
94
         */
95
        public void execute(String s) {
96
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
97
                         .getActiveWindow();
98
                MapContext mapa = null;
99
                Envelope selectedExtent = null;
100
                if (f instanceof DefaultViewPanel) {
101
                        DefaultViewPanel vista = (DefaultViewPanel)f;
102
                        mapa = vista.getModel().getMapContext();
103
                }
104
                try {
105
                        selectedExtent = mapa.getSelectionBounds();
106
                        mapa.getViewPort().setEnvelope(selectedExtent);
107
                } catch (BaseException e) {
108
                        NotificationManager.addError(e);
109
                }
110

    
111
                //if (selectedExtent != null) {
112
                        //Envelope env=new DefaultEnvelope(2,new double[]{selectedExtent.getX(),selectedExtent.getY()},new double[]{selectedExtent.getMaxX(),selectedExtent.getMaxY()});
113
                        //((ProjectDocument) vista.getModel()).setModified(true);
114

    
115
                //}
116

    
117
        }
118

    
119
        /**
120
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
121
         */
122
        public boolean isVisible() {
123
                org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow();
124
                if (window != null && window instanceof DefaultViewPanel) {
125
                        MapContext mapa = ((DefaultViewPanel) window).getModel().getMapContext();
126
                        return mapa.getLayers().getLayersCount() > 0;
127
                }
128
                return false;
129
        }
130

    
131
        /**
132
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
133
         */
134
        public boolean isEnabled() {
135
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
136
                         .getActiveWindow();
137
                if (f == null) {
138
                        return false;
139
                }
140
                if (f instanceof DefaultViewPanel) {
141
                        DefaultViewPanel view = (DefaultViewPanel) f;
142
                        FLayer[] selected = view.getModel().getMapContext().getLayers().getActives();
143
                        if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){
144
                                try {
145
                                        if (!((FLyrVect) selected[0]).getFeatureStore()
146
                                                        .getFeatureSelection().isEmpty()) {
147
                                                return true;
148
                                        }
149
                                } catch (DataException e) {
150
                                        NotificationManager.addError(e);
151
                                        return false;
152
                                }
153
                        }
154
        }
155

    
156

    
157
                return false;
158
        }
159

    
160
        /**
161
         * @see org.gvsig.andami.plugins.IExtension#initialize()
162
         */
163
        public void initialize() {
164
                   IconThemeHelper.registerIcon("action", "view-navigation-zoom-to-selection", this);
165
        }
166
}