Statistics
| Revision:

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

History | View | Annotate | Download (5.59 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.andami.ui.mdiManager.IWindow;
53
import org.gvsig.app.project.documents.table.gui.FeatureTableDocumentPanel;
54
import org.gvsig.app.project.documents.view.gui.View;
55
import org.gvsig.fmap.dal.exception.DataException;
56
import org.gvsig.fmap.geom.primitive.Envelope;
57
import org.gvsig.fmap.mapcontext.MapContext;
58
import org.gvsig.fmap.mapcontext.layers.FLayer;
59
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
60
import org.gvsig.tools.exception.BaseException;
61

    
62

    
63

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

    
86
                try {
87
                        selectedExtent = mapa.getSelectionBounds();
88
                        mapa.getViewPort().setEnvelope(selectedExtent);
89
                } catch (BaseException e) {
90
                        NotificationManager.addError(e);
91
                }
92

    
93
                //if (selectedExtent != null) {
94
                        //Envelope env=new DefaultEnvelope(2,new double[]{selectedExtent.getX(),selectedExtent.getY()},new double[]{selectedExtent.getMaxX(),selectedExtent.getMaxY()});
95
                        //((ProjectDocument) vista.getModel()).setModified(true);
96

    
97
                //}
98

    
99
        }
100

    
101
        /**
102
         * @see com.iver.mdiApp.plugins.IExtension#isVisible()
103
         */
104
        public boolean isVisible() {
105
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
106
                                                                                                                         .getActiveWindow();
107
                if (f != null && f instanceof View) {
108
                        MapContext mapa = ((View) f).getModel().getMapContext();
109
                        return mapa.getLayers().getLayersCount() > 0;
110
//                }else if (f instanceof Table) {
111
//                        Table t=(Table)f;
112
//                        IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
113
//                        for (int i=0;i<windows.length;i++) {
114
//                                if (windows[i] instanceof View) {
115
//                                        if (t.getModel().getAssociatedTable()!=null)
116
//                                        if (((View)windows[i]).getMapControl().getMapContext().equals(((FLyrVect)t.getModel().getAssociatedTable()).getMapContext())){
117
//                                                return true;
118
//                                        }
119
//                                }
120
//                        }
121
                }
122

    
123
                return false;
124
        }
125

    
126
        /**
127
         * @see org.gvsig.andami.plugins.IExtension#isEnabled()
128
         */
129
        public boolean isEnabled() {
130
                org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
131
                         .getActiveWindow();
132
                if (f == null) {
133
                        return false;
134
                }
135
                if (f instanceof View) {
136
                        View view = (View) f;
137
                        FLayer[] selected = view.getModel().getMapContext().getLayers().getActives();
138
                        if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){
139
                                try {
140
                                        if (!((FLyrVect) selected[0]).getFeatureStore()
141
                                                        .getFeatureSelection().isEmpty()) {
142
                                                return true;
143
                                        }
144
                                } catch (DataException e) {
145
                                        NotificationManager.addError(e);
146
                                        return false;
147
                                }
148
                        }
149
                }else if (f instanceof FeatureTableDocumentPanel) {
150
                        FeatureTableDocumentPanel t=(FeatureTableDocumentPanel)f;
151
                        IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
152
                        for (int i=0;i<windows.length;i++) {
153
                                if (windows[i] instanceof View) {
154
                                        if (((View)windows[i]).getMapControl().getMapContext().equals((t.getModel().getAssociatedLayer()).getMapContext())){
155
                                                try {
156
                                                        if (!t.getModel().getStore().getFeatureSelection()
157
                                                                        .isEmpty()) {
158
                                                                return true;
159
                                                        }
160
                                                } catch (DataException e) {
161
                                                        NotificationManager.addError(e);
162
                                                        return false;
163
                                                }
164
                                        }
165
                                }
166
                        }
167

    
168
                }
169
                return false;
170
        }
171

    
172
        /**
173
         * @see org.gvsig.andami.plugins.IExtension#initialize()
174
         */
175
        public void initialize() {
176
                registerIcons();
177
        }
178

    
179
        private void registerIcons(){
180
                PluginServices.getIconTheme().registerDefault(
181
                                "view-zoom-to-seleccion",
182
                                this.getClass().getClassLoader().getResource("images/ZoomSeleccion.png")
183
                        );
184
        }
185
}