You can find the API for this class in the JavaStar API Reference.
There are two methods that must be provided:
JSNCLData findObject(Component c, AWTEvent e)
JSNCLData getNamedObjectData(Component c, String name)
The findObject()
method must determine what object is at a given mouse position. To do this it must:
JTree
, for example, must be sure that the component passed is an instance of a JTree
, and the event is a mouse event. Otherwise, it should return null. Here is the code in Tree.java
that ensures this is a JTree
and a mouse event:
if(e instanceof MouseEvent){
int x = ((MouseEvent)e).getX();
int y = ((MouseEvent)e).getY();
if(c instanceof JTree){
JTree t = (JTree)c;
return findObject(t,x,y);
}
}
return null;
Note the cast of the component to the JTree
when it is certain that the component is a JTree
.
JTree
, the NCL uses the getClosestPath()
method to locate the full path, then gets the row index for that path. Here is the code:
public static JSNCLData findObject(JTree t, int x, int y){
TreePath p = t.getClosestPathForLocation(x,y);
if(p!=null){
int r = t.getRowForPath(p);
return getTreeDat(t,r);
}
return null;
}
JTree
, finding the location is easy. Mozart is the fourth row, and the NCL uses the integer 4 as the index. The confirmation is not quite as easy. Simply using the string "Mozart" may not ensure it is the correct component, as there may be many "Mozart" entries in the tree. To be unique, the string must contain the path to Mozart. The Tree.java
uses the various methods available to get the row path, parse it to individual objects, and concatenate a path, separated by the ## delimiter, of the "toString()
" titles of each object. The resulting name, then, is 4:"Music##Classical##Mozart".
JTree
. A click at (44,84) lies within that row.
A Row contained within a Tree
The Point of the Non-Component is a fixed position from which JavaStar can consistently calculate the relative position of the multi-click. In the case of the Mozart example, the point is at the x, y coordinates of 40,72.
If JavaStar calls findObject()
with a mouse click at 44,84, the NCL finds the row at 40,72. JavaStar sees that point in the returned JSNCLData
, and translates the mouse click to be relative to that row. The mouse click coordinates viewed in the script, then, are 4 (44 minus 40), 12 (84 minus 72).
The row bounds of 40,72 were obtained by using the getRowBounds()
method of JTree
.
The last part of the JSNCLData
is the component itself. The NCL provides the component at the appropriate level. For a JTree
, that was determined to be the TreeNode
at that level. If this click was not on a tree node, no object, and no JSNCLData
, would be returned.
The other "half" of the NCL is to be able to generate the JSNCLData
based on the unique name, rather than a coordinate.
When a script is played back, JavaStar needs to find the actual component clicked upon to evaluate whether a verification continues to pass against that component. JavaStar has the unique name found at the time of recording, and the event logged against the component. It needs to verify that the appropriate non-component exists, and invoke the necessary methods against that component to evaluate a verification.
The NCL must provide a method, getNamedObject(),
to get the JSNCLData for a component based on its name. The NCL is provided the containing component, and the unique name created at the time of recording the script.
In our example, getNamedObject(
) is passed the JTree, and the string "4:Music##Classical##Mozart".
These are the things that must occur:
JTree
.
JTree
. If there isn't, the method returns null.
findObject()
. See steps 3-5 of "Finding the JSNCLData while Recording", above.
Once JavaStar has the component, it can run required methods on it to verify that the tests pass.
Send feedback to
JavaStar-feedback@suntest.com
Copyright © 1998
Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, CA 94303.
All rights reserved.