Model.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896
  1. package ui.model;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.LinkedList;
  6. import java.util.List;
  7. import java.util.stream.Collectors;
  8. import javax.swing.JTable;
  9. import com.google.gson.Gson;
  10. import com.google.gson.GsonBuilder;
  11. import TypeAdapter.AbstractCpsObjectAdapter;
  12. import TypeAdapter.ColorAdapter;
  13. import TypeAdapter.PairAdapter;
  14. import TypeAdapter.PositionAdapter;
  15. import classes.AbstractCanvasObject;
  16. import classes.Category;
  17. import classes.Edge;
  18. import classes.GroupNode;
  19. import classes.Holon;
  20. import classes.HolonElement;
  21. import classes.HolonObject;
  22. import classes.HolonSwitch;
  23. import classes.Node;
  24. import classes.Pair;
  25. import classes.Position;
  26. import interfaces.GraphListener;
  27. import interfaces.ObjectListener;
  28. import ui.view.DefaulTable;
  29. import ui.view.PropertyTable;
  30. /**
  31. * The Class Model is the class where everything is saved. All changes made to
  32. * the Data is managed via a controller.
  33. *
  34. * @author Gruppe14
  35. */
  36. public class Model {
  37. private static final int GRAPH_ITERATIONS = 100;
  38. // Global Variables
  39. private static int sCALE = 50; // Picture Scale
  40. private static int sCALEdIV2 = sCALE / 2;
  41. public String[] colNames = {"Field", "Information"};
  42. // Canvas Attributes
  43. private String imgPath = "";
  44. private int backgroundMode = 0;
  45. private int backgroundWidth = 0;
  46. private int backgroundHeight = 0;
  47. private int canvasX = 3000;
  48. private int canvasY = 3000;
  49. private int curIteration = 0;
  50. // ID of the Selected Object
  51. private AbstractCanvasObject selectedCpsObject = null;
  52. private HolonElement selectedHolonElement;
  53. private Edge selectedEdge;
  54. private ArrayList<AbstractCanvasObject> selectedObjects = new ArrayList<>();
  55. private ArrayList<AbstractCanvasObject> clipboardObjects = new ArrayList<>();
  56. private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  57. // Capacity for Edge
  58. private float maxCapacity;
  59. // Table for HolonElements --> all cells are editable
  60. private JTable tableHolonElement;
  61. /** Table for the properties of HolonObjects, Edges etc */
  62. private JTable propertyTable;
  63. private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
  64. // Iteration Speed
  65. private int timerSpeed = 1000;
  66. private int selectedID = 0;
  67. // number of the current autosave
  68. private int autoSaveNr = -1;
  69. // number of max simultaneous autosaves
  70. private int numberOfSaves = 35;
  71. /** whether the supplyBars should be shown or not */
  72. private boolean showSupplyBars = true;
  73. //TODO:
  74. private int iterations=100;
  75. /**
  76. * All implemented FairnessModels:<br>
  77. * {@link FairnessModel#MininumDemandFirst}<br>
  78. * {@link FairnessModel#AllEqual}
  79. */
  80. public enum FairnessModel{
  81. /**
  82. * One Element of each HolonObject will be powered first, starting with the
  83. * smallest Demand. If ale HolonObjects have an active Element, the
  84. * simulation will try to fully supply as many HolonObjects as possible.
  85. */
  86. MininumDemandFirst,
  87. /**
  88. * All HolonObjects will receive the same amount of energy.
  89. */
  90. AllEqual
  91. }
  92. /** the Fairness model in use */
  93. private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
  94. /*
  95. * Array of all categories in the model. It is set by default with the
  96. * categories ENERGY, BUILDINGS and COMPONENTS
  97. */
  98. private ArrayList<Category> categories;
  99. /*
  100. * Array of all CpsObjects in our canvas. It is set by default as an empty
  101. * list.
  102. */
  103. private ArrayList<AbstractCanvasObject> objectsOnCanvas;
  104. private HashMap<String, Integer> cgIdx;
  105. private HashMap<Integer, Integer> cvsObjIdx;
  106. /*
  107. * Array of all CpsObjects in our canvas. It is set by default as an empty
  108. * list.
  109. */
  110. private ArrayList<Edge> edgesOnCanvas;
  111. private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
  112. private ArrayList<Node> nodesOnCanvas= new ArrayList<Node>();
  113. private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
  114. private List<ObjectListener> objectListeners;
  115. private PropertyTable tableModelHolonElementMulti;
  116. private PropertyTable tableModelHolonElementSingle;
  117. private DefaulTable tableModelProperties;
  118. private HashMap<Integer, GroupNode> hashcodeMap = new HashMap<>();
  119. private Holon stateHolon = new Holon("All Holons");
  120. private Gson gson;
  121. /**
  122. * Constructor for the model. It initializes the categories and
  123. * objectsOnCanvas by default values. Listeners are also initialized by
  124. * default values.
  125. */
  126. public Model() {
  127. setCategories(new ArrayList<>());
  128. setObjectsOnCanvas(new ArrayList<>());
  129. setEdgesOnCanvas(new ArrayList<>());
  130. setObjectListeners(new LinkedList<>());
  131. setCgIdx(new HashMap<>());
  132. setCvsObjIdx(new HashMap<>());
  133. setClipboradObjects(new ArrayList<>());
  134. setEleToDelete(new HashMap<>());
  135. setSingleTable(new PropertyTable());
  136. setMultiTable(new PropertyTable());
  137. setPropertyTable(new DefaulTable(1000, colNames.length));
  138. getPropertyTable().setColumnIdentifiers(colNames);
  139. setTableHolonElement(new JTable());
  140. initGson();
  141. }
  142. /**
  143. * Returns all Categories.
  144. *
  145. * @return the categories
  146. */
  147. public ArrayList<Category> getCategories() {
  148. return categories;
  149. }
  150. /**
  151. * Sets all Categories.
  152. *
  153. * @param categories the categories to set
  154. */
  155. public void setCategories(ArrayList<Category> categories) {
  156. this.categories = categories;
  157. }
  158. /**
  159. * Transform the Arraylist of categories into a string of all objectName
  160. * with a separation (',') between each name.
  161. *
  162. * @return String of all names separeted by ','
  163. */
  164. public String toStringCat() {
  165. String text = "";
  166. for (int i = 0; i < categories.size(); i++) {
  167. if (text.equals("")) {
  168. text = categories.get(i).getName();
  169. } else {
  170. text = text + ", " + categories.get(i).getName();
  171. }
  172. }
  173. return text;
  174. }
  175. /**
  176. * Returns all Objects on the Canvas.
  177. *
  178. * @return the objectsOnCanvas
  179. */
  180. public ArrayList<AbstractCanvasObject> getObjectsOnCanvas() {
  181. return objectsOnCanvas;
  182. }
  183. /**
  184. * Sets all Objects on the Canvas.
  185. *
  186. * @param objectsOnCanvas the objectsOnCanvas to set
  187. */
  188. public void setObjectsOnCanvas(ArrayList<AbstractCanvasObject> objectsOnCanvas) {
  189. this.objectsOnCanvas = objectsOnCanvas;
  190. }
  191. /**
  192. * Get all Edges on the Canvas.
  193. *
  194. * @return the edgesOnCanvas
  195. */
  196. public ArrayList<Edge> getEdgesOnCanvas() {
  197. return edgesOnCanvas;
  198. }
  199. /**
  200. * Sets the edges on the Canvas.
  201. *
  202. * @param arrayList the edgesOnCanvas to set
  203. */
  204. public void setEdgesOnCanvas(ArrayList<Edge> arrayList) {
  205. this.edgesOnCanvas = arrayList;
  206. }
  207. /**
  208. * Adds an Edge to The Canvas.
  209. *
  210. * @param edge the edgesOnCanvas to add
  211. */
  212. public void addEdgeOnCanvas(Edge edge) {
  213. this.edgesOnCanvas.add(edge);
  214. }
  215. /**
  216. * Remove an edge from the Canvas.
  217. *
  218. * @param edge the edge to remove
  219. */
  220. public void removeEdgesOnCanvas(Edge edge) {
  221. this.edgesOnCanvas.remove(edge);
  222. }
  223. /**
  224. * Returns the ObjectListener.
  225. *
  226. * @return the objectListeners
  227. */
  228. public List<ObjectListener> getObjectListeners() {
  229. return objectListeners;
  230. }
  231. /**
  232. * Sets the ObjectListener.
  233. *
  234. * @param linkedList the objectListeners to set
  235. */
  236. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  237. this.objectListeners = linkedList;
  238. }
  239. /**
  240. * Returns the ID of the selected Object 0 = no Object is selected.
  241. *
  242. * @return ID
  243. */
  244. public int getSelectedObjectID() {
  245. return selectedID;
  246. }
  247. /**
  248. * Set the ID of the selected Object 0 = no Object is selected.
  249. *
  250. * @param id the ID
  251. */
  252. public void setSelectedObjectID(int id) {
  253. this.selectedID = id;
  254. }
  255. /**
  256. * Returns the Selected Cps Object.
  257. *
  258. * @return selected Cps Object
  259. */
  260. public AbstractCanvasObject getSelectedCpsObject() {
  261. return selectedCpsObject;
  262. }
  263. /**
  264. * Set the Selected Objecs.
  265. *
  266. * @param selectedCpsObject Objects that are selected
  267. */
  268. public void setSelectedCpsObject(AbstractCanvasObject selectedCpsObject) {
  269. this.selectedCpsObject = selectedCpsObject;
  270. }
  271. /**
  272. * Returns all selected Objects on the Canvas.
  273. *
  274. * @return The selected Objects
  275. */
  276. public ArrayList<AbstractCanvasObject> getSelectedCpsObjects() {
  277. return selectedObjects;
  278. }
  279. /**
  280. * Returns all selected Objects on the Canvas.
  281. *
  282. * @return The selected Objects
  283. */
  284. public void setSelectedCpsObjects(ArrayList<AbstractCanvasObject> arr) {
  285. this.selectedObjects = arr;
  286. }
  287. /**
  288. * Returns the Selected Holon Element.
  289. *
  290. * @return selected Holon Element
  291. */
  292. public HolonElement getSelectedHolonElement() {
  293. return selectedHolonElement;
  294. }
  295. /**
  296. * Sets the Selecte HolonElement.
  297. *
  298. * @param selectedHolonElement that is Selected
  299. */
  300. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  301. this.selectedHolonElement = selectedHolonElement;
  302. }
  303. /**
  304. * Returns the sCale (Scale for the Images).
  305. *
  306. * @return sCALE
  307. */
  308. public int getScale() {
  309. return sCALE;
  310. }
  311. public Holon getStateHolon() {
  312. return stateHolon;
  313. }
  314. /**
  315. * Sets the Image Scale.
  316. *
  317. * @param scale for the image
  318. */
  319. public void setScale(int scale) {
  320. sCALE = scale;
  321. if ((sCALE & 1) == 0)
  322. sCALEdIV2 = sCALE / 2;
  323. else
  324. sCALEdIV2 = (sCALE + 1) / 2;
  325. }
  326. /**
  327. * Returns sCALEdIV2 (The Scale divided by 2).
  328. *
  329. * @return sCALEdIV2
  330. */
  331. public int getScaleDiv2() {
  332. return sCALEdIV2;
  333. }
  334. /**
  335. * Returns the maximum ITERATIONS.
  336. *
  337. * @return ITERATIONS
  338. */
  339. public int getIterations() {
  340. return iterations;
  341. }
  342. private void notifyGraphListeners() {
  343. for (GraphListener gl : graphListeners) {
  344. gl.repaintTree();
  345. }
  346. }
  347. /**
  348. * Returns cURiTERATION.
  349. *
  350. * @return cURiTERATION
  351. */
  352. public int getCurIteration() {
  353. return curIteration;
  354. }
  355. /**
  356. * sets the current Iteration.
  357. *
  358. * @param curIT the current Iteration
  359. */
  360. public void setCurIteration(int curIT) {
  361. this.curIteration = curIT;
  362. notifyGraphListeners();
  363. }
  364. /**
  365. * Returns the selected Edge.
  366. *
  367. * @return selectedEdge
  368. */
  369. public Edge getSelectedEdge() {
  370. return selectedEdge;
  371. }
  372. /**
  373. * Set the selected Edge.
  374. *
  375. * @param edge that is selected
  376. */
  377. public void setSelectedEdge(Edge edge) {
  378. this.selectedEdge = edge;
  379. }
  380. /**
  381. * Returns the Categorie Index.
  382. *
  383. * @return the cgIdx
  384. */
  385. public HashMap<String, Integer> getCgIdx() {
  386. return cgIdx;
  387. }
  388. /**
  389. * Sets the Categorie Index.
  390. *
  391. * @param cgIdx the cgIdx to set
  392. */
  393. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  394. this.cgIdx = cgIdx;
  395. }
  396. /**
  397. * Returns the CanvasObject Index.
  398. *
  399. * @return the cvsObjIdx
  400. */
  401. public HashMap<Integer, Integer> getCvsObjIdx() {
  402. return cvsObjIdx;
  403. }
  404. /**
  405. * Sets the CanvasObject Index.
  406. *
  407. * @param cvsObjIdx the cvsObjIdx to set
  408. */
  409. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  410. this.cvsObjIdx = cvsObjIdx;
  411. }
  412. /**
  413. * Returns the auto save Number.
  414. *
  415. * @return the auto save Number
  416. */
  417. public int getAutoSaveNr() {
  418. return autoSaveNr;
  419. }
  420. /**
  421. * Sets the auto save Number.
  422. *
  423. * @param autoSaveNr the auto save number
  424. */
  425. public void setAutoSaveNr(int autoSaveNr) {
  426. this.autoSaveNr = autoSaveNr;
  427. }
  428. /**
  429. * Returns the Number of Saves.
  430. *
  431. * @return the numberOfSaves
  432. */
  433. public int getNumberOfSaves() {
  434. return numberOfSaves;
  435. }
  436. /**
  437. * Set the Number of Saves.
  438. *
  439. * @param numberOfSaves the numberOfSaves to set
  440. */
  441. public void setNumberOfSaves(int numberOfSaves) {
  442. this.numberOfSaves = numberOfSaves;
  443. }
  444. /**
  445. * Returns all Objects in the Clipboard.
  446. *
  447. * @return Objects in the Clipboard
  448. */
  449. public ArrayList<AbstractCanvasObject> getClipboradObjects() {
  450. return clipboardObjects;
  451. }
  452. /**
  453. * Sets the ClipboardObjects.
  454. *
  455. * @param c Array of Objects
  456. */
  457. public void setClipboradObjects(ArrayList<AbstractCanvasObject> c) {
  458. this.clipboardObjects = c;
  459. }
  460. /**
  461. * @return the maxCapacity
  462. */
  463. public float getMaxCapacity() {
  464. return maxCapacity;
  465. }
  466. /**
  467. * @param maxCapacity the maxCapacity to set
  468. */
  469. public void setMaxCapacity(float maxCapacity) {
  470. this.maxCapacity = maxCapacity;
  471. }
  472. /**
  473. * get the Interval in ms between each Iteration.
  474. *
  475. * @return timerSpeed speed for the Iterations
  476. */
  477. public int getTimerSpeed() {
  478. return this.timerSpeed;
  479. }
  480. /**
  481. * Sets the Interval in ms between each Iteration.
  482. *
  483. * @param t speed for the Iterations
  484. */
  485. public void setTimerSpeed(int t) {
  486. this.timerSpeed = t;
  487. }
  488. /**
  489. * Get Canvas X Size.
  490. *
  491. * @return the cANVAS_X
  492. */
  493. public int getCanvasX() {
  494. return canvasX;
  495. }
  496. /**
  497. * Set Canvas X Size.
  498. *
  499. * @param canvasX the cANVAS_X to set
  500. */
  501. public void setCanvasX(int canvasX) {
  502. this.canvasX = canvasX;
  503. }
  504. /**
  505. * get Canvas Y size.
  506. *
  507. * @return the cANVAS_Y
  508. */
  509. public int getCanvasY() {
  510. return canvasY;
  511. }
  512. /**
  513. * Set Canvas Y size.
  514. *
  515. * @param canvasY the cANVAS_Y to set
  516. */
  517. public void setCanvasY(int canvasY) {
  518. this.canvasY = canvasY;
  519. }
  520. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  521. return this.eleToDelete;
  522. }
  523. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  524. this.eleToDelete = theHash;
  525. }
  526. public PropertyTable getSingleTable() {
  527. return this.tableModelHolonElementSingle;
  528. }
  529. public void setSingleTable(PropertyTable pt) {
  530. this.tableModelHolonElementSingle = pt;
  531. }
  532. public PropertyTable getMultiTable() {
  533. return this.tableModelHolonElementMulti;
  534. }
  535. public void setMultiTable(PropertyTable pt) {
  536. this.tableModelHolonElementMulti = pt;
  537. }
  538. public DefaulTable getPropertyTable() {
  539. return this.tableModelProperties;
  540. }
  541. public void setPropertyTable(DefaulTable pt) {
  542. this.tableModelProperties = pt;
  543. }
  544. public JTable getTableHolonElement() {
  545. return tableHolonElement;
  546. }
  547. public void setTableHolonElement(JTable tableHolonElement) {
  548. this.tableHolonElement = tableHolonElement;
  549. }
  550. /**
  551. * @return the tableProperties
  552. */
  553. public JTable getTableProperties() {
  554. return propertyTable;
  555. }
  556. /**
  557. * @return the tableProperties
  558. */
  559. public void setTableProperties(JTable propertyTable) {
  560. this.propertyTable = propertyTable;
  561. }
  562. public List<HolonElement> getAllHolonElemnts() {
  563. return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
  564. }
  565. public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){
  566. ArrayList<HolonObject> objectToReturn = new ArrayList<HolonObject>();
  567. getAllHolonObjectsRecursive(objectToReturn, getObjectsOnCanvas());
  568. return objectToReturn;
  569. }
  570. private void getAllHolonObjectsRecursive(ArrayList<HolonObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
  571. for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
  572. if(aCps instanceof HolonObject) {
  573. addObjectsToThisList.add((HolonObject) aCps);
  574. }else if(aCps instanceof GroupNode){
  575. getAllHolonObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
  576. }
  577. }
  578. }
  579. /**
  580. * get all Switches
  581. */
  582. public ArrayList<HolonSwitch> getAllSwitches() {
  583. ArrayList<HolonSwitch> switches = new ArrayList<>();
  584. for (AbstractCanvasObject obj : getObjectsOnCanvas()) {
  585. if (obj instanceof HolonSwitch) {
  586. switches.add((HolonSwitch) obj);
  587. } else if (obj instanceof GroupNode) {
  588. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  589. }
  590. }
  591. return switches;
  592. }
  593. /**
  594. * get the Amount of Switches help function
  595. *
  596. * @param objects objects
  597. * @param switches List of switches
  598. */
  599. private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCanvasObject> objects,
  600. ArrayList<HolonSwitch> switches) {
  601. for (AbstractCanvasObject obj : objects) {
  602. if (obj instanceof HolonSwitch) {
  603. switches.add((HolonSwitch) obj);
  604. } else if (obj instanceof GroupNode) {
  605. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  606. }
  607. }
  608. return switches;
  609. }
  610. /**
  611. * Returns the Path for the background Image of the Canvas.
  612. *
  613. * @return imgPath the Path
  614. */
  615. public String getCanvasImagePath() {
  616. return imgPath;
  617. }
  618. /**
  619. * Set the Path for the background Image of the Canvas.
  620. *
  621. * @param path the Path
  622. */
  623. public void setCanvasImagePath(String path) {
  624. imgPath = path;
  625. }
  626. /**
  627. * Returns the mode for the background Image of the Canvas.
  628. * <p>
  629. * 0 take size of the Image 1 stretch the Image 2 Custom Image size
  630. *
  631. * @return backgroundMode the mode
  632. */
  633. public int getCanvasImageMode() {
  634. return backgroundMode;
  635. }
  636. /**
  637. * Set the mode for the background Image of the Canvas.
  638. * <p>
  639. * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
  640. *
  641. * @param mode the backgroundMode
  642. */
  643. public void setCanvasImageMode(int mode) {
  644. backgroundMode = mode;
  645. }
  646. /**
  647. * Returns the Custom width of the background Image of the Canvas.
  648. *
  649. * @return backgroundWidth the Width
  650. */
  651. public int getCanvasImageWidth() {
  652. return backgroundWidth;
  653. }
  654. /**
  655. * Set the Custom width of the background Image of the Canvas.
  656. *
  657. * @param width the Width
  658. */
  659. public void setCanvasImageWidth(int width) {
  660. backgroundWidth = width;
  661. }
  662. /**
  663. * Returns the Custom height of the background Image of the Canvas.
  664. *
  665. * @return backgroundHeight the height
  666. */
  667. public int getCanvasImageHeight() {
  668. return backgroundHeight;
  669. }
  670. /**
  671. * Set the Custom height of the background Image of the Canvas.
  672. *
  673. * @param height the height
  674. */
  675. public void setCanvasImageHeight(int height) {
  676. backgroundHeight = height;
  677. }
  678. /**
  679. * @return true if SupplyBars should be shown
  680. */
  681. public boolean getShowSupplyBars() {
  682. return showSupplyBars;
  683. }
  684. /**
  685. * @param showSupplyBars true if the SupplyBars should be shown
  686. */
  687. public void setShowSupplyBars(boolean showSupplyBars) {
  688. this.showSupplyBars = showSupplyBars;
  689. }
  690. /**
  691. * @param iterations the number of steps for this simulation
  692. */
  693. public void setIterations(int iterations){
  694. this.iterations=iterations;
  695. }
  696. /**
  697. * @return the fairnessModel
  698. */
  699. public FairnessModel getFairnessModel() {
  700. return fairnessModel;
  701. }
  702. /**
  703. * @param fairnessModel the fairnessModel to set
  704. */
  705. public void setFairnessModel(FairnessModel fairnessModel) {
  706. this.fairnessModel = fairnessModel;
  707. }
  708. public int getGraphIterations(){
  709. return GRAPH_ITERATIONS;
  710. }
  711. /**
  712. * Initialize the Gson with wanted parameters
  713. */
  714. private void initGson() {
  715. GsonBuilder builder = new GsonBuilder();
  716. builder.serializeNulls();
  717. builder.excludeFieldsWithoutExposeAnnotation();
  718. builder.setPrettyPrinting();
  719. builder.registerTypeAdapter(AbstractCanvasObject.class, new AbstractCpsObjectAdapter());
  720. builder.registerTypeAdapter(Position.class, new PositionAdapter());
  721. builder.registerTypeAdapter(Color.class, new ColorAdapter());
  722. builder.registerTypeAdapter(Pair.class, new PairAdapter());
  723. // use the builder and make a instance of the Gson
  724. this.setGson(builder.create());
  725. }
  726. /**
  727. * @return the gson
  728. */
  729. public Gson getGson() {
  730. return gson;
  731. }
  732. /**
  733. * @param gson the gson to set
  734. */
  735. public void setGson(Gson gson) {
  736. this.gson = gson;
  737. }
  738. /**
  739. * @return the hashcodeMap
  740. */
  741. public HashMap<Integer, GroupNode> getHashcodeMap() {
  742. return hashcodeMap;
  743. }
  744. /**
  745. * @param hashcodeMap the hashcodeMap to set
  746. */
  747. public void setHashcodeMap(HashMap<Integer, GroupNode> hashcodeMap) {
  748. this.hashcodeMap = hashcodeMap;
  749. }
  750. public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
  751. return switchsOnCanvas;
  752. }
  753. public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
  754. this.switchsOnCanvas = switchsOnCanvas;
  755. }
  756. public ArrayList<Node> getNodesOnCanvas() {
  757. return nodesOnCanvas;
  758. }
  759. public void setNodesOnCanvas(ArrayList<Node> nodesOnCanvas) {
  760. this.nodesOnCanvas = nodesOnCanvas;
  761. }
  762. public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
  763. return holonObjectsOnCanvas;
  764. }
  765. public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
  766. this.holonObjectsOnCanvas = holonObjectsOnCanvas;
  767. }
  768. public void defineLists() {
  769. switchsOnCanvas.clear();
  770. nodesOnCanvas.clear();
  771. holonObjectsOnCanvas.clear();
  772. for(AbstractCanvasObject aCps : this.objectsOnCanvas) {
  773. if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
  774. else if(aCps instanceof Node)nodesOnCanvas.add((Node) aCps);
  775. else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
  776. }
  777. }
  778. }