2 * This file is part of the LibreOffice project.
4 * This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 * This file incorporates work covered by the following license notice:
10 * Licensed to the Apache Software Foundation (ASF) under one or more
11 * contributor license agreements. See the NOTICE file distributed
12 * with this work for additional information regarding copyright
13 * ownership. The ASF licenses this file to you under the Apache
14 * License, Version 2.0 (the "License"); you may not use this file
15 * except in compliance with the License. You may obtain a copy of
16 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 import java
.util
.ArrayList
;
21 import javax
.swing
.event
.TreeModelListener
;
22 import javax
.swing
.tree
.TreeModel
;
23 import javax
.swing
.tree
.TreePath
;
25 public class AccessibilityTreeModelBase
28 public AccessibilityTreeModelBase ()
31 maTMListeners
= new ArrayList
<TreeModelListener
>();
34 public synchronized void addTreeModelListener(TreeModelListener l
)
39 public synchronized void removeTreeModelListener(TreeModelListener l
)
41 maTMListeners
.remove(l
);
44 public synchronized int getChildCount(Object aParent
)
46 return (aParent
instanceof AccessibleTreeNode
) ?
47 ((AccessibleTreeNode
)aParent
).getChildCount() : 0;
50 public synchronized Object
getChild (Object aParent
, int nIndex
)
55 if (aParent
instanceof AccessibleTreeNode
)
56 aChild
= ((AccessibleTreeNode
)aParent
).getChild(nIndex
);
58 System
.out
.println ("getChild called for unknown parent node");
60 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
62 aChild
= ("no child " + nIndex
+ " from " + aParent
+ ": " + e
);
67 public synchronized Object
getChildNoCreate (Object aParent
, int nIndex
)
72 if (aParent
instanceof AccessibleTreeNode
)
73 aChild
= ((AccessibleTreeNode
)aParent
).getChildNoCreate(nIndex
);
75 System
.out
.println ("getChild called for unknown parent node");
77 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
82 /** iterate over all children and look for child */
83 public synchronized int getIndexOfChild (Object aParent
, Object aChild
)
88 if ((aParent
instanceof AccessibleTreeNode
) && (aChild
instanceof AccessibleTreeNode
))
90 AccessibleTreeNode aParentNode
= (AccessibleTreeNode
) aParent
;
91 AccessibleTreeNode aChildNode
= (AccessibleTreeNode
) aChild
;
93 int nChildCount
= aParentNode
.getChildCount();
94 for( int i
= 0; i
< nChildCount
; i
++ )
96 if (aChildNode
.equals (aParentNode
.getChild (i
)))
104 catch (com
.sun
.star
.lang
.IndexOutOfBoundsException e
)
106 // Return -1 by falling through.
113 public boolean isLeaf (Object aNode
)
115 return (aNode
instanceof AccessibleTreeNode
) ?
116 ((AccessibleTreeNode
)aNode
).isLeaf() : true;
121 public synchronized Object
getRoot()
126 public void valueForPathChanged(TreePath path
, Object newValue
)
129 protected synchronized void setRoot (AccessibleTreeNode aRoot
)
135 // The list of TreeModelListener objects.
136 protected ArrayList
<TreeModelListener
> maTMListeners
;
138 // The root node of the tree. Use setRoot to change it.
139 private AccessibleTreeNode maRoot
= null;