summaryrefslogtreecommitdiff
path: root/toolkit/test
diff options
context:
space:
mode:
authorVladimir Glazounov <vg@openoffice.org>2003-04-11 16:13:15 +0000
committerVladimir Glazounov <vg@openoffice.org>2003-04-11 16:13:15 +0000
commit89dc5f0f736e5c069812b805082354e976420a7e (patch)
tree23dc94d7235a4efc04bf7dc25ff024d387b18175 /toolkit/test
parent16e0e1808e7b031b6c2d91363b6990584267463f (diff)
INTEGRATION: CWS vcl07 (1.2.2); FILE ADDED
2003/04/08 14:28:51 obr 1.2.2.1: re-added accessibility workbench
Diffstat (limited to 'toolkit/test')
-rw-r--r--toolkit/test/accessibility/NodeMap.java112
1 files changed, 112 insertions, 0 deletions
diff --git a/toolkit/test/accessibility/NodeMap.java b/toolkit/test/accessibility/NodeMap.java
new file mode 100644
index 000000000000..f32cfd5d4301
--- /dev/null
+++ b/toolkit/test/accessibility/NodeMap.java
@@ -0,0 +1,112 @@
+import drafts.com.sun.star.accessibility.XAccessibleContext;
+
+import java.util.HashMap;
+
+abstract class NodeMapCallback
+{
+ public abstract void Apply (AccTreeNode aNode);
+}
+
+/** This map translates from XAccessible objects to our internal
+ representations.
+*/
+class NodeMap
+{
+ public NodeMap ()
+ {
+ maXAccessibleToNode = new HashMap ();
+ }
+
+ /** Clear the whole map.
+ */
+ public void Clear ()
+ {
+ maXAccessibleToNode.clear();
+ }
+
+ /** @return
+ whether the new node was different from a previous one
+ repspectively was the first one set.
+ */
+ public boolean InsertNode (XAccessibleContext xContext, AccessibleTreeNode aNode)
+ {
+ AccessibleTreeNode aPreviousNode = (AccessibleTreeNode)maXAccessibleToNode.put (
+ xContext,
+ aNode);
+ return aPreviousNode != aNode;
+ }
+
+ protected void RemoveNode (AccessibleTreeNode aNode)
+ {
+ try
+ {
+ if ((aNode != null) && (aNode instanceof AccTreeNode))
+ {
+ maXAccessibleToNode.remove (((AccTreeNode)aNode).getContext());
+ }
+ }
+ catch (Exception e)
+ {
+ System.out.println ("caught exception while removing node "
+ + aNode + " : " + e);
+ e.printStackTrace();
+ }
+ }
+
+
+ public void ForEach (NodeMapCallback aFunctor)
+ {
+ Object[] aNodes = maXAccessibleToNode.values().toArray();
+ for (int i=0; i<aNodes.length; i++)
+ {
+ if (aNodes[i] != null && (aNodes[i] instanceof AccTreeNode))
+ {
+ try
+ {
+ aFunctor.Apply ((AccTreeNode)aNodes[i]);
+ }
+ catch (Exception e)
+ {
+ System.out.println ("caught exception applying functor to "
+ + i + "th node " + aNodes[i] + " : " + e);
+ e.printStackTrace();
+ }
+ }
+ }
+ }
+
+ AccessibleTreeNode GetNode (XAccessibleContext xContext)
+ {
+ return (AccessibleTreeNode)maXAccessibleToNode.get (xContext);
+ }
+
+ AccessibleTreeNode GetNode (Object aObject)
+ {
+ if (aObject instanceof XAccessibleContext)
+ return GetNode ((XAccessibleContext)aObject);
+ else
+ return null;
+ }
+
+ XAccessibleContext GetAccessible (AccessibleTreeNode aNode)
+ {
+ if ((aNode != null) && (aNode instanceof AccTreeNode))
+ return ((AccTreeNode)aNode).getContext();
+ else
+ return null;
+ }
+
+ boolean IsMember (XAccessibleContext xContext)
+ {
+ return maXAccessibleToNode.containsKey(xContext);
+ }
+
+ boolean ValueIsMember (AccessibleTreeNode aNode)
+ {
+ return maXAccessibleToNode.containsValue(aNode);
+ }
+
+
+
+ private HashMap maXAccessibleToNode;
+}