Our application requires drawing arrows on the JGoLabeledLink. Other than the from port and the to port i want the arrows to be displayed on the center of all the three segments of the link. how I can get it work?
This isn’t perfect, but it was easy to implement:
[code]/*
- Copyright © Northwoods Software Corporation, 2000-2008. All Rights
- Reserved.
- Restricted Rights: Use, duplication, or disclosure by the U.S.
- Government is subject to restrictions as set forth in subparagraph
- © (1) (ii) of DFARS 252.227-7013, or in FAR 52.227-19, or in FAR
- 52.227-14 Alt. III, as applicable.
*/
package com.nwoods.jgo.examples.demo1;
import com.nwoods.jgo.;
import java.awt.;
public class MidArrowLink extends JGoLink {
public MidArrowLink() { }
public MidArrowLink(JGoPort from, JGoPort to) { super(from, to); }
protected void drawArrowHeads(Graphics2D g) {
super.drawArrowHeads(g);
int[] headx = new int[4];
int[] heady = new int[4];
int nPoints = getNumPoints();
if (nPoints < 2) return;
int midEnd = nPoints/2;
int startx, starty, endx, endy;
if (nPoints % 2 == 0) { // even number of points means odd number of segments
// get the middle segment (perhaps the only one)
startx = getPointX(midEnd-1);
starty = getPointY(midEnd-1);
endx = getPointX(midEnd);
endy = getPointY(midEnd);
} else {
// also find the points on either side of the middle point
// then figure out if one segment is much longer than the other
int ax = getPointX(midEnd-1);
int ay = getPointY(midEnd-1);
int bx = getPointX(midEnd);
int by = getPointY(midEnd);
int cx = getPointX(midEnd+1);
int cy = getPointY(midEnd+1);
float d1x = bx-ax;
float d1y = by-ay;
float d2x = cx-bx;
float d2y = cy-by;
if (d1x*d1x+d1y*d1y >= d2x*d2x+d2y*d2y) {
startx = ax;
starty = ay;
endx = bx;
endy = by;
} else {
startx = bx;
starty = by;
endx = cx;
endy = cy;
}
}
int mx = (startx+endx)/2;
int my = (starty+endy)/2;
// this has the end point being the middle of the middle segment of the stroke
calculateFilledArrowhead(startx,starty,mx,my, 1, headx,heady);
drawArrowhead(g, true, headx, heady);
}
}[/code]