UnitGraphPoint.java 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. package classes;
  2. import java.awt.Point;
  3. import java.awt.geom.Point2D;
  4. /**
  5. * A class for saving all points of a Object with a editable state.
  6. * e.g HolonElement, HolonSwitch
  7. * @author Tom Troppmann
  8. *
  9. */
  10. public class UnitGraphPoint {
  11. /** Relative position in the UnitGraphCanvas */
  12. public double x,y;
  13. /** To determine if this point has changed to only write back points that are changed.*/
  14. public boolean changed;
  15. /** The displayed Position of the UnitGraphPoint*/
  16. public Position displayedPosition;
  17. /** Default Constructor */
  18. public UnitGraphPoint(double x, double y, boolean changed){
  19. this.x = x;
  20. this.y = y;
  21. this.changed = changed;
  22. }
  23. /** Constructor with a Point2D.Double*/
  24. public UnitGraphPoint(Point2D.Double pos, boolean changed){
  25. this.x = pos.getX();
  26. this.y = pos.getY();
  27. this.changed = changed;
  28. }
  29. /** Constructor with a Point2D.Double
  30. * when changed not specified is false;
  31. * */
  32. public UnitGraphPoint(Point2D.Double pos){
  33. this.x = pos.getX();
  34. this.y = pos.getY();
  35. this.changed = false;
  36. }
  37. public void calcDisplayedPosition(int border, int widthWithBorder, int heightWithBorder) {
  38. //Relativ to Border
  39. //1-p.y because its on the Top
  40. displayedPosition = new Position((int) (x * widthWithBorder) + border, (int) ((1-y) * heightWithBorder) + border);
  41. }
  42. public Point.Double getPoint()
  43. {
  44. return new Point2D.Double(x, y);
  45. }
  46. @Override
  47. public String toString() {
  48. return "[" + x + ":" + y + "]";
  49. }
  50. }