root / branches / v10 / applications / appgvSIG / src / com / iver / cit / gvsig / ViewSelectionControls.java @ 20910
History | View | Annotate | Download (6.78 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
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 |
* Av. Blasco Ib??ez, 50
|
24 |
* 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 |
*
|
44 |
* $Id: ViewSelectionControls.java 9478 2006-12-27 09:10:27Z fdiaz $
|
45 |
* $Log$
|
46 |
* Revision 1.7.4.5 2006-12-27 09:10:27 fdiaz
|
47 |
* Arreglado el metodo hasVectorLayers para que no se pare en las agrupaciones.
|
48 |
*
|
49 |
* Revision 1.7.4.4 2006/11/15 00:08:08 jjdelcerro
|
50 |
* *** empty log message ***
|
51 |
*
|
52 |
* Revision 1.13 2006/09/25 16:54:12 caballero
|
53 |
* invert selection
|
54 |
*
|
55 |
* Revision 1.12 2006/09/20 13:17:40 jaume
|
56 |
* *** empty log message ***
|
57 |
*
|
58 |
* Revision 1.11 2006/09/20 10:56:56 sbayarri
|
59 |
* Refactorizaci?n clases View y ProjectView
|
60 |
*
|
61 |
* Revision 1.10 2006/09/15 10:40:03 caballero
|
62 |
* extensibilidad de documentos
|
63 |
*
|
64 |
* Revision 1.9 2006/09/11 16:14:15 fjp
|
65 |
* Invertir seleccion. Falta subirlo al branch de la 1.0
|
66 |
*
|
67 |
* Revision 1.8 2006/09/11 06:53:13 fjp
|
68 |
* Antes del parto
|
69 |
*
|
70 |
* Revision 1.7 2006/09/04 16:26:54 fjp
|
71 |
* Seleccionar por pol?gono
|
72 |
*
|
73 |
* Revision 1.6 2006/08/29 07:56:27 cesar
|
74 |
* Rename the *View* family of classes to *Window* (ie: SingletonView to SingletonWindow, ViewInfo to WindowInfo, etc)
|
75 |
*
|
76 |
* Revision 1.5 2006/08/29 07:21:08 cesar
|
77 |
* Rename com.iver.cit.gvsig.fmap.Fmap class to com.iver.cit.gvsig.fmap.MapContext
|
78 |
*
|
79 |
* Revision 1.4 2006/08/29 07:13:53 cesar
|
80 |
* Rename class com.iver.andami.ui.mdiManager.View to com.iver.andami.ui.mdiManager.IWindow
|
81 |
*
|
82 |
* Revision 1.3 2006/08/18 08:40:04 jmvivo
|
83 |
* Actualizado para que el isEnabled tenga en cuenta que las capas esten 'avialable'
|
84 |
*
|
85 |
* Revision 1.2 2006/07/27 06:20:28 jaume
|
86 |
* *** empty log message ***
|
87 |
*
|
88 |
* Revision 1.1 2006/07/26 09:53:05 jaume
|
89 |
* separadas las herramientas de selecci?n del viewControls al ViewSelectionControls
|
90 |
*
|
91 |
*
|
92 |
*/
|
93 |
package com.iver.cit.gvsig; |
94 |
|
95 |
import org.apache.log4j.Logger; |
96 |
|
97 |
import com.iver.andami.PluginServices; |
98 |
import com.iver.andami.messages.NotificationManager; |
99 |
import com.iver.andami.plugins.Extension; |
100 |
import com.iver.andami.ui.mdiManager.IWindow; |
101 |
import com.iver.cit.gvsig.fmap.DriverException; |
102 |
import com.iver.cit.gvsig.fmap.MapContext; |
103 |
import com.iver.cit.gvsig.fmap.MapControl; |
104 |
import com.iver.cit.gvsig.fmap.layers.FBitSet; |
105 |
import com.iver.cit.gvsig.fmap.layers.FLayer; |
106 |
import com.iver.cit.gvsig.fmap.layers.FLayers; |
107 |
import com.iver.cit.gvsig.fmap.layers.FLyrVect; |
108 |
import com.iver.cit.gvsig.fmap.layers.SelectableDataSource; |
109 |
import com.iver.cit.gvsig.gui.selectionByTheme.DefaultSelectionByThemeModel; |
110 |
import com.iver.cit.gvsig.gui.selectionByTheme.MySelectionByThemeListener; |
111 |
import com.iver.cit.gvsig.gui.selectionByTheme.SelectionByTheme; |
112 |
import com.iver.cit.gvsig.project.documents.view.IProjectView; |
113 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
114 |
|
115 |
/**
|
116 |
* Extension that handles the selection tools, selection tools have sense on
|
117 |
* vectorial layers only.
|
118 |
*
|
119 |
* @author jaume dominguez faus - jaume.dominguez@iver.es
|
120 |
*
|
121 |
*/
|
122 |
public class ViewSelectionControls extends Extension { |
123 |
private static Logger logger = Logger.getLogger(ViewControls.class |
124 |
.getName()); |
125 |
|
126 |
public void initialize() { |
127 |
// TODO Auto-generated method stub
|
128 |
|
129 |
} |
130 |
|
131 |
public void execute(String actionCommand) { |
132 |
View vista = (View) PluginServices.getMDIManager().getActiveWindow(); |
133 |
IProjectView model = vista.getModel(); |
134 |
MapContext mapa = model.getMapContext(); |
135 |
MapControl mapCtrl = vista.getMapControl(); |
136 |
logger.debug("Comand : " + actionCommand);
|
137 |
if (actionCommand.equals("SELRECT")) { |
138 |
mapCtrl.setTool("rectSelection");
|
139 |
} else if (actionCommand.equals("SELPOINT")) { |
140 |
mapCtrl.setTool("pointSelection");
|
141 |
} else if (actionCommand.equals("SELPOL")) { |
142 |
mapCtrl.setTool("polSelection");
|
143 |
} else if (actionCommand.equals("SELECTIONBYSHAPE")) { |
144 |
SelectionByTheme dlg = new SelectionByTheme();
|
145 |
// FLayer[] layers = mapa.getLayers().getActives();
|
146 |
// int count = 0;
|
147 |
dlg.setModel(new DefaultSelectionByThemeModel());
|
148 |
dlg.addSelectionListener(new MySelectionByThemeListener());
|
149 |
PluginServices.getMDIManager().addWindow(dlg); |
150 |
} else if (actionCommand.equals("INVERT_SELECTION")) { |
151 |
for (int i = 0; i < mapa.getLayers().getActives().length; i++) { |
152 |
FLayer lyr = mapa.getLayers().getActives()[i]; |
153 |
if (lyr.isAvailable() && lyr instanceof FLyrVect) { |
154 |
FLyrVect lyrVect = (FLyrVect) lyr; |
155 |
SelectableDataSource sds; |
156 |
try {
|
157 |
sds = lyrVect.getRecordset(); |
158 |
FBitSet selectedRows = sds.getSelection(); |
159 |
selectedRows.flip(0, (int)sds.getRowCount()); |
160 |
sds.setSelection(selectedRows); |
161 |
} catch (DriverException e) {
|
162 |
e.printStackTrace(); |
163 |
NotificationManager.addError(e); |
164 |
} catch (com.hardcode.gdbms.engine.data.driver.DriverException e) {
|
165 |
e.printStackTrace(); |
166 |
NotificationManager.addError(e); |
167 |
} |
168 |
|
169 |
} |
170 |
} |
171 |
} |
172 |
} |
173 |
|
174 |
public boolean isEnabled() { |
175 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
176 |
if (f instanceof View) { |
177 |
|
178 |
View vista = (View) f; |
179 |
IProjectView model = vista.getModel(); |
180 |
MapContext mapa = model.getMapContext(); |
181 |
|
182 |
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 |
return true; |
186 |
} |
187 |
} |
188 |
return false; |
189 |
} |
190 |
return true; |
191 |
} |
192 |
|
193 |
public boolean isVisible() { |
194 |
IWindow f = PluginServices.getMDIManager().getActiveWindow(); |
195 |
|
196 |
if (f != null && f instanceof View) { |
197 |
View vista = (View) f; |
198 |
IProjectView model = vista.getModel(); |
199 |
MapContext mapa = model.getMapContext(); |
200 |
|
201 |
return hasVectorLayers(mapa.getLayers());
|
202 |
|
203 |
} |
204 |
return false; |
205 |
} |
206 |
|
207 |
private boolean hasVectorLayers(FLayers layers) { |
208 |
for (int i = 0; i < layers.getLayersCount(); i++) { |
209 |
FLayer lyr =layers.getLayer(i); |
210 |
if (lyr instanceof FLayers){ |
211 |
if (hasVectorLayers((FLayers) lyr)){
|
212 |
return true; |
213 |
} |
214 |
} else if (lyr instanceof FLyrVect) { |
215 |
return true; |
216 |
} |
217 |
} |
218 |
return false; |
219 |
} |
220 |
} |