RenderHelper.java 1.3 KB

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