1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package net.sf.jameleon.event;
20
21 import net.sf.jameleon.function.FunctionTag;
22
23 import java.util.Collections;
24 import java.util.Iterator;
25 import java.util.LinkedList;
26 import java.util.List;
27
28 public class FunctionEventHandler{
29
30 private static FunctionEventHandler eventHandler;
31 private final List functionListeners = Collections.synchronizedList(new LinkedList());;
32
33 private FunctionEventHandler(){}
34
35 public static FunctionEventHandler getInstance(){
36 if (eventHandler == null) {
37 eventHandler = new FunctionEventHandler();
38 }
39 return eventHandler;
40 }
41
42 public void clearInstance(){
43 eventHandler = null;
44 }
45
46 public void addFunctionListener(FunctionListener fl){
47 if (fl != null && !functionListeners.contains(fl)){
48 functionListeners.add(fl);
49 }
50 }
51
52 public List getFunctionListeners(){
53 return functionListeners;
54 }
55
56 public void removeFunctionListener(FunctionListener fl){
57 functionListeners.remove(fl);
58 }
59
60 public void beginFunction(FunctionTag ft, int rowNum){
61 FunctionEvent fe = new FunctionEvent(ft);
62 synchronized(functionListeners){
63 Iterator it = functionListeners.iterator();
64 FunctionListener fl;
65 while (it.hasNext()) {
66 fl = (FunctionListener)it.next();
67 fl.beginFunction(fe, rowNum);
68 }
69 }
70 }
71
72 public void endFunction(FunctionTag ft, int rowNum){
73 FunctionEvent fe = new FunctionEvent(ft);
74 synchronized(functionListeners){
75 Iterator it = functionListeners.iterator();
76 FunctionListener fl;
77 while (it.hasNext()) {
78 fl = (FunctionListener)it.next();
79 fl.endFunction(fe, rowNum);
80 }
81 }
82 }
83
84 }