2002-04-02 07:06:32 -06:00
|
|
|
import com.sun.star.uno.UnoRuntime;
|
|
|
|
import drafts.com.sun.star.accessibility.XAccessible;
|
|
|
|
import drafts.com.sun.star.accessibility.XAccessibleContext;
|
2002-03-08 10:30:18 -06:00
|
|
|
import java.util.Vector;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The node type for the AccessibleTreeModel.
|
|
|
|
* This implements all the child-handling based on the appropriate
|
|
|
|
* NodeHandlers. Trivial nodes can be implemented by any Object
|
|
|
|
* type.
|
|
|
|
*/
|
|
|
|
class AccTreeNode
|
2002-04-02 07:06:32 -06:00
|
|
|
extends AccessibleTreeNode
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
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);
|
|
|
|
}
|
2002-03-08 10:30:18 -06:00
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
public AccTreeNode (XAccessibleContext xContext, Object aDisplay, AccessibleTreeNode aParent)
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
super (aDisplay, aParent);
|
|
|
|
|
|
|
|
maHandlers = new Vector(5);
|
|
|
|
mxContext = xContext;
|
|
|
|
mxAccessible = null;
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
/** 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 ()
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
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);
|
|
|
|
}
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
public XAccessibleContext getContext()
|
|
|
|
{
|
|
|
|
return mxContext;
|
|
|
|
}
|
|
|
|
|
|
|
|
public XAccessible getAccessible()
|
|
|
|
{
|
|
|
|
if ((mxAccessible == null) && (mxContext != null))
|
|
|
|
mxAccessible = (XAccessible)UnoRuntime.queryInterface(
|
|
|
|
XAccessible.class, mxContext);
|
|
|
|
return mxAccessible;
|
|
|
|
}
|
2002-03-08 10:30:18 -06:00
|
|
|
|
|
|
|
public void addHandler( NodeHandler aHandler )
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
if (aHandler != null)
|
|
|
|
maHandlers.add (new HandlerDescriptor (aHandler));
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/** iterate over handlers and return child sum */
|
2002-04-02 07:06:32 -06:00
|
|
|
protected HandlerDescriptor getHandlerDescriptor (int i)
|
|
|
|
{
|
|
|
|
HandlerDescriptor aDescriptor = (HandlerDescriptor)maHandlers.get(i);
|
|
|
|
if (aDescriptor.mnChildCount < 0)
|
|
|
|
aDescriptor.mnChildCount =
|
|
|
|
aDescriptor.maHandler.getChildCount (this);
|
|
|
|
return aDescriptor;
|
|
|
|
}
|
|
|
|
|
2002-03-08 10:30:18 -06:00
|
|
|
public int getChildCount()
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
int nChildCount = 0;
|
|
|
|
for (int i = 0; i < maHandlers.size(); i++)
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
HandlerDescriptor aDescriptor = getHandlerDescriptor (i);
|
|
|
|
nChildCount += aDescriptor.mnChildCount;
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
2002-04-02 07:06:32 -06:00
|
|
|
return nChildCount;
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
/** iterate over handlers until the child is found */
|
2002-04-02 07:06:32 -06:00
|
|
|
public AccessibleTreeNode getChild (int nIndex)
|
|
|
|
throws IndexOutOfBoundsException
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
|
|
|
if( nIndex >= 0 )
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
for(int i = 0; i < maHandlers.size(); i++)
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
|
|
|
// check if this handler has the child, and if not
|
|
|
|
// search with next handler
|
2002-04-02 07:06:32 -06:00
|
|
|
HandlerDescriptor aDescriptor = getHandlerDescriptor (i);
|
|
|
|
if (nIndex < aDescriptor.mnChildCount)
|
|
|
|
return aDescriptor.maHandler.getChild (this, nIndex);
|
2002-03-08 10:30:18 -06:00
|
|
|
else
|
2002-04-02 07:06:32 -06:00
|
|
|
nIndex -= aDescriptor.mnChildCount;
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
}
|
2002-04-02 07:06:32 -06:00
|
|
|
else
|
|
|
|
throw new IndexOutOfBoundsException();
|
2002-03-08 10:30:18 -06:00
|
|
|
|
|
|
|
// nothing found?
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2002-03-08 11:14:24 -06:00
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
public int indexOf (AccessibleTreeNode aNode)
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
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;
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
/** this node is a leaf if have no handlers, or is those
|
|
|
|
handlers show no children */
|
|
|
|
public boolean isLeaf()
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
return (maHandlers.size() == 0);// || (getChildCount() == 0);
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
public boolean equals (Object aOther)
|
2002-03-08 10:30:18 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
return (this == aOther) || aOther.equals(mxContext);
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|
2002-03-08 11:14:24 -06:00
|
|
|
|
|
|
|
|
|
|
|
/** iterate over handlers until the child is found */
|
|
|
|
public void getActions(Vector aActions)
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
for(int i = 0; i < maHandlers.size(); i++)
|
2002-03-08 11:14:24 -06:00
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
HandlerDescriptor aDescriptor = getHandlerDescriptor (i);
|
|
|
|
NodeHandler aHandler = aDescriptor.maHandler;
|
|
|
|
String[] aHandlerActions = aHandler.getActions (this);
|
2002-03-08 11:14:24 -06:00
|
|
|
for(int j = 0; j < aHandlerActions.length; j++ )
|
|
|
|
{
|
|
|
|
aActions.add( aHandlerActions[j] );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void performAction( int nIndex )
|
|
|
|
{
|
|
|
|
if( nIndex >= 0 )
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
for(int i = 0; i < maHandlers.size(); i++)
|
2002-03-08 11:14:24 -06:00
|
|
|
{
|
|
|
|
// check if this handler has the child, and if not
|
|
|
|
// search with next handler
|
2002-04-02 07:06:32 -06:00
|
|
|
HandlerDescriptor aDescriptor = getHandlerDescriptor (i);
|
|
|
|
NodeHandler aHandler = aDescriptor.maHandler;
|
|
|
|
int nCount = aHandler.getActions(this).length;
|
2002-03-08 11:14:24 -06:00
|
|
|
if( nCount > nIndex )
|
|
|
|
{
|
2002-04-02 07:06:32 -06:00
|
|
|
aHandler.performAction(this, nIndex );
|
2002-03-08 11:14:24 -06:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
nIndex -= nCount;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-02 07:06:32 -06:00
|
|
|
/** 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;
|
|
|
|
}
|
2002-03-08 10:30:18 -06:00
|
|
|
}
|