summaryrefslogtreecommitdiff
path: root/accessibility/workben/org/openoffice/accessibility/misc/Connector.java
blob: de188676e22462d0042a7a7b2b5157922794daa5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
package org.openoffice.accessibility.misc;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.Timer;
import java.util.TimerTask;
import java.util.Vector;


/** Wait for an Office application and connect to it.
*/
public class Connector
    extends TimerTask
{
    final public static long snDelay = 3000;

    public Connector ()
    {
        maTimer = new Timer (true);
        maListeners = new Vector();
        run ();
    }

    public void AddConnectionListener (ActionListener aListener)
    {
        SimpleOffice aOffice = SimpleOffice.Instance();
        if (aOffice!=null && aOffice.IsConnected())
            aListener.actionPerformed (
                new ActionEvent (aOffice,0,"<connected>"));
        maListeners.add (aListener);
    }

    public void run ()
    {
        SimpleOffice aOffice = SimpleOffice.Instance();
        if (aOffice!=null && !aOffice.IsConnected())
            if ( ! aOffice.Connect())
                 maTimer.schedule (this, snDelay);
            else
            {
                ActionEvent aEvent = new ActionEvent (aOffice,0,"<connected>");
                for (int i=0; i<maListeners.size(); i++)
                    ((ActionListener)maListeners.elementAt(i)).actionPerformed(
                        aEvent);
            }
    }

    Timer maTimer;
    Vector maListeners;
}