UnitGraphPoint.java 1.4 KB

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