Tuesday, August 17, 2010

Find a VisualItem directly

In order to find a VisualItem in prefuse Visualization, there are two ways.

#1 The general way is to get an Iterator by calling Visualization class' item(), getGroup(), or other methods, which will return an Iterator. Then in a while loop, query this Iterator one by one and search for the VisualItem with certain contents.

Iterator i= v.items(SOURCE);
VisualItem vitem, v1=null, v2=null;
while(i.hasNext()){
vitem=(VisualItem) i.next();
if (vitem instanceof VisualItem){
if (vitem.getInt("ID")==s){
v1=vitem;
}
if (vitem.getInt("ID")==t){
v2=vitem;
}
}
}

#2 A specific way is to cast the TupleSet into a VisualTable if your back up data is a Table. So in this way, the VisualItem can be directly queried by using the row number.

VisualTable ts=(VisualTable) v.getGroup(SOURCE);
VisualItem v1=ts.getItem(s-1);
VisualItem v2=ts.getItem(t-1);

The speed of #2 is much fast than #1. Using this solution, it is easy to handle ~10000 nodes and lines.
But #1 is safe, since if your backup data is not a Table, there may be an exception of casting TupleSet into VisualTable.

If your data nodes is small, ~1000, #1 solution would be safe to use. If you want speed, use #2 with careful data design.

No comments:

Post a Comment