Hi.
Actually, the AvoidsNodes property only works when the Orthogonal property is also true. And it’s also true that orthogonal links can have segments that overlap.
If you stay with cubic links, you could detect the case where you are linking to the same node and route the link yourself. You might want to do this by overriding JGoLink.calculateStroke() so this will occur whenever the route needs to be recalculated.Thanks for the tip ssmith. I will try that.
How’s about some sample code maybe? Please? The overidden calculateStroke() method will look like this, but I need some help with the actual recalculation of the link.
{
if(this.getFromPort().getParent() == this.getToPort().getParent())
{
//Recalculation of link to avoid node done here...
}
else
{
super.calculateStroke();
}
}
The following code is on the JGoDocumentChanged event when a link is added to the document rather than an override of calculateStroke(), but it seems to work fine.
switch (e.getHint()) {
case JGoDocumentEvent.INSERTED:
if (e.getJGoObject()instanceof JGoLink) {
JGoLink link = (JGoLink) e.getJGoObject();
link.setArrowHeads(false, true);
link.setCubic(true);
JGoPort from = link.getFromPort();
JGoPort to = link.getToPort();
int existingSelfLinkCount = 0;
for (JGoListPosition pos = from.getFirstLinkPos(); pos != null; pos = from.getNextLinkPos(pos)) {
JGoLink l = from.getLinkAtPos(pos);
if ((from == l.getFromPort()) && (to == l.getToPort()) && (link != l)) {
existingSelfLinkCount++;
}
}
link.setCurviness(existingSelfLinkCount * 10);
link.calculateStroke();
}
break;
}
}
Thanks, I have thought about such a solution, where one sets the curviness on a self link based on the amount of existing self links on that specific node, but the problem is I’m running version 4.1, which does not have the cool setCurviness method
Actually, the upgrading is a really good idea. Version 4.1 is quite old now.
However, if you really want to stay with the old version, you could do something like the following:
void jGoView1_documentChanged(JGoDocumentEvent e) {
switch (e.getHint()) {
case JGoDocumentEvent.INSERTED:
if (e.getJGoObject()instanceof JGoLink) {
JGoLink link = (JGoLink) e.getJGoObject();
link.setArrowHeads(false, true);
link.setCubic(true);
JGoPort from = link.getFromPort();
JGoPort to = link.getToPort();
int existingSelfLinkCount = 0;
for (JGoListPosition pos = from.getFirstLinkPos(); pos != null; pos = from.getNextLinkPos(pos)) {
JGoLink l = from.getLinkAtPos(pos);
if ((from == l.getFromPort()) && (to == l.getToPort()) && (link != l)) {
existingSelfLinkCount++;
}
}
if (from == to) {
Point fromPoint = link.getStartPoint();
Point endPoint = link.getEndPoint();
link.removeAllPoints();
link.addPoint(fromPoint);
link.addPoint(from.getLocation().x + (existingSelfLinkCount + 1) * 40, from.getLocation().y);
link.addPoint(from.getLocation().x , from.getLocation().y + (existingSelfLinkCount + 1) * 40);
link.addPoint(endPoint);
}
}
break;
}
}
Thanks a lot man, I haven’t tried the code but reading it makes sense. Thanks again. Yes, I want to upgrade to the latest, but I first have to convince management… Thus far we have been able to do almost everything we need to with 4.1, its probably going to take a big halt point, which is solvable out of the box with 5.1.2 to convince them.