AbstractCanvasObject.java 4.5 KB

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