Statistics
| Revision:

root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ZoomToSelectExtension.java @ 24759

History | View | Annotate | Download (5.33 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 com.iver.cit.gvsig;
48

    
49
import org.gvsig.fmap.dal.exception.ReadException;
50
import org.gvsig.fmap.geom.primitive.Envelope;
51
import org.gvsig.fmap.mapcontext.MapContext;
52
import org.gvsig.fmap.mapcontext.layers.FLayer;
53
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect;
54
import org.gvsig.tools.exception.BaseException;
55

    
56
import com.iver.andami.PluginServices;
57
import com.iver.andami.messages.NotificationManager;
58
import com.iver.andami.plugins.Extension;
59
import com.iver.andami.ui.mdiManager.IWindow;
60
import com.iver.cit.gvsig.project.documents.table.gui.Table;
61
import com.iver.cit.gvsig.project.documents.view.gui.View;
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
                com.iver.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 Table) {
82
                        Table table=(Table)f;
83
                        mapa = (table.getModel().getAssociatedTable()).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
                com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager()
106
                                                                                                                         .getActiveWindow();
107
                if (f == null) {
108
                        return false;
109
                }
110
                if (f instanceof View) {
111
                        MapContext mapa = ((View) f).getModel().getMapContext();
112
                        return mapa.getLayers().getLayersCount() > 0;
113
//                }else if (f instanceof Table) {
114
//                        Table t=(Table)f;
115
//                        IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
116
//                        for (int i=0;i<windows.length;i++) {
117
//                                if (windows[i] instanceof View) {
118
//                                        if (t.getModel().getAssociatedTable()!=null)
119
//                                        if (((View)windows[i]).getMapControl().getMapContext().equals(((FLyrVect)t.getModel().getAssociatedTable()).getMapContext())){
120
//                                                return true;
121
//                                        }
122
//                                }
123
//                        }
124
                }
125

    
126
                return false;
127
        }
128

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

    
165
                }
166
                return false;
167
        }
168

    
169
        /**
170
         * @see com.iver.andami.plugins.IExtension#initialize()
171
         */
172
        public void initialize() {
173
                registerIcons();
174
        }
175

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