| | | | Browse by category |
Question
How to customize tooltip text to display information about all overlapped nodes?
Answer
In order to customize tooltip text to display information about all the overlapped nodes, you need to:
1. Subclass the
and override the following method and constructors:
- getTooltipText to return dynamically generated text
- default constructor
- constructor that accepts an IlvInputStream
- constructor that accepts another object of the same type
- copy method that returns a copy of the same object type
public class MySDMCompositeNode extends IlvSDMCompositeNode {
public MySDMCompositeNode()
{
super();
}
public MySDMCompositeNode(IlvLayoutManager layout)
{
super(layout);
}
public MySDMCompositeNode(MySDMCompositeNode source)
{
super(source);
}
public MySDMCompositeNode(IlvInputStream stream)
throws IlvReadFileException
{
super(stream);
}
public IlvGraphic copy()
{
return new MySDMCompositeNode(this);
}
public String getToolTipText(IlvPoint p, IlvTransformer t)
{
String text = computeComplexTooltip(p, t);
if (!text.isEmpty())
return text;
// otherwise, use the base functionality
return super.getToolTipText(p, t);
}
private String computeComplexTooltip(IlvPoint p, IlvTransformer t) {
ArrayList<String> lines = new ArrayList<String>();
IlvManager mgr = null;
IlvGraphicBag gb = getGraphicBag();
while( gb!= null)
{
if( gb instanceof IlvManager )
{
mgr = (IlvManager) gb;
Enumeration e = mgr.getViews();
while (e.hasMoreElements()) {
IlvManagerView view = (IlvManagerView)e.nextElement();
if (view != null)
{
IlvGraphicVector vector =
mgr.getAllObjects(p, view, true, false);
for( int i = 0; i < vector.size(); i++ )
{
IlvGraphic g = vector.elementAt(i);
// Expecting HalfZoomingGraphic when HalfZooming
// renderer is being used in the CSS file
if( mgr.isVisible(g) &&
g instanceof
IlvHalfZoomingRenderer.HalfZoomingGraphic )
{
lines.add(
((IlvHalfZoomingRenderer.HalfZoomingGraphic)g).
getObject().getToolTipText());
}
}
}
}
break;
}
gb = gb.getGraphicBag();
}
String[] linesArray = lines.toArray(new String[lines.size()]);
return
ilog.views.util.swing.IlvSwingUtil.createMultiLineToolTipText(
linesArray, SwingConstants.LEFT);
}
}
Note: When HalfZooming renderer is being used, the manager will return IlvHalfZoomingRenderer
.HalfZoomingGraphic
objects. If HalfZooming renderer is not used, then you should be getting the MySDMCompositeNode as the graphic objects in the IlvGraphicVector
returned by the IlvManager.getAllObjects
method.
2. Set the above custom composite node to the node rule via CSS:
node { class : "MySDMCompositeNode" ; ... // define other properties for the node as usual
}