root / tags / v1_1_Build_914 / libraries / libFMap / src / com / iver / cit / gvsig / fmap / EventBuffer.java @ 11873
History | View | Annotate | Download (7.6 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 |
package com.iver.cit.gvsig.fmap; |
42 |
|
43 |
import com.iver.cit.gvsig.fmap.layers.CancelationException; |
44 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent; |
45 |
import com.iver.cit.gvsig.fmap.layers.LayerCollectionListener; |
46 |
import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
47 |
import com.iver.cit.gvsig.fmap.layers.LayerListener; |
48 |
import com.iver.cit.gvsig.fmap.layers.LayerPositionEvent; |
49 |
import com.iver.cit.gvsig.fmap.layers.LegendListener; |
50 |
import com.iver.cit.gvsig.fmap.layers.SelectionEvent; |
51 |
import com.iver.cit.gvsig.fmap.layers.SelectionListener; |
52 |
import com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent; |
53 |
|
54 |
import java.util.ArrayList; |
55 |
import java.util.Iterator; |
56 |
|
57 |
|
58 |
/**
|
59 |
* Evento sobre el buffer.
|
60 |
*
|
61 |
* @author Fernando Gonz?lez Cort?s
|
62 |
*/
|
63 |
public class EventBuffer implements LegendListener, LayerCollectionListener, |
64 |
SelectionListener, ViewPortListener, LayerListener { |
65 |
private ArrayList events = new ArrayList(); |
66 |
private ArrayList listeners = new ArrayList(); |
67 |
private boolean dispatching = true; |
68 |
|
69 |
/**
|
70 |
* Pone el buffer en modo acumulaci?n de eventos. Los eventos que se
|
71 |
* reciban a partir de una llamada a este m?todo ser?n acumulados y no
|
72 |
* ser?n notificados a los listeners hasta que no se reciba una llamada a
|
73 |
* endAtomicEvent
|
74 |
*/
|
75 |
public void beginAtomicEvent() { |
76 |
dispatching = false;
|
77 |
} |
78 |
|
79 |
/**
|
80 |
* Termina la acumulaci?n de eventos y notifica a los l?steners.
|
81 |
*/
|
82 |
public void endAtomicEvent() { |
83 |
fireAtomicEventListener(); |
84 |
events.clear(); |
85 |
dispatching = true;
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* @see com.iver.cit.gvsig.fmap.layers.LegendListener#legendChanged(com.iver.cit.gvsig.fmap.rendering.LegendChangedEvent)
|
90 |
*/
|
91 |
public void legendChanged(LegendChangedEvent e) { |
92 |
events.add(e); |
93 |
|
94 |
if (dispatching) {
|
95 |
fireAtomicEventListener(); |
96 |
} |
97 |
} |
98 |
|
99 |
/**
|
100 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdded(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
101 |
*/
|
102 |
public void layerAdded(LayerCollectionEvent e) { |
103 |
events.add(e); |
104 |
|
105 |
if (dispatching) {
|
106 |
fireAtomicEventListener(); |
107 |
} |
108 |
} |
109 |
|
110 |
/**
|
111 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoved(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
112 |
*/
|
113 |
public void layerMoved(LayerPositionEvent e) { |
114 |
events.add(e); |
115 |
|
116 |
if (dispatching) {
|
117 |
fireAtomicEventListener(); |
118 |
} |
119 |
} |
120 |
|
121 |
/**
|
122 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoved(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
123 |
*/
|
124 |
public void layerRemoved(LayerCollectionEvent e) { |
125 |
events.add(e); |
126 |
|
127 |
if (dispatching) {
|
128 |
fireAtomicEventListener(); |
129 |
} |
130 |
} |
131 |
|
132 |
/**
|
133 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerAdding(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
134 |
*/
|
135 |
public void layerAdding(LayerCollectionEvent e) throws CancelationException { |
136 |
events.add(e); |
137 |
|
138 |
if (dispatching) {
|
139 |
fireAtomicEventListener(); |
140 |
} |
141 |
} |
142 |
|
143 |
/**
|
144 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerMoving(com.iver.cit.gvsig.fmap.layers.LayerPositionEvent)
|
145 |
*/
|
146 |
public void layerMoving(LayerPositionEvent e) throws CancelationException { |
147 |
events.add(e); |
148 |
|
149 |
if (dispatching) {
|
150 |
fireAtomicEventListener(); |
151 |
} |
152 |
} |
153 |
|
154 |
/**
|
155 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#layerRemoving(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
156 |
*/
|
157 |
public void layerRemoving(LayerCollectionEvent e) |
158 |
throws CancelationException {
|
159 |
events.add(e); |
160 |
|
161 |
if (dispatching) {
|
162 |
fireAtomicEventListener(); |
163 |
} |
164 |
} |
165 |
|
166 |
|
167 |
/**
|
168 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
169 |
*/
|
170 |
public void visibilityChanged(LayerCollectionEvent e) |
171 |
throws CancelationException {
|
172 |
events.add(e); |
173 |
|
174 |
if (dispatching) {
|
175 |
fireAtomicEventListener(); |
176 |
} |
177 |
} |
178 |
|
179 |
/**
|
180 |
* @see com.iver.cit.gvsig.fmap.layers.SelectionListener#selectionChanged(com.iver.cit.gvsig.fmap.layers.SelectionEvent)
|
181 |
*/
|
182 |
public void selectionChanged(SelectionEvent e) { |
183 |
events.add(e); |
184 |
|
185 |
if (dispatching) {
|
186 |
fireAtomicEventListener(); |
187 |
} |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
192 |
*/
|
193 |
public void extentChanged(ExtentEvent e) { |
194 |
events.add(e); |
195 |
|
196 |
if (dispatching) {
|
197 |
fireAtomicEventListener(); |
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* A?ade un AtomicEventListener a la lista de listener.
|
203 |
*
|
204 |
* @param listener AtomicEventListener.
|
205 |
*
|
206 |
* @return True si ha sido a?adido correctamente.
|
207 |
*/
|
208 |
public boolean addAtomicEventListener(AtomicEventListener listener) { |
209 |
boolean bFound = false; |
210 |
for (int i=0; i < listeners.size(); i++) |
211 |
if (listeners.get(i) == listener)
|
212 |
bFound = true;
|
213 |
if (!bFound)
|
214 |
listeners.add(listener); |
215 |
return true; |
216 |
} |
217 |
|
218 |
/**
|
219 |
* Borra el AtomicEventListener de la lista de listeners.
|
220 |
*
|
221 |
* @param listener AtomicEventListener.
|
222 |
*
|
223 |
* @return True si ha sido borrado correctamente.
|
224 |
*/
|
225 |
public boolean removeAtomicEventListener(AtomicEventListener listener) { |
226 |
return listeners.remove(listener);
|
227 |
} |
228 |
|
229 |
/**
|
230 |
* Ejecuta el m?todo atomicEvent de todos los listeners.
|
231 |
*/
|
232 |
private void fireAtomicEventListener() { |
233 |
if (events.size() == 0) |
234 |
return; // No hay eventos que lanzar. |
235 |
for (Iterator i = listeners.iterator(); i.hasNext();) { |
236 |
AtomicEventListener listener = (AtomicEventListener) i.next(); |
237 |
AtomicEvent e = new AtomicEvent(events);
|
238 |
listener.atomicEvent(e); |
239 |
} |
240 |
|
241 |
events.clear(); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
246 |
*/
|
247 |
public void visibilityChanged(LayerEvent e) { |
248 |
events.add(e); |
249 |
|
250 |
if (dispatching) {
|
251 |
fireAtomicEventListener(); |
252 |
} |
253 |
} |
254 |
|
255 |
/**
|
256 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
257 |
*/
|
258 |
public void activationChanged(LayerEvent e) { |
259 |
events.add(e); |
260 |
|
261 |
if (dispatching) {
|
262 |
fireAtomicEventListener(); |
263 |
} |
264 |
} |
265 |
|
266 |
/**
|
267 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#nameChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
268 |
*/
|
269 |
public void nameChanged(LayerEvent e) { |
270 |
events.add(e); |
271 |
|
272 |
if (dispatching) {
|
273 |
fireAtomicEventListener(); |
274 |
} |
275 |
} |
276 |
|
277 |
/**
|
278 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
279 |
*/
|
280 |
public void backColorChanged(ColorEvent e) { |
281 |
events.add(e); |
282 |
|
283 |
if (dispatching) {
|
284 |
fireAtomicEventListener(); |
285 |
} |
286 |
} |
287 |
|
288 |
public void editionChanged(LayerEvent e) { |
289 |
events.add(e); |
290 |
|
291 |
if (dispatching) {
|
292 |
fireAtomicEventListener(); |
293 |
} |
294 |
|
295 |
} |
296 |
|
297 |
public void projectionChanged(ProjectionEvent e) { |
298 |
events.add(e); |
299 |
|
300 |
if (dispatching) {
|
301 |
fireAtomicEventListener(); |
302 |
} |
303 |
} |
304 |
} |