AbstractCpsObject.java 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326
  1. package classes;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import ui.model.idCounter;
  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. String objName;
  16. /* Name given by the user. */
  17. String name;
  18. /* ID of the Obj. */
  19. int id;
  20. /* Path of the image for the Obj. */
  21. String image;
  22. /* Array of neighbors */
  23. ArrayList<CpsEdge> connections;
  24. /* Position with a X and Y value */
  25. Position position;
  26. /*
  27. * Energy input and output of each object in the grid Where the Object is
  28. * Stored
  29. */
  30. 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. }
  48. /**
  49. * Constructor for a new CpsObject with an unique ID (This constructor
  50. * correspond to the interaction between the Categories and Canvas)-->
  51. * actually the "new" Object is a copy.
  52. *
  53. * @param obj
  54. * Object to be copied
  55. */
  56. public AbstractCpsObject(AbstractCpsObject obj) {
  57. setObjName(obj.getObjName());
  58. setName(obj.getObjName());
  59. setConnections(new ArrayList<CpsEdge>());
  60. setPosition(new Position());
  61. setID(idCounter.nextId());
  62. setImage(obj.getImage());
  63. }
  64. /**
  65. * Getter for the type of the Object.
  66. *
  67. * @return String
  68. */
  69. public String getObjName() {
  70. return objName;
  71. }
  72. /**
  73. * Set the type of Object.
  74. *
  75. * @param objName
  76. * String
  77. */
  78. public void setObjName(String objName) {
  79. this.objName = objName;
  80. }
  81. /**
  82. * Getter for the user-defined name (no unique).
  83. *
  84. * @return String
  85. */
  86. public String getName() {
  87. return name;
  88. }
  89. /**
  90. * Set the name.
  91. *
  92. * @param name
  93. * String
  94. */
  95. public void setName(String name) {
  96. this.name = name;
  97. }
  98. /**
  99. * Getter of the unique ID.
  100. *
  101. * @return int
  102. */
  103. public int getID() {
  104. return id;
  105. }
  106. /**
  107. * Set the ID to a new one.
  108. *
  109. * @param id
  110. * the iD to set
  111. */
  112. public void setID(int id) {
  113. this.id = id;
  114. }
  115. /**
  116. * Get the path of the image for the selected Object.
  117. *
  118. * @return String
  119. */
  120. public String getImage() {
  121. return image;
  122. }
  123. /**
  124. * Set the path of the image.
  125. *
  126. * @param image
  127. * the Image to set
  128. */
  129. public void setImage(String image) {
  130. this.image = image;
  131. }
  132. /**
  133. * List of all existing connections.
  134. *
  135. * @return the connections ArrayList
  136. */
  137. public ArrayList<CpsEdge> getConnections() {
  138. return connections;
  139. }
  140. /**
  141. * Set a new ArrayList of connections (Update).
  142. *
  143. * @param arrayList
  144. * the connections to set
  145. */
  146. public void setConnections(ArrayList<CpsEdge> arrayList) {
  147. this.connections = arrayList;
  148. }
  149. /**
  150. * List of all existing connections.
  151. *
  152. * @return the connections ArrayList
  153. */
  154. public ArrayList<CpsEdge> getConnectedTo() {
  155. return connections;
  156. }
  157. /**
  158. * Add a new connection to the selected Object.
  159. *
  160. * @param toConnect
  161. * Edge
  162. */
  163. public void addConnection(CpsEdge toConnect) {
  164. connections.add(toConnect);
  165. }
  166. /**
  167. * Set the position of the Object in the canvas.
  168. *
  169. * @param pos
  170. * Coordinates
  171. */
  172. public void setPosition(Position pos) {
  173. this.position = pos;
  174. }
  175. /**
  176. * Set the position of the Object in the canvas.
  177. *
  178. * @param x
  179. * X-Coord
  180. * @param y
  181. * Y-Coord
  182. */
  183. public void setPosition(int x, int y) {
  184. setPosition(new Position(x, y));
  185. }
  186. /**
  187. * Get the actual position of the Object.
  188. *
  189. * @return Position Position of this Object
  190. */
  191. public Position getPosition() {
  192. return position;
  193. }
  194. /**
  195. * For save purpose.
  196. *
  197. * @return the stored
  198. */
  199. public String getSav() {
  200. return sav;
  201. }
  202. /**
  203. * For save purpose.
  204. *
  205. * @param sav
  206. * the stored to set
  207. */
  208. public void setSav(String sav) {
  209. this.sav = sav;
  210. }
  211. /**
  212. * Get the color of the border.
  213. *
  214. * @return the BorderColor
  215. */
  216. public Color getBorderColor() {
  217. return borderColor;
  218. }
  219. /**
  220. * Set the Border Color of this CpsObject.
  221. *
  222. * @param c
  223. * the BorderColor
  224. */
  225. public void setBorderColor(Color c) {
  226. this.borderColor = c;
  227. }
  228. /**
  229. * Set the Color of the edges.
  230. *
  231. * @param color
  232. * the Color to set
  233. */
  234. public void setConnections(Color color) {
  235. this.borderColor = color;
  236. }
  237. /**
  238. * For internal purpose (energy flow).
  239. *
  240. * @param tag
  241. * for internal purpose
  242. */
  243. public void addTag(int tag) {
  244. this.tags.add(tag);
  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. }
  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 ArrayList<Integer> addPseudoTag() {
  292. return this.pseudoTags;
  293. }
  294. }