Model.java 22 KB

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