diff options
Diffstat (limited to 'toolkit/test/accessibility')
20 files changed, 1369 insertions, 667 deletions
diff --git a/toolkit/test/accessibility/AccTreeNode.java b/toolkit/test/accessibility/AccTreeNode.java index c8c861d6a77e..752db6692241 100644 --- a/toolkit/test/accessibility/AccTreeNode.java +++ b/toolkit/test/accessibility/AccTreeNode.java @@ -1,4 +1,6 @@ - +import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessible; +import drafts.com.sun.star.accessibility.XAccessibleContext; import java.util.Vector; /** @@ -8,92 +10,188 @@ import java.util.Vector; * type. */ class AccTreeNode + extends AccessibleTreeNode { - private Vector aHandlers; /// NodeHandlers for this node - private Object aDataObject; /// the actual data object - private Object aDisplayObject; /// object to be displayed + class HandlerDescriptor + { + public HandlerDescriptor (NodeHandler aHandler) + { + maHandler = aHandler; + mnChildCount = -1; + } + public NodeHandler maHandler; + public int mnChildCount; + } + /// NodeHandlers for this node + private Vector maHandlers; + + // The accessible context of this node. + private XAccessible mxAccessible; + private XAccessibleContext mxContext; + + public AccTreeNode (XAccessibleContext xContext, AccessibleTreeNode aParent) + { + this (xContext, xContext, aParent); + } - public AccTreeNode( Object aData ) + public AccTreeNode (XAccessibleContext xContext, Object aDisplay, AccessibleTreeNode aParent) { - this( aData, aData ); + super (aDisplay, aParent); + + maHandlers = new Vector(5); + mxContext = xContext; + mxAccessible = null; } - public AccTreeNode( Object aData, Object aDisplay ) + /** Update the internal data extracted from the corresponding accessible + object. This is done by replacing every handler by a new one. An + update method at each handler would be better of course. + */ + public void update () { - aHandlers = new Vector(); - aDataObject = aData; - aDisplayObject = aDisplay; + for (int i=0; i<maHandlers.size(); i++) + { + System.out.println ("replacing handler " + i); + HandlerDescriptor aDescriptor = (HandlerDescriptor)maHandlers.get(i); + aDescriptor.maHandler = aDescriptor.maHandler.createHandler (mxContext); + aDescriptor.mnChildCount = + aDescriptor.maHandler.getChildCount (this); + } } - public Object getDataObject() { return aDataObject; } - public Object getDisplayObject() { return aDisplayObject; } + public XAccessibleContext getContext() + { + return mxContext; + } + + public XAccessible getAccessible() + { + if ((mxAccessible == null) && (mxContext != null)) + mxAccessible = (XAccessible)UnoRuntime.queryInterface( + XAccessible.class, mxContext); + return mxAccessible; + } public void addHandler( NodeHandler aHandler ) { - aHandlers.add( aHandler ); + if (aHandler != null) + maHandlers.add (new HandlerDescriptor (aHandler)); } /** iterate over handlers and return child sum */ + protected HandlerDescriptor getHandlerDescriptor (int i) + { + HandlerDescriptor aDescriptor = (HandlerDescriptor)maHandlers.get(i); + if (aDescriptor.mnChildCount < 0) + aDescriptor.mnChildCount = + aDescriptor.maHandler.getChildCount (this); + return aDescriptor; + } + public int getChildCount() { - int nRet = 0; - for(int i = 0; i < aHandlers.size(); i++) + int nChildCount = 0; + for (int i = 0; i < maHandlers.size(); i++) { - nRet += ((NodeHandler)aHandlers.get(i)). - getChildCount( aDataObject ); + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + nChildCount += aDescriptor.mnChildCount; } - return nRet; + return nChildCount; } /** iterate over handlers until the child is found */ - public Object getChild(int nIndex) + public AccessibleTreeNode getChild (int nIndex) + throws IndexOutOfBoundsException { if( nIndex >= 0 ) { - for(int i = 0; i < aHandlers.size(); i++) + for(int i = 0; i < maHandlers.size(); i++) { // check if this handler has the child, and if not // search with next handler - NodeHandler aHandler = (NodeHandler)aHandlers.get(i); - int nCount = aHandler.getChildCount( aDataObject ); - if( nCount > nIndex ) - return aHandler.getChild( aDataObject, nIndex ); + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + if (nIndex < aDescriptor.mnChildCount) + return aDescriptor.maHandler.getChild (this, nIndex); else - nIndex -= nCount; + nIndex -= aDescriptor.mnChildCount; } } + else + throw new IndexOutOfBoundsException(); // nothing found? return null; } + public boolean removeChild (int nIndex) + throws IndexOutOfBoundsException + { + boolean bStatus = false; + if (nIndex >= 0) + { + for (int i=0; i<maHandlers.size(); i++) + { + // check if this handler has the child, and if not + // search with next handler + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + if (nIndex < aDescriptor.mnChildCount) + { + bStatus = aDescriptor.maHandler.removeChild (this, nIndex); + aDescriptor.mnChildCount = aDescriptor.maHandler.getChildCount (this); + break; + } + else + nIndex -= aDescriptor.mnChildCount; + } + } + else + throw new IndexOutOfBoundsException(); + + return bStatus; + } + - /** this node is a leaf if have no handlers, or is those - handlers show no children */ - public boolean isLeaf() + public int indexOf (AccessibleTreeNode aNode) { - return (aHandlers.size() == 0) || (getChildCount() == 0); + int nBaseIndex = 0; + if (aNode != null) + { + for (int i=0; i<maHandlers.size(); i++) + { + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + int nIndex = aDescriptor.maHandler.indexOf (aNode); + if (nIndex >= 0) + return nBaseIndex + nIndex; + else + nBaseIndex += aDescriptor.mnChildCount; + } + } + + return -1; } - public boolean equals(Object aOther) + /** this node is a leaf if have no handlers, or is those + handlers show no children */ + public boolean isLeaf() { - return (this == aOther) || aOther.equals( aDataObject ); + return (maHandlers.size() == 0);// || (getChildCount() == 0); } - public String toString() + public boolean equals (Object aOther) { - return aDisplayObject.toString(); + return (this == aOther) || aOther.equals(mxContext); } /** iterate over handlers until the child is found */ public void getActions(Vector aActions) { - for(int i = 0; i < aHandlers.size(); i++) + for(int i = 0; i < maHandlers.size(); i++) { - NodeHandler aHandler = (NodeHandler)aHandlers.get(i); - String[] aHandlerActions = aHandler.getActions( aDataObject ); + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + NodeHandler aHandler = aDescriptor.maHandler; + String[] aHandlerActions = aHandler.getActions (this); for(int j = 0; j < aHandlerActions.length; j++ ) { aActions.add( aHandlerActions[j] ); @@ -105,15 +203,16 @@ class AccTreeNode { if( nIndex >= 0 ) { - for(int i = 0; i < aHandlers.size(); i++) + for(int i = 0; i < maHandlers.size(); i++) { // check if this handler has the child, and if not // search with next handler - NodeHandler aHandler = (NodeHandler)aHandlers.get(i); - int nCount = aHandler.getActions( aDataObject ).length; + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + NodeHandler aHandler = aDescriptor.maHandler; + int nCount = aHandler.getActions(this).length; if( nCount > nIndex ) { - aHandler.performAction( aDataObject, nIndex ); + aHandler.performAction(this, nIndex ); return; } else @@ -122,4 +221,24 @@ class AccTreeNode } } + /** Try to add the specified accessible object as new accessible child of the + AccessibleTreeHandler. + Note that child is used in another context than + it is used in the other methods of this class. + */ + public AccessibleTreeNode addAccessibleChild (XAccessible xChild) + { + for(int i = 0; i < maHandlers.size(); i++) + { + HandlerDescriptor aDescriptor = getHandlerDescriptor (i); + if (aDescriptor.maHandler instanceof AccessibleTreeHandler) + { + AccessibleTreeHandler aHandler = (AccessibleTreeHandler)aDescriptor.maHandler; + AccessibleTreeNode aNode = aHandler.addAccessibleChild (this, xChild); + aDescriptor.mnChildCount = aHandler.getChildCount (this); + return aNode; + } + } + return null; + } } diff --git a/toolkit/test/accessibility/AccessibilityTree.java b/toolkit/test/accessibility/AccessibilityTree.java index abaedfcbfcaa..5342b9e5365c 100755 --- a/toolkit/test/accessibility/AccessibilityTree.java +++ b/toolkit/test/accessibility/AccessibilityTree.java @@ -42,12 +42,14 @@ public class AccessibilityTree */ public AccessibilityTree ( MessageInterface aMessageDisplay, - Canvas aCanvas) + Canvas aCanvas, + Print aPrinter) { maMessageDisplay = aMessageDisplay; maCanvas = aCanvas; + maPrinter = aPrinter; - setModel( new AccessibilityTreeModel( "Please press Update button" ) ); + setModel( new AccessibilityTreeModel( "Please press Update button", aMessageDisplay, aPrinter) ); maCellRenderer = new AccessibleTreeCellRenderer(); // setCellRenderer (maCellRenderer); @@ -56,7 +58,7 @@ public class AccessibilityTree // setEditable (true); // maTreeModel.addTreeModelListener( new TextUpdateListener() ); - addMouseListener( new MouseListener() ); + addMouseListener (new MouseListener (this)); } @@ -76,48 +78,84 @@ public class AccessibilityTree /** expand all nodes with accessibility roles > 100 */ class ShapeExpander extends Expander { - public boolean expand(Object aObject) + public boolean expand (Object aObject) { - aObject = AccessibilityTreeModel.normalize( aObject ); - XAccessibleContext xContext = - (XAccessibleContext)UnoRuntime.queryInterface( - XAccessibleContext.class, aObject ); - int nRole = ( xContext == null ) ? -1 : - xContext.getAccessibleRole(); - return (nRole >= 100); + if (aObject instanceof AccTreeNode) + { + AccTreeNode aNode = (AccTreeNode)aObject; + XAccessibleContext xContext = aNode.getContext(); + if (xContext != null) + if (xContext.getAccessibleRole() >= 100) + return true; + } + return false; } } + /** Expand the nodes in the subtree rooted in aNode according to the the + specified expander. The tree is locked during the expansion. + */ + protected void expandTree (AccessibleTreeNode aNode, Expander aExpander) + { + message ("Expanding tree"); + maPrinter.println ("Expanding tree:"); + setEnabled (false); + ((AccessibilityTreeModel)getModel()).lock (); + + try + { + expandTree (new TreePath (aNode.createPath()), aExpander); + } + catch (Exception e) + { + // Ignore + } + + setEnabled (true); + ((AccessibilityTreeModel)getModel()).unlock (aNode); + maPrinter.println ("Done."); + message (""); + } + private TreePath expandTree( TreePath aPath, Expander aExpander ) { // return first expanded object TreePath aFirst = null; - // get 'our' object - Object aObj = aPath.getLastPathComponent(); + // System.out.print ("e"); - // expand this object, if the Expander tells us so - if( aExpander.expand( aObj ) ) + try { - expandPath (aPath); - if( aFirst == null ) - aFirst = aPath; - } + // get 'our' object + Object aObj = aPath.getLastPathComponent(); - // visit all children - if( aObj instanceof AccTreeNode ) - { - AccTreeNode aNode = (AccTreeNode)aObj; - int nLength = aNode.getChildCount(); - for( int i = 0; i < nLength; i++ ) + // expand this object, if the Expander tells us so + if( aExpander.expand( aObj ) ) { - TreePath aRet = expandTree( - aPath.pathByAddingChild( aNode.getChild( i ) ), - aExpander ); + expandPath (aPath); if( aFirst == null ) - aFirst = aRet; + aFirst = aPath; + } + + // visit all children + if (aObj instanceof AccessibleTreeNode) + { + AccessibleTreeNode aNode = (AccessibleTreeNode)aObj; + int nLength = aNode.getChildCount(); + for( int i = 0; i < nLength; i++ ) + { + TreePath aRet = expandTree( + aPath.pathByAddingChild( aNode.getChild( i ) ), + aExpander ); + if( aFirst == null ) + aFirst = aRet; + } } } + catch (Exception e) + { + System.out.println ("caught exception while expanding tree path " + aPath + ": " + e); + } return aFirst; } @@ -127,21 +165,25 @@ public class AccessibilityTree * this method from the outside. */ public void expandShapes () { - message ("Expanding shapes."); - - TreePath aFirst = expandTree( new TreePath( getModel().getRoot() ), - new ShapeExpander() ); - if( aFirst != null ) - { - makeVisible (aFirst); - } + expandShapes ((AccessibleTreeNode)getModel().getRoot()); + } + public void expandShapes (AccessibleTreeNode aNode) + { + expandTree ( + new TreePath (aNode.createPath()), + new ShapeExpander()); } /** Expand all nodes */ public void expandAll () { - message ("Expanding complete tree"); - expandTree( new TreePath( getModel().getRoot() ), new AllExpander() ); + expandAll ((AccessibleTreeNode)getModel().getRoot()); + } + public void expandAll (AccessibleTreeNode aNode) + { + expandTree( + new TreePath (aNode.createPath()), + new AllExpander() ); } @@ -160,6 +202,8 @@ public class AccessibilityTree class MouseListener extends MouseAdapter { + private AccessibilityTree maTree; + public MouseListener (AccessibilityTree aTree) {maTree=aTree;} public void mousePressed(MouseEvent e) { popupTrigger(e); } public void mouseClicked(MouseEvent e) { popupTrigger(e); } public void mouseEntered(MouseEvent e) { popupTrigger(e); } @@ -172,28 +216,32 @@ public class AccessibilityTree if( bIsPopup ) { int selRow = getRowForLocation(e.getX(), e.getY()); - TreePath aPath = getPathForLocation(e.getX(), e.getY()); - - // check for actions - Object aObject = aPath.getLastPathComponent(); - if( aObject instanceof AccTreeNode ) + if (selRow != -1) { - AccTreeNode aNode = (AccTreeNode)aObject; - - JPopupMenu aMenu = new JPopupMenu(); + TreePath aPath = getPathForLocation(e.getX(), e.getY()); - Vector aActions = new Vector(); - aNode.getActions(aActions); - for( int i = 0; i < aActions.size(); i++ ) + // check for actions + Object aObject = aPath.getLastPathComponent(); + if( aObject instanceof AccTreeNode ) { - aMenu.add( new NodeAction( - aActions.elementAt(i).toString(), - aNode, i ) ); - } + AccTreeNode aNode = (AccTreeNode)aObject; + + JPopupMenu aMenu = new JPopupMenu(); + + Vector aActions = new Vector(); + aMenu.add (new ShapeExpandAction(maTree, aNode)); + aMenu.add (new SubtreeExpandAction(maTree, aNode)); + + aNode.getActions(aActions); + for( int i = 0; i < aActions.size(); i++ ) + { + aMenu.add( new NodeAction( + aActions.elementAt(i).toString(), + aNode, i ) ); + } - // show menu (if we have actions) - if( aActions.size() > 0 ) aMenu.show( AccessibilityTree.this, e.getX(), e.getY() ); + } } } @@ -218,6 +266,38 @@ public class AccessibilityTree maNode.performAction(mnIndex); } } + // This action expands all shapes in the subtree rooted in the specified node. + class ShapeExpandAction extends AbstractAction + { + private AccessibilityTree maTree; + private AccTreeNode maNode; + public ShapeExpandAction (AccessibilityTree aTree, AccTreeNode aNode) + { + super ("Expand Shapes"); + maTree = aTree; + maNode = aNode; + } + public void actionPerformed (ActionEvent e) + { + maTree.expandShapes (maNode); + } + } + // This action expands all nodes in the subtree rooted in the specified node. + class SubtreeExpandAction extends AbstractAction + { + private AccessibilityTree maTree; + private AccTreeNode maNode; + public SubtreeExpandAction (AccessibilityTree aTree, AccTreeNode aNode) + { + super ("Expand Subtree"); + maTree = aTree; + maNode = aNode; + } + public void actionPerformed (ActionEvent e) + { + maTree.expandAll (maNode); + } + } /** listen to tree model changes in order to update XAccessibleText objects @@ -381,6 +461,8 @@ public class AccessibilityTree protected MessageInterface maMessageDisplay; + protected Print + maPrinter; protected AccessibleTreeCellRenderer maCellRenderer; diff --git a/toolkit/test/accessibility/AccessibilityTreeModel.java b/toolkit/test/accessibility/AccessibilityTreeModel.java index ab933df174df..f005df4c8e9b 100644 --- a/toolkit/test/accessibility/AccessibilityTreeModel.java +++ b/toolkit/test/accessibility/AccessibilityTreeModel.java @@ -20,18 +20,45 @@ import com.sun.star.lang.XServiceInfo; public class AccessibilityTreeModel implements TreeModel, XAccessibleEventListener { - public AccessibilityTreeModel( Object aRoot ) + // Map to translate from accessible object to corresponding tree node. + protected HashMap maXAccessibleToNode; + + // Making both of these static is clearly a hack. + protected static MessageInterface maMessageArea; + protected static Print maPrinter; + protected static boolean mbVerbose = true; + + // If the lock count is higher then zero, then no events are processed. + private int mnLockCount; + + // The list of TreeModelListener objects. + private Vector maTMListeners; + + // default handlers, Vector<HandlerPair> + private static Vector aDefaultHandlers; + private static NodeHandler maContextHandler = new AccessibleContextHandler(); + private static NodeHandler maTextHandler = new AccessibleTextHandler(); + private static NodeHandler maEditableTextHandler = new AccessibleEditableTextHandler(); + private static NodeHandler maComponentHandler = new AccessibleComponentHandler(); + private static NodeHandler maExtendedComponentHandler = new AccessibleExtendedComponentHandler(); + private static NodeHandler maActionHandler = new AccessibleActionHandler(); + private static NodeHandler maImageHandler = new AccessibleImageHandler(); + private static NodeHandler maTableHandler = new AccessibleTableHandler(); + private static NodeHandler maHypertextHandler = new AccessibleHypertextHandler(); + private static NodeHandler maHyperlinkHandler = new AccessibleHyperlinkHandler(); + private static NodeHandler maTreeHandler = new AccessibleTreeHandler(); + + public AccessibilityTreeModel (Object aRoot, MessageInterface aMessageArea, Print aPrinter) { // create default node (unless we have a 'proper' node) - if( ! (aRoot instanceof AccTreeNode) ) - aRoot = createDefaultNode( aRoot ); + if( ! (aRoot instanceof AccessibleTreeNode) ) + aRoot = new StringNode ("Root", null); maRoot = aRoot; + maMessageArea = aMessageArea; + maPrinter = aPrinter; - aListeners = new Vector(); - aParents = new HashMap(); - aChildren = new HashMap(); - aNodes = new HashMap(); - aNodes.put( normalize(maRoot), maRoot ); + maTMListeners = new Vector(); + maXAccessibleToNode = new HashMap (); // syncronous or asyncronous event delivery? (i.e. same thread // or in s seperate event delivery thread) @@ -39,6 +66,29 @@ public class AccessibilityTreeModel xListener = new QueuedListener(); // asyncronous event delivery } + /** Lock the tree. While the tree is locked, events from the outside are + not processed. Lock the tree when you change its internal structure. + */ + public void lock () + { + mnLockCount += 1; + } + + /** Unlock the tree. After unlocking the tree as many times as locking + it, a treeStructureChange event is sent to the event listeners. + @param aNodeHint + If not null and treeStructureChange events are thrown then this + node is used as root of the modified subtree. + */ + public void unlock (AccessibleTreeNode aNodeHint) + { + mnLockCount -= 1; + if (mnLockCount == 0) + { + if (aNodeHint instanceof AccTreeNode) + fireTreeStructureChanged (createEvent (((AccTreeNode)aNodeHint).getAccessible())); + } + } // // the root node @@ -58,198 +108,150 @@ public class AccessibilityTreeModel public int getChildCount(Object aParent) { - return (aParent instanceof AccTreeNode) ? - ((AccTreeNode)aParent).getChildCount() : 0; + return (aParent instanceof AccessibleTreeNode) ? + ((AccessibleTreeNode)aParent).getChildCount() : 0; } - public Object getChild(Object aParent, int nIndex) + public Object getChild (Object aParent, int nIndex) { - Object aRet = (aParent instanceof AccTreeNode) ? - ((AccTreeNode)aParent).getChild(nIndex) : null; - setNode( aParent, nIndex, aRet ); // update tree cache - return aRet; + Object aChild = null; + try + { + if (aParent instanceof AccessibleTreeNode) + aChild = getChild ((AccessibleTreeNode)aParent, nIndex); + else + System.out.println ("getChild called for unknown parent node"); + } + catch (com.sun.star.lang.IndexOutOfBoundsException e) + { + aChild = ("no child " + nIndex + " from " + aParent + ": " + e); + } + return aChild; + } + + /** Delegate the request to the parent and then register listeners at + the child and add the child to the canvas. + */ + public synchronized AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex) + throws com.sun.star.lang.IndexOutOfBoundsException + { + AccessibleTreeNode aChild = null; + if (aParent != null) + aChild = aParent.getChild(nIndex); + registerAccListener (aChild); + + // Keep translation table up-to-date. + if (aChild != null) + if (aChild instanceof AccTreeNode) + { + maXAccessibleToNode.put (((AccTreeNode)aChild).getAccessible(), aChild); + addToCanvas ((AccTreeNode)aChild); + } + if (aChild == null) + System.out.println ("getChild: child not found"); + return aChild; } /** iterate over all children and look for child */ - public int getIndexOfChild(Object aParent, Object aChild) + public int getIndexOfChild (Object aParent, Object aChild) { - aChild = normalize( aChild ); + int nIndex = -1; + try + { + if ((aParent instanceof AccessibleTreeNode) && (aChild instanceof AccessibleTreeNode)) + { + AccessibleTreeNode aParentNode = (AccessibleTreeNode) aParent; + AccessibleTreeNode aChildNode = (AccessibleTreeNode) aChild; - // compare to all children - int nChildCount = getChildCount( aParent ); - for( int i = 0; i < nChildCount; i++ ) + int nChildCount = aParentNode.getChildCount(); + for( int i = 0; i < nChildCount; i++ ) + { + if (aChildNode.equals (aParentNode.getChild (i))) + { + nIndex = i; + break; + } + } + } + } + catch (com.sun.star.lang.IndexOutOfBoundsException e) { - if( aChild.equals( normalize( getChild(aParent, i) ) ) ) - return i; + // Return -1 by falling through. } // not found? - return -1; + return nIndex; } - public boolean isLeaf(Object aNode) + public boolean isLeaf (Object aNode) { - return (aNode instanceof AccTreeNode) ? - ((AccTreeNode)aNode).isLeaf() : true; + return (aNode instanceof AccessibleTreeNode) ? + ((AccessibleTreeNode)aNode).isLeaf() : true; } - // - // tree cache and child cache - // - - /** store parents of an object in the tree; HashMap<Object> */ - private HashMap aParents; - - /** store a vector with the children in each tree; - * HashMap<Vector<Object>> */ - private HashMap aChildren; - /** store a mapping of 'normalized' nodes to nodes in the tree */ - private HashMap aNodes; - - - /** normalize an object reference: - * 0) for an Any, get the containing Object - * 1) for AccTreeNode, get the data object - * 2) for XAccessible, get the accessible object - * 3) cast all UNO objects to XInterface - */ - static protected Object normalize(Object aObject) + /** Remove a node (and all children) from the tree model. + */ + protected synchronized void removeNode (AccessibleTreeNode aNode) { - // 0) for an Any, get the containing Object - if( aObject instanceof Any ) - aObject = ((Any)aObject).getObject(); - - // 1) for AccTreeNode, get the data object - if( aObject instanceof AccTreeNode ) - aObject = ((AccTreeNode)aObject).getDataObject(); - - if( aObject instanceof XInterface ) + try { - // 2) for XAccessible, get the accessible object - XAccessible xAcc = (XAccessible)UnoRuntime.queryInterface( - XAccessible.class, aObject); - if( xAcc != null ) - aObject = xAcc.getAccessibleContext(); - - // 3) cast all UNO objects to XInterface - aObject = (XInterface)UnoRuntime.queryInterface( XInterface.class, - aObject); - } - return aObject; - } - - /** add a parent/child int the node cache */ - protected void setNode(Object aOParent, int nIndex, Object aOChild) - { - Object aParent = normalize(aOParent); - Object aChild = normalize(aOChild); - - // store nodes - aNodes.put( aParent, aOParent ); - aNodes.put( aChild, aOChild ); - - // store the child's parent - aParents.put( aChild, aParent ); + if( aNode == null ) + return; + removeAccListener (aNode); + removeFromCanvas (aNode); + if (aNode instanceof AccTreeNode) + maXAccessibleToNode.remove (((AccTreeNode)aNode).getAccessible()); + AccessibleTreeNode aParent = aNode.getParent(); + if (aParent != null) + { + int nIndex = aParent.indexOf(aNode); + aParent.removeChild (nIndex); + } - // store the parent's child - Vector aKids = (Vector)aChildren.get( aParent ); - if( aKids == null ) + // depth-first removal of children + while (aNode.getChildCount() > 0) + removeNode (aNode.getChild (0)); + } + catch (com.sun.star.lang.IndexOutOfBoundsException e) { - // no children known... insert a new vector - aKids = new Vector(); - aChildren.put( aParent, aKids ); + // Ignore. } - - // make sure we have enough room - if( aKids.size() <= nIndex ) - aKids.setSize( nIndex + 1 ); // alternative: use child count - - // add child at appropriate positions; remove old listeners, - // get new ones - removeAccListener( aKids.elementAt( nIndex ) ); - aKids.setElementAt( aChild, nIndex ); - registerAccListener( aKids.elementAt( nIndex ) ); - - // update canvas - addToCanvas( aChild ); } - /** remove a node (and all children) from the node cache */ - protected void removeNode(Object aNode) + protected synchronized boolean addNode (AccTreeNode aParentNode, XAccessible xNewChild) { - if( aNode == null ) - return; - - aNode = normalize( aNode ); - removeAccListener( aNode ); - - // get parent + kids (before this information is deleted) - Vector aKids = (Vector)aChildren.get( aNode ); - Object aParent = aParents.get( aNode ); - - // remove information about this node - removeFromCanvas( aNode ); // update canvas - aParents.remove( aNode ); - aChildren.remove( aNode ); - aNodes.remove( aNode ); + boolean bRet = false; - // depth-first removal of children - int nLength = (aKids == null) ? 0 : aKids.size(); - for( int i = nLength-1; i >= 0; i-- ) + AccessibleTreeNode aChildNode = (AccessibleTreeNode)maXAccessibleToNode.get (xNewChild); + if (aChildNode == null) { - removeNode( aKids.elementAt(i) ); - } - - // remove from parents' child vector - if( aParent != null ) - { - Vector aParentKids = (Vector)aChildren.get( aParent ); - if( aParentKids != null ) - aParentKids.remove( aNode ); + AccTreeNode aChild = (AccTreeNode)((AccTreeNode)aParentNode).addAccessibleChild (xNewChild); + TreePath aPath = new TreePath (createPath (aChild)); + if (aChild != null) + { + registerAccListener (aChild); + maXAccessibleToNode.put (aChild.getAccessible(), aChild); + addToCanvas (aChild); + } + bRet = true; } - } + else + System.out.println ("node already present"); - /** determine whether this node is in the node cache */ - protected boolean knowsNode(Object aNode) - { - // we never 'know' null; we 'know' a node if it has a parent - return (aNode != null) && (aNodes.get(normalize(aNode)) != null); + return bRet; } - protected Object getNode(Object aObject) - { - return aNodes.get( normalize(aObject) ); - } - - /** recursively traverse aParents, and add nodes to path in - * post-order fashion. This causes the root to be the first - * element, just as demanded by TreeModelEvent. - * @see javax.swing.event.TreeModelEvent#TreeModelEvent - */ - private void createPath(Object aNode, Vector aPath) - { - aNode = normalize(aNode); - Object aParent = aParents.get(aNode); - if( aParent != null ) - createPath( aParent, aPath ); - Object aPathElem = aNodes.get(aNode); - if( aPathElem != null ) - aPath.add( aPathElem ); - else - System.out.println("Unknown node in path! (" + aNode + - ", pos. " + aPath.size() + ")"); - } /** create path to node, suitable for TreeModelEvent constructor * @see javax.swing.event.TreeModelEvent#TreeModelEvent */ - protected Object[] createPath(Object aNode) + protected Object[] createPath (AccessibleTreeNode aNode) { Vector aPath = new Vector(); - createPath( aNode, aPath ); + aNode.createPath (aPath); return aPath.toArray(); } @@ -260,93 +262,88 @@ public class AccessibilityTreeModel // tree cache, and we should get removed as soon as they are out. // - Vector aListeners; - public void addTreeModelListener(TreeModelListener l) { - aListeners.add(l); + maTMListeners.add(l); } public void removeTreeModelListener(TreeModelListener l) { - aListeners.remove(l); + maTMListeners.remove(l); } protected void fireTreeNodesChanged(TreeModelEvent e) { System.out.println("treeNodesChanges: " + e); - for(int i = 0; i < aListeners.size(); i++) + for(int i = 0; i < maTMListeners.size(); i++) { - ((TreeModelListener)aListeners.get(i)).treeNodesChanged(e); + ((TreeModelListener)maTMListeners.get(i)).treeNodesChanged(e); } } protected void fireTreeNodesInserted(final TreeModelEvent e) { System.out.println("treeNodesInserted: " + e); - for(int i = 0; i < aListeners.size(); i++) + for(int i = 0; i < maTMListeners.size(); i++) { - ((TreeModelListener)aListeners.get(i)).treeNodesInserted(e); + ((TreeModelListener)maTMListeners.get(i)).treeNodesInserted(e); } } protected void fireTreeNodesRemoved(final TreeModelEvent e) { System.out.println("treeNodesRemoved: " + e); - for(int i = 0; i < aListeners.size(); i++) + for(int i = 0; i < maTMListeners.size(); i++) { - ((TreeModelListener)aListeners.get(i)).treeNodesRemoved(e); + ((TreeModelListener)maTMListeners.get(i)).treeNodesRemoved(e); } } - protected void fireTreeStructureChanged(final TreeModelEvent e) + protected synchronized void fireTreeStructureChanged(final TreeModelEvent e) { System.out.println("treeStructureChanged: " + e); - for(int i = 0; i < aListeners.size(); i++) + for(int i = 0; i < maTMListeners.size(); i++) { - ((TreeModelListener)aListeners.get(i)).treeStructureChanged(e); + ((TreeModelListener)maTMListeners.get(i)).treeStructureChanged(e); } } - protected TreeModelEvent createEvent( Object aNode ) + protected TreeModelEvent createEvent (XAccessible xParent) { - return createEvent( aNode, null ); + return createEvent (xParent, null ); } - protected TreeModelEvent createEvent( Object aParent, Object aChild ) + /** Create a TreeModelEvent object that informs listeners that one child + has been removed from or inserted into its parent. + */ + protected TreeModelEvent createEvent (XAccessible xParent, XAccessible xChild) { // get parent node and create the tree path - Object aParentNode = getNode( aParent ); - Object[] aPath = createPath( aParentNode ); - - // if we already know the node (e.g. when deleting a node), - // use the position from the node cache. Else (e.g. when - // inserting a node), call getIndexOfChild to look for it. - int nIndex =-1; - if( aChild != null ) - { - if( knowsNode( aChild ) ) - { - Vector aKids = (Vector)aChildren.get( aParent ); - if( aKids != null ) - { - nIndex = aKids.indexOf( getNode( aChild ) ); - } - } - else - nIndex = getIndexOfChild( aParentNode, aChild ); - } - - - // If we have a position, broadcast the position, otherwise - // create a 'position-less' event without the child info. - return ( nIndex == -1 ) - ? new TreeModelEvent( this, aPath ) - : new TreeModelEvent( this, aPath, - new int[] { nIndex }, - new Object[] { getNode( aChild ) } ); + AccessibleTreeNode aParentNode = (AccessibleTreeNode)maXAccessibleToNode.get (xParent); + Object[] aPathToParent = createPath (aParentNode); + + AccessibleTreeNode aChildNode = null; + if (xChild != null) + aChildNode = (AccessibleTreeNode)maXAccessibleToNode.get (xChild); + int nIndexInParent = -1; + if (xChild != null) + nIndexInParent = aParentNode.indexOf (aChildNode); + + System.out.println (aParentNode + " " + aChildNode); + + if (nIndexInParent == -1) + // This event may be passed only to treeStructureChanged of the listeners. + return new TreeModelEvent (this, + aPathToParent); + else + // General purpose event for removing or inserting known nodes. + return new TreeModelEvent (this, + aPathToParent, + new int[] {nIndexInParent}, + new Object[] {aChildNode} ); } + /** * broadcast a tree event in a seperate Thread * must override fire method @@ -355,9 +352,9 @@ public class AccessibilityTreeModel { public void run() { - for(int i = 0; i < aListeners.size(); i++) + for(int i = 0; i < maTMListeners.size(); i++) { - fire( (TreeModelListener)aListeners.get(i) ); + fire( (TreeModelListener)maTMListeners.get(i) ); } } @@ -375,7 +372,7 @@ public class AccessibilityTreeModel protected XAccessibleEventBroadcaster getBroadcaster( Object aObject ) { if( aObject instanceof AccTreeNode ) - aObject = ((AccTreeNode)aObject).getDataObject(); + aObject = ((AccTreeNode)aObject).getContext(); return (XAccessibleEventBroadcaster) UnoRuntime.queryInterface ( XAccessibleEventBroadcaster.class, aObject); } @@ -411,105 +408,78 @@ public class AccessibilityTreeModel // static methods + members for creating default nodes // - // default handlers, Vector<HandlerPair> - private static Vector aDefaultHandlers; - - // initialize default handlers - static - { - aDefaultHandlers = new Vector(); - aDefaultHandlers.add( - new HandlerPair( Vector.class, - new VectorHandler() ) ); - - aDefaultHandlers.add( - new HandlerPair( XAccessibleContext.class, - new AccessibleContextHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleContext.class, - new AccessibleTreeHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleText.class, - new AccessibleTextHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleComponent.class, - new AccessibleComponentHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleExtendedComponent.class, - new AccessibleExtendedComponentHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleAction.class, - new AccessibleActionHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleImage.class, - new AccessibleImageHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleTable.class, - new AccessibleTableHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleEditableText.class, - new AccessibleEditableTextHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleHypertext.class, - new AccessibleHypertextHandler() ) ); - aDefaultHandlers.add( - new HandlerPair( XAccessibleHyperlink.class, - new AccessibleHyperlinkHandler() ) ); - - // ... ADD NEW DEFAULT HANDLERS HERE ... - - } - /** add default handlers based on the supported interfaces */ - public static void addDefaultHandlers( AccTreeNode aNode ) + public static void addDefaultHandlers (AccTreeNode aNode, XAccessibleContext xContext) { - Object aObject = aNode.getDataObject(); - - // try each type - Enumeration aEnum = aDefaultHandlers.elements(); - while( aEnum.hasMoreElements() ) + if (false) { - HandlerPair aPair = (HandlerPair)aEnum.nextElement(); - Class aType = aPair.aType; + // Slow but complete version: try each handler type separately. + aNode.addHandler (maContextHandler.createHandler (xContext)); + aNode.addHandler (maTextHandler.createHandler (xContext)); + aNode.addHandler (maEditableTextHandler.createHandler (xContext)); + aNode.addHandler (maComponentHandler.createHandler (xContext)); + aNode.addHandler (maExtendedComponentHandler.createHandler (xContext)); + aNode.addHandler (maActionHandler.createHandler (xContext)); + aNode.addHandler (maImageHandler.createHandler (xContext)); + aNode.addHandler (maTableHandler.createHandler (xContext)); + aNode.addHandler (maHypertextHandler.createHandler (xContext)); + aNode.addHandler (maHyperlinkHandler.createHandler (xContext)); + aNode.addHandler (maTreeHandler.createHandler (xContext)); + } + else + { + // Exploit dependencies between interfaces. + NodeHandler aHandler; + aNode.addHandler (maContextHandler.createHandler (xContext)); - // try instanceof, and a UNO query, if we have an XInterface - if( aType.isInstance( aObject ) ) + aHandler = maTextHandler.createHandler (xContext); + if (aHandler != null) { - aNode.addHandler( aPair.aHandler ); + aNode.addHandler (aHandler); + aNode.addHandler (maEditableTextHandler.createHandler (xContext)); + aNode.addHandler (maHypertextHandler.createHandler (xContext)); + aNode.addHandler (maHyperlinkHandler.createHandler (xContext)); } - else if( XInterface.class.isAssignableFrom( aType ) ) + aHandler = maComponentHandler.createHandler (xContext); + if (aHandler != null) { - Object aQuery = UnoRuntime.queryInterface(aType, aObject); - if( aQuery != null ) - aNode.addHandler( aPair.aHandler ); + aNode.addHandler (aHandler); + aNode.addHandler (maExtendedComponentHandler.createHandler (xContext)); } + aNode.addHandler (maActionHandler.createHandler (xContext)); + aNode.addHandler (maImageHandler.createHandler (xContext)); + aNode.addHandler (maTableHandler.createHandler (xContext)); + aNode.addHandler (maTreeHandler.createHandler (xContext)); } } /** create a node with the default handlers */ - public static AccTreeNode createDefaultNode( Object aObject ) + public static AccTreeNode createDefaultNode (XAccessible xAccessible, AccessibleTreeNode aParent) { // default: aObject + aDisplay - Object aDisplay = aObject; + String sDisplay; // if we are accessible, we use the context + name instead - XAccessible xAccessible = - (XAccessible) UnoRuntime.queryInterface ( - XAccessible.class, aObject); + XAccessibleContext xContext = null; if (xAccessible != null) - { - XAccessibleContext aContext = xAccessible.getAccessibleContext(); + xContext = xAccessible.getAccessibleContext(); + if (xContext != null) + sDisplay = xContext.getAccessibleName(); + else + sDisplay = new String ("not accessible"); - // for accessibles, use context + name! - aObject = aContext; - aDisplay = aContext.getAccessibleName(); - } // create node, and add default handlers - AccTreeNode aNode = new AccTreeNode( aObject, aDisplay ); - AccessibilityTreeModel.addDefaultHandlers( aNode ); + AccTreeNode aNode = new AccTreeNode (xContext, sDisplay, aParent); + AccessibilityTreeModel.addDefaultHandlers (aNode, xContext); + + if (mbVerbose) + maPrinter.print (". "); + + if (aNode == null) + System.out.println ("createDefaultNode == null"); return aNode; } @@ -537,7 +507,7 @@ public class AccessibilityTreeModel public void disposing( EventObject aEvent) { - System.out.println("dispose: " + objectToString(aEvent.Source)); + /* System.out.println("dispose: " + objectToString(aEvent.Source)); if( knowsNode( aEvent.Source ) ) { @@ -546,7 +516,7 @@ public class AccessibilityTreeModel removeNode( aEvent.Source ); // fireTreeStructureChanged( createEvent( getRoot() ) ); } - + */ } static final String[] aEventNames = @@ -562,39 +532,74 @@ public class AccessibilityTreeModel "[UNKNOWN]" }; - public void notifyEvent( AccessibleEventObject aEvent ) + /** This method is called from accessible objects that broadcast + modifications of themselves or from their children. The event is + processed only, except printing some messages, if the tree is not + locked. It should be locked during changes to its internal + structure like expanding nodes. + */ + public synchronized void notifyEvent( AccessibleEventObject aEvent ) { int nId = aEvent.EventId; if( (nId < 0) || (nId >= aEventNames.length) ) nId = 0; - Object aSource = normalize( aEvent.Source ); - Object aOld = normalize( aEvent.OldValue ); - Object aNew = normalize( aEvent.NewValue ); + System.out.println( "notify: " + aEvent.EventId + " " + + aEventNames[nId] + ": " + + objectToString(aEvent.Source) + " " + + objectToString(aEvent.OldValue) + "->" + + objectToString(aEvent.NewValue) ); - System.out.println( "notify: " + aEvent.EventId + " " + - aEventNames[nId] + ": " + - objectToString(aEvent.Source) + " (" + - (knowsNode(aEvent.Source) ? "known" : "unknown") + - "), " + - objectToString(aEvent.OldValue) + "->" + - objectToString(aEvent.NewValue) ); + if (mnLockCount > 0) + { + System.out.println ("ignoring event because tree is locked"); + return; + } + XAccessible xSource = (XAccessible)UnoRuntime.queryInterface( + XAccessible.class,aEvent.Source); switch( aEvent.EventId ) { case AccessibleEventId.ACCESSIBLE_CHILD_EVENT: // fire insertion and deletion events: - if( aOld != null ) + if (aEvent.OldValue != null) { - TreeModelEvent aTreeEvent = createEvent( aSource, aOld ); - removeNode( aOld ); - fireTreeNodesRemoved( aTreeEvent ); + XAccessible xOld = (XAccessible)UnoRuntime.queryInterface( + XAccessible.class,aEvent.OldValue); + // Create event before removing the node to get the old + // index of the node. + TreeModelEvent aRemoveEvent = createEvent (xSource, xOld); + removeNode ((AccessibleTreeNode)maXAccessibleToNode.get (xOld)); + fireTreeNodesRemoved (aRemoveEvent); } - if( aNew != null ) + // Insertion and removal of children should be mutually + // exclusive. But then there is this 'should' ... + if (aEvent.NewValue != null) { - fireTreeNodesInserted( createEvent( aSource, aNew ) ); + XAccessible xNew = (XAccessible)UnoRuntime.queryInterface( + XAccessible.class,aEvent.NewValue); + // Create event after inserting it so that its new index + // in the parent can be determined. + AccessibleTreeNode aParentNode = (AccessibleTreeNode)maXAccessibleToNode.get (xSource); + if (aParentNode instanceof AccTreeNode) + { + if (addNode ((AccTreeNode)aParentNode, xNew)) + { + ((AccTreeNode)aParentNode).update (); + updateOnCanvas (xSource); + + // A call to fireTreeNodesInserted for xNew + // should be sufficient but at least the + // StringNode object that contains the number of + // children also changes and we do not know its + // index relative to its parent. Therefore the + // more expensive fireTreeStructureChanged is + // necessary. + fireTreeStructureChanged (createEvent (xSource)); + } + } } break; case AccessibleEventId.ACCESSIBLE_TABLE_MODEL_CHANGED: @@ -628,8 +633,13 @@ public class AccessibilityTreeModel case AccessibleEventId.LABEL_FOR_PROPERTY: case AccessibleEventId.LABELED_BY_PROPERTY: case AccessibleEventId.MEMBER_OF_PROPERTY: - fireTreeNodesChanged( createEvent( aSource ) ); - updateOnCanvas( aSource ); + // fireTreeNodesChanged (createEvent + // (xSource)); + // Some child(s) of xSource have changed. We do not know + // which so all we can do is send a structure change event + // to all listeners. + fireTreeStructureChanged (createEvent (xSource)); + updateOnCanvas (xSource); break; @@ -660,13 +670,15 @@ public class AccessibilityTreeModel return xAcc; } - protected void addToCanvas( Object aObject ) + protected void addToCanvas (AccTreeNode aNode) { - XAccessibleContext xContext = getContext( aObject ); - if( (maCanvas != null) && (xContext != null) ) - maCanvas.addContext( xContext, - new TreePath( createPath( xContext ) ) ); - } + return; + /* XAccessibleContext xContext = aNode.getContext(); + if ((maCanvas != null) && (xContext != null)) + maCanvas.addContext ( + xContext, + new TreePath (createPath (aNode))); + */ } protected void removeFromCanvas( Object aObject ) { diff --git a/toolkit/test/accessibility/AccessibilityWorkBench.java b/toolkit/test/accessibility/AccessibilityWorkBench.java index 8021e12f5d09..7814e146ce9b 100755 --- a/toolkit/test/accessibility/AccessibilityWorkBench.java +++ b/toolkit/test/accessibility/AccessibilityWorkBench.java @@ -179,7 +179,7 @@ public class AccessibilityWorkBench maMainPanel.add (aScrollPane); // Accessible Tree. - maTree = new AccessibilityTree (this, maCanvas); + maTree = new AccessibilityTree (this, maCanvas, this); aScrollPane = new JScrollPane(maTree, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); @@ -212,8 +212,8 @@ public class AccessibilityWorkBench aConnectButton = createButton ("Connect", "connect"); aLoadButton = createButton ("Load", "load"); aUpdateButton = createButton ("Update", "update"); - aShapesButton = createButton ("Shapes", "shapes"); - aExpandButton = createButton ("Expand", "expand"); + aShapesButton = createButton ("Expand Shapes", "shapes"); + aExpandButton = createButton ("Expand All", "expand"); aTextButton = createButton("Text", "text"); aQuitButton = createButton ("Quit", "quit"); @@ -232,6 +232,7 @@ public class AccessibilityWorkBench public JButton createButton (String title, String command) { JButton aButton = new JButton (title); + aButton.setEnabled (false); aButton.setActionCommand (command); aButton.addActionListener (this); GridBagConstraints constraints = new GridBagConstraints (); @@ -253,10 +254,18 @@ public class AccessibilityWorkBench // create new model (with new documents) AccessibilityTreeModel aModel = - new AccessibilityTreeModel( createTreeModelRoot() ); + new AccessibilityTreeModel (createTreeModelRoot(), this, this); aModel.setCanvas( maCanvas ); maTree.setModel( aModel ); + aConnectButton.setEnabled (true); + aQuitButton.setEnabled (true); + aLoadButton.setEnabled (true); + aUpdateButton.setEnabled (true); + aExpandButton.setEnabled (true); + aShapesButton.setEnabled (true); + aTextButton.setEnabled (true); + // if (office != null && office.getDesktop() != null) // office.getDesktop().addTerminateListener (this); } @@ -293,15 +302,22 @@ public class AccessibilityWorkBench } else if (e.getActionCommand().equals("shapes")) { + Cursor aCursor = getCursor(); + setCursor (new Cursor (Cursor.WAIT_CURSOR)); maTree.expandShapes(); + setCursor (aCursor); } else if (e.getActionCommand().equals("expand")) { + Cursor aCursor = getCursor(); + setCursor (new Cursor (Cursor.WAIT_CURSOR)); maTree.expandAll(); + setCursor (aCursor); } else if (e.getActionCommand().equals("text")) { Canvas.bPaintText = ! Canvas.bPaintText; + maCanvas.repaint (); } else { @@ -315,8 +331,8 @@ public class AccessibilityWorkBench /** Create an AccessibilityTreeModel root which contains the documents */ private Object createTreeModelRoot() { - Vector aRoots = new Vector(); - + // create root node + VectorNode aRoot = new VectorNode ("Accessibility Tree", null); try { XDesktop xDesktop = office.getDesktop(); @@ -344,11 +360,9 @@ public class AccessibilityWorkBench XAccessible xRoot = office.getAccessibleRoot (xWindow); // create document node - aRoots.add( - AccessibilityTreeModel.createDefaultNode(xRoot) ); + aRoot.addChild ( + AccessibilityTreeModel.createDefaultNode (xRoot, aRoot)); } - else - aRoots.add( "can't cast component to model" ); } println ("finished getting named documents"); } @@ -357,10 +371,7 @@ public class AccessibilityWorkBench System.out.println ("caught exception while getting document names: " + e); } - // create root node - AccTreeNode aNode = new AccTreeNode( aRoots, "Accessibility Tree" ); - AccessibilityTreeModel.addDefaultHandlers( aNode ); - return aNode; + return aRoot; } @@ -517,6 +528,7 @@ public class AccessibilityWorkBench public void print (String text) { maOutputArea.append (text); + maOutputArea.paintImmediately (maOutputArea.getVisibleRect()); } @@ -527,6 +539,7 @@ public class AccessibilityWorkBench maOutputArea.append (text + "\n"); JScrollBar aBar = maScrollPane.getVerticalScrollBar(); aBar.setValue (aBar.getMaximum()); + maOutputArea.paintImmediately (maOutputArea.getVisibleRect()); } diff --git a/toolkit/test/accessibility/AccessibleActionHandler.java b/toolkit/test/accessibility/AccessibleActionHandler.java index e0c5b6cbb56a..ba9cd2793d00 100644 --- a/toolkit/test/accessibility/AccessibleActionHandler.java +++ b/toolkit/test/accessibility/AccessibleActionHandler.java @@ -1,45 +1,68 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleAction; import com.sun.star.lang.IndexOutOfBoundsException; -class AccessibleActionHandler extends NodeHandler +class AccessibleActionHandler + extends NodeHandler { - protected XAccessibleAction getAction(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) { - return (XAccessibleAction) UnoRuntime.queryInterface ( - XAccessibleAction.class, aObject); + XAccessibleAction xEComponent = + (XAccessibleAction) UnoRuntime.queryInterface ( + XAccessibleAction.class, xContext); + if (xEComponent != null) + return new AccessibleActionHandler (xEComponent); + else + return null; + } + + public AccessibleActionHandler () + { + } + + public AccessibleActionHandler (XAccessibleAction xAction) + { + if (xAction != null) + maChildList.setSize (1 + xAction.getAccessibleActionCount()); } - public int getChildCount(Object aObject) + protected static XAccessibleAction getAction (AccTreeNode aParent) { - XAccessibleAction xAction = getAction(aObject); - return (xAction == null) ? 0 : 1 + xAction.getAccessibleActionCount(); + return (XAccessibleAction) UnoRuntime.queryInterface ( + XAccessibleAction.class, aParent.getContext()); } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - Object aRet = null; + AccessibleTreeNode aChild = null; - XAccessibleAction xAction = getAction(aObject); - if( xAction != null ) + if (aParent instanceof AccTreeNode) { - if( nIndex == 1 ) - aRet = "Actions: " + xAction.getAccessibleActionCount(); - else + XAccessibleAction xAction = getAction ((AccTreeNode)aParent); + if( xAction != null ) { - try - { - aRet = "Action " + (nIndex-1) + " : " + - xAction.getAccessibleActionDescription(nIndex-1); - } - catch( IndexOutOfBoundsException e ) + if (nIndex == 0) + aChild = new StringNode ("Number of actions: " + xAction.getAccessibleActionCount(), + aParent); + else { - aRet = "ERROR"; + nIndex -= 1; + try + { + aChild = new StringNode ("Action " + nIndex + " : " + + xAction.getAccessibleActionDescription (nIndex), + aParent); + } + catch( IndexOutOfBoundsException e ) + { + aChild = new StringNode ("ERROR", aParent); + } } } } - return aRet; + return aChild; } } diff --git a/toolkit/test/accessibility/AccessibleComponentHandler.java b/toolkit/test/accessibility/AccessibleComponentHandler.java index 699043ddacd9..51031533170c 100644 --- a/toolkit/test/accessibility/AccessibleComponentHandler.java +++ b/toolkit/test/accessibility/AccessibleComponentHandler.java @@ -1,45 +1,69 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleComponent; -class AccessibleComponentHandler extends AccessibleTreeHandler +class AccessibleComponentHandler + extends NodeHandler { - private XAccessibleComponent getComponent(Object aObject) + + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleComponent xComponent = getComponent (xContext); + if (xComponent != null) + return new AccessibleComponentHandler (xComponent); + else + return null; + + } + + public AccessibleComponentHandler () { - return (XAccessibleComponent) UnoRuntime.queryInterface ( - XAccessibleComponent.class, aObject); } - public int getChildCount(Object aObject) + public AccessibleComponentHandler (XAccessibleComponent xComponent) { - return (getComponent(aObject) == null) ? 0 : 3; + if (xComponent != null) + maChildList.setSize (3); } - public Object getChild(Object aObject, int nIndex) + private static XAccessibleComponent getComponent(Object aObject) { - XAccessibleComponent xComponent = getComponent(aObject); + return (XAccessibleComponent) UnoRuntime.queryInterface ( + XAccessibleComponent.class, aObject); + } - Object aRet = null; - if( xComponent != null ) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) + { + AccessibleTreeNode aChild = null; + if (aParent instanceof AccTreeNode) { - switch( nIndex ) + XAccessibleComponent xComponent = getComponent ( + ((AccTreeNode)aParent).getContext()); + + if (xComponent != null) { - case 0: - aRet = "Location: "+ xComponent.getLocation().X + - ", " + xComponent.getLocation().Y; - break; - case 1: - aRet = "Location on Screen: "+ - xComponent.getLocationOnScreen().X + ", " + - xComponent.getLocationOnScreen().Y; - break; - case 2: - aRet = "Size: "+ xComponent.getSize().Width + ", " + - xComponent.getSize().Height; - break; + switch (nIndex) + { + case 0: + aChild = new StringNode ("Location: "+ xComponent.getLocation().X + + ", " + xComponent.getLocation().Y, aParent); + break; + case 1: + aChild = new StringNode ("Location on Screen: " + + xComponent.getLocationOnScreen().X + ", " + + xComponent.getLocationOnScreen().Y, + aParent); + break; + case 2: + aChild = new StringNode ("Size: "+ xComponent.getSize().Width + ", " + + xComponent.getSize().Height, + aParent); + break; + } } } - return aRet; + return aChild; } } diff --git a/toolkit/test/accessibility/AccessibleContextHandler.java b/toolkit/test/accessibility/AccessibleContextHandler.java index 1e7ae3c0fae8..521a3f47d5fb 100644 --- a/toolkit/test/accessibility/AccessibleContextHandler.java +++ b/toolkit/test/accessibility/AccessibleContextHandler.java @@ -1,39 +1,60 @@ - +import drafts.com.sun.star.accessibility.XAccessible; import drafts.com.sun.star.accessibility.XAccessibleContext; +import com.sun.star.uno.UnoRuntime; -class AccessibleContextHandler extends AccessibleTreeHandler +class AccessibleContextHandler + extends NodeHandler { - public int getChildCount(Object aObject) + protected int nChildrenCount; + + public NodeHandler createHandler (XAccessibleContext xContext) { - return (getContext(aObject) == null) ? 0 : 4; + if (xContext != null) + return new AccessibleContextHandler (xContext); + else + return null; } - public Object getChild(Object aObject, int nIndex) + public AccessibleContextHandler () { - XAccessibleContext xContext = getContext(aObject); + super (); + } - Object aRet = null; - if( xContext != null ) + public AccessibleContextHandler (XAccessibleContext xContext) + { + super(); + if (xContext != null) + maChildList.setSize (3); + } + + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) + { + XAccessibleContext xContext = null; + if (aParent instanceof AccTreeNode) + xContext = ((AccTreeNode)aParent).getContext(); + + String sChild = new String(); + if (xContext != null) { switch( nIndex ) { case 0: - aRet = "Description: " + + sChild = "Description: " + xContext.getAccessibleDescription(); break; case 1: - aRet = "Role: " + xContext.getAccessibleRole(); + sChild = "Role: " + xContext.getAccessibleRole(); break; case 2: - aRet = "Has parent: " + + sChild = "Has parent: " + (xContext.getAccessibleParent()!=null ? "yes" : "no"); break; - case 3: - aRet = "Child count: " + xContext.getAccessibleChildCount(); - break; + /* case 3: + sChild = "Child count: " + xContext.getAccessibleChildCount(); + break;*/ } } - return aRet; + return new StringNode (sChild, aParent); } } diff --git a/toolkit/test/accessibility/AccessibleEditableTextHandler.java b/toolkit/test/accessibility/AccessibleEditableTextHandler.java index 918f6bb2d787..c1c571435219 100644 --- a/toolkit/test/accessibility/AccessibleEditableTextHandler.java +++ b/toolkit/test/accessibility/AccessibleEditableTextHandler.java @@ -1,24 +1,40 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleEditableText; class AccessibleEditableTextHandler extends NodeHandler { - protected XAccessibleEditableText getEText(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleEditableText xText = + (XAccessibleEditableText) UnoRuntime.queryInterface ( + XAccessibleEditableText.class, xContext); + if (xText != null) + return new AccessibleEditableTextHandler (xText); + else + return null; + } + + public AccessibleEditableTextHandler () { - return (XAccessibleEditableText) UnoRuntime.queryInterface ( - XAccessibleEditableText.class, aObject); } - public int getChildCount(Object aObject) + public AccessibleEditableTextHandler (XAccessibleEditableText xText) { - return (getEText(aObject) == null) ? 0 : 1; + if (xText != null) + maChildList.setSize (1); + } + + protected static XAccessibleEditableText getEText (AccTreeNode aNode) + { + return (XAccessibleEditableText) UnoRuntime.queryInterface ( + XAccessibleEditableText.class, aNode.getContext()); } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - XAccessibleEditableText xContext = getEText(aObject); - return "XAccessibleEditableText is supported"; + return new StringNode ("XAccessibleEditableText is supported", aParent); } } diff --git a/toolkit/test/accessibility/AccessibleExtendedComponentHandler.java b/toolkit/test/accessibility/AccessibleExtendedComponentHandler.java index 17e66d8353b3..1fb2d4518256 100644 --- a/toolkit/test/accessibility/AccessibleExtendedComponentHandler.java +++ b/toolkit/test/accessibility/AccessibleExtendedComponentHandler.java @@ -1,48 +1,71 @@ - import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleExtendedComponent; -class AccessibleExtendedComponentHandler extends AccessibleTreeHandler +class AccessibleExtendedComponentHandler + extends NodeHandler { - private XAccessibleExtendedComponent getComponent(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) { - return (XAccessibleExtendedComponent) UnoRuntime.queryInterface ( - XAccessibleExtendedComponent.class, aObject); + XAccessibleExtendedComponent xEComponent = + (XAccessibleExtendedComponent) UnoRuntime.queryInterface ( + XAccessibleExtendedComponent.class, xContext); + if (xEComponent != null) + return new AccessibleExtendedComponentHandler (xEComponent); + else + return null; } + public AccessibleExtendedComponentHandler () + { + } - public int getChildCount(Object aObject) + public AccessibleExtendedComponentHandler (XAccessibleExtendedComponent xEComponent) { - return (getComponent(aObject) == null) ? 0 : 2; + if (xEComponent != null) + maChildList.setSize (2); } - public Object getChild(Object aObject, int nIndex) + private static XAccessibleExtendedComponent getComponent (AccTreeNode aNode) { - XAccessibleExtendedComponent xEComponent = getComponent(aObject); + return (XAccessibleExtendedComponent) UnoRuntime.queryInterface ( + XAccessibleExtendedComponent.class, + aNode.getContext()); + } + - Object aRet = null; - if( xEComponent != null ) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) + { + AccessibleTreeNode aChild = null; + if (aParent instanceof AccTreeNode) { - int nColor; - switch( nIndex ) + XAccessibleExtendedComponent xEComponent = getComponent ((AccTreeNode)aParent); + + if (xEComponent != null) { - case 0: - nColor = xEComponent.getForeground(); - aRet = "Foreground color: R" - + (nColor>>16&0xff) - + "G" + (nColor>>8&0xff) - + "B" + (nColor>>0&0xff); - break; - case 1: - nColor = xEComponent.getBackground(); - aRet = "Background color: R" - + (nColor>>16&0xff) - + "G" + (nColor>>8&0xff) - + "B" + (nColor>>0&0xff); - break; + int nColor; + switch( nIndex ) + { + case 0: + nColor = xEComponent.getForeground(); + aChild = new StringNode ("Foreground color: R" + + (nColor>>16&0xff) + + "G" + (nColor>>8&0xff) + + "B" + (nColor>>0&0xff), + aParent); + break; + case 1: + nColor = xEComponent.getBackground(); + aChild = new StringNode ("Background color: R" + + (nColor>>16&0xff) + + "G" + (nColor>>8&0xff) + + "B" + (nColor>>0&0xff), + aParent); + break; + } } } - return aRet; + return aChild; } } diff --git a/toolkit/test/accessibility/AccessibleHyperlinkHandler.java b/toolkit/test/accessibility/AccessibleHyperlinkHandler.java index a7bd0583d101..cc7381b78fa3 100644 --- a/toolkit/test/accessibility/AccessibleHyperlinkHandler.java +++ b/toolkit/test/accessibility/AccessibleHyperlinkHandler.java @@ -1,10 +1,32 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleHyperlink; class AccessibleHyperlinkHandler extends AccessibleTreeHandler { + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleHyperlink xLink = + (XAccessibleHyperlink) UnoRuntime.queryInterface ( + XAccessibleHyperlink.class, xContext); + if (xLink != null) + return new AccessibleHyperlinkHandler (xLink); + else + return null; + } + + public AccessibleHyperlinkHandler () + { + } + + public AccessibleHyperlinkHandler (XAccessibleHyperlink xLink) + { + if (xLink != null) + maChildList.setSize (1); + } + protected XAccessibleHyperlink getHyperlink(Object aObject) { XAccessibleHyperlink xHyperlink = @@ -13,13 +35,8 @@ class AccessibleHyperlinkHandler extends AccessibleTreeHandler return xHyperlink; } - public int getChildCount(Object aObject) - { - return (getHyperlink(aObject) == null) ? 0 : 1; - } - - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex) { - return "interface XAccessibleHyperlink is supported"; + return new StringNode ("interface XAccessibleHyperlink is supported", aParent); } } diff --git a/toolkit/test/accessibility/AccessibleHypertextHandler.java b/toolkit/test/accessibility/AccessibleHypertextHandler.java index 0e1f4ece6823..1742ed3a8d9d 100644 --- a/toolkit/test/accessibility/AccessibleHypertextHandler.java +++ b/toolkit/test/accessibility/AccessibleHypertextHandler.java @@ -1,25 +1,42 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleHypertext; class AccessibleHypertextHandler extends AccessibleTreeHandler { - protected XAccessibleHypertext getHypertext(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) { - XAccessibleHypertext xHypertext = + XAccessibleHypertext xText = (XAccessibleHypertext) UnoRuntime.queryInterface ( - XAccessibleHypertext.class, aObject); - return xHypertext; + XAccessibleHypertext.class, xContext); + if (xText != null) + return new AccessibleHypertextHandler (xText); + else + return null; + } + + public AccessibleHypertextHandler () + { } - public int getChildCount(Object aObject) + public AccessibleHypertextHandler (XAccessibleHypertext xText) { - return (getHypertext(aObject) == null) ? 0 : 1; + if (xText != null) + maChildList.setSize (1); + } + + protected static XAccessibleHypertext getHypertext (AccTreeNode aNode) + { + XAccessibleHypertext xHypertext = + (XAccessibleHypertext) UnoRuntime.queryInterface ( + XAccessibleHypertext.class, aNode.getContext()); + return xHypertext; } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex) { - return "interface XAccessibleHypertext is supported"; + return new StringNode ("interface XAccessibleHypertext is supported", aParent); } } diff --git a/toolkit/test/accessibility/AccessibleImageHandler.java b/toolkit/test/accessibility/AccessibleImageHandler.java index 260207699383..de924c00facf 100644 --- a/toolkit/test/accessibility/AccessibleImageHandler.java +++ b/toolkit/test/accessibility/AccessibleImageHandler.java @@ -1,25 +1,48 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleImage; class AccessibleImageHandler extends NodeHandler { - protected XAccessibleImage getImage(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleImage xImage = + (XAccessibleImage) UnoRuntime.queryInterface ( + XAccessibleImage.class, xContext); + if (xImage != null) + return new AccessibleImageHandler (xImage); + else + return null; + } + + public AccessibleImageHandler () { - return (XAccessibleImage) UnoRuntime.queryInterface ( - XAccessibleImage.class, aObject); } - public int getChildCount(Object aObject) + public AccessibleImageHandler (XAccessibleImage xImage) { - return (getImage(aObject) == null) ? 0 : 1; + if (xImage != null) + maChildList.setSize (1); + } + + protected static XAccessibleImage getImage (AccTreeNode aNode) + { + return (XAccessibleImage) UnoRuntime.queryInterface ( + XAccessibleImage.class, aNode.getContext()); } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - XAccessibleImage xImage = getImage(aObject); - return (xImage == null) ? "" : - "Image description: " + xImage.getAccessibleImageDescription(); + if (aParent instanceof AccTreeNode) + { + XAccessibleImage xImage = getImage ((AccTreeNode)aParent); + if (xImage != null) + return new StringNode ( + "Image description: " + xImage.getAccessibleImageDescription(), + aParent); + } + return null; } } diff --git a/toolkit/test/accessibility/AccessibleTableHandler.java b/toolkit/test/accessibility/AccessibleTableHandler.java index 90d6d1b791fd..8d281f83b786 100644 --- a/toolkit/test/accessibility/AccessibleTableHandler.java +++ b/toolkit/test/accessibility/AccessibleTableHandler.java @@ -1,24 +1,40 @@ import com.sun.star.uno.UnoRuntime; +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleTable; class AccessibleTableHandler extends NodeHandler { - protected XAccessibleTable getTable(Object aObject) + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleTable xTable = + (XAccessibleTable) UnoRuntime.queryInterface ( + XAccessibleTable.class, xContext); + if (xTable != null) + return new AccessibleTableHandler (xTable); + else + return null; + } + + public AccessibleTableHandler () { - return (XAccessibleTable) UnoRuntime.queryInterface ( - XAccessibleTable.class, aObject); } - public int getChildCount(Object aObject) + public AccessibleTableHandler (XAccessibleTable xTable) { - return (getTable(aObject) == null) ? 0 : 1; + if (xTable != null) + maChildList.setSize (1); + } + + protected static XAccessibleTable getTable(Object aObject) + { + return (XAccessibleTable) UnoRuntime.queryInterface ( + XAccessibleTable.class, aObject); } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - XAccessibleTable xTable = getTable(aObject); - return "interface XAccessibleTable is supported"; + return new StringNode ("interface XAccessibleTable is supported", aParent); } } diff --git a/toolkit/test/accessibility/AccessibleTextHandler.java b/toolkit/test/accessibility/AccessibleTextHandler.java index a39cd69c9d86..5eb86b5213bb 100644 --- a/toolkit/test/accessibility/AccessibleTextHandler.java +++ b/toolkit/test/accessibility/AccessibleTextHandler.java @@ -1,4 +1,5 @@ +import drafts.com.sun.star.accessibility.XAccessibleContext; import drafts.com.sun.star.accessibility.XAccessibleText; import drafts.com.sun.star.accessibility.XAccessibleEditableText; import drafts.com.sun.star.accessibility.AccessibleTextType; @@ -25,12 +26,32 @@ import javax.swing.text.JTextComponent; class AccessibleTextHandler extends NodeHandler { + private XAccessibleText mxText; + + public NodeHandler createHandler (XAccessibleContext xContext) + { + XAccessibleText xText = (XAccessibleText) UnoRuntime.queryInterface ( + XAccessibleText.class, xContext); + if (xText != null) + return new AccessibleTextHandler (xText); + else + return null; + } + + public AccessibleTextHandler () + { + } + + public AccessibleTextHandler (XAccessibleText xText) + { + mxText = xText; + if (mxText != null) + maChildList.setSize (12); + } + protected XAccessibleText getText( Object aObject ) { - XAccessibleText xText = - (XAccessibleText) UnoRuntime.queryInterface ( - XAccessibleText.class, aObject); - return xText; + return mxText; } protected XAccessibleEditableText getEditText( Object aObject ) @@ -43,67 +64,82 @@ class AccessibleTextHandler extends NodeHandler - public int getChildCount(Object aObject) - { - return (getText(aObject) != null) ? 12 : 0; - } - - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - Object aRet = null; + AccessibleTreeNode aChild = null; + XAccessibleText xText = null; + if (aParent instanceof AccTreeNode) + xText = getText (((AccTreeNode)aParent).getContext()); - XAccessibleText xText = getText( aObject ); - if( xText != null ) + try { - switch( nIndex ) + if( xText != null ) { - case 0: - aRet = xText.getText(); - break; - case 1: - aRet = "# chars: " + xText.getCharacterCount(); - break; - case 2: - aRet = characters( xText ); - break; - case 3: - aRet = "selection: " + "[" + xText.getSelectionStart() + - "," + xText.getSelectionEnd() + "] \"" + - xText.getSelectedText() + "\""; - break; - case 4: - aRet = "getCaretPosition: " + xText.getCaretPosition(); - break; - case 5: - aRet = textAtIndexNode( xText, "Character", - AccessibleTextType.CHARACTER ); - break; - case 6: - aRet = textAtIndexNode( xText, "Word", - AccessibleTextType.WORD ); - break; - case 7: - aRet = textAtIndexNode( xText, "Sentence", - AccessibleTextType.SENTENCE ); - break; - case 8: - aRet = textAtIndexNode( xText, "Paragraph", - AccessibleTextType.PARAGRAPH ); - break; - case 9: - aRet = textAtIndexNode( xText, "Line", - AccessibleTextType.LINE ); - break; - case 10: - aRet = textAtIndexNode( xText, "Attribute", - (short)6/*AccessibleTextType.ATTRIBUTE*/); - break; - case 11: - aRet = bounds( xText ); - break; + switch( nIndex ) + { + case 0: + aChild = new StringNode (xText.getText(), aParent); + break; + case 1: + aChild = new StringNode ("# chars: " + xText.getCharacterCount(), aParent); + break; + case 2: + aChild = new StringNode (characters( xText ), aParent); + break; + case 3: + aChild = new StringNode ("selection: " + + "[" + xText.getSelectionStart() + + "," + xText.getSelectionEnd() + + "] \"" + xText.getSelectedText() + "\"", + aParent); + break; + case 4: + aChild = new StringNode ("getCaretPosition: " + xText.getCaretPosition(), aParent); + break; + case 5: + aChild = textAtIndexNode( xText, "Character", + AccessibleTextType.CHARACTER, + aParent); + break; + case 6: + aChild = textAtIndexNode( xText, "Word", + AccessibleTextType.WORD, + aParent); + break; + case 7: + aChild = textAtIndexNode( xText, "Sentence", + AccessibleTextType.SENTENCE, + aParent); + break; + case 8: + aChild = textAtIndexNode( xText, "Paragraph", + AccessibleTextType.PARAGRAPH, + aParent); + break; + case 9: + aChild = textAtIndexNode( xText, "Line", + AccessibleTextType.LINE, + aParent); + break; + case 10: + aChild = textAtIndexNode( xText, "Attribute", + (short)6/*AccessibleTextType.ATTRIBUTE*/, + aParent); + break; + case 11: + aChild = new StringNode (bounds( xText ), aParent); + break; + default: + aChild = new StringNode ("unknown child index " + nIndex, aParent); + } } } - return aRet; + catch (Exception e) + { + // Return empty child. + } + + return aChild; } @@ -119,12 +155,13 @@ class AccessibleTextHandler extends NodeHandler /** Create a text node that lists all strings of a particular text type */ - private Object textAtIndexNode( + private AccessibleTreeNode textAtIndexNode( XAccessibleText xText, String sName, - short nTextType) + short nTextType, + AccessibleTreeNode aParent) { - Vector aWords = new Vector(); + VectorNode aNode = new VectorNode (sName, aParent); // get word at all positions; // for nicer display, compare current word to previous one and @@ -149,8 +186,8 @@ class AccessibleTextHandler extends NodeHandler if( ! ( sTmp.equals( sWord ) && sTBef.equals( sBefore ) && sTBeh.equals( sBehind ) ) ) { - aWords.add( textAtIndexNodeString( - nStart, i, sWord, sBefore, sBehind) ); + aNode.addChild (new StringNode (textAtIndexNodeString( + nStart, i, sWord, sBefore, sBehind), aNode)); sWord = sTmp; sBefore = sTBef; sBehind = sTBeh; @@ -158,24 +195,21 @@ class AccessibleTextHandler extends NodeHandler } // don't generate more than 50 children. - if( aWords.size() > 50 ) + if (aNode.getChildCount() > 50) { sWord = "..."; break; } } - aWords.add( textAtIndexNodeString( - nStart, nLength, sWord, sBefore, sBehind) ); + aNode.addChild (new StringNode (textAtIndexNodeString( + nStart, nLength, sWord, sBefore, sBehind), aNode)); } catch( IndexOutOfBoundsException e ) { - aWords.add( e.toString() ); + aNode.addChild (new StringNode (e.toString(), aNode)); } } - // create node, and add default handlers - AccTreeNode aNode = new AccTreeNode( aWords, sName ); - AccessibilityTreeModel.addDefaultHandlers( aNode ); return aNode; } diff --git a/toolkit/test/accessibility/AccessibleTreeHandler.java b/toolkit/test/accessibility/AccessibleTreeHandler.java index f3e3a65ce1ca..f734b14a5d19 100644 --- a/toolkit/test/accessibility/AccessibleTreeHandler.java +++ b/toolkit/test/accessibility/AccessibleTreeHandler.java @@ -1,3 +1,4 @@ +import drafts.com.sun.star.accessibility.XAccessible; import drafts.com.sun.star.accessibility.XAccessibleContext; import com.sun.star.uno.UnoRuntime; import com.sun.star.lang.IndexOutOfBoundsException; @@ -7,36 +8,80 @@ import com.sun.star.lang.IndexOutOfBoundsException; * Map the tree of accessibility objects into their * AccessibilityTreeModel counterparts. */ -class AccessibleTreeHandler extends NodeHandler +class AccessibleTreeHandler + extends NodeHandler { - protected XAccessibleContext getContext(Object aObject) + protected XAccessibleContext mxContext; + + public NodeHandler createHandler (XAccessibleContext xContext) + { + if (xContext != null) + return new AccessibleTreeHandler (xContext); + else + return null; + } + + public AccessibleTreeHandler () { - XAccessibleContext xContext = - (XAccessibleContext) UnoRuntime.queryInterface ( - XAccessibleContext.class, aObject); - return xContext; + super(); + mxContext = null; } - public int getChildCount(Object aObject) + public AccessibleTreeHandler (XAccessibleContext xContext) { - XAccessibleContext aContext = getContext(aObject); - return (aContext == null) ? 0 : aContext.getAccessibleChildCount(); + super(); + mxContext = xContext; + if (mxContext != null) + // Add one to the number of children to include the string node + // that tells you how many children there are. + maChildList.setSize (1 + mxContext.getAccessibleChildCount()); } - public Object getChild(Object aObject, int nIndex) + public AccessibleTreeNode createChild (AccessibleTreeNode aParent, int nIndex) { - Object aRet = null; - XAccessibleContext aContext = getContext(aObject); - if( aContext != null ) + AccessibleTreeNode aChild = null; + if (mxContext != null) { - try + if (nIndex == 0) + aChild = new StringNode ("Child count: " + mxContext.getAccessibleChildCount(), + aParent); + else { - aRet = AccessibilityTreeModel. - createDefaultNode(aContext.getAccessibleChild(nIndex)); + // Lower index to skip the string node. + nIndex -= 1; + try + { + XAccessible xChild = mxContext.getAccessibleChild (nIndex); + aChild = AccessibilityTreeModel.createDefaultNode ( + xChild, aParent); + } + catch( IndexOutOfBoundsException e ) + { + aChild = new StringNode ("ERROR: no child with index " + nIndex, aParent); + } } - catch( IndexOutOfBoundsException e ) - { } // return null } - return aRet; + else + aChild = new StringNode ("XAccessibleContext interface not supported", aParent); + return aChild; } + + /** Try to add the specified accessible child into the lists of + children. The insertion position is determined from the + getIndexInParent method of the child. + */ + public AccessibleTreeNode addAccessibleChild (AccessibleTreeNode aParent, XAccessible xChild) + { + AccessibleTreeNode aChild = null; + + XAccessibleContext xContext = xChild.getAccessibleContext(); + int nIndex = xContext.getAccessibleIndexInParent() + 1; + if ((nIndex >= 0) || (nIndex <= maChildList.size())) + { + aChild = AccessibilityTreeModel.createDefaultNode (xChild, aParent); + maChildList.insertElementAt (aChild, nIndex); + } + return aChild; + } + } diff --git a/toolkit/test/accessibility/AccessibleTreeNode.java b/toolkit/test/accessibility/AccessibleTreeNode.java new file mode 100644 index 000000000000..490530b3f5b3 --- /dev/null +++ b/toolkit/test/accessibility/AccessibleTreeNode.java @@ -0,0 +1,84 @@ +import java.util.Vector; +import com.sun.star.lang.IndexOutOfBoundsException; + +/** + Base class for all tree nodes. + */ +class AccessibleTreeNode +{ + /// The parent node. It is null for the root node. + protected AccessibleTreeNode maParent; + + /// The object to be displayed. + private Object maDisplayObject; + + public AccessibleTreeNode (Object aDisplayObject, AccessibleTreeNode aParent) + { + maDisplayObject = aDisplayObject; + maParent = aParent; + } + + public void update () + { + // Empty + } + + public AccessibleTreeNode getParent () + { + return maParent; + } + + public Object getDisplayObject () + { + return maDisplayObject; + } + + public int getChildCount () + { + return 0; + } + + public AccessibleTreeNode getChild (int nIndex) + throws IndexOutOfBoundsException + { + throw new IndexOutOfBoundsException(); + } + + public boolean removeChild (int nIndex) + throws IndexOutOfBoundsException + { + throw new IndexOutOfBoundsException(); + } + + public int indexOf (AccessibleTreeNode aNode) + { + return -1; + } + + /** Create a path to this node by first asking the parent for its path + and then appending this object. + */ + public void createPath (java.util.Vector aPath) + { + if (maParent != null) + maParent.createPath (aPath); + aPath.add (this); + } + + public Object[] createPath () + { + Vector aPath = new Vector (1); + createPath (aPath); + return aPath.toArray(); + } + + public boolean isLeaf() + { + return true; + } + + public String toString() + { + return maDisplayObject.toString(); + } +} diff --git a/toolkit/test/accessibility/Canvas.java b/toolkit/test/accessibility/Canvas.java index afacc0265330..ad72c3545cc7 100755 --- a/toolkit/test/accessibility/Canvas.java +++ b/toolkit/test/accessibility/Canvas.java @@ -172,34 +172,36 @@ class Canvas public void mouseMoved (MouseEvent e) { - maActiveObject = null; - for (int i=0; i<maObjects.size(); i++) + int nObjects = maObjects.size(); + for (int i=nObjects-1; i>=0; i--) { AccessibleObject aObject = (AccessibleObject)(maObjects.elementAt(i)); if (aObject != null) { - aObject.deselect (); - if (aObject != null) - if (aObject.contains (e.getX(),e.getY())) + if (aObject.contains (e.getX(),e.getY())) + { + if (aObject != maActiveObject) { + if (maActiveObject != null) + maActiveObject.deselect(); + maActiveObject = aObject; - } - } - } - if (maActiveObject != null) - { - maActiveObject.select (); - maMessageDisplay.message ("mouse moved to " + e.getX() + "," + e.getY() + ": " - +maActiveObject.toString()); - System.out.println ("path: " + maActiveObject.getPath()); + maMessageDisplay.message ("object under mouse is " + +maActiveObject.toString()); + maActiveObject.select (); - if (maTree != null) - { - maTree.scrollPathToVisible (maActiveObject.getPath()); - maTree.repaint (); + if (maTree != null) + { + maTree.scrollPathToVisible (maActiveObject.getPath()); + maTree.repaint (); + } + + repaint (); + } + break; + } } } - repaint (); } protected int diff --git a/toolkit/test/accessibility/NodeHandler.java b/toolkit/test/accessibility/NodeHandler.java index 3b1653ba34eb..4514207d6300 100644 --- a/toolkit/test/accessibility/NodeHandler.java +++ b/toolkit/test/accessibility/NodeHandler.java @@ -1,19 +1,85 @@ +import java.util.Vector; + + /** * Map an arbitrary object into parts of a tree node. */ abstract class NodeHandler { + /** This vector is used as cache for the child objects. + */ + protected Vector maChildList; + + + public abstract NodeHandler createHandler ( + drafts.com.sun.star.accessibility.XAccessibleContext xContext); + + public NodeHandler () + { + maChildList = new Vector (); + } + + /** Clear the cache of child objects. + */ + public void clear () + { + maChildList = new Vector (); + } + + /** This factory method creates an individual handler for the specified + object that may hold information to accelerate the access to its children. + */ + // public abstract NodeHandler createHandler (Object aObject); + /** return the number of children this object has */ - public abstract int getChildCount(Object aObject); + public int getChildCount(Object aObject) + { + return maChildList.size(); + } /** - * return a child object. - * You can use any object type for trivial nodes. Complex + * return a child object. Complex * children have to be AccTreeNode instances. * @see AccTreeNode */ - public abstract Object getChild(Object aObject, int nIndex); + public AccessibleTreeNode getChild (AccessibleTreeNode aParent, int nIndex) + { + AccessibleTreeNode aChild = (AccessibleTreeNode)maChildList.get(nIndex); + if (aChild == null) + { + aChild = createChild (aParent, nIndex); + if (aChild == null) + aChild = new StringNode ("could not create child", aParent); + maChildList.setElementAt (aChild, nIndex); + } + return aChild; + } + + /** Remove the specified child from the list of children. + */ + public boolean removeChild (AccessibleTreeNode aNode, int nIndex) + { + try + { + maChildList.remove (nIndex); + } + catch (Exception e) + { + return false; + } + return true; + } + + public int indexOf (AccessibleTreeNode aNode) + { + return maChildList.indexOf (aNode); + } + /** Create a child object for the specified data. This method is called + usually from getChild and put there into the cache. + */ + public abstract AccessibleTreeNode createChild ( + AccessibleTreeNode aParent, int nIndex); // // The following methods support editing of children and actions. @@ -27,7 +93,7 @@ abstract class NodeHandler } /** change this child's value */ - public void setChild(Object aObject, int nIndex) { } + // public void setChild(Object aObject, int nIndex) { } /** get names of suported actions */ @@ -37,5 +103,7 @@ abstract class NodeHandler } /** perform action */ - public void performAction(Object aObject, int nIndex) { } + public void performAction(Object aObject, int nIndex) + { + } } diff --git a/toolkit/test/accessibility/StringNode.java b/toolkit/test/accessibility/StringNode.java new file mode 100644 index 000000000000..11a7286c60f1 --- /dev/null +++ b/toolkit/test/accessibility/StringNode.java @@ -0,0 +1,13 @@ +import com.sun.star.lang.IndexOutOfBoundsException; + +/** + Base class for all tree nodes. + */ +class StringNode + extends AccessibleTreeNode +{ + public StringNode (String aDisplayObject, AccessibleTreeNode aParent) + { + super (aDisplayObject, aParent); + } +} diff --git a/toolkit/test/accessibility/VectorNode.java b/toolkit/test/accessibility/VectorNode.java new file mode 100644 index 000000000000..708fbda09d3a --- /dev/null +++ b/toolkit/test/accessibility/VectorNode.java @@ -0,0 +1,50 @@ +import com.sun.star.lang.IndexOutOfBoundsException; +import java.util.Vector; + +/** + Base class for all tree nodes. + */ +class VectorNode + extends StringNode +{ + private Vector maChildren; + + public VectorNode (String sDisplayObject, AccessibleTreeNode aParent) + { + super (sDisplayObject, aParent); + + maChildren = new Vector (); + } + + public void addChild (AccessibleTreeNode aChild) + { + maChildren.add (aChild); + } + + public int getChildCount () + { + return maChildren.size(); + } + + public AccessibleTreeNode getChild (int nIndex) + throws IndexOutOfBoundsException + { + return (AccessibleTreeNode)maChildren.elementAt (nIndex); + } + + public boolean removeChild (int nIndex) + throws IndexOutOfBoundsException + { + return maChildren.remove (nIndex) != null; + } + + public int indexOf (AccessibleTreeNode aNode) + { + return maChildren.indexOf (aNode); + } + + public boolean isLeaf() + { + return maChildren.isEmpty(); + } +} |