bump product version to 7.2.5.1
[LibreOffice.git] / toolkit / test / accessibility / AccessibilityTreeModelBase.java
blob5ff2d96c9e48011a32360c7cb597a347306a87ad
1 /*
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
26 implements TreeModel
28 public AccessibilityTreeModelBase ()
30 setRoot (null);
31 maTMListeners = new ArrayList<TreeModelListener>();
34 public synchronized void addTreeModelListener(TreeModelListener l)
36 maTMListeners.add(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)
52 Object aChild = null;
53 try
55 if (aParent instanceof AccessibleTreeNode)
56 aChild = ((AccessibleTreeNode)aParent).getChild(nIndex);
57 else
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);
64 return aChild;
67 public synchronized Object getChildNoCreate (Object aParent, int nIndex)
69 Object aChild = null;
70 try
72 if (aParent instanceof AccessibleTreeNode)
73 aChild = ((AccessibleTreeNode)aParent).getChildNoCreate(nIndex);
74 else
75 System.out.println ("getChild called for unknown parent node");
77 catch (com.sun.star.lang.IndexOutOfBoundsException e)
78 { }
79 return aChild;
82 /** iterate over all children and look for child */
83 public synchronized int getIndexOfChild (Object aParent, Object aChild)
85 int nIndex = -1;
86 try
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)))
98 nIndex = i;
99 break;
104 catch (com.sun.star.lang.IndexOutOfBoundsException e)
106 // Return -1 by falling through.
109 // not found?
110 return nIndex;
113 public boolean isLeaf (Object aNode)
115 return (aNode instanceof AccessibleTreeNode) ?
116 ((AccessibleTreeNode)aNode).isLeaf() : true;
121 public synchronized Object getRoot()
123 return maRoot;
126 public void valueForPathChanged(TreePath path, Object newValue)
129 protected synchronized void setRoot (AccessibleTreeNode aRoot)
131 maRoot = 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;