AbstractCanvasObject.java 2.9 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
  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 = 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. /**
  51. * Getter for the user-defined name (no unique).
  52. *
  53. * @return String
  54. */
  55. public String getName() {
  56. return name;
  57. }
  58. /**
  59. * Set the name.
  60. *
  61. * @param name String
  62. */
  63. public void setName(String name) {
  64. this.name = name;
  65. }
  66. /**
  67. * Get the path of the image for the selected Object.
  68. *
  69. * @return String
  70. */
  71. public String getImagePath() {
  72. return imagePath;
  73. }
  74. /**
  75. * Set the path of the image.
  76. *
  77. * @param imagePath the Image to set
  78. */
  79. public void setImagePath(String imagePath) {
  80. this.imagePath = imagePath;
  81. }
  82. public int getId() {
  83. return id;
  84. }
  85. /**
  86. * Set the position of the Object in the canvas.
  87. *
  88. * @param x X-Coord
  89. * @param y Y-Coord
  90. */
  91. public void setPosition(int x, int y) {
  92. setPosition(new Vec2i(x, y));
  93. }
  94. /**
  95. * Get the actual position of the Object.
  96. *
  97. * @return Position Position of this Object
  98. */
  99. public Vec2i getPosition() {
  100. return position;
  101. }
  102. /**
  103. * Set the position of the Object in the canvas.
  104. *
  105. * @param pos Coordinates
  106. */
  107. public void setPosition(Vec2i pos) {
  108. this.position = pos;
  109. }
  110. }