Model.java 23 KB

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