AbstractCanvasObject.java 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. package holeg.model;
  2. import holeg.ui.model.IdCounter;
  3. import holeg.utility.math.vector.Vec2i;
  4. import java.util.Optional;
  5. /**
  6. * The abstract class "CpsObject" represents any possible object in the system (except Edges). The
  7. * representation of any object contains following variables: see description of variables
  8. *
  9. * @author Gruppe14
  10. */
  11. public abstract class AbstractCanvasObject {
  12. /* ID of the Obj. */
  13. private final int id;
  14. /* Name given by the user. */
  15. String name = "";
  16. /* Path of the image for the Obj. */
  17. String imagePath = "";
  18. /* Position with a X and Y value */
  19. Vec2i position = new Vec2i(0, 0);
  20. private transient GroupNode groupNode;
  21. /**
  22. * Constructor for a CpsObejct with an unique ID.
  23. *
  24. * @param objName of the Object
  25. */
  26. public AbstractCanvasObject(String objName) {
  27. setName(objName);
  28. this.id = IdCounter.next();
  29. }
  30. /**
  31. * Constructor for a new CpsObject with an unique ID (This constructor correspond to the
  32. * interaction between the Categories and Canvas)--> actually the "new" Object is a copy.
  33. *
  34. * @param other Object to be copied
  35. */
  36. public AbstractCanvasObject(AbstractCanvasObject other) {
  37. setName(other.getName());
  38. setImagePath(other.getImagePath());
  39. this.position = new Vec2i(other.position);
  40. this.id = IdCounter.next();
  41. }
  42. public Optional<GroupNode> getGroupNode() {
  43. return Optional.ofNullable(groupNode);
  44. }
  45. public void setGroupNode(GroupNode groupNode) {
  46. this.groupNode = groupNode;
  47. }
  48. public abstract AbstractCanvasObject copy();
  49. /**
  50. * Getter for the user-defined name (no unique).
  51. *
  52. * @return String
  53. */
  54. public String getName() {
  55. return name;
  56. }
  57. /**
  58. * Set the name.
  59. *
  60. * @param name String
  61. */
  62. public void setName(String name) {
  63. this.name = name;
  64. }
  65. /**
  66. * Get the path of the image for the selected Object.
  67. *
  68. * @return String
  69. */
  70. public String getImagePath() {
  71. return imagePath;
  72. }
  73. /**
  74. * Set the path of the image.
  75. *
  76. * @param imagePath the Image to set
  77. */
  78. public void setImagePath(String imagePath) {
  79. this.imagePath = imagePath;
  80. }
  81. public int getId() {
  82. return id;
  83. }
  84. /**
  85. * Set the position of the Object in the canvas.
  86. *
  87. * @param x X-Coord
  88. * @param y Y-Coord
  89. */
  90. public void setPosition(int x, int y) {
  91. setPosition(new Vec2i(x, y));
  92. }
  93. /**
  94. * Get the actual position of the Object.
  95. *
  96. * @return Position Position of this Object
  97. */
  98. public Vec2i getPosition() {
  99. return position;
  100. }
  101. /**
  102. * Set the position of the Object in the canvas.
  103. *
  104. * @param pos Coordinates
  105. */
  106. public void setPosition(Vec2i pos) {
  107. this.position = pos;
  108. }
  109. }