Model.java 23 KB

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