Defining custom link style

We have a need for different link sytles: links represented by two and three lines, instead of the default 1 line. A two-line link would be two lines separated by the width of the arrowhead and connecting to the arrowhead at it’s width.

default -->

2-line __> (top line missing)

Is overriding calculateStroke() the way to do this? I didn’t notice anything like this in the examples…can anyone share an example?

thanks

The easiest thing to do is to have the JGoLink (i.e. JGoStroke) display with two pens, the regular pen and the highlight pen, where the highlight pen has a width equal to the width of your arrowheads, and the regular pen is somewhat less wide. Something like:
JGoPen OutsidePen = JGoPen.make(JGoPen.SOLID, 8, Color.black);
JGoPen InsidePen = JGoPen.make(JGoPen.SOLID, 6, Color.white);
public void viewChanged(JGoViewEvent evt) {
if (evt.getHint() == JGoViewEvent.LINK_CREATED) {
if (evt.getJGoObject() instanceof JGoLink) {
JGoLink link = (JGoLink)evt.getJGoObject();
link.setPen(InsidePen);
link.setHighlight(OutsidePen);
}
}
}

Ah, well, what I posted basically works, except for the arrowhead part isn’t drawn the way I assume you would want.
Here’s one possible work-around for that. I took a short-cut and assumed that there would be an arrowhead only at the “To” end.
public class ThickLink extends JGoLabeledLink {
public ThickLink() { init(); }
public ThickLink(JGoPort a, JGoPort b) { super(a, b); init(); }
private void init() {
setPen(JGoPen.make(JGoPen.SOLID, 6, Color.yellow));
setHighlight(JGoPen.make(JGoPen.SOLID, 8, Color.blue));
setBrush(JGoBrush.make(JGoBrush.SOLID, Color.blue));
setArrowShaftLength(10);
setArrowHeads(false, true);
}
public void calculateStroke() {
super.calculateStroke();
// assume no arrow at start
if (hasArrowAtEnd()) {
Point start = getArrowToAnchorPoint();
Point end = getArrowToEndPoint();
if (start == null || end == null) return;
int[] headx = new int[4];
int[] heady = new int[4];
calculateFilledArrowhead(start.x, start.y, end.x, end.y, 1, headx, heady);
myEndPointX = end.x;
myEndPointY = end.y;
setPoint(getNumPoints()-1, headx[0], heady[0]);
}
}
protected void drawArrowHeads(Graphics2D g) {
// assume no arrow at start
if (hasArrowAtEnd()) {
Point start = getArrowToAnchorPoint();
if (start == null) return;
int[] headx = new int[4];
int[] heady = new int[4];
calculateFilledArrowhead(start.x, start.y, myEndPointX, myEndPointY, 1, headx, heady);
JGoStroke.drawPolygon(g, null, getBrush(), headx, heady, 4);
}
}
private int myEndPointX;
private int myEndPointY;
}

Walter.

That works well…thanks!

I can change the arrowhead properties (width, length) to minimize the effect of seeing the wider highlight pen throught the end of the arrow.
Is there an easy way you know of to end the link before the end of the arrow? or maybe extend the end point of the arrow some?

[Edit] Ah, this was before I saw your last post, Walter.

Is it possible to have the highlight cover the arrow head also?