AbstractCpsObject.java 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325
  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. }
  47. /**
  48. * Constructor for a new CpsObject with an unique ID (This constructor
  49. * correspond to the interaction between the Categories and Canvas)-->
  50. * actually the "new" Object is a copy.
  51. *
  52. * @param obj
  53. * Object to be copied
  54. */
  55. public AbstractCpsObject(AbstractCpsObject obj) {
  56. setObjName(obj.getObjName());
  57. setName(obj.getObjName());
  58. setConnections(new ArrayList<CpsEdge>());
  59. setPosition(new Position());
  60. setID(IdCounter.nextId());
  61. setImage(obj.getImage());
  62. }
  63. /**
  64. * Getter for the type of the Object.
  65. *
  66. * @return String
  67. */
  68. public String getObjName() {
  69. return objName;
  70. }
  71. /**
  72. * Set the type of Object.
  73. *
  74. * @param objName
  75. * String
  76. */
  77. public void setObjName(String objName) {
  78. this.objName = objName;
  79. }
  80. /**
  81. * Getter for the user-defined name (no unique).
  82. *
  83. * @return String
  84. */
  85. public String getName() {
  86. return name;
  87. }
  88. /**
  89. * Set the name.
  90. *
  91. * @param name
  92. * String
  93. */
  94. public void setName(String name) {
  95. this.name = name;
  96. }
  97. /**
  98. * Getter of the unique ID.
  99. *
  100. * @return int
  101. */
  102. public int getID() {
  103. return id;
  104. }
  105. /**
  106. * Set the ID to a new one.
  107. *
  108. * @param id
  109. * the iD to set
  110. */
  111. public void setID(int id) {
  112. this.id = id;
  113. }
  114. /**
  115. * Get the path of the image for the selected Object.
  116. *
  117. * @return String
  118. */
  119. public String getImage() {
  120. return image;
  121. }
  122. /**
  123. * Set the path of the image.
  124. *
  125. * @param image
  126. * the Image to set
  127. */
  128. public void setImage(String image) {
  129. this.image = image;
  130. }
  131. /**
  132. * List of all existing connections.
  133. *
  134. * @return the connections ArrayList
  135. */
  136. public ArrayList<CpsEdge> getConnections() {
  137. return connections;
  138. }
  139. /**
  140. * Set a new ArrayList of connections (Update).
  141. *
  142. * @param arrayList
  143. * the connections to set
  144. */
  145. public void setConnections(ArrayList<CpsEdge> arrayList) {
  146. this.connections = arrayList;
  147. }
  148. /**
  149. * List of all existing connections.
  150. *
  151. * @return the connections ArrayList
  152. */
  153. public ArrayList<CpsEdge> getConnectedTo() {
  154. return connections;
  155. }
  156. /**
  157. * Add a new connection to the selected Object.
  158. *
  159. * @param toConnect
  160. * Edge
  161. */
  162. public void addConnection(CpsEdge toConnect) {
  163. connections.add(toConnect);
  164. }
  165. /**
  166. * Set the position of the Object in the canvas.
  167. *
  168. * @param pos
  169. * Coordinates
  170. */
  171. public void setPosition(Position pos) {
  172. this.position = pos;
  173. }
  174. /**
  175. * Set the position of the Object in the canvas.
  176. *
  177. * @param x
  178. * X-Coord
  179. * @param y
  180. * Y-Coord
  181. */
  182. public void setPosition(int x, int y) {
  183. setPosition(new Position(x, y));
  184. }
  185. /**
  186. * Get the actual position of the Object.
  187. *
  188. * @return Position Position of this Object
  189. */
  190. public Position getPosition() {
  191. return position;
  192. }
  193. /**
  194. * For save purpose.
  195. *
  196. * @return the stored
  197. */
  198. public String getSav() {
  199. return sav;
  200. }
  201. /**
  202. * For save purpose.
  203. *
  204. * @param sav
  205. * the stored to set
  206. */
  207. public void setSav(String sav) {
  208. this.sav = sav;
  209. }
  210. /**
  211. * Get the color of the border.
  212. *
  213. * @return the BorderColor
  214. */
  215. public Color getBorderColor() {
  216. return borderColor;
  217. }
  218. /**
  219. * Set the Border Color of this CpsObject.
  220. *
  221. * @param c
  222. * the BorderColor
  223. */
  224. public void setBorderColor(Color c) {
  225. this.borderColor = c;
  226. }
  227. /**
  228. * Set the Color of the edges.
  229. *
  230. * @param color
  231. * the Color to set
  232. */
  233. public void setConnections(Color color) {
  234. this.borderColor = color;
  235. }
  236. /**
  237. * For internal purpose (energy flow).
  238. *
  239. * @param tag
  240. * for internal purpose
  241. */
  242. public void addTag(int tag) {
  243. this.tags.add(tag);
  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. }
  259. /**
  260. * For internal purpose (energy flow).
  261. *
  262. * @param tags
  263. * for internal purpose
  264. */
  265. public void setTags(ArrayList<Integer> tags) {
  266. this.tags = tags;
  267. }
  268. /**
  269. * For internal purpose (energy flow).
  270. *
  271. * @param tags
  272. * for internal purpose
  273. */
  274. public void setPseudoTags(ArrayList<Integer> tags) {
  275. this.pseudoTags= tags;
  276. }
  277. /**
  278. * Get the pseudo tags.
  279. *
  280. * @return ArrayList
  281. */
  282. public ArrayList<Integer> getPseudoTags() {
  283. return this.pseudoTags;
  284. }
  285. /**
  286. * add a pseudo tag.
  287. *
  288. * @return ArrayList
  289. */
  290. public ArrayList<Integer> addPseudoTag() {
  291. return this.pseudoTags;
  292. }
  293. }