merge the formfield patch from ooo-build
[ooovba.git] / toolkit / test / accessibility / AccessibilityTreeModelBase.java
blob23e403a67c897191c2831fcb076a0347fdd46e27
1 import javax.swing.tree.TreeModel;
2 import javax.swing.event.TreeModelListener;
3 import javax.swing.tree.TreePath;
4 import javax.swing.event.TreeModelEvent;
5 import java.util.Vector;
7 public class AccessibilityTreeModelBase
8 implements TreeModel
10 public AccessibilityTreeModelBase ()
12 setRoot (null);
13 maTMListeners = new Vector();
16 public synchronized void addTreeModelListener(TreeModelListener l)
18 maTMListeners.add(l);
21 public synchronized void removeTreeModelListener(TreeModelListener l)
23 maTMListeners.remove(l);
26 public synchronized int getChildCount(Object aParent)
28 return (aParent instanceof AccessibleTreeNode) ?
29 ((AccessibleTreeNode)aParent).getChildCount() : 0;
32 public synchronized Object getChild (Object aParent, int nIndex)
34 Object aChild = null;
35 try
37 if (aParent != null && aParent instanceof AccessibleTreeNode)
38 aChild = ((AccessibleTreeNode)aParent).getChild(nIndex);
39 else
40 System.out.println ("getChild called for unknown parent node");
42 catch (com.sun.star.lang.IndexOutOfBoundsException e)
44 aChild = ("no child " + nIndex + " from " + aParent + ": " + e);
46 return aChild;
49 public synchronized Object getChildNoCreate (Object aParent, int nIndex)
51 Object aChild = null;
52 try
54 if (aParent != null && aParent instanceof AccessibleTreeNode)
55 aChild = ((AccessibleTreeNode)aParent).getChildNoCreate(nIndex);
56 else
57 System.out.println ("getChild called for unknown parent node");
59 catch (com.sun.star.lang.IndexOutOfBoundsException e)
60 { }
61 return aChild;
64 /** iterate over all children and look for child */
65 public synchronized int getIndexOfChild (Object aParent, Object aChild)
67 int nIndex = -1;
68 try
70 if ((aParent instanceof AccessibleTreeNode) && (aChild instanceof AccessibleTreeNode))
72 AccessibleTreeNode aParentNode = (AccessibleTreeNode) aParent;
73 AccessibleTreeNode aChildNode = (AccessibleTreeNode) aChild;
75 int nChildCount = aParentNode.getChildCount();
76 for( int i = 0; i < nChildCount; i++ )
78 if (aChildNode.equals (aParentNode.getChild (i)))
80 nIndex = i;
81 break;
86 catch (com.sun.star.lang.IndexOutOfBoundsException e)
88 // Return -1 by falling through.
91 // not found?
92 return nIndex;
95 public boolean isLeaf (Object aNode)
97 return (aNode instanceof AccessibleTreeNode) ?
98 ((AccessibleTreeNode)aNode).isLeaf() : true;
103 public synchronized Object getRoot()
105 return maRoot;
108 public void valueForPathChanged(TreePath path, Object newValue)
111 protected synchronized void setRoot (AccessibleTreeNode aRoot)
113 maRoot = aRoot;
117 // The list of TreeModelListener objects.
118 protected Vector maTMListeners;
120 // The root node of the tree. Use setRoot to change it.
121 private AccessibleTreeNode maRoot = null;