Control.java 25 KB

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