Model.java 7.0 KB

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