我想用箭頭畫一條線。該線可以有任何角度。如何在SWT中實現它?如何在畫布上用SWT中的箭頭畫線
我發現了類似的帖子,但它在AWT
。我想將它轉換成SWT
。但面臨問題將以下方法轉換爲SWT。特別是在以下行:
at.concatenate(AffineTransform.getRotateInstance(angle));
這裏是this post
void drawArrow(Graphics g1, int x1, int y1, int x2, int y2) {
Graphics2D g = (Graphics2D) g1.create();
double dx = x2 - x1, dy = y2 - y1;
double angle = Math.atan2(dy, dx);
int len = (int) Math.sqrt(dx*dx + dy*dy);
AffineTransform at = AffineTransform.getTranslateInstance(x1, y1);
at.concatenate(AffineTransform.getRotateInstance(angle));
g.transform(at);
// Draw horizontal arrow starting in (0, 0)
g.drawLine(0, 0, len, 0);
g.fillPolygon(new int[] {len, len-ARR_SIZE, len-ARR_SIZE, len}, new int[] {0, -ARR_SIZE, ARR_SIZE, 0}, 4);
}
[Eclipse的GEF(http://eclipse.org/gef/)可能有一些 –