merged tag ooo/DEV300_m102
[LibreOffice.git] / toolkit / test / accessibility / NodeMap.java
blob43479278aec4fa1dae6c90162eb2b61ee05a28f0
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
11 representations.
13 class NodeMap
15 public NodeMap ()
17 maXAccessibleToNode = new HashMap ();
20 /** Clear the whole map.
22 public void Clear ()
24 maXAccessibleToNode.clear();
27 /** @return
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 (
34 xContext,
35 aNode);
36 return aPreviousNode != aNode;
39 protected void RemoveNode (AccessibleTreeNode aNode)
41 try
43 if ((aNode != null) && (aNode instanceof AccTreeNode))
45 maXAccessibleToNode.remove (((AccTreeNode)aNode).getContext());
48 catch (Exception e)
50 System.out.println ("caught exception while removing node "
51 + aNode + " : " + e);
52 e.printStackTrace();
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))
64 try
66 aFunctor.Apply ((AccTreeNode)aNodes[i]);
68 catch (Exception e)
70 System.out.println ("caught exception applying functor to "
71 + i + "th node " + aNodes[i] + " : " + e);
72 e.printStackTrace();
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);
87 else
88 return null;
91 XAccessibleContext GetAccessible (AccessibleTreeNode aNode)
93 if ((aNode != null) && (aNode instanceof AccTreeNode))
94 return ((AccTreeNode)aNode).getContext();
95 else
96 return null;
99 boolean IsMember (XAccessibleContext xContext)
101 return maXAccessibleToNode.containsKey(xContext);
104 boolean ValueIsMember (AccessibleTreeNode aNode)
106 return maXAccessibleToNode.containsValue(aNode);
111 private HashMap maXAccessibleToNode;