AbstractCanvasObject.java 4.1 KB

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