Model.java 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423
  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.AbstractCpsObject;
  11. import classes.HolonElement;
  12. import ui.controller.*;
  13. import ui.view.Console;
  14. public class Model {
  15. // Global Variables
  16. private static int SCALE = 50; // Picture Scale
  17. private static int SCALE_DIV2 = SCALE / 2;
  18. private static final int ITERATIONS = 100;
  19. private int CUR_ITERATION = 0;
  20. // ID of the Selected Object
  21. private AbstractCpsObject selectedCpsObject = null;
  22. private HolonElement selectedHolonElement;
  23. private CpsEdge selectedEdge;
  24. private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<AbstractCpsObject>();
  25. private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<AbstractCpsObject>();
  26. private Console console;
  27. // Iteration Speed
  28. private int timerSpeed = 1000;
  29. // Simulation boolean
  30. private boolean isSimulation = false;
  31. private int selectedID = 0;
  32. // number of the current autosave
  33. private int autoSaveNr = -1;
  34. // number of max simultaneous autosaves
  35. private int numberOfSaves = 35;
  36. // eventuell wenn Canvasgröße gewählt werden kann
  37. private int HEIGHT;
  38. private int WIDTH;
  39. /*
  40. * Array of all categories in the model. It is set by default with the
  41. * categories ENERGY, BUILDINGS and COMPONENTS
  42. */
  43. private ArrayList<Category> categories;
  44. /*
  45. * Array of all CpsObjects in our canvas. It is set by default as an empty
  46. * list.
  47. */
  48. private ArrayList<AbstractCpsObject> objectsOnCanvas;
  49. private HashMap<String, Integer> cgIdx;
  50. private HashMap<Integer, Integer> cvsObjIdx;
  51. /*
  52. * Array of all CpsObjects in our canvas. It is set by default as an empty
  53. * list.
  54. */
  55. private ArrayList<CpsEdge> edgesOnCanvas;
  56. /*
  57. * Array for all Listeners
  58. */
  59. private List<CategoryListener> categoryListeners;
  60. private List<ObjectListener> objectListeners;
  61. /*
  62. * Constructor for the model. It initializes the categories and
  63. * objectsOnCanvas by default values. Listeners are also initialized by
  64. * default values.
  65. */
  66. public Model() {
  67. setCategories(new ArrayList<Category>());
  68. setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
  69. setEdgesOnCanvas(new ArrayList<CpsEdge>());
  70. setCategoryListeners(new LinkedList<CategoryListener>());
  71. setObjectListeners(new LinkedList<ObjectListener>());
  72. setCgIdx(new HashMap<String, Integer>());
  73. setCvsObjIdx(new HashMap<Integer, Integer>());
  74. setClipboradObjects(new ArrayList<AbstractCpsObject>());
  75. }
  76. /**
  77. * @return the categories
  78. */
  79. public ArrayList<Category> getCategories() {
  80. return categories;
  81. }
  82. /**
  83. * @param categories
  84. * the categories to set
  85. */
  86. public void setCategories(ArrayList<Category> categories) {
  87. this.categories = categories;
  88. }
  89. /**
  90. * Transform the Arraylist of categories into a string of all objectName
  91. * with a separation (',') between each name
  92. *
  93. * @return String of all names separeted by ','
  94. */
  95. public String toStringCat() {
  96. String text = "";
  97. for (int i = 0; i < categories.size(); i++) {
  98. if (text == "") {
  99. text = categories.get(i).getName();
  100. } else {
  101. text = text + ", " + categories.get(i).getName();
  102. }
  103. }
  104. return text;
  105. }
  106. /**
  107. * @return the objectsOnCanvas
  108. */
  109. public ArrayList<AbstractCpsObject> getObjectsOnCanvas() {
  110. return objectsOnCanvas;
  111. }
  112. /**
  113. * @param objectsOnCanvas
  114. * the objectsOnCanvas to set
  115. */
  116. public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
  117. this.objectsOnCanvas = objectsOnCanvas;
  118. }
  119. /**
  120. * @return the objectsOnCanvas
  121. */
  122. public ArrayList<CpsEdge> getEdgesOnCanvas() {
  123. return edgesOnCanvas;
  124. }
  125. /**
  126. * @param objectsOnCanvas
  127. * the objectsOnCanvas to set
  128. */
  129. public void addEdgeOnCanvas(CpsEdge edge) {
  130. this.edgesOnCanvas.add(edge);
  131. }
  132. /**
  133. * @param edgesOnCanvas
  134. * the edge to remove
  135. */
  136. public void removeEdgesOnCanvas(CpsEdge edge) {
  137. this.edgesOnCanvas.remove(edge);
  138. }
  139. /**
  140. * @param EdgesOnCanvas
  141. * the edgesOnCanvas to set
  142. */
  143. public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
  144. this.edgesOnCanvas = arrayList;
  145. }
  146. /**
  147. * @return the objectListeners
  148. */
  149. public List<ObjectListener> getObjectListeners() {
  150. return objectListeners;
  151. }
  152. /**
  153. * @param linkedList
  154. * the objectListeners to set
  155. */
  156. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  157. this.objectListeners = linkedList;
  158. }
  159. /**
  160. * @return the categoryListeners
  161. */
  162. public List<CategoryListener> getCategoryListeners() {
  163. return categoryListeners;
  164. }
  165. /**
  166. * @param linkedList
  167. * the categoryListeners to set
  168. */
  169. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  170. this.categoryListeners = linkedList;
  171. }
  172. /**
  173. * Set the ID of the selected Object 0 = no Object is selected
  174. *
  175. * @param ID
  176. *
  177. */
  178. public void setSelectedObjectID(int id) {
  179. this.selectedID = id;
  180. }
  181. /**
  182. * Returns the ID of the selected Object 0 = no Object is selected
  183. *
  184. * @return ID
  185. */
  186. public int getSelectedObjectID() {
  187. return selectedID;
  188. }
  189. public AbstractCpsObject getSelectedCpsObject() {
  190. return selectedCpsObject;
  191. }
  192. public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
  193. this.selectedCpsObject = selectedCpsObject;
  194. }
  195. public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
  196. return selectedObjects;
  197. }
  198. public HolonElement getSelectedHolonElement() {
  199. return selectedHolonElement;
  200. }
  201. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  202. this.selectedHolonElement = selectedHolonElement;
  203. }
  204. /**
  205. * Returns SCALE
  206. *
  207. * @return SCALE
  208. */
  209. public int getScale() {
  210. return SCALE;
  211. }
  212. /**
  213. * Returns SCALE_DIV2
  214. *
  215. * @return SCALE_DIV2
  216. */
  217. public int getScaleDiv2() {
  218. return SCALE_DIV2;
  219. }
  220. public void setScale(int scale) {
  221. SCALE = scale;
  222. SCALE_DIV2 = SCALE / 2;
  223. }
  224. /**
  225. * Returns ITERATIONS
  226. *
  227. * @return ITERATIONS
  228. */
  229. public int getIterations() {
  230. return ITERATIONS;
  231. }
  232. /**
  233. * sets the current Iteration
  234. *
  235. * @param cur_it,
  236. * the current Iteration
  237. */
  238. public void setCurIteration(int cur_it) {
  239. this.CUR_ITERATION = cur_it;
  240. }
  241. /**
  242. * Returns CUR_ITERATIONS
  243. *
  244. * @return CUR_ITERATIONS
  245. */
  246. public int getCurIteration() {
  247. return CUR_ITERATION;
  248. }
  249. /**
  250. * Set the selected Edge
  251. *
  252. * @param edge
  253. *
  254. */
  255. public void setSelectedEdge(CpsEdge edge) {
  256. this.selectedEdge = edge;
  257. }
  258. /**
  259. * Returns the selected Edge
  260. *
  261. * @return selectedEdge
  262. */
  263. public CpsEdge getSelectedEdge() {
  264. return selectedEdge;
  265. }
  266. /**
  267. * @return the cgIdx
  268. */
  269. public HashMap<String, Integer> getCgIdx() {
  270. return cgIdx;
  271. }
  272. /**
  273. * @param cgIdx
  274. * the cgIdx to set
  275. */
  276. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  277. this.cgIdx = cgIdx;
  278. }
  279. /**
  280. * @return the cvsObjIdx
  281. */
  282. public HashMap<Integer, Integer> getCvsObjIdx() {
  283. return cvsObjIdx;
  284. }
  285. /**
  286. * @param cvsObjIdx
  287. * the cvsObjIdx to set
  288. */
  289. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  290. this.cvsObjIdx = cvsObjIdx;
  291. }
  292. public void setAutoSaveNr(int autoSaveNr) {
  293. this.autoSaveNr = autoSaveNr;
  294. }
  295. public int getAutoSaveNr() {
  296. return autoSaveNr;
  297. }
  298. /**
  299. * @return the numberOfSaves
  300. */
  301. public int getNumberOfSaves() {
  302. return numberOfSaves;
  303. }
  304. /**
  305. * @param numberOfSaves
  306. * the numberOfSaves to set
  307. */
  308. public void setNumberOfSaves(int numberOfSaves) {
  309. this.numberOfSaves = numberOfSaves;
  310. }
  311. /**
  312. * @param Objects
  313. * Array of Objects
  314. */
  315. public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
  316. this.clipboardObjects = c;
  317. }
  318. /**
  319. *
  320. * @return Objects in the Clipboard
  321. */
  322. public ArrayList<AbstractCpsObject> getClipboradObjects() {
  323. return clipboardObjects;
  324. }
  325. /**
  326. *
  327. * @param console
  328. * the console
  329. */
  330. public void setConsole(Console console) {
  331. this.console = console;
  332. }
  333. /**
  334. *
  335. * @return console the console
  336. */
  337. public Console getConsole() {
  338. return console;
  339. }
  340. /**
  341. * @param timerSpeed
  342. * speed for the Iterations
  343. */
  344. public void setTimerSpeed(int t) {
  345. this.timerSpeed = t;
  346. }
  347. /**
  348. * @return timerSpeed speed for the Iterations
  349. */
  350. public int getTimerSpeed() {
  351. return this.timerSpeed;
  352. }
  353. /**
  354. * @param isSimulation
  355. * boolean for for isSimulation
  356. */
  357. public void setIsSimulation(boolean b) {
  358. this.isSimulation = b;
  359. }
  360. /**
  361. * @return isSimulation boolean for for isSimulation
  362. */
  363. public boolean getIsSimulation() {
  364. return this.isSimulation;
  365. }
  366. }