Model.java 20 KB

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