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