root / branches / v2_0_0_prep / applications / appgvSIG / src / com / iver / cit / gvsig / ZoomToSelectExtension.java @ 22932
History | View | Annotate | Download (5.28 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.exceptions.BaseException; |
50 |
import org.gvsig.fmap.data.ReadException; |
51 |
import org.gvsig.fmap.geom.primitive.Envelope; |
52 |
import org.gvsig.fmap.mapcontext.MapContext; |
53 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
54 |
import org.gvsig.fmap.mapcontext.layers.vectorial.FLyrVect; |
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().getSelection().isEmpty()) { |
144 |
return true; |
145 |
} |
146 |
} catch (ReadException e) {
|
147 |
return false; |
148 |
} |
149 |
} |
150 |
}else if (f instanceof Table) { |
151 |
Table t=(Table)f; |
152 |
IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
153 |
for (int i=0;i<windows.length;i++) { |
154 |
if (windows[i] instanceof View) { |
155 |
if (((View)windows[i]).getMapControl().getMapContext().equals((t.getModel().getAssociatedTable()).getMapContext())){ |
156 |
if (!t.getModel().getModel().getSelection().isEmpty()) {
|
157 |
return true; |
158 |
} |
159 |
} |
160 |
} |
161 |
} |
162 |
|
163 |
} |
164 |
return false; |
165 |
} |
166 |
|
167 |
/**
|
168 |
* @see com.iver.andami.plugins.IExtension#initialize()
|
169 |
*/
|
170 |
public void initialize() { |
171 |
registerIcons(); |
172 |
} |
173 |
|
174 |
private void registerIcons(){ |
175 |
PluginServices.getIconTheme().registerDefault( |
176 |
"view-zoom-to-seleccion",
|
177 |
this.getClass().getClassLoader().getResource("images/ZoomSeleccion.png") |
178 |
); |
179 |
} |
180 |
} |