root / trunk / applications / appgvSIG / src / com / iver / cit / gvsig / ViewSelectionControls.java @ 27352
History | View | Annotate | Download (7.79 KB)
1 | 14821 | jmvivo | /* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 6513 | jaume | *
|
3 | * Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
||
4 | *
|
||
5 | * This program is free software; you can redistribute it and/or
|
||
6 | * modify it under the terms of the GNU General Public License
|
||
7 | * as published by the Free Software Foundation; either version 2
|
||
8 | * of the License, or (at your option) any later version.
|
||
9 | *
|
||
10 | * This program is distributed in the hope that it will be useful,
|
||
11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
13 | * GNU General Public License for more details.
|
||
14 | *
|
||
15 | * You should have received a copy of the GNU General Public License
|
||
16 | * along with this program; if not, write to the Free Software
|
||
17 | * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
||
18 | *
|
||
19 | * For more information, contact:
|
||
20 | *
|
||
21 | * Generalitat Valenciana
|
||
22 | * Conselleria d'Infraestructures i Transport
|
||
23 | 14821 | jmvivo | * Av. Blasco Ib��ez, 50
|
24 | 6513 | jaume | * 46010 VALENCIA
|
25 | * SPAIN
|
||
26 | *
|
||
27 | * +34 963862235
|
||
28 | * gvsig@gva.es
|
||
29 | * www.gvsig.gva.es
|
||
30 | *
|
||
31 | * or
|
||
32 | *
|
||
33 | * IVER T.I. S.A
|
||
34 | * Salamanca 50
|
||
35 | * 46005 Valencia
|
||
36 | * Spain
|
||
37 | *
|
||
38 | * +34 963163400
|
||
39 | * dac@iver.es
|
||
40 | */
|
||
41 | |||
42 | /* CVS MESSAGES:
|
||
43 | 7163 | fjp | *
|
44 | * $Id$
|
||
45 | * $Log$
|
||
46 | 10626 | caballero | * Revision 1.16 2007-03-06 16:34:02 caballero
|
47 | * Exceptions
|
||
48 | *
|
||
49 | * Revision 1.15 2007/01/04 07:24:32 caballero
|
||
50 | 9532 | caballero | * isModified
|
51 | *
|
||
52 | * Revision 1.14 2006/12/27 11:08:56 fdiaz
|
||
53 | 9483 | fdiaz | * Arreglado el metodo hasVectorLayers para que no se pare en los grupos de capas cuando estos no tienen capas vectoriales.
|
54 | *
|
||
55 | * Revision 1.13 2006/09/25 16:54:12 caballero
|
||
56 | 7572 | caballero | * invert selection
|
57 | *
|
||
58 | * Revision 1.12 2006/09/20 13:17:40 jaume
|
||
59 | 7407 | jaume | * *** empty log message ***
|
60 | *
|
||
61 | * Revision 1.11 2006/09/20 10:56:56 sbayarri
|
||
62 | 14821 | jmvivo | * Refactorizaci�n clases View y ProjectView
|
63 | 7392 | sbayarri | *
|
64 | * Revision 1.10 2006/09/15 10:40:03 caballero
|
||
65 | 7304 | caballero | * extensibilidad de documentos
|
66 | *
|
||
67 | * Revision 1.9 2006/09/11 16:14:15 fjp
|
||
68 | 7190 | fjp | * Invertir seleccion. Falta subirlo al branch de la 1.0
|
69 | *
|
||
70 | * Revision 1.8 2006/09/11 06:53:13 fjp
|
||
71 | 7163 | fjp | * Antes del parto
|
72 | *
|
||
73 | * Revision 1.7 2006/09/04 16:26:54 fjp
|
||
74 | 14821 | jmvivo | * Seleccionar por pol�gono
|
75 | 7163 | fjp | *
|
76 | * Revision 1.6 2006/08/29 07:56:27 cesar
|
||
77 | * Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
||
78 | *
|
||
79 | * Revision 1.5 2006/08/29 07:21:08 cesar
|
||
80 | * Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
||
81 | *
|
||
82 | * Revision 1.4 2006/08/29 07:13:53 cesar
|
||
83 | * Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
||
84 | *
|
||
85 | * Revision 1.3 2006/08/18 08:40:04 jmvivo
|
||
86 | * Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
|
||
87 | *
|
||
88 | * Revision 1.2 2006/07/27 06:20:28 jaume
|
||
89 | * *** empty log message ***
|
||
90 | *
|
||
91 | * Revision 1.1 2006/07/26 09:53:05 jaume
|
||
92 | 14821 | jmvivo | * separadas las herramientas de selecci�n del viewControls al ViewSelectionControls
|
93 | 7163 | fjp | *
|
94 | *
|
||
95 | */
|
||
96 | 6513 | jaume | package com.iver.cit.gvsig; |
97 | |||
98 | import org.apache.log4j.Logger; |
||
99 | |||
100 | 10626 | caballero | import com.hardcode.gdbms.driver.exceptions.ReadDriverException; |
101 | 6513 | jaume | import com.iver.andami.PluginServices; |
102 | 7163 | fjp | import com.iver.andami.messages.NotificationManager; |
103 | 6513 | jaume | import com.iver.andami.plugins.Extension; |
104 | 7407 | jaume | import com.iver.andami.ui.mdiManager.IWindow; |
105 | 6878 | cesar | import com.iver.cit.gvsig.fmap.MapContext; |
106 | 6513 | jaume | import com.iver.cit.gvsig.fmap.MapControl; |
107 | 7163 | fjp | import com.iver.cit.gvsig.fmap.layers.FBitSet; |
108 | 6513 | jaume | import com.iver.cit.gvsig.fmap.layers.FLayer; |
109 | 7163 | fjp | import com.iver.cit.gvsig.fmap.layers.FLayers; |
110 | 6513 | jaume | import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
111 | 7163 | fjp | import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
112 | 6513 | jaume | import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel; |
113 | import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener; |
||
114 | import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme; |
||
115 | 9532 | caballero | import com.iver.cit.gvsig.project.documents.ProjectDocument; |
116 | 7392 | sbayarri | import com.iver.cit.gvsig.project.documents.view.IProjectView; |
117 | 7304 | caballero | import com.iver.cit.gvsig.project.documents.view.gui.View; |
118 | 6513 | jaume | |
119 | /**
|
||
120 | 7163 | fjp | * Extension that handles the selection tools, selection tools have sense on
|
121 | * vectorial layers only.
|
||
122 | 7407 | jaume | *
|
123 | 6513 | jaume | * @author jaume dominguez faus - jaume.dominguez@iver.es
|
124 | 7407 | jaume | *
|
125 | 6513 | jaume | */
|
126 | public class ViewSelectionControls extends Extension { |
||
127 | 7163 | fjp | private static Logger logger = Logger.getLogger(ViewControls.class |
128 | .getName()); |
||
129 | 6513 | jaume | |
130 | public void initialize() { |
||
131 | // TODO Auto-generated method stub
|
||
132 | 14821 | jmvivo | registerIcons(); |
133 | } |
||
134 | 6513 | jaume | |
135 | 14821 | jmvivo | private void registerIcons(){ |
136 | |||
137 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
138 | 14821 | jmvivo | "view-select-geometry",
|
139 | this.getClass().getClassLoader().getResource("images/Select.png") |
||
140 | ); |
||
141 | |||
142 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
143 | 14821 | jmvivo | "view-select-by-rectangle",
|
144 | this.getClass().getClassLoader().getResource("images/SelEspacial2b.png") |
||
145 | ); |
||
146 | |||
147 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
148 | 14821 | jmvivo | "view-select-by-polygon",
|
149 | this.getClass().getClassLoader().getResource("images/SelectByPolygon.png") |
||
150 | ); |
||
151 | |||
152 | 15647 | jmvivo | PluginServices.getIconTheme().registerDefault( |
153 | 14821 | jmvivo | "view-select-invert",
|
154 | this.getClass().getClassLoader().getResource("images/invertSelection.png") |
||
155 | ); |
||
156 | 6513 | jaume | } |
157 | |||
158 | public void execute(String actionCommand) { |
||
159 | 6880 | cesar | View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
160 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
161 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
162 | 6513 | jaume | MapControl mapCtrl = vista.getMapControl(); |
163 | logger.debug("Comand : " + actionCommand);
|
||
164 | 7163 | fjp | if (actionCommand.equals("SELRECT")) { |
165 | 6513 | jaume | mapCtrl.setTool("rectSelection");
|
166 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
167 | 7163 | fjp | } else if (actionCommand.equals("SELPOINT")) { |
168 | 6513 | jaume | mapCtrl.setTool("pointSelection");
|
169 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
170 | 7163 | fjp | } else if (actionCommand.equals("SELPOL")) { |
171 | 7011 | fjp | mapCtrl.setTool("polSelection");
|
172 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
173 | 7163 | fjp | } else if (actionCommand.equals("SELECTIONBYSHAPE")) { |
174 | 6513 | jaume | SelectionByTheme dlg = new SelectionByTheme();
|
175 | 7163 | fjp | // FLayer[] layers = mapa.getLayers().getActives();
|
176 | // int count = 0;
|
||
177 | 6513 | jaume | dlg.setModel(new DefaultSelectionByThemeModel());
|
178 | dlg.addSelectionListener(new MySelectionByThemeListener());
|
||
179 | 6880 | cesar | PluginServices.getMDIManager().addWindow(dlg); |
180 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
181 | 7190 | fjp | } else if (actionCommand.equals("INVERT_SELECTION")) { |
182 | 7163 | fjp | for (int i = 0; i < mapa.getLayers().getActives().length; i++) { |
183 | FLayer lyr = mapa.getLayers().getActives()[i]; |
||
184 | if (lyr.isAvailable() && lyr instanceof FLyrVect) { |
||
185 | FLyrVect lyrVect = (FLyrVect) lyr; |
||
186 | SelectableDataSource sds; |
||
187 | try {
|
||
188 | sds = lyrVect.getRecordset(); |
||
189 | FBitSet selectedRows = sds.getSelection(); |
||
190 | 7572 | caballero | selectedRows.flip(0, (int)sds.getRowCount()); |
191 | 7163 | fjp | sds.setSelection(selectedRows); |
192 | 10626 | caballero | } catch (ReadDriverException e) {
|
193 | 7163 | fjp | e.printStackTrace(); |
194 | NotificationManager.addError(e); |
||
195 | } |
||
196 | |||
197 | } |
||
198 | } |
||
199 | 9532 | caballero | ((ProjectDocument)vista.getModel()).setModified(true);
|
200 | 6513 | jaume | } |
201 | } |
||
202 | |||
203 | public boolean isEnabled() { |
||
204 | 7407 | jaume | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
205 | 6513 | jaume | if (f instanceof View) { |
206 | |||
207 | View vista = (View) f; |
||
208 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
209 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
210 | 6513 | jaume | |
211 | for (int i = 0; i < mapa.getLayers().getActives().length; i++) { |
||
212 | FLayer lyr = mapa.getLayers().getActives()[i]; |
||
213 | 6779 | jmvivo | if (lyr.isAvailable() && lyr instanceof FLyrVect) { |
214 | 6513 | jaume | return true; |
215 | } |
||
216 | } |
||
217 | return false; |
||
218 | } |
||
219 | return true; |
||
220 | } |
||
221 | |||
222 | public boolean isVisible() { |
||
223 | 7407 | jaume | IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
224 | 6513 | jaume | |
225 | 6533 | jaume | if (f != null && f instanceof View) { |
226 | 6513 | jaume | View vista = (View) f; |
227 | 7392 | sbayarri | IProjectView model = vista.getModel(); |
228 | 6878 | cesar | MapContext mapa = model.getMapContext(); |
229 | 6513 | jaume | |
230 | 7407 | jaume | return hasVectorLayers(mapa.getLayers());
|
231 | |||
232 | } |
||
233 | return false; |
||
234 | } |
||
235 | |||
236 | private boolean hasVectorLayers(FLayers layers) { |
||
237 | for (int i = 0; i < layers.getLayersCount(); i++) { |
||
238 | FLayer lyr =layers.getLayer(i); |
||
239 | 9483 | fdiaz | if (lyr instanceof FLayers){ |
240 | if (hasVectorLayers((FLayers) lyr)){
|
||
241 | return true; |
||
242 | } |
||
243 | } else if (lyr instanceof FLyrVect) { |
||
244 | 7407 | jaume | return true; |
245 | 6513 | jaume | } |
246 | } |
||
247 | 6533 | jaume | return false; |
248 | 6513 | jaume | } |
249 | 6533 | jaume | } |