AbstractCpsObject.java 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358
  1. package classes;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import com.google.gson.annotations.Expose;
  5. /**
  6. * The abstract class "CpsObject" represents any possible object in the system
  7. * (except Edges). The representation of any object contains following
  8. * variables: see description of variables
  9. *
  10. * @author Gruppe14
  11. *
  12. */
  13. public abstract class AbstractCpsObject {
  14. /* Type of the Object. */
  15. @Expose
  16. String objName;
  17. /* Name given by the user. */
  18. @Expose
  19. String name;
  20. /* ID of the Obj. */
  21. @Expose
  22. int id;
  23. /* Path of the image for the Obj. */
  24. @Expose
  25. String image;
  26. /* Array of neighbors */
  27. ArrayList<CpsEdge> connections;
  28. /* Position with a X and Y value */
  29. @Expose
  30. Position position;
  31. /*
  32. * Energy input and output of each object in the grid Where the Object is
  33. * Stored
  34. */
  35. @Expose
  36. String sav;
  37. /* borderColor the user sets */
  38. Color borderColor = Color.WHITE;
  39. /* a Tag that can be used */
  40. ArrayList<Integer> tags;
  41. /* a Tag that can be used */
  42. ArrayList<Integer> pseudoTags;
  43. /**
  44. * Constructor for a CpsObejct with an unique ID.
  45. *
  46. * @param objName
  47. * of the Object
  48. */
  49. public AbstractCpsObject(String objName) {
  50. setObjName(objName);
  51. setName(objName);
  52. setImage("/Images/Dummy_House.png");
  53. tags = new ArrayList<Integer>();
  54. pseudoTags = new ArrayList<Integer>();
  55. }
  56. /**
  57. * Constructor for a new CpsObject with an unique ID (This constructor
  58. * correspond to the interaction between the Categories and Canvas)-->
  59. * actually the "new" Object is a copy.
  60. *
  61. * @param obj
  62. * Object to be copied
  63. */
  64. public AbstractCpsObject(AbstractCpsObject obj) {
  65. setObjName(obj.getObjName());
  66. setName(obj.getObjName());
  67. setConnections(new ArrayList<CpsEdge>());
  68. setPosition(new Position());
  69. setID(IdCounter.nextId());
  70. setImage(obj.getImage());
  71. }
  72. /**
  73. * Getter for the type of the Object.
  74. *
  75. * @return String
  76. */
  77. public String getObjName() {
  78. return objName;
  79. }
  80. /**
  81. * Set the type of Object.
  82. *
  83. * @param objName
  84. * String
  85. */
  86. public void setObjName(String objName) {
  87. this.objName = objName;
  88. }
  89. /**
  90. * Getter for the user-defined name (no unique).
  91. *
  92. * @return String
  93. */
  94. public String getName() {
  95. return name;
  96. }
  97. /**
  98. * Set the name.
  99. *
  100. * @param name
  101. * String
  102. */
  103. public void setName(String name) {
  104. this.name = name;
  105. }
  106. /**
  107. * Getter of the unique ID.
  108. *
  109. * @return int
  110. */
  111. public int getID() {
  112. return id;
  113. }
  114. /**
  115. * Set the ID to a new one.
  116. *
  117. * @param id
  118. * the iD to set
  119. */
  120. public void setID(int id) {
  121. this.id = id;
  122. }
  123. /**
  124. * Get the path of the image for the selected Object.
  125. *
  126. * @return String
  127. */
  128. public String getImage() {
  129. return image;
  130. }
  131. /**
  132. * Set the path of the image.
  133. *
  134. * @param image
  135. * the Image to set
  136. */
  137. public void setImage(String image) {
  138. this.image = image;
  139. }
  140. /**
  141. * List of all existing connections.
  142. *
  143. * @return the connections ArrayList
  144. */
  145. public ArrayList<CpsEdge> getConnections() {
  146. return connections;
  147. }
  148. /**
  149. * Set a new ArrayList of connections (Update).
  150. *
  151. * @param arrayList
  152. * the connections to set
  153. */
  154. public void setConnections(ArrayList<CpsEdge> arrayList) {
  155. this.connections = arrayList;
  156. }
  157. /**
  158. * List of all existing connections.
  159. *
  160. * @return the connections ArrayList
  161. */
  162. public ArrayList<CpsEdge> getConnectedTo() {
  163. return connections;
  164. }
  165. /**
  166. * Add a new connection to the selected Object.
  167. *
  168. * @param toConnect
  169. * Edge
  170. */
  171. public void addConnection(CpsEdge toConnect) {
  172. connections.add(toConnect);
  173. }
  174. /**
  175. * Set the position of the Object in the canvas.
  176. *
  177. * @param pos
  178. * Coordinates
  179. */
  180. public void setPosition(Position pos) {
  181. this.position = pos;
  182. }
  183. /**
  184. * Set the position of the Object in the canvas.
  185. *
  186. * @param x
  187. * X-Coord
  188. * @param y
  189. * Y-Coord
  190. */
  191. public void setPosition(int x, int y) {
  192. setPosition(new Position(x, y));
  193. }
  194. /**
  195. * Get the actual position of the Object.
  196. *
  197. * @return Position Position of this Object
  198. */
  199. public Position getPosition() {
  200. return position;
  201. }
  202. /**
  203. * For save purpose.
  204. *
  205. * @return the stored
  206. */
  207. public String getSav() {
  208. return sav;
  209. }
  210. /**
  211. * For save purpose.
  212. *
  213. * @param sav
  214. * the stored to set
  215. */
  216. public void setSav(String sav) {
  217. this.sav = sav;
  218. }
  219. /**
  220. * Get the color of the border.
  221. *
  222. * @return the BorderColor
  223. */
  224. public Color getBorderColor() {
  225. return borderColor;
  226. }
  227. /**
  228. * Set the Border Color of this CpsObject.
  229. *
  230. * @param c
  231. * the BorderColor
  232. */
  233. public void setBorderColor(Color c) {
  234. this.borderColor = c;
  235. }
  236. /**
  237. * For internal purpose (energy flow).
  238. *
  239. * @param tag
  240. * for internal purpose
  241. */
  242. public void addTag(int tag) {
  243. if (!(tags.contains(tag))) {
  244. this.tags.add(tag);
  245. }
  246. }
  247. public void addAllTags(ArrayList<Integer> tags) {
  248. for (Integer tag : tags) {
  249. addTag(tag);
  250. }
  251. }
  252. /**
  253. * Get the actual tags.
  254. *
  255. * @return ArrayList
  256. */
  257. public ArrayList<Integer> getTag() {
  258. return tags;
  259. }
  260. /**
  261. * Rest the tags to Null.
  262. */
  263. public void resetTags() {
  264. this.tags = new ArrayList<Integer>();
  265. this.pseudoTags = new ArrayList<Integer>();
  266. }
  267. /**
  268. * For internal purpose (energy flow).
  269. *
  270. * @param tags
  271. * for internal purpose
  272. */
  273. public void setTags(ArrayList<Integer> tags) {
  274. this.tags = tags;
  275. }
  276. /**
  277. * For internal purpose (energy flow).
  278. *
  279. * @param tags
  280. * for internal purpose
  281. */
  282. public void setPseudoTags(ArrayList<Integer> tags) {
  283. this.pseudoTags = tags;
  284. }
  285. /**
  286. * Get the pseudo tags.
  287. *
  288. * @return ArrayList
  289. */
  290. public ArrayList<Integer> getPseudoTags() {
  291. return this.pseudoTags;
  292. }
  293. /**
  294. * add a pseudo tag.
  295. *
  296. * @return ArrayList
  297. */
  298. public void addPseudoTag(int tag) {
  299. if (!pseudoTags.contains(tag)) {
  300. pseudoTags.add(tag);
  301. }
  302. }
  303. /**
  304. * adds all given pseudotags to the tags
  305. *
  306. * @param pseudoTags
  307. */
  308. public void addAllPseudoTags(ArrayList<Integer> pseudoTags) {
  309. for (Integer tag : pseudoTags) {
  310. addPseudoTag(tag);
  311. }
  312. }
  313. /**
  314. * adds All pseudoTags to tags without duplicates
  315. */
  316. public void recalculateTags() {
  317. for (Integer tag : pseudoTags) {
  318. if (!tags.contains(tag)) {
  319. tags.add(tag);
  320. }
  321. }
  322. }
  323. }