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