AbstractCanvasObject.java 4.5 KB

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