Control.java 26 KB

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