Control.java 22 KB

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