Dépôt du be graphe
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PathDrawing.java 1.1KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. package org.insa.drawing.graph;
  2. import java.awt.Color;
  3. import org.insa.drawing.Drawing;
  4. import org.insa.graph.Arc;
  5. import org.insa.graph.Path;
  6. public class PathDrawing {
  7. // Default color
  8. public static final Color DEFAULT_PATH_COLOR = new Color(255, 0, 255);
  9. // Drawing
  10. private Drawing drawing;
  11. private GraphDrawing graphDrawing;
  12. /**
  13. * @param drawing
  14. */
  15. public PathDrawing(Drawing drawing) {
  16. this.drawing = drawing;
  17. this.graphDrawing = new GraphDrawing(drawing);
  18. }
  19. /**
  20. * Draw the given path with the given color.
  21. *
  22. * @param path
  23. * @param color
  24. */
  25. public void drawPath(Path path, Color color) {
  26. this.graphDrawing.drawPoint(path.getFirstNode().getPoint(), 4, color);
  27. this.drawing.setColor(color);
  28. this.drawing.setWidth(2);
  29. for (Arc arc: path.getArcs()) {
  30. this.graphDrawing.drawArc(arc, false);
  31. }
  32. this.graphDrawing.drawPoint(path.getLastNode().getPoint(), 4, color);
  33. }
  34. /**
  35. * Draw the given path with default color.
  36. *
  37. * @param path
  38. */
  39. public void drawPath(Path path) {
  40. drawPath(path, DEFAULT_PATH_COLOR);
  41. drawing.repaint();
  42. }
  43. }