Each link is attached to what is called a pin.
Each pin describes the position of a contact point on a node.
The class IlvPinLinkConnector, which is a subclass of
the class IlvLinkConnector, manages the link
connections to a node. An instance of the class
IlvPinLinkConnector
may be installed on a graphic object. This instance holds a set of
pins.
When you create an
IlvPinLinkConnector
instance, it is empty and does not contain any pins. You must
provide a set of pins describing the position of the contact points
that you need. The pins are defined by the class IlvGrapherPin. This class is an abstract
class because its
getPosition
method is an abstract method. For this reason, you must first
create a subclass of the
IlvGrapherPin
class. Specifying an implementation to the getPosition method enables you to indicate
the position of the grapher pin. The
signature of this method follows:
IlvPoint getPosition(IlvTransformer t)
The position of the pin depends on the transformer used to draw the
node. This transformer is passed to the
getPosition
method. To compute the position of the pin, you may need to know
the position of the node. For its position, use:
IlvGraphic getNode()
You may also decide to allow or inhibit the connection of a certain
type of link to this pin. To do so, you overwrite the
allow
method of your pin, which is called when you create a link with an
interactor:
boolean allow(Object oClass, Object dClass, Object linkOrClass, boolean origin)
The interactor is authorized to highlight
only the specified pin based on the result of this method.
Once the pin classes are created, you must add the pins to the
previously created instance of
IlvPinLinkConnector
using the following method:
void addPin(IlvGrapherPin pin)
Example: Defining your connection points
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 classInPin
are placed on the left border of the object and the pins of typeOutPin
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)