AbstractCanvasObject.java 4.5 KB

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