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
.XAccessibleContext
;
21 import java
.util
.HashMap
;
23 abstract class NodeMapCallback
25 public abstract void Apply (AccTreeNode aNode
);
28 /** This map translates from XAccessible objects to our internal
35 maXAccessibleToNode
= new HashMap
<XAccessibleContext
, AccessibleTreeNode
> ();
38 /** Clear the whole map.
42 maXAccessibleToNode
.clear();
46 whether the new node was different from a previous one
47 repspectively was the first one set.
49 public boolean InsertNode (XAccessibleContext xContext
, AccessibleTreeNode aNode
)
51 AccessibleTreeNode aPreviousNode
= maXAccessibleToNode
.put (
54 return aPreviousNode
!= aNode
;
57 protected void RemoveNode (AccessibleTreeNode aNode
)
61 if ((aNode
!= null) && (aNode
instanceof AccTreeNode
))
63 maXAccessibleToNode
.remove (((AccTreeNode
)aNode
).getContext());
68 System
.out
.println ("caught exception while removing node "
75 public void ForEach (NodeMapCallback aFunctor
)
77 Object
[] aNodes
= maXAccessibleToNode
.values().toArray();
78 for (int i
=0; i
<aNodes
.length
; i
++)
80 if (aNodes
[i
] != null && (aNodes
[i
] instanceof AccTreeNode
))
84 aFunctor
.Apply ((AccTreeNode
)aNodes
[i
]);
88 System
.out
.println ("caught exception applying functor to "
89 + i
+ "th node " + aNodes
[i
] + " : " + e
);
96 AccessibleTreeNode
GetNode (XAccessibleContext xContext
)
98 return maXAccessibleToNode
.get (xContext
);
101 AccessibleTreeNode
GetNode (Object aObject
)
103 if (aObject
instanceof XAccessibleContext
)
104 return GetNode ((XAccessibleContext
)aObject
);
109 boolean ValueIsMember (AccessibleTreeNode aNode
)
111 return maXAccessibleToNode
.containsValue(aNode
);
116 private final HashMap
<XAccessibleContext
, AccessibleTreeNode
> maXAccessibleToNode
;