Model.java 25 KB

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