CpsObject.java 4.8 KB

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