AbstractCanvasObject.java 4.5 KB

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