Model.java 23 KB

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