Control.java 25 KB

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