svn-gvsig-desktop / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ZoomToSelectExtension.java @ 27390
History | View | Annotate | Download (5.58 KB)
1 | 9846 | caballero | /*
|
---|---|---|---|
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 | 24760 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
50 | 21530 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
51 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
52 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
53 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
54 | 24962 | vcaballero | import org.gvsig.project.document.table.gui.FeatureTableDocumentPanel; |
55 | 23214 | jmvivo | import org.gvsig.tools.exception.BaseException; |
56 | 20994 | jmvivo | |
57 | 9846 | caballero | import com.iver.andami.PluginServices; |
58 | 22252 | jmvivo | import com.iver.andami.messages.NotificationManager; |
59 | 9846 | caballero | import com.iver.andami.plugins.Extension; |
60 | import com.iver.andami.ui.mdiManager.IWindow; |
||
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 | 22252 | jmvivo | MapContext mapa = null;
|
77 | Envelope selectedExtent = null;
|
||
78 | 9846 | caballero | if (f instanceof View) { |
79 | View vista = (View)f; |
||
80 | 22252 | jmvivo | mapa = vista.getModel().getMapContext(); |
81 | 24962 | vcaballero | }else if (f instanceof FeatureTableDocumentPanel) { |
82 | FeatureTableDocumentPanel table=(FeatureTableDocumentPanel)f; |
||
83 | mapa = (table.getModel().getAssociatedLayer()).getMapContext(); |
||
84 | 22252 | jmvivo | } |
85 | 9846 | caballero | |
86 | 22252 | jmvivo | try {
|
87 | selectedExtent = mapa.getSelectionBounds(); |
||
88 | mapa.getViewPort().setEnvelope(selectedExtent); |
||
89 | } catch (BaseException e) {
|
||
90 | NotificationManager.addError(e); |
||
91 | 9846 | caballero | } |
92 | 22252 | jmvivo | |
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 | 9846 | caballero | } |
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 | 26053 | vcaballero | if (f != null && f instanceof View) { |
108 | 9846 | caballero | MapContext mapa = ((View) f).getModel().getMapContext();
|
109 | return mapa.getLayers().getLayersCount() > 0; |
||
110 | 22136 | jmvivo | // }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 | 9846 | caballero | } |
122 | |||
123 | return false; |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
128 | */
|
||
129 | public boolean isEnabled() { |
||
130 | com.iver.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 | 24759 | jmvivo | if (!((FLyrVect) selected[0]).getFeatureStore() |
141 | .getFeatureSelection().isEmpty()) { |
||
142 | 9846 | caballero | return true; |
143 | 22252 | jmvivo | } |
144 | 24760 | jmvivo | } catch (DataException e) {
|
145 | NotificationManager.addError(e); |
||
146 | 9846 | caballero | return false; |
147 | } |
||
148 | } |
||
149 | 24962 | vcaballero | }else if (f instanceof FeatureTableDocumentPanel) { |
150 | FeatureTableDocumentPanel t=(FeatureTableDocumentPanel)f; |
||
151 | 9846 | caballero | IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
152 | for (int i=0;i<windows.length;i++) { |
||
153 | if (windows[i] instanceof View) { |
||
154 | 24962 | vcaballero | if (((View)windows[i]).getMapControl().getMapContext().equals((t.getModel().getAssociatedLayer()).getMapContext())){ |
155 | 24760 | jmvivo | try {
|
156 | 24962 | vcaballero | if (!t.getModel().getStore().getFeatureSelection()
|
157 | 24760 | jmvivo | .isEmpty()) { |
158 | return true; |
||
159 | } |
||
160 | } catch (DataException e) {
|
||
161 | NotificationManager.addError(e); |
||
162 | return false; |
||
163 | 9846 | caballero | } |
164 | } |
||
165 | } |
||
166 | } |
||
167 | |||
168 | } |
||
169 | return false; |
||
170 | } |
||
171 | |||
172 | /**
|
||
173 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
174 | */
|
||
175 | public void initialize() { |
||
176 | 14821 | jmvivo | registerIcons(); |
177 | 9846 | caballero | } |
178 | 14821 | jmvivo | |
179 | private void registerIcons(){ |
||
180 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
181 | 14821 | jmvivo | "view-zoom-to-seleccion",
|
182 | this.getClass().getClassLoader().getResource("images/ZoomSeleccion.png") |
||
183 | ); |
||
184 | } |
||
185 | 9846 | caballero | } |