Model.java 6.5 KB

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