This example defines two classes of pins:
The class InPin
that
allows links to go to the node.
The class OutPin
that
allows links to come from the node.
The
pins of class InPin
are placed on the left
border of the object and the pins of type OutPin
on
the right border.
The classes are:
final class InPin extends IlvGrapherPin
{
static final int numberOfPins = 5;
int index;
public InPin(IlvPinLinkConnector connector, int index)
{
super(connector);
this.index = index;
}
protected boolean allow(Object orig, Object dest,
Object linkOrClass,
boolean origin)
{
return !origin;
}
public IlvPoint getPosition(IlvTransformer t)
{
IlvRect bbox = getNode().boundingBox(null);
IlvPoint p = new IlvPoint(bbox.x,
bbox.y+(bbox.height/(numberOfPins+1)*
(index+1));
if (t != null) t.apply(p);
return p;
}
}
In this example, five instances of InPin
will
be created. Each pin has an index giving its position on the node.
The getPosition
method returns the position
of the pin on the left side of the node according to its index. The allow
method
returns true
only for links going to this
pin (parameter origin
is false
).
The OutPin
class is very similar:
final class OutPin extends IlvGrapherPin
{
static final int numberOfPins = 5;
int index;
public OutPin(IlvPinLinkConnector connector, int index)
{
super(connector);
this.index = index;
}
protected boolean allow(Object orig, Object dest,
Object linkOrClass, boolean origin)
{
return origin;
}
public IlvPoint getPosition(IlvTransformer t)
{
IlvRect bbox = getNode().boundingBox(null);
IlvPoint p = new IlvPoint(bbox.x+ bbox.width,
bbox.y+(bbox.height/
(numberOfPins+1))*(index+1));
if (t != null) t.apply(p);
return p;
}
}
The pins are located on the right side and only allow
links leaving the node.
If node
is a graphic object,
the method that adds the pins to the node is:
grapher.addNode(node, 1, false);
IlvPinLinkConnector lc = new IlvPinLinkConnector(node);
for (int i = 0; i < 5; i++) {
new InPin(lc, i);
new OutPin(lc, i);
}
If you want to connect a link to a particular pin, use
the method connectLink
of the class IlvPinLinkConnector
:
public void connectLink(IlvLinkImage link, IlvGrapherPin pin, boolean origin)