merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / NodeFactory.java
blob403c482e5ea1509ac64d738d17da6b3531c7011b
1 import com.sun.star.accessibility.*;
2 import java.util.Vector;
4 import tools.NameProvider;
6 /** This singleton class creates nodes for given accessible objects.
7 */
8 class NodeFactory
10 public synchronized static NodeFactory Instance ()
12 if (maInstance == null)
14 maInstance = new NodeFactory();
16 return maInstance;
19 private NodeFactory ()
21 mbVerbose = false;
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();
41 /** add default handlers based on the supported interfaces */
42 private void addDefaultHandlers (AccTreeNode aNode, XAccessibleContext xContext)
44 if (false)
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));
63 else
65 // Exploit dependencies between interfaces.
66 NodeHandler aHandler;
67 aNode.addHandler (maContextHandler.createHandler (xContext));
69 aHandler = maTextHandler.createHandler (xContext);
70 if (aHandler != null)
72 aNode.addHandler (aHandler);
73 aNode.addHandler (maEditableTextHandler.createHandler (xContext));
74 aNode.addHandler (maHypertextHandler.createHandler (xContext));
75 aNode.addHandler (maHyperlinkHandler.createHandler (xContext));
77 aHandler = maComponentHandler.createHandler (xContext);
78 if (aHandler != null)
80 aNode.addHandler (aHandler);
81 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext));
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));
94 /** create a node with the default handlers */
95 public AccTreeNode createDefaultNode (XAccessible xAccessible, AccessibleTreeNode aParent)
97 // default: aObject + aDisplay
98 String sDisplay;
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)
106 sDisplay = xContext.getAccessibleName();
107 if (sDisplay.length()==0)
109 sDisplay = "<no name> Role: "
110 + NameProvider.getRoleName (
111 xContext.getAccessibleRole());
114 else
115 sDisplay = new String ("not accessible");
118 // create node, and add default handlers
119 AccTreeNode aNode = new AccTreeNode (xAccessible, xContext, sDisplay, aParent);
120 addDefaultHandlers (aNode, xContext);
122 if (aNode == null)
123 System.out.println ("createDefaultNode == null");
124 return aNode;
127 private static NodeFactory maInstance = null;
129 private boolean mbVerbose;
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();