AbstractCanvasObject.java 3.1 KB

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