1 /* 2 * This file is part of the LibreOffice project. 3 * 4 * This Source Code Form is subject to the terms of the Mozilla Public 5 * License, v. 2.0. If a copy of the MPL was not distributed with this 6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 7 * 8 * This file incorporates work covered by the following license notice: 9 * 10 * Licensed to the Apache Software Foundation (ASF) under one or more 11 * contributor license agreements. See the NOTICE file distributed 12 * with this work for additional information regarding copyright 13 * ownership. The ASF licenses this file to you under the Apache 14 * License, Version 2.0 (the "License"); you may not use this file 15 * except in compliance with the License. You may obtain a copy of 16 * the License at http://www.apache.org/licenses/LICENSE-2.0 . 17 */ 18 19 import com.sun.star.accessibility.*; 20 21 /** Objects of this class (usually one, singleton?) listen to accessible 22 events of all objects in all trees. 23 */ 24 public class EventListener 25 { 26 private boolean mbVerbose = false; 27 EventListener(AccessibilityTreeModel aTreeModel)28 public EventListener (AccessibilityTreeModel aTreeModel) 29 { 30 maTreeModel = aTreeModel; 31 } 32 33 34 /** This method handles accessibility objects that are being disposed. 35 */ disposing(XAccessibleContext xContext)36 public void disposing (XAccessibleContext xContext) 37 { 38 if (mbVerbose) 39 System.out.println("disposing " + xContext); 40 maTreeModel.removeNode (xContext); 41 } 42 43 /** This method is called from accessible objects that broadcast 44 modifications of themselves or from their children. The event is 45 processed only, except printing some messages, if the tree is not 46 locked. It should be locked during changes to its internal 47 structure like expanding nodes. 48 */ notifyEvent(AccessibleEventObject aEvent)49 public void notifyEvent (AccessibleEventObject aEvent) 50 { 51 EventHandler aHandler; 52 53 switch (aEvent.EventId) 54 { 55 case AccessibleEventId.CHILD: 56 aHandler = new ChildEventHandler (aEvent, maTreeModel); 57 break; 58 59 case AccessibleEventId.BOUNDRECT_CHANGED: 60 case AccessibleEventId.VISIBLE_DATA_CHANGED: 61 aHandler = new GeometryEventHandler (aEvent, maTreeModel); 62 break; 63 64 65 case AccessibleEventId.NAME_CHANGED: 66 case AccessibleEventId.DESCRIPTION_CHANGED: 67 case AccessibleEventId.STATE_CHANGED: 68 case AccessibleEventId.SELECTION_CHANGED: 69 aHandler = new ContextEventHandler (aEvent, maTreeModel); 70 break; 71 72 case AccessibleEventId.TABLE_MODEL_CHANGED: 73 case AccessibleEventId.TABLE_CAPTION_CHANGED: 74 case AccessibleEventId.TABLE_COLUMN_DESCRIPTION_CHANGED: 75 case AccessibleEventId.TABLE_COLUMN_HEADER_CHANGED: 76 case AccessibleEventId.TABLE_ROW_DESCRIPTION_CHANGED: 77 case AccessibleEventId.TABLE_ROW_HEADER_CHANGED: 78 case AccessibleEventId.TABLE_SUMMARY_CHANGED: 79 aHandler = new TableEventHandler (aEvent, maTreeModel); 80 break; 81 82 case AccessibleEventId.ACTION_CHANGED: 83 case AccessibleEventId.HYPERTEXT_CHANGED: 84 case AccessibleEventId.ACTIVE_DESCENDANT_CHANGED: 85 case AccessibleEventId.CARET_CHANGED: 86 case AccessibleEventId.TEXT_CHANGED: 87 case AccessibleEventId.VALUE_CHANGED: 88 aHandler = new EventHandler (aEvent, maTreeModel); 89 break; 90 91 default: 92 aHandler = null; 93 break; 94 } 95 96 if (aHandler == null) 97 System.out.println (" unhandled event"); 98 else 99 { 100 if (mbVerbose) 101 aHandler.Print (System.out); 102 aHandler.Process (); 103 } 104 } 105 106 107 private final AccessibilityTreeModel maTreeModel; 108 } 109