01: package prefuse.data.util;
02:
03: import prefuse.data.event.ProjectionListener;
04: import prefuse.util.collections.CopyOnWriteArrayList;
05:
06: /**
07: * Abstract base class for column projection instances. Implements the
08: * listener functionality.
09: *
10: * @author <a href="http://jheer.org">jeffrey heer</a>
11: */
12: public abstract class AbstractColumnProjection implements
13: ColumnProjection {
14:
15: // ------------------------------------------------------------------------
16: // Listener Methods
17:
18: private CopyOnWriteArrayList m_listeners;
19:
20: /**
21: * @see prefuse.data.util.ColumnProjection#addProjectionListener(prefuse.data.event.ProjectionListener)
22: */
23: public void addProjectionListener(ProjectionListener lstnr) {
24: if (m_listeners == null)
25: m_listeners = new CopyOnWriteArrayList();
26: if (!m_listeners.contains(lstnr))
27: m_listeners.add(lstnr);
28: }
29:
30: /**
31: * @see prefuse.data.util.ColumnProjection#removeProjectionListener(prefuse.data.event.ProjectionListener)
32: */
33: public void removeProjectionListener(ProjectionListener lstnr) {
34: if (m_listeners != null)
35: m_listeners.remove(lstnr);
36: if (m_listeners.size() == 0)
37: m_listeners = null;
38: }
39:
40: public void fireUpdate() {
41: if (m_listeners == null)
42: return;
43: Object[] lstnrs = m_listeners.getArray();
44: for (int i = 0; i < lstnrs.length; ++i) {
45: ((ProjectionListener) lstnrs[i]).projectionChanged(this );
46: }
47: }
48:
49: } // end of abstract class AbstractColumnProjection
|