1 package prefuse.data.expression; 2 3 import prefuse.data.Tuple; 4 import prefuse.data.event.ExpressionListener; 5 import prefuse.util.collections.CopyOnWriteArrayList; 6 7 14 public abstract class AbstractExpression 15 implements Expression, ExpressionListener 16 { 17 private CopyOnWriteArrayList m_listeners = new CopyOnWriteArrayList(); 18 19 22 public void visit(ExpressionVisitor v) { 23 v.visitExpression(this); 24 } 25 26 29 public final void addExpressionListener(ExpressionListener lstnr) { 30 if ( !m_listeners.contains(lstnr) ) { 31 m_listeners.add(lstnr); 32 addChildListeners(); 33 } 34 } 35 36 39 public final void removeExpressionListener(ExpressionListener lstnr) { 40 m_listeners.remove(lstnr); 41 if ( m_listeners.size() == 0 ) 42 removeChildListeners(); 43 } 44 45 49 protected final boolean hasListeners() { 50 return m_listeners != null && m_listeners.size() > 0; 51 } 52 53 56 protected final void fireExpressionChange() { 57 Object [] lstnrs = m_listeners.getArray(); 58 for ( int i=0; i<lstnrs.length; ++i ) { 59 ((ExpressionListener)lstnrs[i]).expressionChanged(this); 60 } 61 } 62 63 66 protected void addChildListeners() { 67 } 69 70 73 protected void removeChildListeners() { 74 } 76 77 81 public void expressionChanged(Expression expr) { 82 fireExpressionChange(); 83 } 84 85 88 92 public Object get(Tuple t) { 93 throw new UnsupportedOperationException (); 94 } 95 96 100 public int getInt(Tuple t) { 101 throw new UnsupportedOperationException (); 102 } 103 104 108 public long getLong(Tuple t) { 109 throw new UnsupportedOperationException (); 110 } 111 112 116 public float getFloat(Tuple t) { 117 throw new UnsupportedOperationException (); 118 } 119 120 124 public double getDouble(Tuple t) { 125 throw new UnsupportedOperationException (); 126 } 127 128 132 public boolean getBoolean(Tuple t) { 133 throw new UnsupportedOperationException (); 134 } 135 136 } | Popular Tags |