Model.java 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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 HashMap<Integer, ArrayList<HolonElement>> eleToDelete;
  47. // Capacity for Edge
  48. private float maxCapacity;
  49. // Table for HolonElements --> all cells are editable
  50. private JTable tableHolonElement;
  51. /** Table for the properties of HolonObjects, Edges etc */
  52. private JTable propertyTable;
  53. private ArrayList<GraphListener> graphListeners = new ArrayList<GraphListener>();
  54. // Iteration Speed
  55. private int timerSpeed = 1000;
  56. private int selectedID = 0;
  57. // number of the current autosave
  58. private int autoSaveNr = -1;
  59. // number of max simultaneous autosaves
  60. private int numberOfSaves = 35;
  61. // whether the simulation is running and has not been reseted
  62. private boolean isSimRunning = false;
  63. // whether the console log of the program should be displayed
  64. private boolean showConsoleLog = true;
  65. // whether the console log of the program should be displayed
  66. private boolean useFlexibleDevices = true;
  67. /** whether the supplyBars should be shown or not */
  68. private boolean showSupplyBars = true;
  69. //TODO:
  70. private int iterations=100;
  71. /** the Fairness model in use */
  72. private short fairnessModel = 0;
  73. /*
  74. * Array of all categories in the model. It is set by default with the
  75. * categories ENERGY, BUILDINGS and COMPONENTS
  76. */
  77. private ArrayList<Category> categories;
  78. /*
  79. * Array of all HolonObj and HolonSwitches, that should be tracked through
  80. * out the statistics tab
  81. */
  82. private ArrayList<AbstractCpsObject> trackedObjects;
  83. /*
  84. * Array of all CpsObjects in our canvas. It is set by default as an empty
  85. * list.
  86. */
  87. private ArrayList<AbstractCpsObject> objectsOnCanvas;
  88. private HashMap<String, Integer> cgIdx;
  89. private HashMap<Integer, Integer> cvsObjIdx;
  90. /*
  91. * Array of all CpsObjects in our canvas. It is set by default as an empty
  92. * list.
  93. */
  94. private ArrayList<CpsEdge> edgesOnCanvas;
  95. private ArrayList<HolonObject> holonObjectsOnCanvas = new ArrayList<HolonObject>();
  96. private ArrayList<CpsNode> nodesOnCanvas= new ArrayList<CpsNode>();
  97. private ArrayList<HolonSwitch> switchsOnCanvas= new ArrayList<HolonSwitch>();
  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. /*
  107. * Object that runs the Algorithm
  108. */
  109. private Object algorithm = null;
  110. private int selectedHolonBody;
  111. // Statistic Graph Data
  112. private Hashtable<String, StatisticGraphPanel> statisticGraphTable = new Hashtable<>();
  113. private HashMap<Integer, CpsUpperNode> hashcodeMap = new HashMap<>();
  114. private ArrayList<JsonObject> statisticData = new ArrayList<>();
  115. private Gson gson;
  116. private StatisticPanel statPanel;
  117. /**
  118. * Constructor for the model. It initializes the categories and
  119. * objectsOnCanvas by default values. Listeners are also initialized by
  120. * default values.
  121. */
  122. public Model() {
  123. setCategories(new ArrayList<>());
  124. setObjectsOnCanvas(new ArrayList<>());
  125. setEdgesOnCanvas(new ArrayList<>());
  126. setCategoryListeners(new LinkedList<>());
  127. setObjectListeners(new LinkedList<>());
  128. setCgIdx(new HashMap<>());
  129. setCvsObjIdx(new HashMap<>());
  130. setClipboradObjects(new ArrayList<>());
  131. setTrackingObj(new ArrayList<>());
  132. setEleToDelete(new HashMap<>());
  133. setSingleTable(new PropertyTable());
  134. setMultiTable(new PropertyTable());
  135. setPropertyTable(new DefaulTable(1000, colNames.length));
  136. getPropertyTable().setColumnIdentifiers(colNames);
  137. setTableHolonElement(new JTable());
  138. initGson();
  139. }
  140. /**
  141. * Returns all Categories.
  142. *
  143. * @return the categories
  144. */
  145. public ArrayList<Category> getCategories() {
  146. return categories;
  147. }
  148. /**
  149. * Sets all Categories.
  150. *
  151. * @param categories 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.equals("")) {
  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 the objectsOnCanvas to set
  185. */
  186. public void setObjectsOnCanvas(ArrayList<AbstractCpsObject> objectsOnCanvas) {
  187. this.objectsOnCanvas = objectsOnCanvas;
  188. }
  189. /**
  190. * Get all Edges on the Canvas.
  191. *
  192. * @return the edgesOnCanvas
  193. */
  194. public ArrayList<CpsEdge> getEdgesOnCanvas() {
  195. return edgesOnCanvas;
  196. }
  197. /**
  198. * Sets the edges on the Canvas.
  199. *
  200. * @param arrayList the edgesOnCanvas to set
  201. */
  202. public void setEdgesOnCanvas(ArrayList<CpsEdge> arrayList) {
  203. this.edgesOnCanvas = arrayList;
  204. }
  205. /**
  206. * Adds an Edge to The Canvas.
  207. *
  208. * @param edge the edgesOnCanvas to add
  209. */
  210. public void addEdgeOnCanvas(CpsEdge edge) {
  211. this.edgesOnCanvas.add(edge);
  212. }
  213. /**
  214. * Remove an edge from the Canvas.
  215. *
  216. * @param edge the edge to remove
  217. */
  218. public void removeEdgesOnCanvas(CpsEdge edge) {
  219. this.edgesOnCanvas.remove(edge);
  220. }
  221. /**
  222. * Returns the ObjectListener.
  223. *
  224. * @return the objectListeners
  225. */
  226. public List<ObjectListener> getObjectListeners() {
  227. return objectListeners;
  228. }
  229. /**
  230. * Sets the ObjectListener.
  231. *
  232. * @param linkedList the objectListeners to set
  233. */
  234. public void setObjectListeners(LinkedList<ObjectListener> linkedList) {
  235. this.objectListeners = linkedList;
  236. }
  237. /**
  238. * Returns the CategorieListener.
  239. *
  240. * @return the categoryListeners
  241. */
  242. public List<CategoryListener> getCategoryListeners() {
  243. return categoryListeners;
  244. }
  245. /**
  246. * Sets the CategorieListener.
  247. *
  248. * @param linkedList the categoryListeners to set
  249. */
  250. public void setCategoryListeners(LinkedList<CategoryListener> linkedList) {
  251. this.categoryListeners = linkedList;
  252. }
  253. /**
  254. * Returns the ID of the selected Object 0 = no Object is selected.
  255. *
  256. * @return ID
  257. */
  258. public int getSelectedObjectID() {
  259. return selectedID;
  260. }
  261. /**
  262. * Set the ID of the selected Object 0 = no Object is selected.
  263. *
  264. * @param id the ID
  265. */
  266. public void setSelectedObjectID(int id) {
  267. this.selectedID = id;
  268. }
  269. /**
  270. * Returns the Selected Cps Object.
  271. *
  272. * @return selected Cps Object
  273. */
  274. public AbstractCpsObject getSelectedCpsObject() {
  275. return selectedCpsObject;
  276. }
  277. /**
  278. * Set the Selected Objecs.
  279. *
  280. * @param selectedCpsObject Objects that are selected
  281. */
  282. public void setSelectedCpsObject(AbstractCpsObject selectedCpsObject) {
  283. this.selectedCpsObject = selectedCpsObject;
  284. }
  285. /**
  286. * Returns all selected Objects on the Canvas.
  287. *
  288. * @return The selected Objects
  289. */
  290. public ArrayList<AbstractCpsObject> getSelectedCpsObjects() {
  291. return selectedObjects;
  292. }
  293. /**
  294. * Returns all selected Objects on the Canvas.
  295. *
  296. * @return The selected Objects
  297. */
  298. public void setSelectedCpsObjects(ArrayList<AbstractCpsObject> arr) {
  299. this.selectedObjects = arr;
  300. }
  301. /**
  302. * Returns the Selected Holon Element.
  303. *
  304. * @return selected Holon Element
  305. */
  306. public HolonElement getSelectedHolonElement() {
  307. return selectedHolonElement;
  308. }
  309. /**
  310. * Sets the Selecte HolonElement.
  311. *
  312. * @param selectedHolonElement that is Selected
  313. */
  314. public void setSelectedHolonElement(HolonElement selectedHolonElement) {
  315. this.selectedHolonElement = selectedHolonElement;
  316. }
  317. /**
  318. * Returns the sCale (Scale for the Images).
  319. *
  320. * @return sCALE
  321. */
  322. public int getScale() {
  323. return sCALE;
  324. }
  325. /**
  326. * Sets the Image Scale.
  327. *
  328. * @param scale for the image
  329. */
  330. public void setScale(int scale) {
  331. sCALE = scale;
  332. if ((sCALE & 1) == 0)
  333. sCALEdIV2 = sCALE / 2;
  334. else
  335. sCALEdIV2 = (sCALE + 1) / 2;
  336. }
  337. /**
  338. * Returns sCALEdIV2 (The Scale divided by 2).
  339. *
  340. * @return sCALEdIV2
  341. */
  342. public int getScaleDiv2() {
  343. return sCALEdIV2;
  344. }
  345. /**
  346. * Returns ITERATIONS.
  347. *
  348. * @return ITERATIONS
  349. */
  350. public int getIterations() {
  351. return iterations;
  352. }
  353. private void notifyGraphListeners() {
  354. for (GraphListener gl : graphListeners) {
  355. gl.repaintTree();
  356. }
  357. }
  358. /**
  359. * Returns cURiTERATION.
  360. *
  361. * @return cURiTERATION
  362. */
  363. public int getCurIteration() {
  364. return curIteration;
  365. }
  366. /**
  367. * sets the current Iteration.
  368. *
  369. * @param curIT the current Iteration
  370. */
  371. public void setCurIteration(int curIT) {
  372. this.curIteration = curIT;
  373. notifyGraphListeners();
  374. }
  375. /**
  376. * Returns the selected Edge.
  377. *
  378. * @return selectedEdge
  379. */
  380. public CpsEdge getSelectedEdge() {
  381. return selectedEdge;
  382. }
  383. /**
  384. * Set the selected Edge.
  385. *
  386. * @param edge that is selected
  387. */
  388. public void setSelectedEdge(CpsEdge edge) {
  389. this.selectedEdge = edge;
  390. }
  391. /**
  392. * Returns the Categorie Index.
  393. *
  394. * @return the cgIdx
  395. */
  396. public HashMap<String, Integer> getCgIdx() {
  397. return cgIdx;
  398. }
  399. /**
  400. * Sets the Categorie Index.
  401. *
  402. * @param cgIdx the cgIdx to set
  403. */
  404. public void setCgIdx(HashMap<String, Integer> cgIdx) {
  405. this.cgIdx = cgIdx;
  406. }
  407. /**
  408. * Returns the CanvasObject Index.
  409. *
  410. * @return the cvsObjIdx
  411. */
  412. public HashMap<Integer, Integer> getCvsObjIdx() {
  413. return cvsObjIdx;
  414. }
  415. /**
  416. * Sets the CanvasObject Index.
  417. *
  418. * @param cvsObjIdx the cvsObjIdx to set
  419. */
  420. public void setCvsObjIdx(HashMap<Integer, Integer> cvsObjIdx) {
  421. this.cvsObjIdx = cvsObjIdx;
  422. }
  423. /**
  424. * Returns the auto save Number.
  425. *
  426. * @return the auto save Number
  427. */
  428. public int getAutoSaveNr() {
  429. return autoSaveNr;
  430. }
  431. /**
  432. * Sets the auto save Number.
  433. *
  434. * @param autoSaveNr the auto save number
  435. */
  436. public void setAutoSaveNr(int autoSaveNr) {
  437. this.autoSaveNr = autoSaveNr;
  438. }
  439. /**
  440. * Returns the Number of Saves.
  441. *
  442. * @return the numberOfSaves
  443. */
  444. public int getNumberOfSaves() {
  445. return numberOfSaves;
  446. }
  447. /**
  448. * Set the Number of Saves.
  449. *
  450. * @param numberOfSaves the numberOfSaves to set
  451. */
  452. public void setNumberOfSaves(int numberOfSaves) {
  453. this.numberOfSaves = numberOfSaves;
  454. }
  455. /**
  456. * Returns all Objects in the Clipboard.
  457. *
  458. * @return Objects in the Clipboard
  459. */
  460. public ArrayList<AbstractCpsObject> getClipboradObjects() {
  461. return clipboardObjects;
  462. }
  463. /**
  464. * Sets the ClipboardObjects.
  465. *
  466. * @param c Array of Objects
  467. */
  468. public void setClipboradObjects(ArrayList<AbstractCpsObject> c) {
  469. this.clipboardObjects = c;
  470. }
  471. /**
  472. * @return the maxCapacity
  473. */
  474. public float getMaxCapacity() {
  475. return maxCapacity;
  476. }
  477. /**
  478. * @param maxCapacity the maxCapacity to set
  479. */
  480. public void setMaxCapacity(float maxCapacity) {
  481. this.maxCapacity = maxCapacity;
  482. }
  483. /**
  484. * get the Interval in ms between each Iteration.
  485. *
  486. * @return timerSpeed speed for the Iterations
  487. */
  488. public int getTimerSpeed() {
  489. return this.timerSpeed;
  490. }
  491. /**
  492. * Sets the Interval in ms between each Iteration.
  493. *
  494. * @param t speed for the Iterations
  495. */
  496. public void setTimerSpeed(int t) {
  497. this.timerSpeed = t;
  498. }
  499. /**
  500. * Get Canvas X Size.
  501. *
  502. * @return the cANVAS_X
  503. */
  504. public int getCanvasX() {
  505. return canvasX;
  506. }
  507. /**
  508. * Set Canvas X Size.
  509. *
  510. * @param canvasX the cANVAS_X to set
  511. */
  512. public void setCanvasX(int canvasX) {
  513. this.canvasX = canvasX;
  514. }
  515. /**
  516. * get Canvas Y size.
  517. *
  518. * @return the cANVAS_Y
  519. */
  520. public int getCanvasY() {
  521. return canvasY;
  522. }
  523. /**
  524. * Set Canvas Y size.
  525. *
  526. * @param canvasY the cANVAS_Y to set
  527. */
  528. public void setCanvasY(int canvasY) {
  529. this.canvasY = canvasY;
  530. }
  531. /**
  532. * get the Algorithm.
  533. *
  534. * @return the Algorithm
  535. */
  536. public Object getAlgorithm() {
  537. return algorithm;
  538. }
  539. /**
  540. * Set the Algorithm.
  541. *
  542. * @param obj the Algorithm
  543. */
  544. public void setAlgorithm(Object obj) {
  545. this.algorithm = null;
  546. this.algorithm = obj;
  547. }
  548. /**
  549. * Add a SubNetColor.
  550. *
  551. * @param c the Color
  552. */
  553. public void addSubNetColor(Color c) {
  554. this.subNetColors.add(c);
  555. }
  556. /**
  557. * Get the SubNetColors.
  558. *
  559. * @return SubNetColors
  560. */
  561. public LinkedList<Color> getSubNetColors() {
  562. return this.subNetColors;
  563. }
  564. public ArrayList<AbstractCpsObject> getTrackingObj() {
  565. return trackedObjects;
  566. }
  567. public void setTrackingObj(ArrayList<AbstractCpsObject> toTrack) {
  568. trackedObjects = toTrack;
  569. }
  570. public void addGraphListener(GraphListener gl) {
  571. graphListeners.add(gl);
  572. }
  573. public HashMap<Integer, ArrayList<HolonElement>> getEleToDelete() {
  574. return this.eleToDelete;
  575. }
  576. public void setEleToDelete(HashMap<Integer, ArrayList<HolonElement>> theHash) {
  577. this.eleToDelete = theHash;
  578. }
  579. public PropertyTable getSingleTable() {
  580. return this.tableModelHolonElementSingle;
  581. }
  582. public void setSingleTable(PropertyTable pt) {
  583. this.tableModelHolonElementSingle = pt;
  584. }
  585. public PropertyTable getMultiTable() {
  586. return this.tableModelHolonElementMulti;
  587. }
  588. public void setMultiTable(PropertyTable pt) {
  589. this.tableModelHolonElementMulti = pt;
  590. }
  591. public void addObjectsToGraphListeners() {
  592. for (GraphListener gl : graphListeners) {
  593. gl.addTrackedObject(trackedObjects);
  594. gl.repaintTree();
  595. }
  596. }
  597. public DefaulTable getPropertyTable() {
  598. return this.tableModelProperties;
  599. }
  600. public void setPropertyTable(DefaulTable pt) {
  601. this.tableModelProperties = pt;
  602. }
  603. public JTable getTableHolonElement() {
  604. return tableHolonElement;
  605. }
  606. public void setTableHolonElement(JTable tableHolonElement) {
  607. this.tableHolonElement = tableHolonElement;
  608. }
  609. /**
  610. * @return the tableProperties
  611. */
  612. public JTable getTableProperties() {
  613. return propertyTable;
  614. }
  615. /**
  616. * @return the tableProperties
  617. */
  618. public void setTableProperties(JTable propertyTable) {
  619. this.propertyTable = propertyTable;
  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. public ArrayList<HolonSwitch> getSwitchsOnCanvas() {
  889. return switchsOnCanvas;
  890. }
  891. public void setSwitchsOnCanvas(ArrayList<HolonSwitch> switchsOnCanvas) {
  892. this.switchsOnCanvas = switchsOnCanvas;
  893. }
  894. public ArrayList<CpsNode> getNodesOnCanvas() {
  895. return nodesOnCanvas;
  896. }
  897. public void setNodesOnCanvas(ArrayList<CpsNode> nodesOnCanvas) {
  898. this.nodesOnCanvas = nodesOnCanvas;
  899. }
  900. public ArrayList<HolonObject> getHolonObjectsOnCanvas() {
  901. return holonObjectsOnCanvas;
  902. }
  903. public void setHolonObjectsOnCanvas(ArrayList<HolonObject> holonObjectsOnCanvas) {
  904. this.holonObjectsOnCanvas = holonObjectsOnCanvas;
  905. }
  906. public void defineLists() {
  907. switchsOnCanvas.clear();
  908. nodesOnCanvas.clear();
  909. holonObjectsOnCanvas.clear();
  910. for(AbstractCpsObject aCps : this.objectsOnCanvas) {
  911. if(aCps instanceof HolonObject)holonObjectsOnCanvas.add((HolonObject) aCps);
  912. else if(aCps instanceof CpsNode)nodesOnCanvas.add((CpsNode) aCps);
  913. else if(aCps instanceof HolonSwitch)switchsOnCanvas.add((HolonSwitch) aCps);
  914. }
  915. }
  916. }