Model.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993
  1. package ui.model;
  2. import java.awt.Color;
  3. import java.util.ArrayList;
  4. import java.util.HashMap;
  5. import java.util.Hashtable;
  6. import java.util.LinkedList;
  7. import java.util.List;
  8. import javax.swing.JTable;
  9. import com.google.gson.Gson;
  10. import com.google.gson.GsonBuilder;
  11. import com.google.gson.JsonObject;
  12. import com.google.gson.JsonParser;
  13. import TypeAdapter.AbstractCpsObjectAdapter;
  14. import TypeAdapter.ColorAdapter;
  15. import TypeAdapter.PositionAdapter;
  16. import classes.AbstractCpsObject;
  17. import classes.Category;
  18. import classes.CpsEdge;
  19. import classes.CpsUpperNode;
  20. import classes.HolonElement;
  21. import classes.HolonSwitch;
  22. import classes.Position;
  23. import interfaces.CategoryListener;
  24. import interfaces.GraphListener;
  25. import interfaces.ObjectListener;
  26. import ui.view.Console;
  27. import ui.view.DefaulTable;
  28. import ui.view.PropertyTable;
  29. import ui.view.StatisticGraphPanel;
  30. import ui.view.StatisticPanel;
  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. */
  38. public class Model {
  39. // Canvas Attributes
  40. private String imgPath = "";
  41. private int backgroundMode = 0;
  42. private int backgroundWidth = 0;
  43. private int backgroundHeight = 0;
  44. private int canvasX = 1000;
  45. private int canvasY = 1000;
  46. // Global Variables
  47. private static int sCALE = 50; // Picture Scale
  48. private static int sCALEdIV2 = sCALE / 2;
  49. private static int holonBodysCALE = 100; // Picture Scale
  50. private static final int ITERATIONS = 100;
  51. private int curIteration = 0;
  52. private LinkedList<Color> subNetColors = new LinkedList<>();
  53. // ID of the Selected Object
  54. private AbstractCpsObject selectedCpsObject = null;
  55. private HolonElement selectedHolonElement;
  56. private CpsEdge selectedEdge;
  57. private ArrayList<AbstractCpsObject> selectedObjects = new ArrayList<AbstractCpsObject>();
  58. private ArrayList<AbstractCpsObject> clipboardObjects = new ArrayList<AbstractCpsObject>();
  59. private Console console;
  60. private HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  61. // Capacity for Edge
  62. private float maxCapacity;
  63. // Table for HolonElements --> all cells are editable
  64. private JTable tableHolonElement;
  65. private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
  66. // Iteration Speed
  67. private int timerSpeed = 1000;
  68. private int selectedID = 0;
  69. // number of the current autosave
  70. private int autoSaveNr = -1;
  71. // number of max simultaneous autosaves
  72. private int numberOfSaves = 35;
  73. // if the simulation is running and has not been reseted
  74. private boolean isSimRunning = false;
  75. // if the console log of the program should be displayed
  76. private boolean showConsoleLog = true;
  77. /*
  78. * Array of all categories in the model. It is set by default with the
  79. * categories ENERGY, BUILDINGS and COMPONENTS
  80. */
  81. private ArrayList<Category> categories;
  82. /*
  83. * Array of all HolonObj and HolonSwitches, that should be tracked through
  84. * out the statistics tab
  85. */
  86. private ArrayList<AbstractCpsObject> trackedObjects;
  87. /*
  88. * Array of all CpsObjects in our canvas. It is set by default as an empty
  89. * list.
  90. */
  91. private ArrayList<AbstractCpsObject> objectsOnCanvas;
  92. private HashMap<String, Integer> cgIdx;
  93. private HashMap<Integer, Integer> cvsObjIdx;
  94. /*
  95. * Array of all CpsObjects in our canvas. It is set by default as an empty
  96. * list.
  97. */
  98. private ArrayList<CpsEdge> edgesOnCanvas;
  99. /*
  100. * Array for all Listeners
  101. */
  102. private List<CategoryListener> categoryListeners;
  103. private List<ObjectListener> objectListeners;
  104. private PropertyTable tableModelHolonElementMulti;
  105. private PropertyTable tableModelHolonElementSingle;
  106. private DefaulTable tableModelProperties;
  107. public String[] colNames = { "Field", "Information" };
  108. /*
  109. * Object that runs the Algorithm
  110. */
  111. private Object algorithm = null;
  112. private int selectedHolonBody;
  113. // Statistic Graph Data
  114. private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<String, StatisticGraphPanel>();
  115. private ArrayList<JsonObject> statisticData = new ArrayList<>();
  116. private Gson gson;
  117. private StatisticPanel statPanel;
  118. /**
  119. * Constructor for the model. It initializes the categories and
  120. * objectsOnCanvas by default values. Listeners are also initialized by
  121. * default values.
  122. */
  123. public Model() {
  124. setCategories(new ArrayList<Category>());
  125. setObjectsOnCanvas(new ArrayList<AbstractCpsObject>());
  126. setEdgesOnCanvas(new ArrayList<CpsEdge>());
  127. setCategoryListeners(new LinkedList<CategoryListener>());
  128. setObjectListeners(new LinkedList<ObjectListener>());
  129. setCgIdx(new HashMap<String, Integer>());
  130. setCvsObjIdx(new HashMap<Integer, Integer>());
  131. setClipboradObjects(new ArrayList<AbstractCpsObject>());
  132. setTrackingObj(new ArrayList<AbstractCpsObject>());
  133. setEleToDelete(new HashMap<Integer, ArrayList<HolonElement>>());
  134. setSingleTable(new PropertyTable());
  135. setMultiTable(new PropertyTable());
  136. setPropertyTable(new DefaulTable(1000, colNames.length));
  137. getPropertyTable().setColumnIdentifiers(colNames);
  138. setTableHolonElement(new JTable());
  139. initGson();
  140. }
  141. /**
  142. * Returns all Categories.
  143. *
  144. * @return the categories
  145. */
  146. public ArrayList<Category> getCategories() {
  147. return categories;
  148. }
  149. /**
  150. * Sets all Categories.
  151. *
  152. * @param categories
  153. * the categories to set
  154. */
  155. public void setCategories(ArrayList<Category> categories) {
  156. this.categories = categories;
  157. }
  158. /**
  159. * Transform the Arraylist of categories into a string of all objectName
  160. * with a separation (',') between each name.
  161. *
  162. * @return String of all names separeted by ','
  163. */
  164. public String toStringCat() {
  165. String text = "";
  166. for (int i = 0; i < categories.size(); i++) {
  167. if (text == "") {
  168. text = categories.get(i).getName();
  169. } else {
  170. text = text + ", " + categories.get(i).getName();
  171. }
  172. }
  173. return text;
  174. }
  175. /**
  176. * Returns all Objects on the Canvas.
  177. *
  178. * @return the objectsOnCanvas
  179. */
  180. public ArrayList<AbstractCpsObject> getObjectsOnCanvas() {
  181. return objectsOnCanvas;
  182. }
  183. /**
  184. * Sets all Objects on the Canvas.
  185. *
  186. * @param objectsOnCanvas
  187. * the objectsOnCanvas to set
  188. */
  189. public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
  190. this.objectsOnCanvas = objectsOnCanvas;
  191. }
  192. /**
  193. * Get all Edges on the Canvas.
  194. *
  195. * @return the objectsOnCanvas
  196. */
  197. public ArrayList<CpsEdge> getEdgesOnCanvas() {
  198. return edgesOnCanvas;
  199. }
  200. /**
  201. * Adds an Edge to The Canvas.
  202. *
  203. * @param edge
  204. * the edgesOnCanvas to add
  205. */
  206. public void addEdgeOnCanvas(CpsEdge edge) {
  207. this.edgesOnCanvas.add(edge);
  208. }
  209. /**
  210. * Remove an edge from the Canvas.
  211. *
  212. * @param edge
  213. * the edge to remove
  214. */
  215. public void removeEdgesOnCanvas(CpsEdge edge) {
  216. this.edgesOnCanvas.remove(edge);
  217. }
  218. /**
  219. * Sets the edges on the Canvas.
  220. *
  221. * @param arrayList
  222. * the edgesOnCanvas to set
  223. */
  224. public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
  225. this.edgesOnCanvas = arrayList;
  226. }
  227. /**
  228. * Returns the ObjectListener.
  229. *
  230. * @return the objectListeners
  231. */
  232. public List<ObjectListener> getObjectListeners() {
  233. return objectListeners;
  234. }
  235. /**
  236. * Sets the ObjectListener.
  237. *
  238. * @param linkedList
  239. * the objectListeners to set
  240. */
  241. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  242. this.objectListeners = linkedList;
  243. }
  244. /**
  245. * Returns the CategorieListener.
  246. *
  247. * @return the categoryListeners
  248. */
  249. public List<CategoryListener> getCategoryListeners() {
  250. return categoryListeners;
  251. }
  252. /**
  253. * Sets the CategorieListener.
  254. *
  255. * @param linkedList
  256. * the categoryListeners to set
  257. */
  258. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  259. this.categoryListeners = linkedList;
  260. }
  261. /**
  262. * Set the ID of the selected Object 0 = no Object is selected.
  263. *
  264. * @param id
  265. * the ID
  266. *
  267. */
  268. public void setSelectedObjectID(int id) {
  269. this.selectedID = id;
  270. }
  271. /**
  272. * Returns the ID of the selected Object 0 = no Object is selected.
  273. *
  274. * @return ID
  275. */
  276. public int getSelectedObjectID() {
  277. return selectedID;
  278. }
  279. /**
  280. * Returns the Selected Cps Object.
  281. *
  282. * @return selected Cps Object
  283. */
  284. public AbstractCpsObject getSelectedCpsObject() {
  285. return selectedCpsObject;
  286. }
  287. /**
  288. * Set the Selected Objecs.
  289. *
  290. * @param selectedCpsObject
  291. * Objects that are selected
  292. */
  293. public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
  294. this.selectedCpsObject = selectedCpsObject;
  295. }
  296. /**
  297. * Returns all selected Objects on the Canvas.
  298. *
  299. * @return The selected Objects
  300. */
  301. public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
  302. return selectedObjects;
  303. }
  304. /**
  305. * Returns all selected Objects on the Canvas.
  306. *
  307. * @return The selected Objects
  308. */
  309. public void setSelectedCpsObjects(ArrayList<AbstractCpsObject> arr) {
  310. this.selectedObjects = arr;
  311. }
  312. /**
  313. * Returns the Selected Holon Element.
  314. *
  315. * @return selected Holon Element
  316. */
  317. public HolonElement getSelectedHolonElement() {
  318. return selectedHolonElement;
  319. }
  320. /**
  321. * Sets the Selecte HolonElement.
  322. *
  323. * @param selectedHolonElement
  324. * that is Selected
  325. */
  326. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  327. this.selectedHolonElement = selectedHolonElement;
  328. }
  329. /**
  330. * Returns the sCale (Scale for the Images).
  331. *
  332. * @return sCALE
  333. */
  334. public int getScale() {
  335. return sCALE;
  336. }
  337. /**
  338. * Returns sCALEdIV2 (The Scale divided by 2).
  339. *
  340. * @return sCALEdIV2
  341. */
  342. public int getScaleDiv2() {
  343. return sCALEdIV2;
  344. }
  345. /**
  346. * Sets the Image Scale.
  347. *
  348. * @param scale
  349. * for the image
  350. */
  351. public void setScale(int scale) {
  352. sCALE = scale;
  353. sCALEdIV2 = sCALE / 2;
  354. }
  355. /**
  356. * Returns ITERATIONS.
  357. *
  358. * @return ITERATIONS
  359. */
  360. public int getIterations() {
  361. return ITERATIONS;
  362. }
  363. /**
  364. * sets the current Iteration.
  365. *
  366. * @param curIT
  367. * the current Iteration
  368. */
  369. public void setCurIteration(int curIT) {
  370. this.curIteration = curIT;
  371. notifyGraphListeners();
  372. }
  373. private void notifyGraphListeners() {
  374. for (GraphListener gl : graphListeners) {
  375. gl.repaintTree();
  376. }
  377. }
  378. /**
  379. * Returns cURiTERATION.
  380. *
  381. * @return cURiTERATION
  382. */
  383. public int getCurIteration() {
  384. return curIteration;
  385. }
  386. /**
  387. * Set the selected Edge.
  388. *
  389. * @param edge
  390. * that is selected
  391. *
  392. */
  393. public void setSelectedEdge(CpsEdge edge) {
  394. this.selectedEdge = edge;
  395. }
  396. /**
  397. * Returns the selected Edge.
  398. *
  399. * @return selectedEdge
  400. */
  401. public CpsEdge getSelectedEdge() {
  402. return selectedEdge;
  403. }
  404. /**
  405. * Returns the Categorie Index.
  406. *
  407. * @return the cgIdx
  408. */
  409. public HashMap<String, Integer> getCgIdx() {
  410. return cgIdx;
  411. }
  412. /**
  413. * Sets the Categorie Index.
  414. *
  415. * @param cgIdx
  416. * the cgIdx to set
  417. */
  418. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  419. this.cgIdx = cgIdx;
  420. }
  421. /**
  422. * Returns the CanvasObject Index.
  423. *
  424. * @return the cvsObjIdx
  425. */
  426. public HashMap<Integer, Integer> getCvsObjIdx() {
  427. return cvsObjIdx;
  428. }
  429. /**
  430. * Sets the CanvasObject Index.
  431. *
  432. * @param cvsObjIdx
  433. * the cvsObjIdx to set
  434. */
  435. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  436. this.cvsObjIdx = cvsObjIdx;
  437. }
  438. /**
  439. * Sets the auto save Number.
  440. *
  441. * @param autoSaveNr
  442. * the auto save number
  443. */
  444. public void setAutoSaveNr(int autoSaveNr) {
  445. this.autoSaveNr = autoSaveNr;
  446. }
  447. /**
  448. * Returns the auto save Number.
  449. *
  450. * @return the auto save Number
  451. */
  452. public int getAutoSaveNr() {
  453. return autoSaveNr;
  454. }
  455. /**
  456. * Returns the Number of Saves.
  457. *
  458. * @return the numberOfSaves
  459. */
  460. public int getNumberOfSaves() {
  461. return numberOfSaves;
  462. }
  463. /**
  464. * Set the Number of Saves.
  465. *
  466. * @param numberOfSaves
  467. * the numberOfSaves to set
  468. */
  469. public void setNumberOfSaves(int numberOfSaves) {
  470. this.numberOfSaves = numberOfSaves;
  471. }
  472. /**
  473. * Sets the ClipboardObjects.
  474. *
  475. * @param c
  476. * Array of Objects
  477. */
  478. public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
  479. this.clipboardObjects = c;
  480. }
  481. /**
  482. * Returns all Objects in the Clipboard.
  483. *
  484. * @return Objects in the Clipboard
  485. */
  486. public ArrayList<AbstractCpsObject> getClipboradObjects() {
  487. return clipboardObjects;
  488. }
  489. /**
  490. * Sets the console.
  491. *
  492. * @param console
  493. * the console
  494. */
  495. public void setConsole(Console console) {
  496. this.console = console;
  497. }
  498. /**
  499. * Returns the Console.
  500. *
  501. * @return console the console
  502. */
  503. public Console getConsole() {
  504. return console;
  505. }
  506. /**
  507. * @return the maxCapacity
  508. */
  509. public float getMaxCapacity() {
  510. return maxCapacity;
  511. }
  512. /**
  513. * @param maxCapacity
  514. * the maxCapacity to set
  515. */
  516. public void setMaxCapacity(float maxCapacity) {
  517. this.maxCapacity = maxCapacity;
  518. }
  519. /**
  520. * Sets the Interval in ms between each Iteration.
  521. *
  522. * @param t
  523. * speed for the Iterations
  524. */
  525. public void setTimerSpeed(int t) {
  526. this.timerSpeed = t;
  527. }
  528. /**
  529. * get the Interval in ms between each Iteration.
  530. *
  531. * @return timerSpeed speed for the Iterations
  532. */
  533. public int getTimerSpeed() {
  534. return this.timerSpeed;
  535. }
  536. /**
  537. * Get Canvas X Size.
  538. *
  539. * @return the cANVAS_X
  540. */
  541. public int getCanvasX() {
  542. return canvasX;
  543. }
  544. /**
  545. * Set Canvas X Size.
  546. *
  547. * @param canvasX
  548. * the cANVAS_X to set
  549. */
  550. public void setCanvasX(int canvasX) {
  551. this.canvasX = canvasX;
  552. }
  553. /**
  554. * get Canvas Y size.
  555. *
  556. * @return the cANVAS_Y
  557. */
  558. public int getCanvasY() {
  559. return canvasY;
  560. }
  561. /**
  562. * Set Canvas Y size.
  563. *
  564. * @param canvasY
  565. * the cANVAS_Y to set
  566. */
  567. public void setCanvasY(int canvasY) {
  568. this.canvasY = canvasY;
  569. }
  570. /**
  571. * get the Algorithm.
  572. *
  573. * @return the Algorithm
  574. */
  575. public Object getAlgorithm() {
  576. return algorithm;
  577. }
  578. /**
  579. * Set the Algorithm.
  580. *
  581. * @param obj
  582. * the Algorithm
  583. */
  584. public void setAlgorithm(Object obj) {
  585. this.algorithm = null;
  586. this.algorithm = obj;
  587. }
  588. /**
  589. * Add a SubNetColor.
  590. *
  591. * @param c
  592. * the Color
  593. */
  594. public void addSubNetColor(Color c) {
  595. this.subNetColors.add(c);
  596. }
  597. /**
  598. * Get the SubNetColors.
  599. *
  600. * @return SubNetColors
  601. */
  602. public LinkedList<Color> getSubNetColors() {
  603. return this.subNetColors;
  604. }
  605. public void setTrackingObj(ArrayList<AbstractCpsObject> toTrack) {
  606. trackedObjects = toTrack;
  607. }
  608. public ArrayList<AbstractCpsObject> getTrackingObj() {
  609. return trackedObjects;
  610. }
  611. public void addGraphListener(GraphListener gl) {
  612. graphListeners.add(gl);
  613. }
  614. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  615. this.eleToDelete = theHash;
  616. }
  617. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  618. return this.eleToDelete;
  619. }
  620. public void setSingleTable(PropertyTable pt) {
  621. this.tableModelHolonElementSingle = pt;
  622. }
  623. public PropertyTable getSingleTable() {
  624. return this.tableModelHolonElementSingle;
  625. }
  626. public PropertyTable getMultiTable() {
  627. return this.tableModelHolonElementMulti;
  628. }
  629. public void setMultiTable(PropertyTable pt) {
  630. this.tableModelHolonElementMulti = pt;
  631. }
  632. public void addObjectsToGraphListeners() {
  633. for (GraphListener gl : graphListeners) {
  634. gl.addTrackedObject(trackedObjects);
  635. gl.repaintTree();
  636. }
  637. }
  638. public DefaulTable getPropertyTable() {
  639. return this.tableModelProperties;
  640. }
  641. public void setPropertyTable(DefaulTable pt) {
  642. this.tableModelProperties = pt;
  643. }
  644. public JTable getTableHolonElement() {
  645. return tableHolonElement;
  646. }
  647. public void setTableHolonElement(JTable tableHolonElement) {
  648. this.tableHolonElement = tableHolonElement;
  649. }
  650. /**
  651. * Sets the HolonBody Scale.
  652. *
  653. * @param scale
  654. * for the HolonBody
  655. */
  656. public void setHolonBodyScale(int scale) {
  657. holonBodysCALE = scale;
  658. }
  659. /**
  660. * Returns the sCale (Scale for the Images).
  661. *
  662. * @return sCALE
  663. */
  664. public int getHolonBodyScale() {
  665. return holonBodysCALE;
  666. }
  667. /**
  668. * Sets the ID of the selected HolonBody
  669. *
  670. * @param i
  671. * int
  672. */
  673. public void setSelectedHolonBody(int i) {
  674. selectedHolonBody = i;
  675. }
  676. /**
  677. * Returns the ID of the selected HolonBody
  678. *
  679. * @return selectedHolonBody
  680. */
  681. public int getSelectedHolonBody() {
  682. return selectedHolonBody;
  683. }
  684. /**
  685. * get all Switches
  686. */
  687. public ArrayList<HolonSwitch> getSwitches() {
  688. ArrayList<HolonSwitch> switches = new ArrayList<>();
  689. for (AbstractCpsObject obj : getObjectsOnCanvas()) {
  690. if (obj instanceof HolonSwitch) {
  691. switches.add((HolonSwitch) obj);
  692. } else if (obj instanceof CpsUpperNode) {
  693. getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
  694. }
  695. }
  696. return switches;
  697. }
  698. /**
  699. * get the Amount of Switches help function
  700. *
  701. * @param objects
  702. * objects
  703. * @param switches
  704. * List of switches
  705. */
  706. private ArrayList<HolonSwitch> getSwitchesRec(ArrayList<AbstractCpsObject> objects,
  707. ArrayList<HolonSwitch> switches) {
  708. for (AbstractCpsObject obj : objects) {
  709. if (obj instanceof HolonSwitch) {
  710. switches.add((HolonSwitch) obj);
  711. } else if (obj instanceof CpsUpperNode) {
  712. getSwitchesRec(((CpsUpperNode) obj).getNodes(), switches);
  713. }
  714. }
  715. return switches;
  716. }
  717. /**
  718. * Returns the Path for the background Image of the Canvas.
  719. *
  720. * @return imgPath the Path
  721. */
  722. public String getCanvasImagePath() {
  723. return imgPath;
  724. }
  725. /**
  726. * Returns the mode for the background Image of the Canvas.
  727. *
  728. * 0 take size of the Image 1 stretch the Image 2 Custom Image size
  729. *
  730. * @return backgroundMode the mode
  731. */
  732. public int getCanvasImageMode() {
  733. return backgroundMode;
  734. }
  735. /**
  736. * Returns the Custom width of the background Image of the Canvas.
  737. *
  738. * @return backgroundWidth the Width
  739. */
  740. public int getCanvasImageWidth() {
  741. return backgroundWidth;
  742. }
  743. /**
  744. * Returns the Custom height of the background Image of the Canvas.
  745. *
  746. * @return backgroundHeight the height
  747. */
  748. public int getCanvasImageHeight() {
  749. return backgroundHeight;
  750. }
  751. /**
  752. * Set the Path for the background Image of the Canvas.
  753. *
  754. * @param paththe
  755. * Path
  756. */
  757. public void setCanvasImagePath(String path) {
  758. imgPath = path;
  759. }
  760. /**
  761. * Set the mode for the background Image of the Canvas.
  762. *
  763. * 0 take size of the Image, 1 stretch the Image, 2 Custom Image size
  764. *
  765. * @param backgroundMode
  766. * the mode
  767. */
  768. public void setCanvasImageMode(int mode) {
  769. backgroundMode = mode;
  770. }
  771. /**
  772. * Set the Custom width of the background Image of the Canvas.
  773. *
  774. * @param width
  775. * the Width
  776. */
  777. public void setCanvasImageWidth(int width) {
  778. backgroundWidth = width;
  779. }
  780. /**
  781. * Set the Custom height of the background Image of the Canvas.
  782. *
  783. * @param height
  784. * the height
  785. */
  786. public void setCanvasImageHeight(int height) {
  787. backgroundHeight = height;
  788. }
  789. /**
  790. * Set the graphtable for Statistic Graphs
  791. */
  792. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  793. statisticGraphTable = gT;
  794. }
  795. /**
  796. * Returns the graphtable for Statistic Graphs.
  797. */
  798. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  799. return statisticGraphTable;
  800. }
  801. /**
  802. * Returns if the Simulation is running.
  803. */
  804. public boolean getIsSimRunning() {
  805. return isSimRunning;
  806. }
  807. /**
  808. * Sets isSimRunning.
  809. *
  810. * @param isRunning
  811. */
  812. public void setIsSimRunning(boolean isRunning) {
  813. isSimRunning = isRunning;
  814. }
  815. /**
  816. * @return the statisticData
  817. */
  818. public ArrayList<JsonObject> getStatisticData() {
  819. return statisticData;
  820. }
  821. /**
  822. * @param statisticData
  823. * the statisticData to set
  824. */
  825. public void setStatisticData(ArrayList<JsonObject> statisticData) {
  826. this.statisticData = statisticData;
  827. }
  828. /**
  829. * Returns showConsoleLog.
  830. */
  831. public boolean getShowConsoleLog() {
  832. return this.showConsoleLog;
  833. }
  834. /**
  835. * Sets showConsoleLog.
  836. *
  837. * @param showConsoleLog
  838. */
  839. public void setShowConsoleLog(boolean showConsoleLog) {
  840. this.showConsoleLog = showConsoleLog;
  841. }
  842. /**
  843. * Initialize the Gson with wanted parameters
  844. */
  845. private void initGson() {
  846. // TODO Auto-generated method stub
  847. GsonBuilder builder = new GsonBuilder();
  848. builder.serializeNulls();
  849. builder.excludeFieldsWithoutExposeAnnotation();
  850. builder.setPrettyPrinting();
  851. builder.registerTypeAdapter(AbstractCpsObject.class, new AbstractCpsObjectAdapter());
  852. builder.registerTypeAdapter(Position.class, new PositionAdapter());
  853. builder.registerTypeAdapter(Color.class, new ColorAdapter());
  854. // use the builder and make a instance of the Gson
  855. this.setGson(builder.create());
  856. }
  857. /**
  858. * @return the gson
  859. */
  860. public Gson getGson() {
  861. return gson;
  862. }
  863. /**
  864. * @param gson the gson to set
  865. */
  866. public void setGson(Gson gson) {
  867. this.gson = gson;
  868. }
  869. public void setStatPanel(StatisticPanel sP){
  870. statPanel = sP;
  871. }
  872. public StatisticPanel getStatPanel(){
  873. return statPanel;
  874. }
  875. }