The following private methods of the Flag Renderer handle
the flag on a node:
checkNode
cleanNode
moveNode
The following code example shows the code for checkNode
.
Checking for a flag
//////////////
// local method
The checkNode method fetches the graphic property to see if a flag is defined for the node in its current state.
// manage graphic props
private void checkNode(IlvSDMEngine engine, Object obj,
IlvGraphic graphic) {
Object rawFlag = IlvRendererUtil.getGraphicProperty(engine, obj,
FLAG, REND_CLASS, null);
if (rawFlag != null && rawFlag instanceof IlvGraphic) {
IlvGraphic g = (IlvGraphic) rawFlag;
// set flag location at top left corner
IlvRect r = graphic.boundingBox(null);
g.move(r.x, r.y);
// add object
engine.getGrapher().addObject(g, _flagLayer, true);
// save flag in the graphic itself
graphic.addProperty(FLAG_GRAPHICS, g);
}
}
The checkNode
method checks
if a flag is requested and renders the flag if necessary by adding
it at the upper left of the object.
The following code example shows the code for cleanNode
.
Removing a flag
// remove previous flag
private void cleanNode(IlvSDMEngine engine, IlvGraphic graphic) {
// get the flag object from the source
Object previous = graphic.getProperty(FLAG_GRAPHICS);
if (previous != null) {
// remove it and clear the property
engine.getGrapher().removeObject((IlvGraphic)previous,true);
graphic.removeProperty(FLAG_GRAPHICS);
}
}
The cleanNode
method is used
to remove the flag when it is no longer needed.
The following code example shows the code for moveNode
.
Moving the flag with the node
// adjust flag position
private void moveNode(IlvRect newBBox, IlvGraphic flag) {
if (flag == null)
return;
flag.move(newBBox.x, newBBox.y);
}
The moveNode
method is used
to move only the flag, according to the new bounding box of the node
on which it appears.