Model.java 21 KB

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