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 | 1100 | fjp | /* 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 | 679 | fernando | 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 | 727 | fernando | import com.iver.cit.gvsig.fmap.layers.LayerEvent; |
47 | import com.iver.cit.gvsig.fmap.layers.LayerListener; |
||
48 | 679 | fernando | 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 | 1034 | vcaballero | * Evento sobre el buffer.
|
60 | 679 | fernando | *
|
61 | * @author Fernando Gonz?lez Cort?s
|
||
62 | */
|
||
63 | public class EventBuffer implements LegendListener, LayerCollectionListener, |
||
64 | 956 | vcaballero | SelectionListener, ViewPortListener, LayerListener { |
65 | 679 | fernando | private ArrayList events = new ArrayList(); |
66 | private ArrayList listeners = new ArrayList(); |
||
67 | private boolean dispatching = true; |
||
68 | |||
69 | /**
|
||
70 | 956 | vcaballero | * 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 | 679 | fernando | */
|
75 | public void beginAtomicEvent() { |
||
76 | dispatching = false;
|
||
77 | } |
||
78 | |||
79 | /**
|
||
80 | 956 | vcaballero | * Termina la acumulaci?n de eventos y notifica a los l?steners.
|
81 | 679 | fernando | */
|
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 | 956 | vcaballero | |
94 | if (dispatching) {
|
||
95 | fireAtomicEventListener(); |
||
96 | } |
||
97 | 679 | fernando | } |
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 | 956 | vcaballero | |
105 | if (dispatching) {
|
||
106 | fireAtomicEventListener(); |
||
107 | } |
||
108 | 679 | fernando | } |
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 | 956 | vcaballero | |
116 | if (dispatching) {
|
||
117 | fireAtomicEventListener(); |
||
118 | } |
||
119 | 679 | fernando | } |
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 | 956 | vcaballero | |
127 | if (dispatching) {
|
||
128 | fireAtomicEventListener(); |
||
129 | } |
||
130 | 679 | fernando | } |
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 | 956 | vcaballero | |
138 | if (dispatching) {
|
||
139 | fireAtomicEventListener(); |
||
140 | } |
||
141 | 679 | fernando | } |
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 | 956 | vcaballero | |
149 | if (dispatching) {
|
||
150 | fireAtomicEventListener(); |
||
151 | } |
||
152 | 679 | fernando | } |
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 | 956 | vcaballero | |
161 | if (dispatching) {
|
||
162 | fireAtomicEventListener(); |
||
163 | } |
||
164 | 679 | fernando | } |
165 | |||
166 | 956 | vcaballero | |
167 | 679 | fernando | /**
|
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 | 956 | vcaballero | |
174 | if (dispatching) {
|
||
175 | fireAtomicEventListener(); |
||
176 | } |
||
177 | 679 | fernando | } |
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 | 956 | vcaballero | |
185 | if (dispatching) {
|
||
186 | fireAtomicEventListener(); |
||
187 | } |
||
188 | 679 | fernando | } |
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 | 956 | vcaballero | |
196 | if (dispatching) {
|
||
197 | fireAtomicEventListener(); |
||
198 | } |
||
199 | 679 | fernando | } |
200 | |||
201 | /**
|
||
202 | 1034 | vcaballero | * A?ade un AtomicEventListener a la lista de listener.
|
203 | 679 | fernando | *
|
204 | 1034 | vcaballero | * @param listener AtomicEventListener.
|
205 | 679 | fernando | *
|
206 | 1034 | vcaballero | * @return True si ha sido a?adido correctamente.
|
207 | 679 | fernando | */
|
208 | public boolean addAtomicEventListener(AtomicEventListener listener) { |
||
209 | 4147 | fjp | 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 | 679 | fernando | } |
217 | |||
218 | /**
|
||
219 | 1034 | vcaballero | * Borra el AtomicEventListener de la lista de listeners.
|
220 | 679 | fernando | *
|
221 | 1034 | vcaballero | * @param listener AtomicEventListener.
|
222 | 679 | fernando | *
|
223 | 1034 | vcaballero | * @return True si ha sido borrado correctamente.
|
224 | 679 | fernando | */
|
225 | public boolean removeAtomicEventListener(AtomicEventListener listener) { |
||
226 | return listeners.remove(listener);
|
||
227 | } |
||
228 | |||
229 | /**
|
||
230 | 1034 | vcaballero | * Ejecuta el m?todo atomicEvent de todos los listeners.
|
231 | 679 | fernando | */
|
232 | private void fireAtomicEventListener() { |
||
233 | 4147 | fjp | if (events.size() == 0) |
234 | return; // No hay eventos que lanzar. |
||
235 | 679 | fernando | 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 | 956 | vcaballero | |
241 | 679 | fernando | events.clear(); |
242 | } |
||
243 | 727 | fernando | |
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 | 956 | vcaballero | |
250 | if (dispatching) {
|
||
251 | fireAtomicEventListener(); |
||
252 | } |
||
253 | 727 | fernando | } |
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 | 956 | vcaballero | |
261 | if (dispatching) {
|
||
262 | fireAtomicEventListener(); |
||
263 | } |
||
264 | 727 | fernando | } |
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 | 956 | vcaballero | |
272 | if (dispatching) {
|
||
273 | fireAtomicEventListener(); |
||
274 | } |
||
275 | 727 | fernando | } |
276 | 956 | vcaballero | |
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 | 979 | fernando | fireAtomicEventListener(); |
285 | 956 | vcaballero | } |
286 | } |
||
287 | 4144 | fjp | |
288 | public void editionChanged(LayerEvent e) { |
||
289 | events.add(e); |
||
290 | |||
291 | if (dispatching) {
|
||
292 | fireAtomicEventListener(); |
||
293 | } |
||
294 | |||
295 | } |
||
296 | 5939 | jmvivo | |
297 | public void projectionChanged(ProjectionEvent e) { |
||
298 | events.add(e); |
||
299 | |||
300 | if (dispatching) {
|
||
301 | fireAtomicEventListener(); |
||
302 | } |
||
303 | } |
||
304 | 679 | fernando | } |