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.
26 public synchronized static NodeFactory
Instance ()
28 if (maInstance
== null)
30 maInstance
= new NodeFactory();
35 private NodeFactory ()
40 /** add default handlers based on the supported interfaces */
41 private void addDefaultHandlers (AccTreeNode aNode
, XAccessibleContext xContext
)
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
));
64 // Exploit dependencies between interfaces.
66 aNode
.addHandler (maContextHandler
.createHandler (xContext
));
68 aHandler
= maTextHandler
.createHandler (xContext
);
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
);
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
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());
114 sDisplay
= "not accessible";
117 // create node, and add default handlers
118 AccTreeNode aNode
= new AccTreeNode (xContext
, sDisplay
, aParent
);
119 addDefaultHandlers (aNode
, xContext
);
124 private static NodeFactory maInstance
= null;
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();