svn-gvsig-desktop / tags / v1_0_2_Build_907 / applications / appgvSIG / src / com / iver / cit / gvsig / ZoomToSelectExtension.java @ 11015
History | View | Annotate | Download (4.9 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 | import java.awt.geom.Rectangle2D; |
||
50 | |||
51 | import com.iver.andami.PluginServices; |
||
52 | import com.iver.andami.plugins.Extension; |
||
53 | import com.iver.andami.ui.mdiManager.IWindow; |
||
54 | import com.iver.cit.gvsig.fmap.DriverException; |
||
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.table.gui.Table; |
||
59 | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
||
60 | import com.iver.cit.gvsig.project.documents.view.gui.View; |
||
61 | |||
62 | |||
63 | /**
|
||
64 | * Extensi?n de zoom a lo seleccionado teniendo como ventana activa una vista o una tabla.
|
||
65 | *
|
||
66 | * @author Vicente Caballero Navarro
|
||
67 | */
|
||
68 | public class ZoomToSelectExtension extends Extension { |
||
69 | /**
|
||
70 | * @see com.iver.mdiApp.plugins.IExtension#updateUI(java.lang.String)
|
||
71 | */
|
||
72 | public void execute(String s) { |
||
73 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
||
74 | .getActiveWindow(); |
||
75 | if (f instanceof View) { |
||
76 | View vista = (View)f; |
||
77 | IProjectView model = vista.getModel(); |
||
78 | MapContext mapa = model.getMapContext(); |
||
79 | Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
||
80 | |||
81 | if (selectedExtent != null) { |
||
82 | mapa.getViewPort().setExtent(selectedExtent); |
||
83 | } |
||
84 | }else if (f instanceof Table) { |
||
85 | Table table=(Table)f; |
||
86 | MapContext mapa=((FLyrVect)table.getModel().getAssociatedTable()).getMapContext(); |
||
87 | Rectangle2D selectedExtent = mapa.getSelectionBounds();
|
||
88 | |||
89 | if (selectedExtent != null) { |
||
90 | mapa.getViewPort().setExtent(selectedExtent); |
||
91 | 10184 | caballero | table.getModel().setModified(true);
|
92 | 9846 | caballero | } |
93 | } |
||
94 | } |
||
95 | |||
96 | /**
|
||
97 | * @see com.iver.mdiApp.plugins.IExtension#isVisible()
|
||
98 | */
|
||
99 | public boolean isVisible() { |
||
100 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
||
101 | .getActiveWindow(); |
||
102 | if (f == null) { |
||
103 | return false; |
||
104 | } |
||
105 | if (f instanceof View) { |
||
106 | MapContext mapa = ((View) f).getModel().getMapContext();
|
||
107 | return mapa.getLayers().getLayersCount() > 0; |
||
108 | }else if (f instanceof Table) { |
||
109 | Table t=(Table)f; |
||
110 | IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
||
111 | for (int i=0;i<windows.length;i++) { |
||
112 | if (windows[i] instanceof View) { |
||
113 | 10184 | caballero | if (((FLyrVect)t.getModel().getAssociatedTable())!=null) |
114 | if (((View)windows[i]).getMapControl().getMapContext().equals(((FLyrVect)t.getModel().getAssociatedTable()).getMapContext())){ |
||
115 | return true; |
||
116 | 9846 | caballero | } |
117 | } |
||
118 | } |
||
119 | } |
||
120 | |||
121 | return false; |
||
122 | } |
||
123 | |||
124 | /**
|
||
125 | * @see com.iver.andami.plugins.IExtension#isEnabled()
|
||
126 | */
|
||
127 | public boolean isEnabled() { |
||
128 | com.iver.andami.ui.mdiManager.IWindow f = PluginServices.getMDIManager() |
||
129 | .getActiveWindow(); |
||
130 | if (f == null) { |
||
131 | return false; |
||
132 | } |
||
133 | if (f instanceof View) { |
||
134 | View view = (View) f; |
||
135 | FLayer[] selected = view.getModel().getMapContext().getLayers().getActives();
|
||
136 | if (selected.length == 1 && selected[0] instanceof FLyrVect && selected[0].isAvailable()){ |
||
137 | try {
|
||
138 | if (!((FLyrVect)selected[0]).getRecordset().getSelection().isEmpty()) |
||
139 | return true; |
||
140 | } catch (DriverException e) {
|
||
141 | return false; |
||
142 | } |
||
143 | } |
||
144 | }else if (f instanceof Table) { |
||
145 | Table t=(Table)f; |
||
146 | IWindow[] windows=PluginServices.getMDIManager().getAllWindows();
|
||
147 | for (int i=0;i<windows.length;i++) { |
||
148 | if (windows[i] instanceof View) { |
||
149 | if (((View)windows[i]).getMapControl().getMapContext().equals(((FLyrVect)t.getModel().getAssociatedTable()).getMapContext())){ |
||
150 | if (!t.getModel().getModelo().getSelection().isEmpty()) {
|
||
151 | return true; |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | |||
157 | } |
||
158 | return false; |
||
159 | } |
||
160 | |||
161 | /**
|
||
162 | * @see com.iver.andami.plugins.IExtension#initialize()
|
||
163 | */
|
||
164 | public void initialize() { |
||
165 | } |
||
166 | } |