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