root / branches / Mobile_Compatible_Hito_1 / libFMap / src / es / prodevelop / gvsig / mobile / fmap / layer / SelectionSupport.java @ 21606
History | View | Annotate | Download (5.46 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 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 |
* *
|
43 |
* Modfied By: *
|
44 |
* Prodevelop Integraci?n de Tecnolog?as SL *
|
45 |
* Conde Salvatierra de ?lava , 34-10 *
|
46 |
* 46004 Valencia *
|
47 |
* Spain *
|
48 |
* *
|
49 |
* +34 963 510 612 *
|
50 |
* +34 963 510 968 *
|
51 |
* gis@prodevelop.es *
|
52 |
* http://www.prodevelop.es *
|
53 |
* *
|
54 |
* gvSIG Mobile Team 2006 *
|
55 |
* *
|
56 |
************************************************/
|
57 |
|
58 |
package es.prodevelop.gvsig.mobile.fmap.layer; |
59 |
|
60 |
import java.util.ArrayList; |
61 |
import java.util.Iterator; |
62 |
|
63 |
import org.apache.log4j.Logger; |
64 |
|
65 |
import es.prodevelop.gvsig.mobile.fmap.util.graph2d.FBitSet; |
66 |
|
67 |
//import es.prodevelop.gvsig.mobile.fmap.util.xml.XMLEntity;
|
68 |
|
69 |
/**
|
70 |
* Clase que gestiona las operaci?nes sobre la selecci?n.
|
71 |
*
|
72 |
* @author Vicente Caballero Navarro
|
73 |
*/
|
74 |
public class SelectionSupport { |
75 |
|
76 |
private static Logger logger = Logger.getLogger(SelectionSupport.class); |
77 |
|
78 |
private FBitSet selection = new FBitSet(); |
79 |
private ArrayList listeners = new ArrayList(); |
80 |
|
81 |
/**
|
82 |
* Inserta una nueva selecci?n.
|
83 |
*
|
84 |
* @param selection FBitSet con la selecci?n.
|
85 |
*/
|
86 |
public void setSelection(FBitSet selection) { |
87 |
this.selection = selection;
|
88 |
fireSelectionEvents(); |
89 |
} |
90 |
|
91 |
/**
|
92 |
* Devuelve un FBitSet con los ?ndices de los elementos seleccionados.
|
93 |
*
|
94 |
* @return FBitSet.
|
95 |
*/
|
96 |
public FBitSet getSelection() {
|
97 |
return selection;
|
98 |
} |
99 |
|
100 |
/**
|
101 |
* Devuelve true si el elemento est? seleccionado.
|
102 |
*
|
103 |
* @param recordIndex ?ndice del registro.
|
104 |
*
|
105 |
* @return True si est? seleccionado.
|
106 |
*/
|
107 |
public boolean isSelected(int recordIndex) { |
108 |
return selection.get(recordIndex);
|
109 |
} |
110 |
|
111 |
/**
|
112 |
* Elimina la selecci?n.
|
113 |
*/
|
114 |
public boolean clearSelection(boolean fire_event) { |
115 |
|
116 |
logger.debug("Support clearSelection - 0, fire_event = " + fire_event);
|
117 |
|
118 |
boolean resp = false; |
119 |
|
120 |
|
121 |
if (!selection.isEmpty()) {
|
122 |
|
123 |
logger.debug("Support clearSelection - 1");
|
124 |
|
125 |
selection.clear(); |
126 |
resp = true;
|
127 |
} else {
|
128 |
logger.debug("Support clearSelection - 2");
|
129 |
} |
130 |
if (resp && fire_event) fireSelectionEvents();
|
131 |
|
132 |
logger.debug("Support clearSelection - 3, resp = " + resp);
|
133 |
|
134 |
return resp;
|
135 |
} |
136 |
|
137 |
/**
|
138 |
* A?ade un SelectionListener al ArrayList de Listeners.
|
139 |
*
|
140 |
* @param listener SelectionListener a a?adir.
|
141 |
*/
|
142 |
public void addSelectionListener(SelectionListener listener) { |
143 |
if (!listeners.contains(listener))
|
144 |
listeners.add(listener); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Borra el SelectionListener que se le pasa como par?metro del ArrayList
|
149 |
* de Listener.
|
150 |
*
|
151 |
* @param listener SlectionListener a borrar.
|
152 |
*/
|
153 |
public void removeSelectionListener(SelectionListener listener) { |
154 |
listeners.remove(listener); |
155 |
} |
156 |
|
157 |
/**
|
158 |
* Cuando ocurre un evento de cambio en la selecci?n, ?ste puede ser uno de
|
159 |
* una gran cantidad de eventos. Con el fin de no propagar todos estos
|
160 |
* eventos, se realiza la propagaci?n de manera manual al final de la
|
161 |
* "r?faga" de eventos
|
162 |
*/
|
163 |
public void fireSelectionEvents() { |
164 |
for (Iterator iter = listeners.iterator(); iter.hasNext();) { |
165 |
SelectionListener listener = (SelectionListener) iter.next(); |
166 |
|
167 |
listener.selectionChanged(new SelectionEvent());
|
168 |
} |
169 |
} |
170 |
|
171 |
/**
|
172 |
* Devuelve el XMLEntity con la informaci?n necesaria para reproducir un
|
173 |
* objeto igual al actual.
|
174 |
*
|
175 |
* @return XMLEntity.
|
176 |
*//* |
177 |
public XMLEntity getXMLEntity() {
|
178 |
XMLEntity xml = new XMLEntity();
|
179 |
xml.putProperty("className",this.getClass().getName());
|
180 |
|
181 |
if (selection != null) {
|
182 |
xml.putProperty("numBitSet", selection.cardinality());
|
183 |
|
184 |
int n = 0;
|
185 |
|
186 |
for (int i = 0; i < selection.length(); i++) {
|
187 |
if (selection.get(i)) {
|
188 |
xml.putProperty(String.valueOf(n), i);
|
189 |
n++;
|
190 |
}
|
191 |
}
|
192 |
}
|
193 |
|
194 |
return xml;
|
195 |
}*/
|
196 |
|
197 |
/**
|
198 |
* A partir del XMLEntity reproduce la selecci?n.
|
199 |
*
|
200 |
* @param xml
|
201 |
*//* |
202 |
public void setXMLEntity(XMLEntity xml) {
|
203 |
int numBitSet = xml.getIntProperty("numBitSet");
|
204 |
|
205 |
if (numBitSet != 0) {
|
206 |
for (int i = 0; i < numBitSet; i++) {
|
207 |
selection.set(xml.getIntProperty(String.valueOf(i)));
|
208 |
}
|
209 |
}
|
210 |
}*/
|
211 |
|
212 |
/**
|
213 |
* A partir del XMLEntity reproduce la selecci?n.
|
214 |
*
|
215 |
* @param xml
|
216 |
*//* |
217 |
public void setXMLEntity03(XMLEntity xml) {
|
218 |
int numBitSet = xml.getIntProperty("numBitSet");
|
219 |
|
220 |
if (numBitSet != 0) {
|
221 |
for (int i = 0; i < numBitSet; i++) {
|
222 |
selection.set(xml.getIntProperty(String.valueOf(i)));
|
223 |
}
|
224 |
}
|
225 |
}*/
|
226 |
|
227 |
} |