AbstractCanvasObject.java 3.0 KB

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