/************************************************************** * * Licensed to the Apache Software Foundation (ASF) under one * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information * regarding copyright ownership. The ASF licenses this file * to you under the Apache License, Version 2.0 (the * "License"); you may not use this file except in compliance * with the License. You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, * software distributed under the License is distributed on an * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. * *************************************************************/ import java.util.Vector; import com.sun.star.uno.AnyConverter; import com.sun.star.uno.UnoRuntime; import com.sun.star.uno.Type; import com.sun.star.accessibility.*; /** Handle all the events send from accessibility objects. The events denoting new or removed top windows are handled as well. It does not implement any listener interface as does the EventListenerProxy class because it is interested only in a sub set of the event types. */ public class EventHandler { public EventHandler () { mnTopWindowCount = 0; maListenerProxy = new EventListenerProxy (this); maConnectionTask = new ConnectionTask (maListenerProxy); maObjectDisplays = new Vector (); } public synchronized void addObjectDisplay (IAccessibleObjectDisplay aDisplay) { maObjectDisplays.add (aDisplay); } public void finalize () { // When it is running then cancel the timer that tries to connect to // the Office. if (maConnectionTask != null) maConnectionTask.cancel(); } public void disposing (com.sun.star.lang.EventObject aEvent) { // Ignored: We are not holding references to accessibility objects. } /** This method is called back when a new top level window has been opened. */ public void windowOpened (XAccessible xAccessible) { if (xAccessible != null) { // Update the counter of currently open top level windows // observed by this object. mnTopWindowCount += 1; XAccessibleContext xContext = xAccessible.getAccessibleContext(); if (xContext != null) { MessageArea.println ("new top level window has accessible name " + xContext.getAccessibleName()); // Register at all accessible objects of the new window. new RegistrationThread ( maListenerProxy, xContext, true, true); } else MessageArea.println ("new top level window is not accessible."); } else MessageArea.println ("new top level window is not accessible."); } public void windowClosed (XAccessible xAccessible) { mnTopWindowCount -= 1; MessageArea.println ("window closed, " + mnTopWindowCount + " still open"); if (mnTopWindowCount == 0) { // This was the last window. Wait for a new connection. MessageArea.println ("lost connection to office"); new ConnectionTask (maListenerProxy); } if (xAccessible != null) new RegistrationThread ( maListenerProxy, xAccessible.getAccessibleContext(), false, true); } /** Print a message that the given object just received the focus. Call all accessible object diplays and tell them to update. */ private synchronized void focusGained (XAccessibleContext xContext) { if (xContext != null) { MessageArea.println ("focusGained: " + xContext.getAccessibleName() + " with role " + NameProvider.getRoleName (xContext.getAccessibleRole())); // Tell the object displays to update their views. for (int i=0; i= 0) { nState = nOldState; aNewValue = false; } else { nState = nNewState; aNewValue = true; } // Print a message about the changed state. MessageArea.print ("setting state " + NameProvider.getStateName(nState) + " to " + aNewValue); if (xContext != null) { MessageArea.println (" at " + xContext.getAccessibleName() + " with role " + NameProvider.getRoleName(xContext.getAccessibleRole())); } else MessageArea.println (" at null"); // Further handling of some states switch (nState) { case AccessibleStateType.FOCUSED: if (aNewValue) focusGained (xContext); else focusLost (xContext); } } /** Handle a child event that describes the creation of removal of a single child. */ private void handleChildEvent ( XAccessibleContext aOldChild, XAccessibleContext aNewChild) { if (aOldChild != null) // Remove event listener from the child and all of its descendants. new RegistrationThread (maListenerProxy, aOldChild, false, false); else if (aNewChild != null) // Add event listener to the new child and all of its descendants. new RegistrationThread (maListenerProxy, aNewChild, true, false); } /** Handle the change of some visible data of an object. */ private void handleVisibleDataEvent (XAccessibleContext xContext) { // The given object may affect the visible appearance of the focused // object even when the two are not identical when the given object // is an ancestor of the focused object. // In order to not check this we simply call an update on the // focused object. if (mxFocusedObject != null) for (int i=0; i