1 /**************************************************************
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one
4  * or more contributor license agreements.  See the NOTICE file
5  * distributed with this work for additional information
6  * regarding copyright ownership.  The ASF licenses this file
7  * to you under the Apache License, Version 2.0 (the
8  * "License"); you may not use this file except in compliance
9  * with the License.  You may obtain a copy of the License at
10  *
11  *   http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing,
14  * software distributed under the License is distributed on an
15  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16  * KIND, either express or implied.  See the License for the
17  * specific language governing permissions and limitations
18  * under the License.
19  *
20  *************************************************************/
21 
22 package org.openoffice.accessibility.misc;
23 
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
26 import java.util.Timer;
27 import java.util.TimerTask;
28 import java.util.Vector;
29 
30 
31 /** Wait for an Office application and connect to it.
32 */
33 public class Connector
34     extends TimerTask
35 {
36     final public static long snDelay = 3000;
37 
Connector()38     public Connector ()
39     {
40         maTimer = new Timer (true);
41         maListeners = new Vector();
42 		run ();
43     }
44 
AddConnectionListener(ActionListener aListener)45     public void AddConnectionListener (ActionListener aListener)
46     {
47         SimpleOffice aOffice = SimpleOffice.Instance();
48         if (aOffice!=null && aOffice.IsConnected())
49             aListener.actionPerformed (
50                 new ActionEvent (aOffice,0,"<connected>"));
51         maListeners.add (aListener);
52     }
53 
run()54     public void run ()
55     {
56         SimpleOffice aOffice = SimpleOffice.Instance();
57         if (aOffice!=null && !aOffice.IsConnected())
58             if ( ! aOffice.Connect())
59                  maTimer.schedule (this, snDelay);
60             else
61             {
62                 ActionEvent aEvent = new ActionEvent (aOffice,0,"<connected>");
63                 for (int i=0; i<maListeners.size(); i++)
64                     ((ActionListener)maListeners.elementAt(i)).actionPerformed(
65                         aEvent);
66             }
67     }
68 
69     Timer maTimer;
70     Vector maListeners;
71 }
72