1*1b0aaa91SAndrew Rist /**************************************************************
2*1b0aaa91SAndrew Rist  *
3*1b0aaa91SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1b0aaa91SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1b0aaa91SAndrew Rist  * distributed with this work for additional information
6*1b0aaa91SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1b0aaa91SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1b0aaa91SAndrew Rist  * "License"); you may not use this file except in compliance
9*1b0aaa91SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1b0aaa91SAndrew Rist  *
11*1b0aaa91SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1b0aaa91SAndrew Rist  *
13*1b0aaa91SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1b0aaa91SAndrew Rist  * software distributed under the License is distributed on an
15*1b0aaa91SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1b0aaa91SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1b0aaa91SAndrew Rist  * specific language governing permissions and limitations
18*1b0aaa91SAndrew Rist  * under the License.
19*1b0aaa91SAndrew Rist  *
20*1b0aaa91SAndrew Rist  *************************************************************/
21*1b0aaa91SAndrew Rist 
22cdf0e10cSrcweir import java.util.Vector;
23cdf0e10cSrcweir 
24cdf0e10cSrcweir 
25cdf0e10cSrcweir /**
26cdf0e10cSrcweir  * Map an arbitrary object into parts of a tree node.
27cdf0e10cSrcweir  */
28cdf0e10cSrcweir abstract class NodeHandler
29cdf0e10cSrcweir {
30cdf0e10cSrcweir     /** This vector is used as cache for the child objects.
31cdf0e10cSrcweir     */
32cdf0e10cSrcweir     protected Vector maChildList;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir 
createHandler( com.sun.star.accessibility.XAccessibleContext xContext)35cdf0e10cSrcweir     public abstract NodeHandler createHandler (
36cdf0e10cSrcweir         com.sun.star.accessibility.XAccessibleContext xContext);
37cdf0e10cSrcweir 
NodeHandler()38cdf0e10cSrcweir     public NodeHandler ()
39cdf0e10cSrcweir     {
40cdf0e10cSrcweir         maChildList = new Vector ();
41cdf0e10cSrcweir     }
42cdf0e10cSrcweir 
43cdf0e10cSrcweir     /** Clear the cache of child objects.
44cdf0e10cSrcweir     */
clear()45cdf0e10cSrcweir     public void clear ()
46cdf0e10cSrcweir     {
47cdf0e10cSrcweir         synchronized (maChildList)
48cdf0e10cSrcweir         {
49cdf0e10cSrcweir             maChildList = new Vector ();
50cdf0e10cSrcweir         }
51cdf0e10cSrcweir     }
52cdf0e10cSrcweir 
53cdf0e10cSrcweir     /** This factory method creates an individual handler for the specified
54cdf0e10cSrcweir         object that may hold information to accelerate the access to its children.
55cdf0e10cSrcweir     */
56cdf0e10cSrcweir     //    public abstract NodeHandler createHandler (Object aObject);
57cdf0e10cSrcweir 
58cdf0e10cSrcweir     /** return the number of children this object has */
getChildCount(Object aObject)59cdf0e10cSrcweir     public int getChildCount(Object aObject)
60cdf0e10cSrcweir     {
61cdf0e10cSrcweir         synchronized (maChildList)
62cdf0e10cSrcweir         {
63cdf0e10cSrcweir             return maChildList.size();
64cdf0e10cSrcweir         }
65cdf0e10cSrcweir     }
66cdf0e10cSrcweir 
67cdf0e10cSrcweir     /**
68cdf0e10cSrcweir      * return a child object. Complex
69cdf0e10cSrcweir      * children have to be AccTreeNode instances.
70cdf0e10cSrcweir      * @see AccTreeNode
71cdf0e10cSrcweir      */
getChild(AccessibleTreeNode aParent, int nIndex)72cdf0e10cSrcweir     public AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex)
73cdf0e10cSrcweir     {
74cdf0e10cSrcweir         synchronized (maChildList)
75cdf0e10cSrcweir         {
76cdf0e10cSrcweir             AccessibleTreeNode aChild = (AccessibleTreeNode)maChildList.get(nIndex);
77cdf0e10cSrcweir             if (aChild == null)
78cdf0e10cSrcweir             {
79cdf0e10cSrcweir                 aChild = createChild (aParent, nIndex);
80cdf0e10cSrcweir                 if (aChild == null)
81cdf0e10cSrcweir                     aChild = new StringNode ("could not create child", aParent);
82cdf0e10cSrcweir                 maChildList.setElementAt (aChild, nIndex);
83cdf0e10cSrcweir             }
84cdf0e10cSrcweir             return aChild;
85cdf0e10cSrcweir         }
86cdf0e10cSrcweir     }
87cdf0e10cSrcweir 
getChildNoCreate(AccessibleTreeNode aParent, int nIndex)88cdf0e10cSrcweir     public AccessibleTreeNode getChildNoCreate (AccessibleTreeNode aParent, int nIndex)
89cdf0e10cSrcweir     {
90cdf0e10cSrcweir         synchronized (maChildList)
91cdf0e10cSrcweir         {
92cdf0e10cSrcweir             return (AccessibleTreeNode)maChildList.get(nIndex);
93cdf0e10cSrcweir         }
94cdf0e10cSrcweir     }
95cdf0e10cSrcweir 
96cdf0e10cSrcweir     /** Remove the specified child from the list of children.
97cdf0e10cSrcweir     */
removeChild(AccessibleTreeNode aNode, int nIndex)98cdf0e10cSrcweir     public boolean removeChild (AccessibleTreeNode aNode, int nIndex)
99cdf0e10cSrcweir     {
100cdf0e10cSrcweir         try
101cdf0e10cSrcweir         {
102cdf0e10cSrcweir             synchronized (maChildList)
103cdf0e10cSrcweir             {
104cdf0e10cSrcweir                 System.out.println ("    removing child at position " + nIndex + ": "
105cdf0e10cSrcweir                     + maChildList.elementAt (nIndex));
106cdf0e10cSrcweir                 maChildList.remove (nIndex);
107cdf0e10cSrcweir             }
108cdf0e10cSrcweir         }
109cdf0e10cSrcweir         catch (Exception e)
110cdf0e10cSrcweir         {
111cdf0e10cSrcweir             return false;
112cdf0e10cSrcweir         }
113cdf0e10cSrcweir         return true;
114cdf0e10cSrcweir     }
115cdf0e10cSrcweir 
indexOf(AccessibleTreeNode aNode)116cdf0e10cSrcweir     public int indexOf (AccessibleTreeNode aNode)
117cdf0e10cSrcweir     {
118cdf0e10cSrcweir         synchronized (maChildList)
119cdf0e10cSrcweir         {
120cdf0e10cSrcweir             return maChildList.indexOf (aNode);
121cdf0e10cSrcweir         }
122cdf0e10cSrcweir     }
123cdf0e10cSrcweir 
124cdf0e10cSrcweir     /** Create a child object for the specified data.  This method is called
125cdf0e10cSrcweir         usually from getChild and put there into the cache.
126cdf0e10cSrcweir     */
createChild( AccessibleTreeNode aParent, int nIndex)127cdf0e10cSrcweir     public abstract AccessibleTreeNode createChild (
128cdf0e10cSrcweir         AccessibleTreeNode aParent, int nIndex);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     //
131cdf0e10cSrcweir     // The following methods support editing of children and actions.
132cdf0e10cSrcweir     // They have default implementations for no actions and read-only.
133cdf0e10cSrcweir     //
134cdf0e10cSrcweir 
135cdf0e10cSrcweir     /** May this child be changed? */
isChildEditable(AccessibleTreeNode aNode, int nIndex)136cdf0e10cSrcweir     public boolean isChildEditable (AccessibleTreeNode aNode, int nIndex)
137cdf0e10cSrcweir     {
138cdf0e10cSrcweir         return false;
139cdf0e10cSrcweir     }
140cdf0e10cSrcweir 
141cdf0e10cSrcweir     /** change this child's value */
142cdf0e10cSrcweir     //    public void setChild(Object aObject, int nIndex) { }
143cdf0e10cSrcweir 
144cdf0e10cSrcweir 
145cdf0e10cSrcweir     /** get names of suported actions */
getActions(AccessibleTreeNode aNode)146cdf0e10cSrcweir     public String[] getActions (AccessibleTreeNode aNode)
147cdf0e10cSrcweir     {
148cdf0e10cSrcweir         return new String[] {};
149cdf0e10cSrcweir     }
150cdf0e10cSrcweir 
151cdf0e10cSrcweir     /** perform action */
performAction(AccessibleTreeNode aNode, int nIndex)152cdf0e10cSrcweir     public void performAction (AccessibleTreeNode aNode, int nIndex)
153cdf0e10cSrcweir     {
154cdf0e10cSrcweir     }
155cdf0e10cSrcweir 
156cdf0e10cSrcweir     /** Update all children.
157cdf0e10cSrcweir     */
update(AccessibleTreeNode aNode)158cdf0e10cSrcweir     public void update (AccessibleTreeNode aNode)
159cdf0e10cSrcweir     {
160cdf0e10cSrcweir     }
161cdf0e10cSrcweir }
162