Model.java 25 KB

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