1 import com
.sun
.star
.accessibility
.XAccessibleContext
;
3 import java
.util
.HashMap
;
5 abstract class NodeMapCallback
7 public abstract void Apply (AccTreeNode aNode
);
10 /** This map translates from XAccessible objects to our internal
17 maXAccessibleToNode
= new HashMap ();
20 /** Clear the whole map.
24 maXAccessibleToNode
.clear();
28 whether the new node was different from a previous one
29 repspectively was the first one set.
31 public boolean InsertNode (XAccessibleContext xContext
, AccessibleTreeNode aNode
)
33 AccessibleTreeNode aPreviousNode
= (AccessibleTreeNode
)maXAccessibleToNode
.put (
36 return aPreviousNode
!= aNode
;
39 protected void RemoveNode (AccessibleTreeNode aNode
)
43 if ((aNode
!= null) && (aNode
instanceof AccTreeNode
))
45 maXAccessibleToNode
.remove (((AccTreeNode
)aNode
).getContext());
50 System
.out
.println ("caught exception while removing node "
57 public void ForEach (NodeMapCallback aFunctor
)
59 Object
[] aNodes
= maXAccessibleToNode
.values().toArray();
60 for (int i
=0; i
<aNodes
.length
; i
++)
62 if (aNodes
[i
] != null && (aNodes
[i
] instanceof AccTreeNode
))
66 aFunctor
.Apply ((AccTreeNode
)aNodes
[i
]);
70 System
.out
.println ("caught exception applying functor to "
71 + i
+ "th node " + aNodes
[i
] + " : " + e
);
78 AccessibleTreeNode
GetNode (XAccessibleContext xContext
)
80 return (AccessibleTreeNode
)maXAccessibleToNode
.get (xContext
);
83 AccessibleTreeNode
GetNode (Object aObject
)
85 if (aObject
instanceof XAccessibleContext
)
86 return GetNode ((XAccessibleContext
)aObject
);
91 XAccessibleContext
GetAccessible (AccessibleTreeNode aNode
)
93 if ((aNode
!= null) && (aNode
instanceof AccTreeNode
))
94 return ((AccTreeNode
)aNode
).getContext();
99 boolean IsMember (XAccessibleContext xContext
)
101 return maXAccessibleToNode
.containsKey(xContext
);
104 boolean ValueIsMember (AccessibleTreeNode aNode
)
106 return maXAccessibleToNode
.containsValue(aNode
);
111 private HashMap maXAccessibleToNode
;