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
10 public AccessibilityTreeModelBase ()
13 maTMListeners
= new Vector();
16 public synchronized void addTreeModelListener(TreeModelListener 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
)
37 if (aParent
!= null && aParent
instanceof AccessibleTreeNode
)
38 aChild
= ((AccessibleTreeNode
)aParent
).getChild(nIndex
);
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
);
49 public synchronized Object
getChildNoCreate (Object aParent
, int nIndex
)
54 if (aParent
!= null && aParent
instanceof AccessibleTreeNode
)
55 aChild
= ((AccessibleTreeNode
)aParent
).getChildNoCreate(nIndex
);
57 System
.out
.println ("getChild called for unknown parent node");
59 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
64 /** iterate over all children and look for child */
65 public synchronized int getIndexOfChild (Object aParent
, Object aChild
)
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
)))
86 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
88 // Return -1 by falling through.
95 public boolean isLeaf (Object aNode
)
97 return (aNode
instanceof AccessibleTreeNode
) ?
98 ((AccessibleTreeNode
)aNode
).isLeaf() : true;
103 public synchronized Object
getRoot()
108 public void valueForPathChanged(TreePath path
, Object newValue
)
111 protected synchronized void setRoot (AccessibleTreeNode 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;