svn-gvsig-desktop / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ZoomToSelectExtension.java @ 10626
History | View | Annotate | Download (5.11 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 java.awt.geom.Rectangle2D; |
50 |
|
51 |
import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
52 |
import com.iver.andami.PluginServices; |
53 |
import com.iver.andami.plugins.Extension; |
54 |
import com.iver.andami.ui.mdiManager.IWindow; |
55 |
import com.iver.cit.gvsig.fmap.MapContext; |
56 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
57 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
58 |
import com.iver.cit.gvsig.project.documents.ProjectDocument; |
59 |
import com.iver.cit.gvsig.project.documents.table.gui.Table; |
60 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
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 |
if (f instanceof View) { |
77 |
View vista = (View)f; |
78 |
IProjectView model = vista.getModel(); |
79 |
MapContext mapa = model.getMapContext(); |
80 |
Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
81 |
|
82 |
if (selectedExtent != null) { |
83 |
mapa.getViewPort().setExtent(selectedExtent); |
84 |
((ProjectDocument)vista.getModel()).setModified(true);
|
85 |
} |
86 |
}else if (f instanceof Table) { |
87 |
Table table=(Table)f; |
88 |
MapContext mapa=((FLyrVect)table.getModel().getAssociatedTable()).getMapContext(); |
89 |
Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
90 |
|
91 |
if (selectedExtent != null) { |
92 |
mapa.getViewPort().setExtent(selectedExtent); |
93 |
table.getModel().setModified(true);
|
94 |
} |
95 |
} |
96 |
} |
97 |
|
98 |
/**
|
99 |
* @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
100 |
*/
|
101 |
public boolean isVisible() { |
102 |
com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
103 |
.getActiveWindow(); |
104 |
if (f == null) { |
105 |
return false; |
106 |
} |
107 |
if (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 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 |
if (!((FLyrVect)selected[0]).getRecordset().getSelection().isEmpty()) |
141 |
return true; |
142 |
} catch (ReadDriverException e) {
|
143 |
return false; |
144 |
} |
145 |
} |
146 |
}else if (f instanceof Table) { |
147 |
Table t=(Table)f; |
148 |
IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
149 |
for (int i=0;i<windows.length;i++) { |
150 |
if (windows[i] instanceof View) { |
151 |
if (((View)windows[i]).getMapControl().getMapContext().equals(((FLyrVect)t.getModel().getAssociatedTable()).getMapContext())){ |
152 |
try {
|
153 |
if (!t.getModel().getModelo().getSelection().isEmpty()) {
|
154 |
return true; |
155 |
} |
156 |
} catch (ReadDriverException e) {
|
157 |
return false; |
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 |
} |
172 |
} |