AbstractCpsObject.java 6.2 KB

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