AbstractCanvasObject.java 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. package model;
  2. import com.google.gson.annotations.Expose;
  3. import ui.model.IdCounter;
  4. import ui.model.IdCounter.CounterType;
  5. import utility.Vector2Int;
  6. import java.util.ArrayList;
  7. /**
  8. * The abstract class "CpsObject" represents any possible object in the system
  9. * (except Edges). The representation of any object contains following
  10. * variables: see description of variables
  11. *
  12. * @author Gruppe14
  13. *
  14. */
  15. public abstract class AbstractCanvasObject {
  16. /* Type of the Object. */
  17. @Expose
  18. String objName;
  19. /* Name given by the user. */
  20. @Expose
  21. String name;
  22. /* ID of the Obj. */
  23. @Expose
  24. private int id;
  25. /* Path of the image for the Obj. */
  26. @Expose
  27. String image;
  28. /* Array of neighbors */
  29. private ArrayList<Edge> connections = new ArrayList<>();
  30. /* Position with a X and Y value */
  31. @Expose
  32. Vector2Int position = new Vector2Int(0,0);
  33. @Expose
  34. String sav;
  35. /**
  36. * Constructor for a CpsObejct with an unique ID.
  37. *
  38. * @param objName
  39. * of the Object
  40. */
  41. public AbstractCanvasObject(String objName) {
  42. setName(objName);
  43. this.id = IdCounter.nextId(CounterType.Object);
  44. }
  45. /**
  46. * Constructor for a new CpsObject with an unique ID (This constructor
  47. * correspond to the interaction between the Categories and Canvas)-->
  48. * actually the "new" Object is a copy.
  49. *
  50. * @param obj
  51. * Object to be copied
  52. */
  53. public AbstractCanvasObject(AbstractCanvasObject obj) {
  54. setName(obj.getName());
  55. setImage(obj.getImage());
  56. this.id = IdCounter.nextId(CounterType.Object);
  57. }
  58. public void initForReflection() {
  59. connections = new ArrayList<>();
  60. }
  61. /**
  62. * Getter for the user-defined name (no unique).
  63. *
  64. * @return String
  65. */
  66. public String getName() {
  67. return name;
  68. }
  69. /**
  70. * Set the name.
  71. *
  72. * @param name
  73. * String
  74. */
  75. public void setName(String name) {
  76. this.name = name;
  77. }
  78. /**
  79. * Get the path of the image for the selected Object.
  80. *
  81. * @return String
  82. */
  83. public String getImage() {
  84. return image;
  85. }
  86. /**
  87. * Set the path of the image.
  88. *
  89. * @param image
  90. * the Image to set
  91. */
  92. public void setImage(String image) {
  93. this.image = image;
  94. }
  95. public int getId() {
  96. return id;
  97. }
  98. /**
  99. * List of all existing connections.
  100. *
  101. * @return the connections ArrayList
  102. */
  103. public ArrayList<Edge> getConnections() {
  104. return connections;
  105. }
  106. /**
  107. * Set a new ArrayList of connections (Update).
  108. *
  109. * @param arrayList
  110. * the connections to set
  111. */
  112. public void setConnections(ArrayList<Edge> arrayList) {
  113. this.connections = arrayList;
  114. }
  115. /**
  116. * List of all existing connections.
  117. *
  118. * @return the connections ArrayList
  119. */
  120. public ArrayList<Edge> getConnectedTo() {
  121. return connections;
  122. }
  123. /**
  124. * Add a new connection to the selected Object.
  125. *
  126. * @param toConnect
  127. * Edge
  128. */
  129. public void addConnection(Edge toConnect) {
  130. connections.add(toConnect);
  131. }
  132. /**
  133. * Set the position of the Object in the canvas.
  134. *
  135. * @param x
  136. * X-Coord
  137. * @param y
  138. * Y-Coord
  139. */
  140. public void setPosition(int x, int y) {
  141. setPosition(new Vector2Int(x, y));
  142. }
  143. /**
  144. * Get the actual position of the Object.
  145. *
  146. * @return Position Position of this Object
  147. */
  148. public Vector2Int getPosition() {
  149. return position;
  150. }
  151. /**
  152. * Set the position of the Object in the canvas.
  153. *
  154. * @param pos Coordinates
  155. */
  156. public void setPosition(Vector2Int pos) {
  157. this.position = pos;
  158. }
  159. /**
  160. * For save purpose.
  161. *
  162. * @return the stored
  163. */
  164. public String getSav() {
  165. return sav;
  166. }
  167. /**
  168. * For save purpose.
  169. *
  170. * @param sav
  171. * the stored to set
  172. */
  173. //TODO(Tom2021-12-1): Remove SAV
  174. public void setSav(String sav) {
  175. this.sav = sav;
  176. }
  177. }