AbstractCpsObject.java 6.1 KB

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