svn-gvsig-desktop / tags / v2_0_0_Build_2031 / applications / appgvSIG / src / org / gvsig / app / extension / ZoomToSelectExtension.java @ 36052
History | View | Annotate | Download (5.95 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 | 29596 | jpiera | package org.gvsig.app.extension; |
48 | 9846 | caballero | |
49 | 29596 | jpiera | 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 | 31496 | jjdelcerro | import org.gvsig.app.project.documents.view.gui.DefaultViewPanel; |
55 | 24760 | jmvivo | import org.gvsig.fmap.dal.exception.DataException; |
56 | 21530 | vcaballero | import org.gvsig.fmap.geom.primitive.Envelope; |
57 | 20994 | jmvivo | import org.gvsig.fmap.mapcontext.MapContext; |
58 | import org.gvsig.fmap.mapcontext.layers.FLayer; |
||
59 | import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
||
60 | 23214 | jmvivo | import org.gvsig.tools.exception.BaseException; |
61 | 20994 | jmvivo | |
62 | 9846 | caballero | |
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 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
75 | 9846 | caballero | .getActiveWindow(); |
76 | 22252 | jmvivo | MapContext mapa = null;
|
77 | Envelope selectedExtent = null;
|
||
78 | 31496 | jjdelcerro | if (f instanceof DefaultViewPanel) { |
79 | DefaultViewPanel vista = (DefaultViewPanel)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 | 35168 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow window = PluginServices.getMDIManager().getActiveWindow(); |
106 | if (window != null && window instanceof DefaultViewPanel) { |
||
107 | MapContext mapa = ((DefaultViewPanel) window).getModel().getMapContext(); |
||
108 | 9846 | caballero | return mapa.getLayers().getLayersCount() > 0; |
109 | 35168 | jpiera | }else if (window instanceof FeatureTableDocumentPanel) { |
110 | FeatureTableDocumentPanel featureTableDocumentPanel = (FeatureTableDocumentPanel)window; |
||
111 | IWindow[] windows = PluginServices.getMDIManager().getAllWindows();
|
||
112 | for (int i=0;i<windows.length;i++) { |
||
113 | 35176 | jpiera | if (windows[i] instanceof DefaultViewPanel) { |
114 | if (featureTableDocumentPanel.getModel().getAssociatedLayer() != null){ |
||
115 | if (((DefaultViewPanel)windows[i]).getMapControl().getMapContext().equals(
|
||
116 | (featureTableDocumentPanel.getModel().getAssociatedLayer()).getMapContext())){ |
||
117 | return true; |
||
118 | } |
||
119 | } |
||
120 | } |
||
121 | 35168 | jpiera | } |
122 | 9846 | caballero | } |
123 | return false; |
||
124 | } |
||
125 | |||
126 | /**
|
||
127 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#isEnabled()
|
128 | 9846 | caballero | */
|
129 | public boolean isEnabled() { |
||
130 | 29596 | jpiera | org.gvsig.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
131 | 9846 | caballero | .getActiveWindow(); |
132 | if (f == null) { |
||
133 | return false; |
||
134 | } |
||
135 | 31496 | jjdelcerro | if (f instanceof DefaultViewPanel) { |
136 | DefaultViewPanel view = (DefaultViewPanel) f; |
||
137 | 9846 | caballero | 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 | 31496 | jjdelcerro | if (windows[i] instanceof DefaultViewPanel) { |
154 | if (((DefaultViewPanel)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 | 29596 | jpiera | * @see org.gvsig.andami.plugins.IExtension#initialize()
|
174 | 9846 | caballero | */
|
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 | } |