bump product version to 4.2.0.1
[LibreOffice.git] / toolkit / test / accessibility / NodeFactory.java
blob7218c3545c1abcdd461305bcbf508531025f2654
1 /*
2 * This file is part of the LibreOffice project.
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/.
8 * This file incorporates work covered by the following license notice:
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 .
19 import com.sun.star.accessibility.*;
20 import tools.NameProvider;
22 /** This singleton class creates nodes for given accessible objects.
24 class NodeFactory
26 public synchronized static NodeFactory Instance ()
28 if (maInstance == null)
30 maInstance = new NodeFactory();
32 return maInstance;
35 private NodeFactory ()
37 mbVerbose = false;
39 maContextHandler = new AccessibleContextHandler();
40 maTextHandler = new AccessibleTextHandler();
41 maEditableTextHandler = new AccessibleEditableTextHandler();
42 maComponentHandler = new AccessibleComponentHandler();
43 maExtendedComponentHandler = new AccessibleExtendedComponentHandler();
44 maActionHandler = new AccessibleActionHandler();
45 maImageHandler = new AccessibleImageHandler();
46 maTableHandler = new AccessibleTableHandler();
47 maCellHandler = new AccessibleCellHandler();
48 maHypertextHandler = new AccessibleHypertextHandler();
49 maHyperlinkHandler = new AccessibleHyperlinkHandler();
50 maSelectionHandler = new AccessibleSelectionHandler();
51 maRelationHandler = new AccessibleRelationHandler();
52 maTreeHandler = new AccessibleTreeHandler();
53 maUNOHandler = new AccessibleUNOHandler();
57 /** add default handlers based on the supported interfaces */
58 private void addDefaultHandlers (AccTreeNode aNode, XAccessibleContext xContext)
60 if (false)
62 // Slow but complete version: try each handler type separately.
63 aNode.addHandler (maContextHandler.createHandler (xContext));
64 aNode.addHandler (maTextHandler.createHandler (xContext));
65 aNode.addHandler (maEditableTextHandler.createHandler (xContext));
66 aNode.addHandler (maComponentHandler.createHandler (xContext));
67 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext));
68 aNode.addHandler (maActionHandler.createHandler (xContext));
69 aNode.addHandler (maImageHandler.createHandler (xContext));
70 aNode.addHandler (maTableHandler.createHandler (xContext));
71 aNode.addHandler (maCellHandler.createHandler (xContext));
72 aNode.addHandler (maHypertextHandler.createHandler (xContext));
73 aNode.addHandler (maHyperlinkHandler.createHandler (xContext));
74 aNode.addHandler (maSelectionHandler.createHandler (xContext));
75 aNode.addHandler (maRelationHandler.createHandler (xContext));
76 aNode.addHandler (maUNOHandler.createHandler (xContext));
77 aNode.addHandler (maTreeHandler.createHandler (xContext));
79 else
81 // Exploit dependencies between interfaces.
82 NodeHandler aHandler;
83 aNode.addHandler (maContextHandler.createHandler (xContext));
85 aHandler = maTextHandler.createHandler (xContext);
86 if (aHandler != null)
88 aNode.addHandler (aHandler);
89 aNode.addHandler (maEditableTextHandler.createHandler (xContext));
90 aNode.addHandler (maHypertextHandler.createHandler (xContext));
91 aNode.addHandler (maHyperlinkHandler.createHandler (xContext));
93 aHandler = maComponentHandler.createHandler (xContext);
94 if (aHandler != null)
96 aNode.addHandler (aHandler);
97 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext));
99 aNode.addHandler (maActionHandler.createHandler (xContext));
100 aNode.addHandler (maImageHandler.createHandler (xContext));
101 aNode.addHandler (maTableHandler.createHandler (xContext));
102 aNode.addHandler (maRelationHandler.createHandler (xContext));
103 aNode.addHandler (maCellHandler.createHandler (xContext));
104 aNode.addHandler (maSelectionHandler.createHandler (xContext));
105 aNode.addHandler (maUNOHandler.createHandler (xContext));
106 aNode.addHandler (maTreeHandler.createHandler (xContext));
110 /** create a node with the default handlers */
111 public AccTreeNode createDefaultNode (XAccessible xAccessible, AccessibleTreeNode aParent)
113 // default: aObject + aDisplay
114 String sDisplay;
116 // if we are accessible, we use the context + name instead
117 XAccessibleContext xContext = null;
118 if (xAccessible != null)
119 xContext = xAccessible.getAccessibleContext();
120 if (xContext != null)
122 sDisplay = xContext.getAccessibleName();
123 if (sDisplay.length()==0)
125 sDisplay = "<no name> Role: "
126 + NameProvider.getRoleName (
127 xContext.getAccessibleRole());
130 else
131 sDisplay = new String ("not accessible");
134 // create node, and add default handlers
135 AccTreeNode aNode = new AccTreeNode (xAccessible, xContext, sDisplay, aParent);
136 addDefaultHandlers (aNode, xContext);
138 return aNode;
141 private static NodeFactory maInstance = null;
143 private boolean mbVerbose;
145 // default handlers
146 private NodeHandler maContextHandler = new AccessibleContextHandler();
147 private NodeHandler maTextHandler = new AccessibleTextHandler();
148 private NodeHandler maEditableTextHandler = new AccessibleEditableTextHandler();
149 private NodeHandler maComponentHandler = new AccessibleComponentHandler();
150 private NodeHandler maExtendedComponentHandler = new AccessibleExtendedComponentHandler();
151 private NodeHandler maActionHandler = new AccessibleActionHandler();
152 private NodeHandler maImageHandler = new AccessibleImageHandler();
153 private NodeHandler maTableHandler = new AccessibleTableHandler();
154 private NodeHandler maCellHandler = new AccessibleCellHandler();
155 private NodeHandler maHypertextHandler = new AccessibleHypertextHandler();
156 private NodeHandler maHyperlinkHandler = new AccessibleHyperlinkHandler();
157 private NodeHandler maSelectionHandler = new AccessibleSelectionHandler();
158 private NodeHandler maRelationHandler = new AccessibleRelationHandler();
159 private NodeHandler maTreeHandler = new AccessibleTreeHandler();
160 private NodeHandler maUNOHandler = new AccessibleUNOHandler();