1 import java.util.Vector; 2 3 4 /** 5 * Map an arbitrary object into parts of a tree node. 6 */ 7 abstract class NodeHandler 8 { 9 /** This vector is used as cache for the child objects. 10 */ 11 protected Vector maChildList; 12 13 14 public abstract NodeHandler createHandler ( 15 com.sun.star.accessibility.XAccessibleContext xContext); 16 17 public NodeHandler () 18 { 19 maChildList = new Vector (); 20 } 21 22 /** Clear the cache of child objects. 23 */ 24 public void clear () 25 { 26 synchronized (maChildList) 27 { 28 maChildList = new Vector (); 29 } 30 } 31 32 /** This factory method creates an individual handler for the specified 33 object that may hold information to accelerate the access to its children. 34 */ 35 // public abstract NodeHandler createHandler (Object aObject); 36 37 /** return the number of children this object has */ 38 public int getChildCount(Object aObject) 39 { 40 synchronized (maChildList) 41 { 42 return maChildList.size(); 43 } 44 } 45 46 /** 47 * return a child object. Complex 48 * children have to be AccTreeNode instances. 49 * @see AccTreeNode 50 */ 51 public AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex) 52 { 53 synchronized (maChildList) 54 { 55 AccessibleTreeNode aChild = (AccessibleTreeNode)maChildList.get(nIndex); 56 if (aChild == null) 57 { 58 aChild = createChild (aParent, nIndex); 59 if (aChild == null) 60 aChild = new StringNode ("could not create child", aParent); 61 maChildList.setElementAt (aChild, nIndex); 62 } 63 return aChild; 64 } 65 } 66 67 public AccessibleTreeNode getChildNoCreate (AccessibleTreeNode aParent, int nIndex) 68 { 69 synchronized (maChildList) 70 { 71 return (AccessibleTreeNode)maChildList.get(nIndex); 72 } 73 } 74 75 /** Remove the specified child from the list of children. 76 */ 77 public boolean removeChild (AccessibleTreeNode aNode, int nIndex) 78 { 79 try 80 { 81 synchronized (maChildList) 82 { 83 System.out.println (" removing child at position " + nIndex + ": " 84 + maChildList.elementAt (nIndex)); 85 maChildList.remove (nIndex); 86 } 87 } 88 catch (Exception e) 89 { 90 return false; 91 } 92 return true; 93 } 94 95 public int indexOf (AccessibleTreeNode aNode) 96 { 97 synchronized (maChildList) 98 { 99 return maChildList.indexOf (aNode); 100 } 101 } 102 103 /** Create a child object for the specified data. This method is called 104 usually from getChild and put there into the cache. 105 */ 106 public abstract AccessibleTreeNode createChild ( 107 AccessibleTreeNode aParent, int nIndex); 108 109 // 110 // The following methods support editing of children and actions. 111 // They have default implementations for no actions and read-only. 112 // 113 114 /** May this child be changed? */ 115 public boolean isChildEditable (AccessibleTreeNode aNode, int nIndex) 116 { 117 return false; 118 } 119 120 /** change this child's value */ 121 // public void setChild(Object aObject, int nIndex) { } 122 123 124 /** get names of suported actions */ 125 public String[] getActions (AccessibleTreeNode aNode) 126 { 127 return new String[] {}; 128 } 129 130 /** perform action */ 131 public void performAction (AccessibleTreeNode aNode, int nIndex) 132 { 133 } 134 135 /** Update all children. 136 */ 137 public void update (AccessibleTreeNode aNode) 138 { 139 } 140 } 141