Control.java 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. package holeg.ui.controller;
  2. import java.awt.Point;
  3. import java.awt.datatransfer.UnsupportedFlavorException;
  4. import java.io.File;
  5. import java.io.IOException;
  6. import java.util.ArrayList;
  7. import java.util.Collection;
  8. import java.util.HashSet;
  9. import java.util.List;
  10. import java.util.Set;
  11. import java.util.stream.Collectors;
  12. import javax.swing.JFrame;
  13. import org.apache.commons.compress.archivers.ArchiveException;
  14. import com.google.gson.JsonParseException;
  15. import holeg.model.AbstractCanvasObject;
  16. import holeg.model.Edge;
  17. import holeg.model.GroupNode;
  18. import holeg.model.HolonElement;
  19. import holeg.model.HolonObject;
  20. import holeg.model.Node;
  21. import holeg.ui.model.Model;
  22. import holeg.ui.model.Model.FairnessModel;
  23. import holeg.ui.view.dialog.CreateTemplatePopUp;
  24. import holeg.ui.view.main.Category;
  25. import holeg.ui.view.main.GUI;
  26. import holeg.utility.events.Event;
  27. /**
  28. * The Class represents the controller in the model, controller view Pattern.
  29. *
  30. * @author Gruppe14
  31. */
  32. public class Control {
  33. private final MultiPurposeController multiPurposeController;
  34. private final CategoryController categoryController;
  35. private final ObjectController objectController;
  36. private final CanvasController canvasController;
  37. private final GlobalController globalController;
  38. private final SaveController saveController;
  39. private final LoadController loadController;
  40. private final AutoSaveController autoSaveController;
  41. private final NodeController nodeController;
  42. private final ClipboardController clipboardController;
  43. private Model model;
  44. private SimulationManager simulationManager;
  45. private String autosaveDir = "";
  46. private String categoryDir = "";
  47. private String otherDir = "";
  48. private String dimensionsFileName = "dimensions";
  49. private int rand;
  50. public Event OnCategoryChanged = new Event();
  51. public Event OnSelectionChanged = new Event();
  52. /**
  53. * Constructor.
  54. *
  55. * @param model the Model
  56. */
  57. public Control(Model model) {
  58. this.model = model;
  59. this.multiPurposeController = new MultiPurposeController(model);
  60. this.categoryController = new CategoryController(model, multiPurposeController, this);
  61. this.objectController = new ObjectController(model, multiPurposeController);
  62. this.canvasController = new CanvasController(model, multiPurposeController);
  63. this.globalController = new GlobalController(model);
  64. this.saveController = new SaveController(model);
  65. this.nodeController = new NodeController(model, canvasController, multiPurposeController);
  66. this.loadController = new LoadController(model, categoryController, canvasController, objectController,
  67. nodeController, multiPurposeController);
  68. this.simulationManager = new SimulationManager(model);
  69. this.autoSaveController = new AutoSaveController(model);
  70. this.clipboardController = new ClipboardController(model, saveController, loadController, canvasController,
  71. objectController, nodeController, this.simulationManager);
  72. autosaveDir = System.getProperty("user.home") + "/.config/HolonGUI/Autosave/";
  73. categoryDir = System.getProperty("user.home") + "/.config/HolonGUI/Category/";
  74. otherDir = System.getProperty("user.home") + "/.config/HolonGUI/Other/";
  75. File autoSave = new File(autosaveDir);
  76. File category = new File(categoryDir);
  77. File other = new File(otherDir);
  78. // deleteDirectory(dest);
  79. autoSave.mkdirs();
  80. category.mkdirs();
  81. other.mkdirs();
  82. createAutoRandom();
  83. tryAutoSave();
  84. }
  85. /**
  86. * Generate random number, so that every instance of the program has unique save
  87. * files
  88. */
  89. private void createAutoRandom() {
  90. rand = (int) (Math.random() * 1000);
  91. while (new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  92. rand = (int) Math.random() * 1000;
  93. }
  94. }
  95. /**
  96. * Delete a Directory.
  97. *
  98. * @param path to delete
  99. */
  100. public void deleteDirectory(File path) {
  101. if (path.exists()) {
  102. File[] files = path.listFiles();
  103. for (File file : files) {
  104. if (file.isDirectory()) {
  105. deleteDirectory(file);
  106. } else {
  107. if (file.getName().contains("" + rand))
  108. file.delete();
  109. }
  110. }
  111. // path.delete();
  112. }
  113. }
  114. /* Operations for searching */
  115. /**
  116. * Search for Object by ID.
  117. *
  118. * @param id the id of the Object
  119. * @return the CpsObject
  120. */
  121. public AbstractCanvasObject searchByID(int id) {
  122. return multiPurposeController.searchByID(id);
  123. }
  124. /**
  125. * Search for Object by ID in upperNode
  126. *
  127. * @param id the id of the Object
  128. * @return the CpsObject
  129. */
  130. public AbstractCanvasObject searchByIDUpperNode(int id, GroupNode upperNode) {
  131. return multiPurposeController.searchByIDUpperNode(id, upperNode);
  132. }
  133. public AbstractCanvasObject searchTracked(int id) {
  134. return multiPurposeController.searchByID(id);
  135. }
  136. /**
  137. * search for category.
  138. *
  139. * @param cat name of the Category
  140. * @return the Category
  141. */
  142. public Category searchCategory(String cat) {
  143. return multiPurposeController.searchCat(cat);
  144. }
  145. /* Operations for Categories and Objects */
  146. /**
  147. * init default category and objects.
  148. *
  149. * @throws IOException
  150. */
  151. public void resetCategorys() throws IOException {
  152. categoryController.initCategories();
  153. objectController.initHolonElements();
  154. saveCategory();
  155. }
  156. /**
  157. * Adds New Category into Model.
  158. *
  159. * @param cat name of the new Category
  160. * @throws IOException
  161. */
  162. public void addCategory(String cat) throws IOException {
  163. categoryController.addNewCategory(cat);
  164. saveCategory();
  165. }
  166. /**
  167. * Gives all Category as String
  168. *
  169. * @return a array of strings from all Categorys
  170. */
  171. public String[] getCategoriesStrings() {
  172. return ((ArrayList<String>) categoryController.getCategories().stream().map(c -> c.getName())
  173. .collect(Collectors.toList())).toArray(new String[categoryController.getCategories().size()]);
  174. }
  175. /**
  176. * Add new Holon Object to a Category.
  177. *
  178. * @param cat Category
  179. * @param obj New Object Name
  180. * @param list Array of Elements
  181. * @param img the image Path
  182. * @throws IOException
  183. */
  184. public void addObject(Category cat, String obj, List<HolonElement> list, String img) throws IOException {
  185. categoryController.addNewHolonObject(cat, obj, list, img);
  186. saveCategory();
  187. }
  188. /**
  189. * Add new Holon Switch to a Category.
  190. *
  191. * @param cat Category
  192. * @param obj New Object Name
  193. * @throws IOException
  194. */
  195. public void addSwitch(Category cat, String obj) throws IOException {
  196. categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
  197. saveCategory();
  198. }
  199. /**
  200. * delete a given Category.
  201. *
  202. * @param cat the Category
  203. * @throws IOException
  204. */
  205. public void deleteCategory(String cat) throws IOException {
  206. categoryController.deleteCategory(cat);
  207. saveCategory();
  208. }
  209. /**
  210. * Delete an Object from a Category.
  211. *
  212. * @param cat the Category
  213. * @param obj the Object
  214. * @throws IOException
  215. */
  216. public void delObjectCategory(String cat, String obj) throws IOException {
  217. categoryController.deleteObject(cat, obj);
  218. saveCategory();
  219. }
  220. /**
  221. * removes a selectedObject from selection.
  222. *
  223. * @param obj Cpsobject
  224. */
  225. public void removeObjectsFromSelection(Collection<AbstractCanvasObject> objects) {
  226. for (AbstractCanvasObject object : objects) {
  227. objectController.removeObjectFromSelection(object);
  228. }
  229. OnSelectionChanged.broadcast();
  230. }
  231. /**
  232. * removes a selectedObject from selection.
  233. *
  234. * @param obj Cpsobject
  235. */
  236. public void removeObjectFromSelection(AbstractCanvasObject obj) {
  237. objectController.removeObjectFromSelection(obj);
  238. OnSelectionChanged.broadcast();
  239. }
  240. /**
  241. * add an Object to selectedObject.
  242. *
  243. * @param obj AbstractCpsobject
  244. */
  245. public void addSelectedObject(AbstractCanvasObject obj) {
  246. objectController.addSelectedObject(obj);
  247. OnSelectionChanged.broadcast();
  248. }
  249. public void addSelectedObjects(Collection<AbstractCanvasObject> objects) {
  250. objectController.addSelectedObjects(objects);
  251. OnSelectionChanged.broadcast();
  252. }
  253. public void clearSelection() {
  254. if(!model.getSelectedObjects().isEmpty()) {
  255. model.getSelectedObjects().clear();
  256. OnSelectionChanged.broadcast();
  257. }
  258. }
  259. /**
  260. * This method is primarily for the multi-selection. It adds unselected objects
  261. * to the selection and Removes selected objects from the selection. Like the
  262. * normal OS Desktop selection.
  263. *
  264. * @param objects
  265. */
  266. public void toggleSelectedObjects(Collection<AbstractCanvasObject> objects) {
  267. Set<AbstractCanvasObject> intersection = new HashSet<>(objects);
  268. intersection.retainAll(model.getSelectedObjects());
  269. model.getSelectedObjects().addAll(objects);
  270. model.getSelectedObjects().removeAll(intersection);
  271. OnSelectionChanged.broadcast();
  272. }
  273. /* Operations for Canvas */
  274. /**
  275. * Add a new Object.
  276. *
  277. * @param object the Object
  278. */
  279. public void addObjectCanvas(AbstractCanvasObject object) {
  280. canvasController.addNewObject(object);
  281. calculateStateAndVisualForTimeStep(model.getActualTimeStep());
  282. if (!(object instanceof Node)) {
  283. tryAutoSave();
  284. }
  285. }
  286. /**
  287. * Deletes an CpsObject on the Canvas and its connections.
  288. *
  289. * @param obj AbstractCpsObject
  290. * @param save
  291. */
  292. public void delCanvasObject(AbstractCanvasObject obj, boolean save) {
  293. canvasController.deleteObjectOnCanvas(obj);
  294. if (obj instanceof GroupNode groupnode) {
  295. canvasController.bfsNodeCleaner(groupnode);
  296. }
  297. calculateStateAndVisualForCurrentTimeStep();
  298. if (save) {
  299. tryAutoSave();
  300. }
  301. }
  302. public void delCanvasObjects(Collection<AbstractCanvasObject> objects) {
  303. canvasController.deleteObjectsOnCanvas(objects);
  304. calculateStateAndVisualForCurrentTimeStep();
  305. tryAutoSave();
  306. }
  307. /**
  308. * Replaces {@code toBeReplaced} by {@code by} on the canvas
  309. *
  310. * @param toBeReplaced the object that will be replaced
  311. * @param by the object that will replace it
  312. */
  313. public void replaceCanvasObject(AbstractCanvasObject toBeReplaced, AbstractCanvasObject by) {
  314. canvasController.replaceObjectOnCanvas(toBeReplaced, by);
  315. tryAutoSave();
  316. }
  317. /**
  318. * Add an edge to the Canvas.
  319. *
  320. * @param edge the edge
  321. */
  322. public void addEdgeOnCanvas(Edge edge) {
  323. canvasController.addEdgeOnCanvas(edge);
  324. tryAutoSave();
  325. }
  326. /**
  327. * Removes an Edge from the Canvas.
  328. *
  329. * @param edge the edge to remove
  330. */
  331. public void removeEdgesOnCanvas(Edge edge) {
  332. canvasController.removeEdgesOnCanvas(edge);
  333. tryAutoSave();
  334. }
  335. /**
  336. * Set the selected Edge.
  337. *
  338. * @param edge that is selected
  339. */
  340. public void setSelecteEdge(Edge edge) {
  341. model.setSelectedEdge(edge);
  342. }
  343. /* Operations for Objects and Elements */
  344. /**
  345. * Add a new Element into a Object on the Canvas.
  346. *
  347. * @param objectId the Object ID
  348. * @param ele the Name of the Element
  349. * @param energy the Energy
  350. * @param elementId the Element ID
  351. */
  352. public void addElementCanvasObject(int objectId, String ele, float energy, int elementId) {
  353. objectController.addNewElementIntoCanvasObject(objectId, ele, energy, elementId);
  354. tryAutoSave();
  355. }
  356. /**
  357. * Add a new Element into a Object in Category.
  358. *
  359. * @param catName the Category
  360. * @param objName the Object
  361. * @param eleName the Element Name
  362. * @param amount the amount
  363. * @param energy the Energy
  364. */
  365. public void addElementCategoryObject(String catName, String objName, String eleName, float energy) {
  366. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, energy);
  367. }
  368. /**
  369. * Returns SCALE.
  370. *
  371. * @return SCALE
  372. */
  373. public int getScale() {
  374. return globalController.getScale();
  375. }
  376. /**
  377. * Changes the value of SCALE and SCALEDIV2.
  378. *
  379. * @param s Scale
  380. */
  381. public void setScale(int s) {
  382. globalController.setScale(s);
  383. }
  384. /**
  385. * Returns SCALE Divided by 2.
  386. *
  387. * @return SCALE Divided by 2
  388. */
  389. public int getScaleDiv2() {
  390. return globalController.getScaleDiv2();
  391. }
  392. /**
  393. * sets the current Iteration.
  394. *
  395. * @param curit the current Iteration
  396. */
  397. public void setCurIteration(int curit) {
  398. globalController.setCurIteration(curit);
  399. // getGui().getTimePanel().getTimeSlider().setValue(curit);
  400. }
  401. /**
  402. * Writes the current State of the Modelling into a JSON File which can be
  403. * loaded.
  404. *
  405. * @param path the Path
  406. * @throws IOException exception
  407. */
  408. public void saveFile(String path) throws IOException, ArchiveException {
  409. saveController.writeSave(path);
  410. }
  411. /**
  412. * Reads the the Save File and load the state into the Model.
  413. *
  414. * @param path the Path
  415. * @throws IOException exception
  416. * @throws ArchiveException
  417. */
  418. public void loadFile(String path) throws IOException, ArchiveException {
  419. loadController.readSave(path);
  420. saveCategory();
  421. autoSave();
  422. }
  423. /**
  424. * Reads the Json File from Autosave
  425. *
  426. * @param path
  427. * @throws IOException
  428. */
  429. public void loadAutoSave(String path) throws IOException {
  430. loadController.readJson(path);
  431. }
  432. public ArrayList<Integer> loadSavedWindowDimensionsIfExistent() {
  433. try {
  434. return loadController.readWindowDimensions(otherDir + dimensionsFileName);
  435. } catch (Exception e) {
  436. return new ArrayList<>();
  437. }
  438. }
  439. /**
  440. * calculates the flow of the edges and the supply for objects for the current
  441. * Timestep.
  442. */
  443. public void calculateStateAndVisualForCurrentTimeStep() {
  444. calculateStateAndVisualForTimeStep(model.getActualTimeStep());
  445. }
  446. public void calculateStateOnlyForCurrentTimeStep() {
  447. simulationManager.calculateStateForTimeStep(model.getActualTimeStep(), false);
  448. }
  449. /**
  450. * calculates the flow of the edges and the supply for objects.
  451. *
  452. * @param x current Iteration
  453. */
  454. public void calculateStateAndVisualForTimeStep(int x) {
  455. simulationManager.calculateStateForTimeStep(x, true);
  456. //TODO(Tom2021-12-2): Convert to Events
  457. updateOutliner();
  458. updateFlexWindow();
  459. this.updateCanvas();
  460. }
  461. /**
  462. * resets the whole State of the simulation including a reset of all Edges to
  463. * the default "is working" state
  464. */
  465. public void resetSimulation() {
  466. model.reset();
  467. }
  468. /**
  469. * make an autosave.
  470. *
  471. * @throws IOException Exception
  472. */
  473. public void autoSave() throws IOException {
  474. autoSaveController.increaseAutoSaveNr();
  475. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  476. if (autoSaveController.allowed()) {
  477. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  478. .delete();
  479. }
  480. }
  481. public void tryAutoSave() {
  482. try {
  483. autoSave();
  484. } catch (IOException e) {
  485. e.printStackTrace();
  486. }
  487. }
  488. /**
  489. * find all old auto save files (with a file-name, that does not contain the
  490. * current rand)
  491. *
  492. * @return a list of files, that are not from the current run
  493. */
  494. public ArrayList<File> filterOldAutoSaveFiles() {
  495. File[] files = new File(autosaveDir).listFiles();
  496. ArrayList<File> oldAutoSaves = new ArrayList<>();
  497. for (File file : files) {
  498. if (!file.getName().contains(String.valueOf(rand)))
  499. oldAutoSaves.add(file);
  500. }
  501. return oldAutoSaves;
  502. }
  503. /**
  504. * deletes the old autosave files
  505. */
  506. public void deleteObsoleteAutoSaveFiles() {
  507. for (File file : filterOldAutoSaveFiles()) {
  508. file.delete();
  509. }
  510. }
  511. public void saveCategory() throws IOException {
  512. saveController.writeCategory(categoryDir + "Category.json");
  513. }
  514. public void savePosAndSizeOfWindow(int x, int y, int width, int height) throws IOException, ArchiveException {
  515. saveController.writeWindowStatus(otherDir + dimensionsFileName, x, y, width, height);
  516. }
  517. /**
  518. * Returns the undo save.
  519. *
  520. * @return the undo save
  521. */
  522. public String getUndoSave() {
  523. autoSaveController.decreaseAutoSaveNr();
  524. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  525. autoSaveController.increaseAutoSaveNr();
  526. }
  527. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  528. }
  529. /**
  530. * Returns the redo save.
  531. *
  532. * @return the redo save
  533. */
  534. public String getRedoSave() {
  535. autoSaveController.increaseAutoSaveNr();
  536. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  537. autoSaveController.decreaseAutoSaveNr();
  538. // if it still does not exist, try old autosaves
  539. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  540. ArrayList<File> oldAutoSaves = filterOldAutoSaveFiles();
  541. if (oldAutoSaves.size() > 0) {
  542. return autosaveDir + oldAutoSaves.get(oldAutoSaves.size() - 1).getName();
  543. }
  544. }
  545. }
  546. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  547. }
  548. /**
  549. * Getter for Model.
  550. *
  551. * @return the Model
  552. */
  553. public Model getModel() {
  554. return model;
  555. }
  556. /**
  557. * get the Simulation Manager.
  558. *
  559. * @return the Simulation Manager
  560. */
  561. public SimulationManager getSimManager() {
  562. return simulationManager;
  563. }
  564. /**
  565. * Set the timerSpeed.
  566. *
  567. * @param t interval in ms
  568. */
  569. public void setTimerSpeed(int t) {
  570. globalController.setTimerSpeed(t);
  571. }
  572. /**
  573. * Set the Canvas X Size.
  574. *
  575. * @param canvasX the cANVAS_X to set
  576. */
  577. public void setCanvasX(int canvasX) {
  578. globalController.setCanvasX(canvasX);
  579. tryAutoSave();
  580. }
  581. /**
  582. * Set the Canvas Y Size.
  583. *
  584. * @param canvasY the cANVAS_Y to set
  585. */
  586. public void setCanvasY(int canvasY) {
  587. globalController.setCanvasY(canvasY);
  588. tryAutoSave();
  589. }
  590. public void setMaxCapacity(float cap) {
  591. globalController.setMaxCapacity(cap);
  592. }
  593. // ========================== MANAGING TRACKED OBJECTS END ================
  594. /**
  595. * Controlling Nodes of Nodes
  596. */
  597. public void addUpperNode(String nodeName, GroupNode upperNode, ArrayList<AbstractCanvasObject> toGroup) {
  598. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  599. tryAutoSave();
  600. }
  601. public void ungroupGroupNode(GroupNode node, GroupNode upperNode) {
  602. nodeController.undoUpperNode(node, upperNode);
  603. tryAutoSave();
  604. }
  605. public void addObjUpperNode(AbstractCanvasObject object, GroupNode upperNode) {
  606. nodeController.addObjectInUpperNode(object, upperNode, true);
  607. tryAutoSave();
  608. }
  609. public void delObjUpperNode(AbstractCanvasObject object, GroupNode upperNode) {
  610. nodeController.deleteObjectInUpperNode(object, upperNode);
  611. if (object instanceof GroupNode groupnode)
  612. canvasController.bfsNodeCleaner(groupnode);
  613. tryAutoSave();
  614. }
  615. /**
  616. * Replaces {@code toBePlaced} by {@code by} in {@code upperNode}
  617. *
  618. * @param toBeReplaced
  619. * @param by
  620. * @param upperNode
  621. */
  622. public void replaceObjUpperNode(AbstractCanvasObject toBeReplaced, AbstractCanvasObject by, GroupNode upperNode) {
  623. nodeController.replaceObjectInUpperNode(toBeReplaced, by, upperNode);
  624. tryAutoSave();
  625. }
  626. /**
  627. * Get the number of HolonObjects in the given List
  628. *
  629. * @param list
  630. */
  631. public int getNumberHolonObjects(ArrayList<AbstractCanvasObject> list) {
  632. return objectController.getNumberHolonObjects(list);
  633. }
  634. /**
  635. * Copy all Selected Objects.
  636. */
  637. public void copy(GroupNode upperNode) {
  638. clipboardController.copy(upperNode);
  639. }
  640. public void paste(GroupNode upperNode, Point point)
  641. throws JsonParseException, UnsupportedFlavorException, IOException {
  642. clipboardController.paste(upperNode, point);
  643. OnSelectionChanged.broadcast();
  644. tryAutoSave();
  645. }
  646. public void cut(GroupNode upperNode) {
  647. clipboardController.cut(upperNode);
  648. OnSelectionChanged.broadcast();
  649. tryAutoSave();
  650. }
  651. /**
  652. * creates a new Template for the given cps Object
  653. *
  654. * @param cps Object, which should become a template
  655. * @param parentFrame
  656. */
  657. public void createTemplate(HolonObject cps, JFrame parentFrame) {
  658. CreateTemplatePopUp t = new CreateTemplatePopUp(cps, model, parentFrame, this);
  659. t.setVisible(true);
  660. }
  661. public void getObjectsInDepth() {
  662. clipboardController.getObjectsInDepth();
  663. }
  664. /**
  665. * Set the Background Image;
  666. *
  667. * @param imagePath Image Path
  668. * @param mode Image Mode
  669. * @param width Image custom width
  670. * @param height Image custom height
  671. */
  672. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  673. canvasController.setBackgroundImage(imagePath, mode, width, height);
  674. }
  675. /**
  676. * Sets show
  677. *
  678. * @param showSupplyBars wether the bars should be shown
  679. */
  680. public void setShowSupplyBars(boolean showSupplyBars) {
  681. globalController.setShowSupplyBars(showSupplyBars);
  682. }
  683. /**
  684. * Sets fairness Model
  685. *
  686. * @param fairnessModel that should be used.
  687. */
  688. public void setFairnessModel(FairnessModel fairnessModel) {
  689. globalController.setFairnessModel(fairnessModel);
  690. }
  691. public void updateOutliner() {
  692. this.canvasController.updateOutliner(simulationManager);
  693. }
  694. public void updateFlexWindow() {
  695. canvasController.updateFlexWindow();
  696. }
  697. public void updateCanvas() {
  698. canvasController.updateCanvas();
  699. }
  700. public GUI getGui() {
  701. return canvasController.getGui();
  702. }
  703. public void guiDisable(boolean state) {
  704. canvasController.guiDisable(state);
  705. }
  706. public void setGui(GUI gui) {
  707. canvasController.setGui(gui);
  708. }
  709. }