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