tdf#130857 qt weld: Implement QtInstanceWidget::get_text_height
[LibreOffice.git] / toolkit / test / accessibility / NodeFactory.java
blob7e1d9f585c3d7e1c73fea788ca0547fca1219e20
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 ()
40 /** add default handlers based on the supported interfaces */
41 private void addDefaultHandlers (AccTreeNode aNode, XAccessibleContext xContext)
43 if (false)
45 // Slow but complete version: try each handler type separately.
46 aNode.addHandler (maContextHandler.createHandler (xContext));
47 aNode.addHandler (maTextHandler.createHandler (xContext));
48 aNode.addHandler (maEditableTextHandler.createHandler (xContext));
49 aNode.addHandler (maComponentHandler.createHandler (xContext));
50 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext));
51 aNode.addHandler (maActionHandler.createHandler (xContext));
52 aNode.addHandler (maImageHandler.createHandler (xContext));
53 aNode.addHandler (maTableHandler.createHandler (xContext));
54 aNode.addHandler (maCellHandler.createHandler (xContext));
55 aNode.addHandler (maHypertextHandler.createHandler (xContext));
56 aNode.addHandler (maHyperlinkHandler.createHandler (xContext));
57 aNode.addHandler (maSelectionHandler.createHandler (xContext));
58 aNode.addHandler (maRelationHandler.createHandler (xContext));
59 aNode.addHandler (maUNOHandler.createHandler (xContext));
60 aNode.addHandler (maTreeHandler.createHandler (xContext));
62 else
64 // Exploit dependencies between interfaces.
65 NodeHandler aHandler;
66 aNode.addHandler (maContextHandler.createHandler (xContext));
68 aHandler = maTextHandler.createHandler (xContext);
69 if (aHandler != null)
71 aNode.addHandler (aHandler);
72 aNode.addHandler (maEditableTextHandler.createHandler (xContext));
73 aNode.addHandler (maHypertextHandler.createHandler (xContext));
74 aNode.addHandler (maHyperlinkHandler.createHandler (xContext));
76 aHandler = maComponentHandler.createHandler (xContext);
77 if (aHandler != null)
79 aNode.addHandler (aHandler);
80 aNode.addHandler (maExtendedComponentHandler.createHandler (xContext));
82 aNode.addHandler (maActionHandler.createHandler (xContext));
83 aNode.addHandler (maImageHandler.createHandler (xContext));
84 aNode.addHandler (maTableHandler.createHandler (xContext));
85 aNode.addHandler (maRelationHandler.createHandler (xContext));
86 aNode.addHandler (maCellHandler.createHandler (xContext));
87 aNode.addHandler (maSelectionHandler.createHandler (xContext));
88 aNode.addHandler (maUNOHandler.createHandler (xContext));
89 aNode.addHandler (maTreeHandler.createHandler (xContext));
93 /** create a node with the default handlers */
94 public AccTreeNode createDefaultNode (XAccessible xAccessible, AccessibleTreeNode aParent)
96 // default: aObject + aDisplay
97 String sDisplay;
99 // if we are accessible, we use the context + name instead
100 XAccessibleContext xContext = null;
101 if (xAccessible != null)
102 xContext = xAccessible.getAccessibleContext();
103 if (xContext != null)
105 sDisplay = xContext.getAccessibleName();
106 if (sDisplay.length()==0)
108 sDisplay = "<no name> Role: "
109 + NameProvider.getRoleName (
110 xContext.getAccessibleRole());
113 else
114 sDisplay = "not accessible";
117 // create node, and add default handlers
118 AccTreeNode aNode = new AccTreeNode (xContext, sDisplay, aParent);
119 addDefaultHandlers (aNode, xContext);
121 return aNode;
124 private static NodeFactory maInstance = null;
126 // default handlers
127 private final NodeHandler maContextHandler = new AccessibleContextHandler();
128 private final NodeHandler maTextHandler = new AccessibleTextHandler();
129 private final NodeHandler maEditableTextHandler = new AccessibleEditableTextHandler();
130 private final NodeHandler maComponentHandler = new AccessibleComponentHandler();
131 private final NodeHandler maExtendedComponentHandler = new AccessibleExtendedComponentHandler();
132 private final NodeHandler maActionHandler = new AccessibleActionHandler();
133 private final NodeHandler maImageHandler = new AccessibleImageHandler();
134 private final NodeHandler maTableHandler = new AccessibleTableHandler();
135 private final NodeHandler maCellHandler = new AccessibleCellHandler();
136 private final NodeHandler maHypertextHandler = new AccessibleHypertextHandler();
137 private final NodeHandler maHyperlinkHandler = new AccessibleHyperlinkHandler();
138 private final NodeHandler maSelectionHandler = new AccessibleSelectionHandler();
139 private final NodeHandler maRelationHandler = new AccessibleRelationHandler();
140 private final NodeHandler maTreeHandler = new AccessibleTreeHandler();
141 private final NodeHandler maUNOHandler = new AccessibleUNOHandler();