summaryrefslogtreecommitdiff
path: root/toolkit/test/accessibility/AccTreeNode.java
diff options
context:
space:
mode:
authorDaniel Vogelheim <dvo@openoffice.org>2002-03-08 16:30:18 +0000
committerDaniel Vogelheim <dvo@openoffice.org>2002-03-08 16:30:18 +0000
commit75345d9b5845e57c3f83ade2266f59fe01ac6572 (patch)
tree1c5fc8380ea0a7a9491804e7d45344f9e733a159 /toolkit/test/accessibility/AccTreeNode.java
parenta403b7e53223c93b47a1afa0d81da155e6920873 (diff)
Now use custom tree model in order to create data on-the-fly.
Diffstat (limited to 'toolkit/test/accessibility/AccTreeNode.java')
-rw-r--r--toolkit/test/accessibility/AccTreeNode.java87
1 files changed, 87 insertions, 0 deletions
diff --git a/toolkit/test/accessibility/AccTreeNode.java b/toolkit/test/accessibility/AccTreeNode.java
new file mode 100644
index 000000000000..6c01f7672050
--- /dev/null
+++ b/toolkit/test/accessibility/AccTreeNode.java
@@ -0,0 +1,87 @@
+
+import java.util.Vector;
+
+/**
+ * The node type for the AccessibleTreeModel.
+ * This implements all the child-handling based on the appropriate
+ * NodeHandlers. Trivial nodes can be implemented by any Object
+ * type.
+ */
+class AccTreeNode
+{
+ private Vector aHandlers; /// NodeHandlers for this node
+ private Object aDataObject; /// the actual data object
+ private Object aDisplayObject; /// object to be displayed
+
+ public AccTreeNode( Object aData )
+ {
+ this( aData, aData );
+ }
+
+ public AccTreeNode( Object aData, Object aDisplay )
+ {
+ aHandlers = new Vector();
+ aDataObject = aData;
+ aDisplayObject = aDisplay;
+ }
+
+ public Object getDataObject() { return aDataObject; }
+ public Object getDisplayObject() { return aDisplayObject; }
+
+ public void addHandler( NodeHandler aHandler )
+ {
+ aHandlers.add( aHandler );
+ }
+
+
+ /** iterate over handlers and return child sum */
+ public int getChildCount()
+ {
+ int nRet = 0;
+ for(int i = 0; i < aHandlers.size(); i++)
+ {
+ nRet += ((NodeHandler)aHandlers.get(i)).
+ getChildCount( aDataObject );
+ }
+ return nRet;
+ }
+
+ /** iterate over handlers until the child is found */
+ public Object getChild(int nIndex)
+ {
+ if( nIndex >= 0 )
+ {
+ for(int i = 0; i < aHandlers.size(); i++)
+ {
+ // check if this handler has the child, and if not
+ // search with next handler
+ NodeHandler aHandler = (NodeHandler)aHandlers.get(i);
+ int nCount = aHandler.getChildCount( aDataObject );
+ if( nCount > nIndex )
+ return aHandler.getChild( aDataObject, nIndex );
+ else
+ nIndex -= nCount;
+ }
+ }
+
+ // nothing found?
+ return null;
+ }
+
+ /** this node is a leaf if have no handlers, or is those
+ handlers show no children */
+ public boolean isLeaf()
+ {
+ return (aHandlers.size() == 0) || (getChildCount() == 0);
+ }
+
+ public boolean equals(Object aOther)
+ {
+ return (this == aOther) || aDataObject.equals( aOther );
+ }
+
+ public String toString()
+ {
+ return aDisplayObject.toString();
+ }
+}