Java Utililty Methods Draw Arrow

List of utility methods to do Draw Arrow

Description

The list of methods to do Draw Arrow are organized into topic(s).

Method

voiddraw_nav1_backward_arrow(Graphics2D g2, int x, int y, int length, int base_width)
dranabackwararrow
GeneralPath polyline;
int arrow_top_y = y - length + (base_width / 3);
int arrow_bottom_y = arrow_top_y + length;
g2.drawLine(x, arrow_top_y, x, arrow_bottom_y);
polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 2);
polyline.moveTo(x - (base_width / 2), arrow_bottom_y);
polyline.lineTo(x, y);
polyline.lineTo(x + (base_width / 2), arrow_bottom_y);
...
voiddraw_nav2_backward_arrow(Graphics2D g2, int x, int y, int length, int base_width)
dranabackwararrow
GeneralPath polyline;
int arrow_top_y = y - length + (base_width / 3);
int arrow_bottom_y = arrow_top_y + length;
polyline = new GeneralPath(GeneralPath.WIND_EVEN_ODD, 9);
polyline.moveTo(x - (base_width / 2), arrow_bottom_y);
polyline.lineTo(x - (base_width / 2), y);
polyline.lineTo(x - (base_width / 4), y - (base_width / 4));
polyline.lineTo(x - (base_width / 4), arrow_top_y + (base_width / 4));
...
voiddrawArrow(final Graphics2D g, final int x1, final int y1, final int x2, final int y2)
Draw arrow of a message in communication diagram
final int ARR_SIZE = 5;
AffineTransform saveAT = g.getTransform();
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);
...
voiddrawArrow(Graphics g, double x0, double y0, double x1, double y1, double weight)
Draws an arrow between two points (specified by their coordinates) using the specified weight.
The arrow is leading from point from to point to.
int ix2, iy2, ix3, iy3;
double sinPhi, cosPhi, dx, dy, xk1, yk1, xk2, yk2, s;
dx = x1 - x0;
dy = y1 - y0;
int maxArrowWidth = 10;
s = Math.sqrt(dy * dy + dx * dx);
int headLength = (int) Math.round(s * 0.5);
double arrowAngle = Math.atan((double) (weight * maxArrowWidth) / headLength);
...
voiddrawArrow(Graphics g, int x0, int y0, int x1, int y1, int headLength, int headAngle)
draw Arrow
double offs = headAngle * Math.PI / 180.0;
double angle = Math.atan2(y0 - y1, x0 - x1);
int[] xs = { x1 + (int) (headLength * Math.cos(angle + offs)), x1,
        x1 + (int) (headLength * Math.cos(angle - offs)) };
int[] ys = { y1 + (int) (headLength * Math.sin(angle + offs)), y1,
        y1 + (int) (headLength * Math.sin(angle - offs)) };
g.drawLine(x0, y0, x1, y1);
g.drawPolyline(xs, ys, 3);
...
voiddrawArrow(Graphics g, int x1, int y1, int x2, int y2, int lineWidth)
draw Arrow
drawLine(g, x1, y1, x2, y2, lineWidth);
calcValues(x1, y1, x2, y2);
g.fillPolygon(xValues, yValues, 3);
voiddrawArrow(Graphics g, Point from, Point to)
draw Arrow
int arrowLength = 10;
int deltaX = to.x - from.x;
int deltaY = to.y - from.y;
float length = (float) Math.sqrt(deltaX * deltaX + deltaY * deltaY);
Point toRotate = new Point();
toRotate.x = Math.round(0 - (arrowLength * deltaX) / length);
toRotate.y = Math.round(0 - (arrowLength * deltaY) / length);
Point one = rotate(toRotate, (float) Math.toRadians(20));
...
voiddrawArrow(Graphics g1, int x1, int y1, int x2, int y2, int lineWidth)
draw Arrow
Graphics2D g = (Graphics2D) g1.create();
double dx = x2 - x1;
double dy = y2 - y1;
double angle = Math.atan2(dy, dx);
int len = (int) Math.sqrt(dx * dx + dy * dy);
AffineTransform t = AffineTransform.getTranslateInstance(x1, y1);
t.concatenate(AffineTransform.getRotateInstance(angle));
g.transform(t);
...
voiddrawArrow(Graphics2D g, Point2D point, double angle, int len)
draw Arrow
AffineTransform at = AffineTransform.getTranslateInstance(point.getX(), point.getY());
at.concatenate(AffineTransform.getRotateInstance(angle));
AffineTransform restoreTransform = g.getTransform();
g.transform(at);
int ARR_SIZE = 42;
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);
...
voiddrawArrow(Graphics2D g2d, double x1, double y1, double x2, double y2)
Draw an arrow, useful for debug
Graphics2D g = (Graphics2D) g2d.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);
g.drawLine(0, 0, len, 0);
...