Model.java 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321
  1. package ui.model;
  2. import Interfaces.CategoryListener;
  3. import Interfaces.ObjectListener;
  4. import java.util.ArrayList;
  5. import java.util.HashMap;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import classes.Category;
  9. import classes.CpsEdge;
  10. import classes.CpsObject;
  11. import classes.HolonElement;
  12. import ui.controller.*;
  13. public class Model {
  14. // Global Variables
  15. private static int SCALE = 50; // Picture Scale
  16. private static int SCALE_DIV2 = SCALE / 2;
  17. private static final int ITERATIONS = 100;
  18. private int CUR_ITERATION = 0;
  19. // ID of the Selected Object
  20. private CpsObject selectedCpsObject = null;
  21. private HolonElement selectedHolonElement;
  22. private CpsEdge selectedEdge;
  23. private int selectedID = 0;
  24. // eventuell wenn Canvasgröße gewählt werden kann
  25. private int HEIGHT;
  26. private int WIDTH;
  27. /*
  28. * Array of all categories in the model. It is set by default with the
  29. * categories ENERGY, BUILDINGS and COMPONENTS
  30. */
  31. private ArrayList<Category> categories;
  32. /*
  33. * Array of all CpsObjects in our canvas. It is set by default as an empty
  34. * list.
  35. */
  36. private ArrayList<CpsObject> objectsOnCanvas;
  37. private HashMap<String, Integer> cgIdx;
  38. private HashMap<Integer, Integer> cvsObjIdx;
  39. /*
  40. * Array of all CpsObjects in our canvas. It is set by default as an empty
  41. * list.
  42. */
  43. private ArrayList<CpsEdge> edgesOnCanvas;
  44. /*
  45. * Array for all Listeners
  46. */
  47. private List<CategoryListener> categoryListeners;
  48. private List<ObjectListener> objectListeners;
  49. /*
  50. * Constructor for the model. It initializes the categories and
  51. * objectsOnCanvas by default values. Listeners are also initialized by
  52. * default values.
  53. */
  54. public Model() {
  55. setCategories(new ArrayList<Category>());
  56. setObjectsOnCanvas(new ArrayList<CpsObject>());
  57. setEdgesOnCanvas(new ArrayList<CpsEdge>());
  58. setCategoryListeners(new LinkedList<CategoryListener>());
  59. setObjectListeners(new LinkedList<ObjectListener>());
  60. setCgIdx(new HashMap<String,Integer>());
  61. setCvsObjIdx(new HashMap<Integer,Integer>());
  62. }
  63. /**
  64. * @return the categories
  65. */
  66. public ArrayList<Category> getCategories() {
  67. return categories;
  68. }
  69. /**
  70. * @param categories
  71. * the categories to set
  72. */
  73. public void setCategories(ArrayList<Category> categories) {
  74. this.categories = categories;
  75. }
  76. /**
  77. * Transform the Arraylist of categories into a string of all objectName
  78. * with a separation (',') between each name
  79. *
  80. * @return String of all names separeted by ','
  81. */
  82. public String toStringCat() {
  83. String text = "";
  84. for (int i = 0; i < categories.size(); i++) {
  85. if (text == "") {
  86. text = categories.get(i).getName();
  87. } else {
  88. text = text + ", " + categories.get(i).getName();
  89. }
  90. }
  91. return text;
  92. }
  93. /**
  94. * @return the objectsOnCanvas
  95. */
  96. public ArrayList<CpsObject> getObjectsOnCanvas() {
  97. return objectsOnCanvas;
  98. }
  99. /**
  100. * @param objectsOnCanvas
  101. * the objectsOnCanvas to set
  102. */
  103. public void setObjectsOnCanvas(ArrayList<CpsObject> objectsOnCanvas) {
  104. this.objectsOnCanvas = objectsOnCanvas;
  105. }
  106. /**
  107. * @return the objectsOnCanvas
  108. */
  109. public ArrayList<CpsEdge> getEdgesOnCanvas() {
  110. return edgesOnCanvas;
  111. }
  112. /**
  113. * @param objectsOnCanvas
  114. * the objectsOnCanvas to set
  115. */
  116. public void addEdgeOnCanvas(CpsEdge edge) {
  117. this.edgesOnCanvas.add(edge);
  118. }
  119. /**
  120. * @param edgesOnCanvas
  121. * the edge to remove
  122. */
  123. public void removeEdgesOnCanvas(CpsEdge edge) {
  124. this.edgesOnCanvas.remove(edge);
  125. }
  126. /**
  127. * @param EdgesOnCanvas
  128. * the edgesOnCanvas to set
  129. */
  130. public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
  131. this.edgesOnCanvas = arrayList;
  132. }
  133. /**
  134. * @return the objectListeners
  135. */
  136. public List<ObjectListener> getObjectListeners() {
  137. return objectListeners;
  138. }
  139. /**
  140. * @param linkedList
  141. * the objectListeners to set
  142. */
  143. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  144. this.objectListeners = linkedList;
  145. }
  146. /**
  147. * @return the categoryListeners
  148. */
  149. public List<CategoryListener> getCategoryListeners() {
  150. return categoryListeners;
  151. }
  152. /**
  153. * @param linkedList
  154. * the categoryListeners to set
  155. */
  156. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  157. this.categoryListeners = linkedList;
  158. }
  159. /**
  160. * Set the ID of the selected Object 0 = no Object is selected
  161. *
  162. * @param ID
  163. *
  164. */
  165. public void setSelectedObjectID(int id) {
  166. this.selectedID = id;
  167. }
  168. /**
  169. * Returns the ID of the selected Object 0 = no Object is selected
  170. *
  171. * @return ID
  172. */
  173. public int getSelectedObjectID() {
  174. return selectedID;
  175. }
  176. public CpsObject getSelectedCpsObject() {
  177. return selectedCpsObject;
  178. }
  179. public void setSelectedCpsObject(CpsObject selectedCpsObject) {
  180. this.selectedCpsObject = selectedCpsObject;
  181. }
  182. public HolonElement getSelectedHolonElement() {
  183. return selectedHolonElement;
  184. }
  185. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  186. this.selectedHolonElement = selectedHolonElement;
  187. }
  188. /**
  189. * Returns SCALE
  190. *
  191. * @return SCALE
  192. */
  193. public int getScale() {
  194. return SCALE;
  195. }
  196. /**
  197. * Returns SCALE_DIV2
  198. *
  199. * @return SCALE_DIV2
  200. */
  201. public int getScaleDiv2() {
  202. return SCALE_DIV2;
  203. }
  204. public void setScale(int scale) {
  205. SCALE = scale;
  206. SCALE_DIV2 = SCALE / 2;
  207. }
  208. /**
  209. * Returns ITERATIONS
  210. *
  211. * @return ITERATIONS
  212. */
  213. public int getIterations() {
  214. return ITERATIONS;
  215. }
  216. /**
  217. * sets the current Iteration
  218. *
  219. * @param cur_it, the current Iteration
  220. */
  221. public void setCurIteration(int cur_it) {
  222. this.CUR_ITERATION = cur_it;
  223. }
  224. /**
  225. * Returns CUR_ITERATIONS
  226. *
  227. * @return CUR_ITERATIONS
  228. */
  229. public int getCurIteration() {
  230. return CUR_ITERATION;
  231. }
  232. /**
  233. * Set the selected Edge
  234. *
  235. * @param edge
  236. *
  237. */
  238. public void setSelectedEdge(CpsEdge edge) {
  239. this.selectedEdge = edge;
  240. }
  241. /**
  242. * Returns the selected Edge
  243. *
  244. * @return selectedEdge
  245. */
  246. public CpsEdge getSelectedEdge(){
  247. return selectedEdge;
  248. }
  249. /**
  250. * @return the cgIdx
  251. */
  252. public HashMap<String, Integer> getCgIdx() {
  253. return cgIdx;
  254. }
  255. /**
  256. * @param cgIdx the cgIdx to set
  257. */
  258. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  259. this.cgIdx = cgIdx;
  260. }
  261. /**
  262. * @return the cvsObjIdx
  263. */
  264. public HashMap<Integer, Integer> getCvsObjIdx() {
  265. return cvsObjIdx;
  266. }
  267. /**
  268. * @param cvsObjIdx the cvsObjIdx to set
  269. */
  270. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  271. this.cvsObjIdx = cvsObjIdx;
  272. }
  273. }