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 import com.sun.star.accessibility.*; 23 import java.util.Vector; 24 25 import tools.NameProvider; 26 27 /** This singleton class creates nodes for given accessible objects. 28 */ 29 class NodeFactory 30 { Instance()31 public synchronized static NodeFactory Instance () 32 { 33 if (maInstance == null) 34 { 35 maInstance = new NodeFactory(); 36 } 37 return maInstance; 38 } 39 NodeFactory()40 private NodeFactory () 41 { 42 mbVerbose = false; 43 44 maContextHandler = new AccessibleContextHandler(); 45 maTextHandler = new AccessibleTextHandler(); 46 maEditableTextHandler = new AccessibleEditableTextHandler(); 47 maComponentHandler = new AccessibleComponentHandler(); 48 maExtendedComponentHandler = new AccessibleExtendedComponentHandler(); 49 maActionHandler = new AccessibleActionHandler(); 50 maImageHandler = new AccessibleImageHandler(); 51 maTableHandler = new AccessibleTableHandler(); 52 maCellHandler = new AccessibleCellHandler(); 53 maHypertextHandler = new AccessibleHypertextHandler(); 54 maHyperlinkHandler = new AccessibleHyperlinkHandler(); 55 maSelectionHandler = new AccessibleSelectionHandler(); 56 maRelationHandler = new AccessibleRelationHandler(); 57 maTreeHandler = new AccessibleTreeHandler(); 58 maUNOHandler = new AccessibleUNOHandler(); 59 } 60 61 62 /** add default handlers based on the supported interfaces */ addDefaultHandlers(AccTreeNode aNode, XAccessibleContext xContext)63 private void addDefaultHandlers (AccTreeNode aNode, XAccessibleContext xContext) 64 { 65 if (false) 66 { 67 // Slow but complete version: try each handler type separately. 68 aNode.addHandler (maContextHandler.createHandler (xContext)); 69 aNode.addHandler (maTextHandler.createHandler (xContext)); 70 aNode.addHandler (maEditableTextHandler.createHandler (xContext)); 71 aNode.addHandler (maComponentHandler.createHandler (xContext)); 72 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext)); 73 aNode.addHandler (maActionHandler.createHandler (xContext)); 74 aNode.addHandler (maImageHandler.createHandler (xContext)); 75 aNode.addHandler (maTableHandler.createHandler (xContext)); 76 aNode.addHandler (maCellHandler.createHandler (xContext)); 77 aNode.addHandler (maHypertextHandler.createHandler (xContext)); 78 aNode.addHandler (maHyperlinkHandler.createHandler (xContext)); 79 aNode.addHandler (maSelectionHandler.createHandler (xContext)); 80 aNode.addHandler (maRelationHandler.createHandler (xContext)); 81 aNode.addHandler (maUNOHandler.createHandler (xContext)); 82 aNode.addHandler (maTreeHandler.createHandler (xContext)); 83 } 84 else 85 { 86 // Exploit dependencies between interfaces. 87 NodeHandler aHandler; 88 aNode.addHandler (maContextHandler.createHandler (xContext)); 89 90 aHandler = maTextHandler.createHandler (xContext); 91 if (aHandler != null) 92 { 93 aNode.addHandler (aHandler); 94 aNode.addHandler (maEditableTextHandler.createHandler (xContext)); 95 aNode.addHandler (maHypertextHandler.createHandler (xContext)); 96 aNode.addHandler (maHyperlinkHandler.createHandler (xContext)); 97 } 98 aHandler = maComponentHandler.createHandler (xContext); 99 if (aHandler != null) 100 { 101 aNode.addHandler (aHandler); 102 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext)); 103 } 104 aNode.addHandler (maActionHandler.createHandler (xContext)); 105 aNode.addHandler (maImageHandler.createHandler (xContext)); 106 aNode.addHandler (maTableHandler.createHandler (xContext)); 107 aNode.addHandler (maRelationHandler.createHandler (xContext)); 108 aNode.addHandler (maCellHandler.createHandler (xContext)); 109 aNode.addHandler (maSelectionHandler.createHandler (xContext)); 110 aNode.addHandler (maUNOHandler.createHandler (xContext)); 111 aNode.addHandler (maTreeHandler.createHandler (xContext)); 112 } 113 } 114 115 /** create a node with the default handlers */ createDefaultNode(XAccessible xAccessible, AccessibleTreeNode aParent)116 public AccTreeNode createDefaultNode (XAccessible xAccessible, AccessibleTreeNode aParent) 117 { 118 // default: aObject + aDisplay 119 String sDisplay; 120 121 // if we are accessible, we use the context + name instead 122 XAccessibleContext xContext = null; 123 if (xAccessible != null) 124 xContext = xAccessible.getAccessibleContext(); 125 if (xContext != null) 126 { 127 sDisplay = xContext.getAccessibleName(); 128 if (sDisplay.length()==0) 129 { 130 sDisplay = "<no name> Role: " 131 + NameProvider.getRoleName ( 132 xContext.getAccessibleRole()); 133 } 134 } 135 else 136 sDisplay = new String ("not accessible"); 137 138 139 // create node, and add default handlers 140 AccTreeNode aNode = new AccTreeNode (xAccessible, xContext, sDisplay, aParent); 141 addDefaultHandlers (aNode, xContext); 142 143 if (aNode == null) 144 System.out.println ("createDefaultNode == null"); 145 return aNode; 146 } 147 148 private static NodeFactory maInstance = null; 149 150 private boolean mbVerbose; 151 152 // default handlers 153 private NodeHandler maContextHandler = new AccessibleContextHandler(); 154 private NodeHandler maTextHandler = new AccessibleTextHandler(); 155 private NodeHandler maEditableTextHandler = new AccessibleEditableTextHandler(); 156 private NodeHandler maComponentHandler = new AccessibleComponentHandler(); 157 private NodeHandler maExtendedComponentHandler = new AccessibleExtendedComponentHandler(); 158 private NodeHandler maActionHandler = new AccessibleActionHandler(); 159 private NodeHandler maImageHandler = new AccessibleImageHandler(); 160 private NodeHandler maTableHandler = new AccessibleTableHandler(); 161 private NodeHandler maCellHandler = new AccessibleCellHandler(); 162 private NodeHandler maHypertextHandler = new AccessibleHypertextHandler(); 163 private NodeHandler maHyperlinkHandler = new AccessibleHyperlinkHandler(); 164 private NodeHandler maSelectionHandler = new AccessibleSelectionHandler(); 165 private NodeHandler maRelationHandler = new AccessibleRelationHandler(); 166 private NodeHandler maTreeHandler = new AccessibleTreeHandler(); 167 private NodeHandler maUNOHandler = new AccessibleUNOHandler(); 168 } 169