Control.java 26 KB

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