RenderHelper.java 1.3 KB

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