1 import com
.sun
.star
.accessibility
.*;
2 import com
.sun
.star
.lang
.EventObject
;
4 import java
.util
.LinkedList
;
6 /** The event queue singleton dispatches events received from OpenOffice.org
7 applications in a thread separate from the AWB main thread.
9 The queue of event objects, LinkedList<Runnable> The queue object will
10 also serve as lock for the consumer/producer type syncronization.
15 public boolean mbVerbose
= false;
16 public boolean mbHandleDisposingEventsSynchronous
= true;
18 public synchronized static EventQueue
Instance ()
20 if (maInstance
== null)
21 maInstance
= new EventQueue ();
25 public void addEvent (Runnable aEvent
)
27 synchronized (maMonitor
)
30 System
.out
.println ("queing regular event " + aEvent
);
31 maRegularQueue
.addLast (aEvent
);
37 public void addDisposingEvent (Runnable aEvent
)
39 if (mbHandleDisposingEventsSynchronous
)
42 synchronized (maMonitor
)
45 System
.out
.println ("queing disposing event " + aEvent
);
46 maDisposingQueue
.addLast (aEvent
);
54 maMonitor
= new Boolean (true);
55 maRegularQueue
= new LinkedList();
56 maDisposingQueue
= new LinkedList();
57 new Thread(this, "AWB.EventQueue").start();
61 /// This thread's main method: deliver all events
64 // in an infinite loop, check for events to deliver, then
65 // wait on lock (which will be notified when new events arrive)
68 Runnable aEvent
= null;
71 synchronized (maMonitor
)
73 if (maDisposingQueue
.size() > 0)
75 aEvent
= (Runnable
)maDisposingQueue
.removeFirst();
77 System
.out
.println ("delivering disposing event " + aEvent
);
79 else if (maRegularQueue
.size() > 0)
81 aEvent
= (Runnable
)maRegularQueue
.removeFirst();
83 System
.out
.println ("delivering regular event " + aEvent
);
97 "caught exception during event delivery: " + e
);
102 while( aEvent
!= null );
106 synchronized (maMonitor
)
114 System
.err
.println("Can't wait!");
120 private static EventQueue maInstance
= null;
121 private Object maMonitor
;
122 private LinkedList maRegularQueue
;
123 private LinkedList maDisposingQueue
;