Control.java 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877
  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.stream.Collectors;
  8. import javax.swing.JFrame;
  9. import org.apache.commons.compress.archivers.ArchiveException;
  10. import com.google.gson.JsonParseException;
  11. import classes.AbstractCanvasObject;
  12. import classes.Category;
  13. import classes.Edge;
  14. import classes.GroupNode;
  15. import classes.HolonElement;
  16. import classes.HolonObject;
  17. import classes.Node;
  18. import ui.model.Model;
  19. import ui.model.Model.FairnessModel;
  20. import ui.view.CreateTemplatePopUp;
  21. import ui.view.GUI;
  22. /**
  23. * The Class represents the controller in the model, controller view Pattern.
  24. *
  25. * @author Gruppe14
  26. */
  27. public class Control {
  28. private final MultiPurposeController multiPurposeController;
  29. private final CategoryController categoryController;
  30. private final ObjectController objectController;
  31. private final CanvasController canvasController;
  32. private final GlobalController globalController;
  33. private final SaveController saveController;
  34. private final LoadController loadController;
  35. private final AutoSaveController autoSaveController;
  36. private final NodeController nodeController;
  37. private final ClipboardController clipboardController;
  38. private final HolonCanvasController holonCanvasController;
  39. private Model model;
  40. private GUI gui;
  41. private SimulationManager simulationManager;
  42. private String autosaveDir = "";
  43. private String categoryDir = "";
  44. private String otherDir = "";
  45. private String dimensionsFileName = "dimensions";
  46. private int rand;
  47. /**
  48. * Constructor.
  49. *
  50. * @param model the Model
  51. */
  52. public Control(Model model) {
  53. this.model = model;
  54. this.multiPurposeController = new MultiPurposeController(model);
  55. this.categoryController = new CategoryController(model, multiPurposeController);
  56. this.objectController = new ObjectController(model, multiPurposeController);
  57. this.canvasController = new CanvasController(model, multiPurposeController);
  58. this.globalController = new GlobalController(model);
  59. this.saveController = new SaveController(model);
  60. this.nodeController = new NodeController(model, canvasController, multiPurposeController);
  61. this.loadController = new LoadController(model, categoryController, canvasController, objectController,
  62. nodeController, multiPurposeController);
  63. this.simulationManager = new SimulationManager(model);
  64. this.autoSaveController = new AutoSaveController(model);
  65. this.clipboardController = new ClipboardController(model, saveController, loadController, canvasController,
  66. objectController, nodeController, multiPurposeController);
  67. this.holonCanvasController = new HolonCanvasController(model);
  68. autosaveDir = System.getProperty("user.home") + "/.config/HolonGUI/Autosave/";
  69. categoryDir = System.getProperty("user.home") + "/.config/HolonGUI/Category/";
  70. otherDir = System.getProperty("user.home") + "/.config/HolonGUI/Other/";
  71. File autoSave = new File(autosaveDir);
  72. File category = new File(categoryDir);
  73. File other = new File(otherDir);
  74. // deleteDirectory(dest);
  75. autoSave.mkdirs();
  76. category.mkdirs();
  77. other.mkdirs();
  78. createAutoRandom();
  79. try {
  80. autoSave();
  81. } catch (IOException e) {
  82. e.printStackTrace();
  83. }
  84. }
  85. /**
  86. * Generate random number, so that every instance of the program has unique
  87. * save 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. * @return a array of strings from all Categorys
  179. */
  180. public String[] getCategoriesStrings()
  181. {
  182. return ((ArrayList<String>) categoryController.getCategories().stream().map(c -> c.getName()).collect(Collectors.toList())).toArray(new String[categoryController.getCategories().size()]);
  183. }
  184. /**
  185. * Add new Holon Object to a Category.
  186. *
  187. * @param cat Category
  188. * @param obj New Object Name
  189. * @param ele Array of Elements
  190. * @param img the image Path
  191. * @throws IOException
  192. */
  193. public void addObject(Category cat, String obj, ArrayList<HolonElement> ele, String img) throws IOException {
  194. categoryController.addNewHolonObject(cat, obj, ele, img);
  195. saveCategory();
  196. }
  197. /**
  198. * Add new Holon Switch to a Category.
  199. *
  200. * @param cat Category
  201. * @param obj New Object Name
  202. * @throws IOException
  203. */
  204. public void addSwitch(Category cat, String obj) throws IOException {
  205. categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
  206. saveCategory();
  207. }
  208. /**
  209. * delete a given Category.
  210. *
  211. * @param cat the Category
  212. * @throws IOException
  213. */
  214. public void deleteCategory(String cat) throws IOException {
  215. categoryController.deleteCategory(cat);
  216. saveCategory();
  217. }
  218. /**
  219. * Delete an Object from a Category.
  220. *
  221. * @param cat the Category
  222. * @param obj the Object
  223. * @throws IOException
  224. */
  225. public void delObjectCategory(String cat, String obj) throws IOException {
  226. categoryController.deleteObject(cat, obj);
  227. saveCategory();
  228. }
  229. /**
  230. * deletes a selectedObject.
  231. *
  232. * @param obj Cpsobject
  233. */
  234. public void deleteSelectedObject(AbstractCanvasObject obj) {
  235. objectController.deleteSelectedObject(obj);
  236. }
  237. /**
  238. * add an Object to selectedObject.
  239. *
  240. * @param obj AbstractCpsobject
  241. */
  242. public void addSelectedObject(AbstractCanvasObject obj) {
  243. objectController.addSelectedObject(obj);
  244. }
  245. /* Operations for Canvas */
  246. /**
  247. * Add a new Object.
  248. *
  249. * @param object the Object
  250. */
  251. public void addObjectCanvas(AbstractCanvasObject object) {
  252. canvasController.addNewObject(object);
  253. calculateStateAndVisualForTimeStep(model.getCurIteration());
  254. if (!(object instanceof Node)) {
  255. try {
  256. autoSave();
  257. } catch (IOException e) {
  258. e.printStackTrace();
  259. }
  260. }
  261. }
  262. /**
  263. * Deletes an CpsObject on the Canvas and its connections.
  264. *
  265. * @param obj AbstractCpsObject
  266. * @param save
  267. */
  268. public void delCanvasObject(AbstractCanvasObject obj, boolean save) {
  269. canvasController.deleteObjectOnCanvas(obj);
  270. if (obj instanceof GroupNode) {
  271. canvasController.bfsNodeCleaner((GroupNode) obj);
  272. }
  273. calculateStateAndVisualForCurrentTimeStep();
  274. if (save)
  275. try {
  276. autoSave();
  277. } catch (IOException e) {
  278. e.printStackTrace();
  279. }
  280. }
  281. /**
  282. * Replaces {@code toBeReplaced} by {@code by} on the canvas
  283. * @param toBeReplaced the object that will be replaced
  284. * @param by the object that will replace it
  285. */
  286. public void replaceCanvasObject(AbstractCanvasObject toBeReplaced, AbstractCanvasObject by) {
  287. canvasController.replaceObjectOnCanvas(toBeReplaced, by);
  288. try {
  289. autoSave();
  290. } catch (IOException e) {
  291. System.out.println("Error by Replacing "+toBeReplaced.toString() + " by " + by.toString());
  292. e.printStackTrace();
  293. }
  294. }
  295. /**
  296. * Add an edge to the Canvas.
  297. *
  298. * @param edge the edge
  299. */
  300. public void addEdgeOnCanvas(Edge edge) {
  301. canvasController.addEdgeOnCanvas(edge);
  302. try {
  303. autoSave();
  304. } catch (IOException e) {
  305. e.printStackTrace();
  306. }
  307. }
  308. /**
  309. * Removes an Edge from the Canvas.
  310. *
  311. * @param edge the edge to remove
  312. */
  313. public void removeEdgesOnCanvas(Edge edge) {
  314. canvasController.removeEdgesOnCanvas(edge);
  315. try {
  316. autoSave();
  317. } catch (IOException e) {
  318. e.printStackTrace();
  319. }
  320. }
  321. /**
  322. * Set the selected Edge.
  323. *
  324. * @param edge that is selected
  325. */
  326. public void setSelecteEdge(Edge edge) {
  327. model.setSelectedEdge(edge);
  328. }
  329. /**
  330. * Returns the ID of the selected Object 0 = no Object is selected.
  331. *
  332. * @param id the ID of the selected Object
  333. */
  334. public void setSelectedObjectID(int id) {
  335. objectController.setSelectedObjectID(id);
  336. }
  337. /* Operations for Objects and Elements */
  338. /**
  339. * Add a new Element into a Object on the Canvas.
  340. *
  341. * @param objectId the Object ID
  342. * @param ele the Name of the Element
  343. * @param amount the Amount
  344. * @param energy the Energy
  345. * @param elementId the Element ID
  346. */
  347. public void addElementCanvasObject(int objectId, String ele, int amount, float energy, int elementId) {
  348. objectController.addNewElementIntoCanvasObject(objectId, ele, amount, energy, elementId);
  349. try {
  350. autoSave();
  351. } catch (IOException e) {
  352. e.printStackTrace();
  353. }
  354. }
  355. /**
  356. * Add a new Element into a Object in Category.
  357. *
  358. * @param catName the Category
  359. * @param objName the Object
  360. * @param eleName the Element Name
  361. * @param amount the amount
  362. * @param energy the Energy
  363. */
  364. public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
  365. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
  366. }
  367. /**
  368. * deletes a Element from a given Canvas Object.
  369. *
  370. * @param id the ID
  371. * @param elementid the Element ID
  372. */
  373. public void deleteElementCanvas(int id, int elementid) {
  374. objectController.deleteElementInCanvas(id, elementid);
  375. try {
  376. autoSave();
  377. } catch (IOException e) {
  378. e.printStackTrace();
  379. }
  380. }
  381. /**
  382. * Returns SCALE.
  383. *
  384. * @return SCALE
  385. */
  386. public int getScale() {
  387. return globalController.getScale();
  388. }
  389. /**
  390. * Changes the value of SCALE and SCALEDIV2.
  391. *
  392. * @param s Scale
  393. */
  394. public void setScale(int s) {
  395. globalController.setScale(s);
  396. }
  397. /**
  398. * Returns SCALE Divided by 2.
  399. *
  400. * @return SCALE Divided by 2
  401. */
  402. public int getScaleDiv2() {
  403. return globalController.getScaleDiv2();
  404. }
  405. /**
  406. * sets the current Iteration.
  407. *
  408. * @param curit the current Iteration
  409. */
  410. public void setCurIteration(int curit) {
  411. globalController.setCurIteration(curit);
  412. //getGui().getTimePanel().getTimeSlider().setValue(curit);
  413. }
  414. /**
  415. * Writes the current State of the Modelling into a JSON File which can be
  416. * loaded.
  417. *
  418. * @param path the Path
  419. * @throws IOException exception
  420. */
  421. public void saveFile(String path) throws IOException, ArchiveException {
  422. saveController.writeSave(path);
  423. }
  424. /**
  425. * Reads the the Save File and load the state into the Model.
  426. *
  427. * @param path the Path
  428. * @throws IOException exception
  429. * @throws ArchiveException
  430. */
  431. public void loadFile(String path) throws IOException, ArchiveException {
  432. loadController.readSave(path);
  433. saveCategory();
  434. autoSave();
  435. }
  436. /**
  437. * Reads the Json File from Autosave
  438. *
  439. * @param path
  440. * @throws IOException
  441. */
  442. public void loadAutoSave(String path) throws IOException {
  443. loadController.readJson(path);
  444. }
  445. public ArrayList<Integer> loadSavedWindowDimensionsIfExistent() {
  446. try {
  447. return loadController.readWindowDimensions(otherDir + dimensionsFileName);
  448. } catch (Exception e) {
  449. return new ArrayList<>();
  450. }
  451. }
  452. /**
  453. * calculates the flow of the edges and the supply for objects for the
  454. * current Timestep.
  455. */
  456. public void calculateStateAndVisualForCurrentTimeStep() {
  457. calculateStateAndVisualForTimeStep(model.getCurIteration());
  458. }
  459. public void calculateStateOnlyForCurrentTimeStep() {
  460. simulationManager.calculateStateForTimeStep(model.getCurIteration(), false);
  461. }
  462. /**
  463. * calculates the flow of the edges and the supply for objects.
  464. *
  465. * @param x current Iteration
  466. */
  467. public void calculateStateAndVisualForTimeStep(int x) {
  468. simulationManager.calculateStateForTimeStep(x, true);
  469. updateOutliner();
  470. updateFlexWindow();
  471. this.updateCanvas();
  472. }
  473. /**
  474. * resets the whole State of the simulation including a reset of all Edges
  475. * to the default "is working" state
  476. */
  477. public void resetSimulation() {
  478. simulationManager.resetFlexManager();
  479. }
  480. /**
  481. * make an autosave.
  482. *
  483. * @throws IOException Exception
  484. */
  485. public void autoSave() throws IOException {
  486. autoSaveController.increaseAutoSaveNr();
  487. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  488. if (autoSaveController.allowed()) {
  489. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  490. .delete();
  491. }
  492. }
  493. /**
  494. * find all old auto save files (with a file-name, that does not contain the current rand)
  495. *
  496. * @return a list of files, that are not from the current run
  497. */
  498. public ArrayList<File> filterOldAutoSaveFiles() {
  499. File[] files = new File(autosaveDir).listFiles();
  500. ArrayList<File> oldAutoSaves = new ArrayList<>();
  501. for (File file : files) {
  502. if (!file.getName().contains(String.valueOf(rand)))
  503. oldAutoSaves.add(file);
  504. }
  505. return oldAutoSaves;
  506. }
  507. /**
  508. * deletes the old autosave files
  509. */
  510. public void deleteObsoleteAutoSaveFiles() {
  511. for (File file : filterOldAutoSaveFiles()) {
  512. file.delete();
  513. }
  514. }
  515. public void saveCategory() throws IOException {
  516. saveController.writeCategory(categoryDir + "Category.json");
  517. }
  518. public void savePosAndSizeOfWindow(int x, int y, int width, int height) throws IOException, ArchiveException {
  519. saveController.writeWindowStatus(otherDir + dimensionsFileName, x, y, width, height);
  520. }
  521. /**
  522. * Returns the undo save.
  523. *
  524. * @return the undo save
  525. */
  526. public String getUndoSave() {
  527. autoSaveController.decreaseAutoSaveNr();
  528. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  529. autoSaveController.increaseAutoSaveNr();
  530. }
  531. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  532. }
  533. /**
  534. * Returns the redo save.
  535. *
  536. * @return the redo save
  537. */
  538. public String getRedoSave() {
  539. autoSaveController.increaseAutoSaveNr();
  540. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  541. autoSaveController.decreaseAutoSaveNr();
  542. // if it still does not exist, try old autosaves
  543. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  544. ArrayList<File> oldAutoSaves = filterOldAutoSaveFiles();
  545. if (oldAutoSaves.size() > 0) {
  546. return autosaveDir + oldAutoSaves.get(oldAutoSaves.size() - 1).getName();
  547. }
  548. }
  549. }
  550. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  551. }
  552. /**
  553. * Getter for Model.
  554. *
  555. * @return the Model
  556. */
  557. public Model getModel() {
  558. return model;
  559. }
  560. /**
  561. * get the Simulation Manager.
  562. *
  563. * @return the Simulation Manager
  564. */
  565. public SimulationManager getSimManager() {
  566. return simulationManager;
  567. }
  568. /**
  569. * Set the timerSpeed.
  570. *
  571. * @param t interval in ms
  572. */
  573. public void setTimerSpeed(int t) {
  574. globalController.setTimerSpeed(t);
  575. }
  576. /**
  577. * Set the Canvas X Size.
  578. *
  579. * @param canvasX the cANVAS_X to set
  580. */
  581. public void setCanvasX(int canvasX) {
  582. globalController.setCanvasX(canvasX);
  583. try {
  584. autoSave();
  585. } catch (IOException e) {
  586. e.printStackTrace();
  587. }
  588. }
  589. /**
  590. * Set the Canvas Y Size.
  591. *
  592. * @param canvasY the cANVAS_Y to set
  593. */
  594. public void setCanvasY(int canvasY) {
  595. globalController.setCanvasY(canvasY);
  596. try {
  597. autoSave();
  598. } catch (IOException e) {
  599. e.printStackTrace();
  600. }
  601. }
  602. public void setMaxCapacity(float cap) {
  603. globalController.setMaxCapacity(cap);
  604. }
  605. // ========================== MANAGING TRACKED OBJECTS END ================
  606. /**
  607. * Controlling Nodes of Nodes
  608. */
  609. public void addUpperNode(String nodeName, GroupNode upperNode, ArrayList<AbstractCanvasObject> toGroup) {
  610. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  611. try {
  612. autoSave();
  613. } catch (IOException e) {
  614. e.printStackTrace();
  615. }
  616. }
  617. public void ungroupGroupNode(GroupNode node, GroupNode upperNode) {
  618. nodeController.undoUpperNode(node, upperNode);
  619. try {
  620. autoSave();
  621. } catch (IOException e) {
  622. e.printStackTrace();
  623. }
  624. }
  625. public void addObjUpperNode(AbstractCanvasObject object, GroupNode upperNode) {
  626. nodeController.addObjectInUpperNode(object, upperNode, true);
  627. try {
  628. autoSave();
  629. } catch (IOException e) {
  630. e.printStackTrace();
  631. }
  632. }
  633. public void delObjUpperNode(AbstractCanvasObject object, GroupNode upperNode) {
  634. nodeController.deleteObjectInUpperNode(object, upperNode);
  635. if (object instanceof GroupNode)
  636. canvasController.bfsNodeCleaner((GroupNode) object);
  637. try {
  638. autoSave();
  639. } catch (IOException e) {
  640. e.printStackTrace();
  641. }
  642. }
  643. /**
  644. * Replaces {@code toBePlaced} by {@code by} in {@code upperNode}
  645. * @param toBeReplaced
  646. * @param by
  647. * @param upperNode
  648. */
  649. public void replaceObjUpperNode(AbstractCanvasObject toBeReplaced,
  650. AbstractCanvasObject by, GroupNode upperNode) {
  651. nodeController.replaceObjectInUpperNode(toBeReplaced, by, upperNode);
  652. try {
  653. autoSave();
  654. } catch (IOException e) {
  655. System.out.println("Error by Replacing "+toBeReplaced.toString()
  656. + " by " + by.toString() + " in UpperNode " + upperNode.toString());
  657. e.printStackTrace();
  658. }
  659. }
  660. /**
  661. * Get the number of HolonObjects in the given List
  662. *
  663. * @param list
  664. */
  665. public int getNumberHolonObjects(ArrayList<AbstractCanvasObject> list) {
  666. return objectController.getNumberHolonObjects(list);
  667. }
  668. /**
  669. * Get the number of HolonObjects in the given List
  670. *
  671. * @param list
  672. */
  673. public ArrayList<HolonObject> getAllHolonObjects(ArrayList<AbstractCanvasObject> list) {
  674. return objectController.getAllHolonObjects(list);
  675. }
  676. /**
  677. * Copy all Selected Objects.
  678. */
  679. public void copy(GroupNode upperNode) {
  680. clipboardController.copy(upperNode);
  681. }
  682. public void paste(GroupNode upperNode, Point point)
  683. throws JsonParseException, UnsupportedFlavorException, IOException {
  684. clipboardController.paste(upperNode, point);
  685. try {
  686. autoSave();
  687. } catch (IOException e) {
  688. e.printStackTrace();
  689. }
  690. }
  691. public void cut(GroupNode upperNode) {
  692. clipboardController.cut(upperNode);
  693. try {
  694. autoSave();
  695. } catch (IOException e) {
  696. e.printStackTrace();
  697. }
  698. }
  699. /**
  700. * creates a new Template for the given cps Object
  701. * @param cps Object, which should become a template
  702. * @param parentFrame
  703. */
  704. public void createTemplate(HolonObject cps, JFrame parentFrame) {
  705. CreateTemplatePopUp t = new CreateTemplatePopUp(cps,model,parentFrame,this);
  706. t.setVisible(true);
  707. }
  708. public void getObjectsInDepth() {
  709. clipboardController.getObjectsInDepth();
  710. }
  711. public float getTotalProduction(ArrayList<AbstractCanvasObject> arrayList) {
  712. return holonCanvasController.getTotalProduction(arrayList);
  713. }
  714. public float getTotalConsumption(ArrayList<AbstractCanvasObject> arrayList) {
  715. return holonCanvasController.getTotalConsumption(arrayList);
  716. }
  717. public int getTotalElements(ArrayList<AbstractCanvasObject> arrayList) {
  718. return holonCanvasController.getTotalElements(arrayList);
  719. }
  720. public int getTotalProducers(ArrayList<AbstractCanvasObject> arrayList) {
  721. return holonCanvasController.getTotalProducers(arrayList);
  722. }
  723. public int getActiveElements(ArrayList<AbstractCanvasObject> arrayList) {
  724. return holonCanvasController.getActiveElements(arrayList);
  725. }
  726. /**
  727. * Set the Background Image;
  728. *
  729. * @param imagePath Image Path
  730. * @param mode Image Mode
  731. * @param width Image custom width
  732. * @param height Image custom height
  733. */
  734. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  735. canvasController.setBackgroundImage(imagePath, mode, width, height);
  736. }
  737. /**
  738. * Sets show
  739. * @param showSupplyBars wether the bars should be shown
  740. */
  741. public void setShowSupplyBars(boolean showSupplyBars) {
  742. globalController.setShowSupplyBars(showSupplyBars);
  743. }
  744. /**
  745. * Sets fairness Model
  746. * @param fairnessModel that should be used.
  747. */
  748. public void setFairnessModel(FairnessModel fairnessModel) {
  749. globalController.setFairnessModel(fairnessModel);
  750. }
  751. public void updateOutliner() {
  752. gui.updateOutliners(simulationManager.getActualDecorState());
  753. }
  754. public void updateFlexWindow() {
  755. gui.updateFlexWindows();
  756. }
  757. public void updateCanvas() {
  758. gui.repaintCanvas();
  759. gui.triggerUpdateController(null);
  760. }
  761. public GUI getGui() {
  762. return gui;
  763. }
  764. public void guiDisable(boolean state) {
  765. gui.guiDisable(state);
  766. }
  767. public void setGui(GUI gui) {
  768. this.gui = gui;
  769. }
  770. }