RenderHelper.java 999 B

1234567891011121314151617181920212223242526272829303132333435
  1. package View;
  2. import java.awt.Point;
  3. import java.awt.Polygon;
  4. import java.awt.Shape;
  5. import java.awt.geom.AffineTransform;
  6. /**
  7. * Contains helper functions for the views.
  8. * @author kolja
  9. *
  10. */
  11. public class RenderHelper {
  12. /**
  13. * creates an arrow shape to draw it, for example as an edge.
  14. * @param fromPt the starting point of the arrow
  15. * @param toPt the destination point of the arrow
  16. * @return the shape
  17. */
  18. public static Shape createArrowShape(Point fromPt, Point toPt) {
  19. Polygon arrowPolygon = new Polygon();
  20. arrowPolygon.addPoint(-3,6);
  21. arrowPolygon.addPoint(3,0);
  22. arrowPolygon.addPoint(-3,-6);
  23. arrowPolygon.addPoint(-3,6);
  24. double rotate = Math.atan2( ( toPt.y - fromPt.y ) , ( toPt.x - fromPt.x ) );
  25. AffineTransform transform = new AffineTransform();
  26. transform.translate(toPt.x, toPt.y);
  27. transform.rotate(rotate);
  28. return transform.createTransformedShape(arrowPolygon);
  29. }
  30. }