4 using ArrayList
= System
.Collections
.ArrayList
;
6 public class InputBufferEventSupport
8 public virtual ArrayList InputBufferListeners
12 return inputBufferListeners
;
16 private object source
;
17 private ArrayList inputBufferListeners
;
18 private InputBufferEventArgs inputBufferEvent
;
19 protected internal const int CONSUME
= 0;
20 protected internal const int LA
= 1;
21 protected internal const int MARK
= 2;
22 protected internal const int REWIND
= 3;
25 public InputBufferEventSupport(object source
)
27 inputBufferEvent
= new InputBufferEventArgs();
30 public virtual void addInputBufferListener(InputBufferListener l
)
32 if (inputBufferListeners
== null)
33 inputBufferListeners
= new ArrayList();
34 inputBufferListeners
.Add(l
);
36 public virtual void fireConsume(char c
)
38 inputBufferEvent
.setValues(InputBufferEventArgs
.CONSUME
, c
, 0);
39 fireEvents(CONSUME
, inputBufferListeners
);
41 public virtual void fireEvent(int type
, Listener l
)
46 ((InputBufferListener
) l
).inputBufferConsume(source
, inputBufferEvent
); break;
49 ((InputBufferListener
) l
).inputBufferLA(source
, inputBufferEvent
); break;
52 ((InputBufferListener
) l
).inputBufferMark(source
, inputBufferEvent
); break;
55 ((InputBufferListener
) l
).inputBufferRewind(source
, inputBufferEvent
); break;
58 throw new System
.ArgumentException("bad type " + type
+ " for fireEvent()");
62 public virtual void fireEvents(int type
, ArrayList listeners
)
64 ArrayList targets
= null;
69 if (listeners
== null)
71 targets
= (ArrayList
) listeners
.Clone();
75 for (int i
= 0; i
< targets
.Count
; i
++)
77 l
= (Listener
) targets
[i
];
81 public virtual void fireLA(char c
, int la
)
83 inputBufferEvent
.setValues(InputBufferEventArgs
.LA
, c
, la
);
84 fireEvents(LA
, inputBufferListeners
);
86 public virtual void fireMark(int pos
)
88 inputBufferEvent
.setValues(InputBufferEventArgs
.MARK
, ' ', pos
);
89 fireEvents(MARK
, inputBufferListeners
);
91 public virtual void fireRewind(int pos
)
93 inputBufferEvent
.setValues(InputBufferEventArgs
.REWIND
, ' ', pos
);
94 fireEvents(REWIND
, inputBufferListeners
);
96 protected internal virtual void refresh(ArrayList listeners
)
101 v
= (ArrayList
) listeners
.Clone();
104 for (int i
= 0; i
< v
.Count
; i
++)
105 ((Listener
) v
[i
]).refresh();
107 public virtual void refreshListeners()
109 refresh(inputBufferListeners
);
111 public virtual void removeInputBufferListener(InputBufferListener l
)
113 if (inputBufferListeners
!= null)
115 ArrayList temp_arraylist
;
117 temp_arraylist
= inputBufferListeners
;
119 temp_arraylist
.Contains(temp_object
);
120 temp_arraylist
.Remove(temp_object
);