Model.java 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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. private HolonElement selectedHolonElement;
  51. private Edge selectedEdge;
  52. private ArrayList<AbstractCanvasObject> selectedObjects = new ArrayList<>();
  53. private ArrayList<AbstractCanvasObject> clipboardObjects = new ArrayList<>();
  54. private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  55. // Capacity for Edge
  56. private float maxCapacity;
  57. // Table for HolonElements --> all cells are editable
  58. private JTable tableHolonElement;
  59. /** Table for the properties of HolonObjects, Edges etc */
  60. private JTable propertyTable;
  61. private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
  62. // Iteration Speed
  63. private int timerSpeed = 1000;
  64. private int selectedID = 0;
  65. // number of the current autosave
  66. private int autoSaveNr = -1;
  67. // number of max simultaneous autosaves
  68. private int numberOfSaves = 35;
  69. /** whether the supplyBars should be shown or not */
  70. private boolean showSupplyBars = true;
  71. //TODO:
  72. private int iterations=100;
  73. /**
  74. * All implemented FairnessModels:<br>
  75. * {@link FairnessModel#MininumDemandFirst}<br>
  76. * {@link FairnessModel#AllEqual}
  77. */
  78. public enum FairnessModel{
  79. /**
  80. * One Element of each HolonObject will be powered first, starting with the
  81. * smallest Demand. If ale HolonObjects have an active Element, the
  82. * simulation will try to fully supply as many HolonObjects as possible.
  83. */
  84. MininumDemandFirst,
  85. /**
  86. * All HolonObjects will receive the same amount of energy.
  87. */
  88. AllEqual
  89. }
  90. /** the Fairness model in use */
  91. private FairnessModel fairnessModel = FairnessModel.MininumDemandFirst;
  92. /*
  93. * Array of all categories in the model. It is set by default with the
  94. * categories ENERGY, BUILDINGS and COMPONENTS
  95. */
  96. private ArrayList<Category> categories;
  97. /*
  98. * Array of all CpsObjects in our canvas. It is set by default as an empty
  99. * list.
  100. */
  101. private ArrayList<AbstractCanvasObject> objectsOnCanvas;
  102. private HashMap<String, Integer> cgIdx;
  103. private HashMap<Integer, Integer> cvsObjIdx;
  104. /*
  105. * Array of all CpsObjects in our canvas. It is set by default as an empty
  106. * list.
  107. */
  108. private ArrayList<Edge> edgesOnCanvas;
  109. private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
  110. private ArrayList<Node> nodesOnCanvas= new ArrayList<Node>();
  111. private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
  112. private List<ObjectListener> objectListeners;
  113. private PropertyTable tableModelHolonElementMulti;
  114. private PropertyTable tableModelHolonElementSingle;
  115. private DefaulTable tableModelProperties;
  116. private HashMap<Integer, GroupNode> hashcodeMap = new HashMap<>();
  117. private Holon stateHolon = new Holon("All Holons");
  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 all selected Objects on the Canvas.
  255. *
  256. * @return The selected Objects
  257. */
  258. public ArrayList<AbstractCanvasObject> getSelectedCpsObjects() {
  259. return selectedObjects;
  260. }
  261. /**
  262. * Returns all selected Objects on the Canvas.
  263. *
  264. * @return The selected Objects
  265. */
  266. public void setSelectedCpsObjects(ArrayList<AbstractCanvasObject> arr) {
  267. this.selectedObjects = arr;
  268. }
  269. /**
  270. * Returns the Selected Holon Element.
  271. *
  272. * @return selected Holon Element
  273. */
  274. public HolonElement getSelectedHolonElement() {
  275. return selectedHolonElement;
  276. }
  277. /**
  278. * Sets the Selecte HolonElement.
  279. *
  280. * @param selectedHolonElement that is Selected
  281. */
  282. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  283. this.selectedHolonElement = selectedHolonElement;
  284. }
  285. /**
  286. * Returns the sCale (Scale for the Images).
  287. *
  288. * @return sCALE
  289. */
  290. public int getScale() {
  291. return sCALE;
  292. }
  293. public Holon getStateHolon() {
  294. return stateHolon;
  295. }
  296. /**
  297. * Sets the Image Scale.
  298. *
  299. * @param scale for the image
  300. */
  301. public void setScale(int scale) {
  302. sCALE = scale;
  303. if ((sCALE & 1) == 0)
  304. sCALEdIV2 = sCALE / 2;
  305. else
  306. sCALEdIV2 = (sCALE + 1) / 2;
  307. }
  308. /**
  309. * Returns sCALEdIV2 (The Scale divided by 2).
  310. *
  311. * @return sCALEdIV2
  312. */
  313. public int getScaleDiv2() {
  314. return sCALEdIV2;
  315. }
  316. /**
  317. * Returns the maximum ITERATIONS.
  318. *
  319. * @return ITERATIONS
  320. */
  321. public int getIterations() {
  322. return iterations;
  323. }
  324. private void notifyGraphListeners() {
  325. for (GraphListener gl : graphListeners) {
  326. gl.repaintTree();
  327. }
  328. }
  329. /**
  330. * Returns cURiTERATION.
  331. *
  332. * @return cURiTERATION
  333. */
  334. public int getCurIteration() {
  335. return curIteration;
  336. }
  337. /**
  338. * sets the current Iteration.
  339. *
  340. * @param curIT the current Iteration
  341. */
  342. public void setCurIteration(int curIT) {
  343. this.curIteration = curIT;
  344. notifyGraphListeners();
  345. }
  346. /**
  347. * Returns the selected Edge.
  348. *
  349. * @return selectedEdge
  350. */
  351. public Edge getSelectedEdge() {
  352. return selectedEdge;
  353. }
  354. /**
  355. * Set the selected Edge.
  356. *
  357. * @param edge that is selected
  358. */
  359. public void setSelectedEdge(Edge edge) {
  360. this.selectedEdge = edge;
  361. }
  362. /**
  363. * Returns the Categorie Index.
  364. *
  365. * @return the cgIdx
  366. */
  367. public HashMap<String, Integer> getCgIdx() {
  368. return cgIdx;
  369. }
  370. /**
  371. * Sets the Categorie Index.
  372. *
  373. * @param cgIdx the cgIdx to set
  374. */
  375. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  376. this.cgIdx = cgIdx;
  377. }
  378. /**
  379. * Returns the CanvasObject Index.
  380. *
  381. * @return the cvsObjIdx
  382. */
  383. public HashMap<Integer, Integer> getCvsObjIdx() {
  384. return cvsObjIdx;
  385. }
  386. /**
  387. * Sets the CanvasObject Index.
  388. *
  389. * @param cvsObjIdx the cvsObjIdx to set
  390. */
  391. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  392. this.cvsObjIdx = cvsObjIdx;
  393. }
  394. /**
  395. * Returns the auto save Number.
  396. *
  397. * @return the auto save Number
  398. */
  399. public int getAutoSaveNr() {
  400. return autoSaveNr;
  401. }
  402. /**
  403. * Sets the auto save Number.
  404. *
  405. * @param autoSaveNr the auto save number
  406. */
  407. public void setAutoSaveNr(int autoSaveNr) {
  408. this.autoSaveNr = autoSaveNr;
  409. }
  410. /**
  411. * Returns the Number of Saves.
  412. *
  413. * @return the numberOfSaves
  414. */
  415. public int getNumberOfSaves() {
  416. return numberOfSaves;
  417. }
  418. /**
  419. * Set the Number of Saves.
  420. *
  421. * @param numberOfSaves the numberOfSaves to set
  422. */
  423. public void setNumberOfSaves(int numberOfSaves) {
  424. this.numberOfSaves = numberOfSaves;
  425. }
  426. /**
  427. * Returns all Objects in the Clipboard.
  428. *
  429. * @return Objects in the Clipboard
  430. */
  431. public ArrayList<AbstractCanvasObject> getClipboradObjects() {
  432. return clipboardObjects;
  433. }
  434. /**
  435. * Sets the ClipboardObjects.
  436. *
  437. * @param c Array of Objects
  438. */
  439. public void setClipboradObjects(ArrayList<AbstractCanvasObject> c) {
  440. this.clipboardObjects = c;
  441. }
  442. /**
  443. * @return the maxCapacity
  444. */
  445. public float getMaxCapacity() {
  446. return maxCapacity;
  447. }
  448. /**
  449. * @param maxCapacity the maxCapacity to set
  450. */
  451. public void setMaxCapacity(float maxCapacity) {
  452. this.maxCapacity = maxCapacity;
  453. }
  454. /**
  455. * get the Interval in ms between each Iteration.
  456. *
  457. * @return timerSpeed speed for the Iterations
  458. */
  459. public int getTimerSpeed() {
  460. return this.timerSpeed;
  461. }
  462. /**
  463. * Sets the Interval in ms between each Iteration.
  464. *
  465. * @param t speed for the Iterations
  466. */
  467. public void setTimerSpeed(int t) {
  468. this.timerSpeed = t;
  469. }
  470. /**
  471. * Get Canvas X Size.
  472. *
  473. * @return the cANVAS_X
  474. */
  475. public int getCanvasX() {
  476. return canvasX;
  477. }
  478. /**
  479. * Set Canvas X Size.
  480. *
  481. * @param canvasX the cANVAS_X to set
  482. */
  483. public void setCanvasX(int canvasX) {
  484. this.canvasX = canvasX;
  485. }
  486. /**
  487. * get Canvas Y size.
  488. *
  489. * @return the cANVAS_Y
  490. */
  491. public int getCanvasY() {
  492. return canvasY;
  493. }
  494. /**
  495. * Set Canvas Y size.
  496. *
  497. * @param canvasY the cANVAS_Y to set
  498. */
  499. public void setCanvasY(int canvasY) {
  500. this.canvasY = canvasY;
  501. }
  502. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  503. return this.eleToDelete;
  504. }
  505. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  506. this.eleToDelete = theHash;
  507. }
  508. public PropertyTable getSingleTable() {
  509. return this.tableModelHolonElementSingle;
  510. }
  511. public void setSingleTable(PropertyTable pt) {
  512. this.tableModelHolonElementSingle = pt;
  513. }
  514. public PropertyTable getMultiTable() {
  515. return this.tableModelHolonElementMulti;
  516. }
  517. public void setMultiTable(PropertyTable pt) {
  518. this.tableModelHolonElementMulti = pt;
  519. }
  520. public DefaulTable getPropertyTable() {
  521. return this.tableModelProperties;
  522. }
  523. public void setPropertyTable(DefaulTable pt) {
  524. this.tableModelProperties = pt;
  525. }
  526. public JTable getTableHolonElement() {
  527. return tableHolonElement;
  528. }
  529. public void setTableHolonElement(JTable tableHolonElement) {
  530. this.tableHolonElement = tableHolonElement;
  531. }
  532. /**
  533. * @return the tableProperties
  534. */
  535. public JTable getTableProperties() {
  536. return propertyTable;
  537. }
  538. /**
  539. * @return the tableProperties
  540. */
  541. public void setTableProperties(JTable propertyTable) {
  542. this.propertyTable = propertyTable;
  543. }
  544. public List<HolonElement> getAllHolonElemnts() {
  545. return getAllHolonObjectsOnCanvas().stream().flatMap(hO -> hO.getElements().stream()).collect(Collectors.toList());
  546. }
  547. public ArrayList<HolonObject> getAllHolonObjectsOnCanvas(){
  548. ArrayList<HolonObject> objectToReturn = new ArrayList<HolonObject>();
  549. getAllHolonObjectsRecursive(objectToReturn, getObjectsOnCanvas());
  550. return objectToReturn;
  551. }
  552. private void getAllHolonObjectsRecursive(ArrayList<HolonObject> addObjectsToThisList, List<AbstractCanvasObject> listOfObjectsToSearch){
  553. for(AbstractCanvasObject aCps : listOfObjectsToSearch) {
  554. if(aCps instanceof HolonObject) {
  555. addObjectsToThisList.add((HolonObject) aCps);
  556. }else if(aCps instanceof GroupNode){
  557. getAllHolonObjectsRecursive(addObjectsToThisList, ((GroupNode)aCps).getNodes());
  558. }
  559. }
  560. }
  561. /**
  562. * get all Switches
  563. */
  564. public ArrayList<HolonSwitch> getAllSwitches() {
  565. ArrayList<HolonSwitch> switches = new ArrayList<>();
  566. for (AbstractCanvasObject obj : getObjectsOnCanvas()) {
  567. if (obj instanceof HolonSwitch) {
  568. switches.add((HolonSwitch) obj);
  569. } else if (obj instanceof GroupNode) {
  570. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  571. }
  572. }
  573. return switches;
  574. }
  575. /**
  576. * get the Amount of Switches help function
  577. *
  578. * @param objects objects
  579. * @param switches List of switches
  580. */
  581. private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCanvasObject> objects,
  582. ArrayList<HolonSwitch> switches) {
  583. for (AbstractCanvasObject obj : objects) {
  584. if (obj instanceof HolonSwitch) {
  585. switches.add((HolonSwitch) obj);
  586. } else if (obj instanceof GroupNode) {
  587. getSwitchesRec(((GroupNode) obj).getNodes(), switches);
  588. }
  589. }
  590. return switches;
  591. }
  592. /**
  593. * Returns the Path for the background Image of the Canvas.
  594. *
  595. * @return imgPath the Path
  596. */
  597. public String getCanvasImagePath() {
  598. return imgPath;
  599. }
  600. /**
  601. * Set the Path for the background Image of the Canvas.
  602. *
  603. * @param path the Path
  604. */
  605. public void setCanvasImagePath(String path) {
  606. imgPath = path;
  607. }
  608. /**
  609. * Returns the mode for the background Image of the Canvas.
  610. * <p>
  611. * 0 take size of the Image 1 stretch the Image 2 Custom Image size
  612. *
  613. * @return backgroundMode the mode
  614. */
  615. public int getCanvasImageMode() {
  616. return backgroundMode;
  617. }
  618. /**
  619. * Set the mode for the background Image of the Canvas.
  620. * <p>
  621. * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
  622. *
  623. * @param mode the backgroundMode
  624. */
  625. public void setCanvasImageMode(int mode) {
  626. backgroundMode = mode;
  627. }
  628. /**
  629. * Returns the Custom width of the background Image of the Canvas.
  630. *
  631. * @return backgroundWidth the Width
  632. */
  633. public int getCanvasImageWidth() {
  634. return backgroundWidth;
  635. }
  636. /**
  637. * Set the Custom width of the background Image of the Canvas.
  638. *
  639. * @param width the Width
  640. */
  641. public void setCanvasImageWidth(int width) {
  642. backgroundWidth = width;
  643. }
  644. /**
  645. * Returns the Custom height of the background Image of the Canvas.
  646. *
  647. * @return backgroundHeight the height
  648. */
  649. public int getCanvasImageHeight() {
  650. return backgroundHeight;
  651. }
  652. /**
  653. * Set the Custom height of the background Image of the Canvas.
  654. *
  655. * @param height the height
  656. */
  657. public void setCanvasImageHeight(int height) {
  658. backgroundHeight = height;
  659. }
  660. /**
  661. * @return true if SupplyBars should be shown
  662. */
  663. public boolean getShowSupplyBars() {
  664. return showSupplyBars;
  665. }
  666. /**
  667. * @param showSupplyBars true if the SupplyBars should be shown
  668. */
  669. public void setShowSupplyBars(boolean showSupplyBars) {
  670. this.showSupplyBars = showSupplyBars;
  671. }
  672. /**
  673. * @param iterations the number of steps for this simulation
  674. */
  675. public void setIterations(int iterations){
  676. this.iterations=iterations;
  677. }
  678. /**
  679. * @return the fairnessModel
  680. */
  681. public FairnessModel getFairnessModel() {
  682. return fairnessModel;
  683. }
  684. /**
  685. * @param fairnessModel the fairnessModel to set
  686. */
  687. public void setFairnessModel(FairnessModel fairnessModel) {
  688. this.fairnessModel = fairnessModel;
  689. }
  690. public int getGraphIterations(){
  691. return GRAPH_ITERATIONS;
  692. }
  693. /**
  694. * Initialize the Gson with wanted parameters
  695. */
  696. private void initGson() {
  697. GsonBuilder builder = new GsonBuilder();
  698. builder.serializeNulls();
  699. builder.excludeFieldsWithoutExposeAnnotation();
  700. builder.setPrettyPrinting();
  701. builder.registerTypeAdapter(AbstractCanvasObject.class, new AbstractCpsObjectAdapter());
  702. builder.registerTypeAdapter(Position.class, new PositionAdapter());
  703. builder.registerTypeAdapter(Color.class, new ColorAdapter());
  704. builder.registerTypeAdapter(Pair.class, new PairAdapter());
  705. // use the builder and make a instance of the Gson
  706. this.setGson(builder.create());
  707. }
  708. /**
  709. * @return the gson
  710. */
  711. public Gson getGson() {
  712. return gson;
  713. }
  714. /**
  715. * @param gson the gson to set
  716. */
  717. public void setGson(Gson gson) {
  718. this.gson = gson;
  719. }
  720. /**
  721. * @return the hashcodeMap
  722. */
  723. public HashMap<Integer, GroupNode> getHashcodeMap() {
  724. return hashcodeMap;
  725. }
  726. /**
  727. * @param hashcodeMap the hashcodeMap to set
  728. */
  729. public void setHashcodeMap(HashMap<Integer, GroupNode> hashcodeMap) {
  730. this.hashcodeMap = hashcodeMap;
  731. }
  732. public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
  733. return switchsOnCanvas;
  734. }
  735. public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
  736. this.switchsOnCanvas = switchsOnCanvas;
  737. }
  738. public ArrayList<Node> getNodesOnCanvas() {
  739. return nodesOnCanvas;
  740. }
  741. public void setNodesOnCanvas(ArrayList<Node> nodesOnCanvas) {
  742. this.nodesOnCanvas = nodesOnCanvas;
  743. }
  744. public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
  745. return holonObjectsOnCanvas;
  746. }
  747. public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
  748. this.holonObjectsOnCanvas = holonObjectsOnCanvas;
  749. }
  750. public void defineLists() {
  751. switchsOnCanvas.clear();
  752. nodesOnCanvas.clear();
  753. holonObjectsOnCanvas.clear();
  754. for(AbstractCanvasObject aCps : this.objectsOnCanvas) {
  755. if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
  756. else if(aCps instanceof Node)nodesOnCanvas.add((Node) aCps);
  757. else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
  758. }
  759. }
  760. }