root / trunk / libraries / libFMap / src / com / iver / cit / gvsig / fmap / EventBuffer.java @ 3217
History | View | Annotate | Download (7.44 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 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
168 |
*/
|
169 |
public void activationChanged(LayerCollectionEvent e) |
170 |
throws CancelationException {
|
171 |
events.add(e); |
172 |
|
173 |
if (dispatching) {
|
174 |
fireAtomicEventListener(); |
175 |
} |
176 |
} |
177 |
|
178 |
/**
|
179 |
* @see com.iver.cit.gvsig.fmap.layers.LayerCollectionListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerCollectionEvent)
|
180 |
*/
|
181 |
public void visibilityChanged(LayerCollectionEvent e) |
182 |
throws CancelationException {
|
183 |
events.add(e); |
184 |
|
185 |
if (dispatching) {
|
186 |
fireAtomicEventListener(); |
187 |
} |
188 |
} |
189 |
|
190 |
/**
|
191 |
* @see com.iver.cit.gvsig.fmap.layers.SelectionListener#selectionChanged(com.iver.cit.gvsig.fmap.layers.SelectionEvent)
|
192 |
*/
|
193 |
public void selectionChanged(SelectionEvent e) { |
194 |
events.add(e); |
195 |
|
196 |
if (dispatching) {
|
197 |
fireAtomicEventListener(); |
198 |
} |
199 |
} |
200 |
|
201 |
/**
|
202 |
* @see com.iver.cit.gvsig.fmap.ExtentListener#extentChanged(com.iver.cit.gvsig.fmap.ExtentEvent)
|
203 |
*/
|
204 |
public void extentChanged(ExtentEvent e) { |
205 |
events.add(e); |
206 |
|
207 |
if (dispatching) {
|
208 |
fireAtomicEventListener(); |
209 |
} |
210 |
} |
211 |
|
212 |
/**
|
213 |
* A?ade un AtomicEventListener a la lista de listener.
|
214 |
*
|
215 |
* @param listener AtomicEventListener.
|
216 |
*
|
217 |
* @return True si ha sido a?adido correctamente.
|
218 |
*/
|
219 |
public boolean addAtomicEventListener(AtomicEventListener listener) { |
220 |
return listeners.add(listener);
|
221 |
} |
222 |
|
223 |
/**
|
224 |
* Borra el AtomicEventListener de la lista de listeners.
|
225 |
*
|
226 |
* @param listener AtomicEventListener.
|
227 |
*
|
228 |
* @return True si ha sido borrado correctamente.
|
229 |
*/
|
230 |
public boolean removeAtomicEventListener(AtomicEventListener listener) { |
231 |
return listeners.remove(listener);
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* Ejecuta el m?todo atomicEvent de todos los listeners.
|
236 |
*/
|
237 |
private void fireAtomicEventListener() { |
238 |
for (Iterator i = listeners.iterator(); i.hasNext();) { |
239 |
AtomicEventListener listener = (AtomicEventListener) i.next(); |
240 |
AtomicEvent e = new AtomicEvent(events);
|
241 |
listener.atomicEvent(e); |
242 |
} |
243 |
|
244 |
events.clear(); |
245 |
} |
246 |
|
247 |
/**
|
248 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#visibilityChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
249 |
*/
|
250 |
public void visibilityChanged(LayerEvent e) { |
251 |
events.add(e); |
252 |
|
253 |
if (dispatching) {
|
254 |
fireAtomicEventListener(); |
255 |
} |
256 |
} |
257 |
|
258 |
/**
|
259 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#activationChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
260 |
*/
|
261 |
public void activationChanged(LayerEvent e) { |
262 |
events.add(e); |
263 |
|
264 |
if (dispatching) {
|
265 |
fireAtomicEventListener(); |
266 |
} |
267 |
} |
268 |
|
269 |
/**
|
270 |
* @see com.iver.cit.gvsig.fmap.layers.LayerListener#nameChanged(com.iver.cit.gvsig.fmap.layers.LayerEvent)
|
271 |
*/
|
272 |
public void nameChanged(LayerEvent e) { |
273 |
events.add(e); |
274 |
|
275 |
if (dispatching) {
|
276 |
fireAtomicEventListener(); |
277 |
} |
278 |
} |
279 |
|
280 |
/**
|
281 |
* @see com.iver.cit.gvsig.fmap.ViewPortListener#backColorChanged(com.iver.cit.gvsig.fmap.ColorEvent)
|
282 |
*/
|
283 |
public void backColorChanged(ColorEvent e) { |
284 |
events.add(e); |
285 |
|
286 |
if (dispatching) {
|
287 |
fireAtomicEventListener(); |
288 |
} |
289 |
} |
290 |
} |