Control.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978
  1. package ui.controller;
  2. import java.awt.Color;
  3. import java.awt.Point;
  4. import java.awt.datatransfer.UnsupportedFlavorException;
  5. import java.io.File;
  6. import java.io.IOException;
  7. import java.util.ArrayList;
  8. import java.util.Hashtable;
  9. import java.util.zip.ZipException;
  10. import org.apache.commons.compress.archivers.ArchiveException;
  11. import com.google.gson.JsonParseException;
  12. import api.CpsAlgorithm;
  13. import classes.AbstractCpsObject;
  14. import classes.Category;
  15. import classes.CpsEdge;
  16. import classes.CpsNode;
  17. import classes.CpsUpperNode;
  18. import classes.HolonElement;
  19. import classes.HolonObject;
  20. import interfaces.CategoryListener;
  21. import ui.model.Model;
  22. import ui.view.FlexiblePane;
  23. import ui.view.MyCanvas;
  24. import ui.view.StatisticGraphPanel;
  25. /**
  26. * The Class represents the controller in the model, controller view Pattern.
  27. *
  28. * @author Gruppe14
  29. *
  30. */
  31. public class Control {
  32. private Model model;
  33. private final ConsoleController consoleController;
  34. private final MultiPurposeController multiPurposeController;
  35. private final CategoryController categoryController;
  36. private final ObjectController objectController;
  37. private final CanvasController canvasController;
  38. private final GlobalController globalController;
  39. private final SaveController saveController;
  40. private final LoadController loadController;
  41. private final AutoSaveController autoSaveController;
  42. private SimulationManager simulationManager;
  43. private final StatsController statsController;
  44. private final NodeController nodeController;
  45. private final ClipboardController clipboardController;
  46. private final HolonCanvasController holonCanvasController;
  47. private String autosaveDir = "";
  48. private String categoryDir = "";
  49. private int rand;
  50. /**
  51. * Constructor.
  52. *
  53. * @param model
  54. * 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);
  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.consoleController = new ConsoleController(model);
  70. this.statsController = new StatsController(model);
  71. this.clipboardController = new ClipboardController(model, saveController, loadController, canvasController,
  72. objectController, nodeController, multiPurposeController);
  73. this.holonCanvasController = new HolonCanvasController(model);
  74. autosaveDir = System.getProperty("user.home") + "/.config/HolonGUI/Autosave/";
  75. categoryDir = System.getProperty("user.home") + "/.config/HolonGUI/Category/";
  76. File autoSave = new File(autosaveDir);
  77. File category = new File(categoryDir);
  78. // deleteDirectory(dest);
  79. autoSave.mkdirs();
  80. category.mkdirs();
  81. createAutoRandom();
  82. try {
  83. autoSave();
  84. } catch (IOException e) {
  85. // TODO Auto-generated catch block
  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
  103. * to delete
  104. */
  105. public void deleteDirectory(File path) {
  106. if (path.exists()) {
  107. File[] files = path.listFiles();
  108. for (int i = 0; i < files.length; i++) {
  109. if (files[i].isDirectory()) {
  110. deleteDirectory(files[i]);
  111. } else {
  112. if(files[i].getName().contains(""+rand))
  113. files[i].delete();
  114. }
  115. }
  116. //path.delete();
  117. }
  118. }
  119. /* Operations for searching */
  120. /**
  121. * Search for Object by ID.
  122. *
  123. * @param id
  124. * the id of the Object
  125. * @return the CpsObject
  126. */
  127. public AbstractCpsObject searchByID(int id) {
  128. return multiPurposeController.searchByID(id);
  129. }
  130. /**
  131. * Search for Object by ID in upperNode
  132. *
  133. * @param id
  134. * the id of the Object
  135. * @return the CpsObject
  136. */
  137. public AbstractCpsObject searchByIDUpperNode(int id, CpsUpperNode upperNode) {
  138. return multiPurposeController.searchByIDUpperNode(id, upperNode);
  139. }
  140. /**
  141. * Search for Object in a Category.
  142. *
  143. * @param category
  144. * name of the Category
  145. * @param object
  146. * Name of the Object
  147. * @return The Object
  148. */
  149. public AbstractCpsObject searchCategoryObject(String category, String object) {
  150. return multiPurposeController.searchCatObj(multiPurposeController.searchCat(category), object);
  151. }
  152. /**
  153. * search for category.
  154. *
  155. * @param cat
  156. * name of the Category
  157. * @return the Category
  158. */
  159. public Category searchCategory(String cat) {
  160. return multiPurposeController.searchCat(cat);
  161. }
  162. /* Operations for Categories and Objects */
  163. /**
  164. * init default category and objects.
  165. *
  166. * @throws IOException
  167. */
  168. public void resetCategorys() throws IOException {
  169. categoryController.initCategories();
  170. saveCategory();
  171. }
  172. /**
  173. * Adds New Category into Model.
  174. *
  175. * @param cat
  176. * name of the new Category
  177. * @throws IOException
  178. */
  179. public void addCategory(String cat) throws IOException {
  180. categoryController.addNewCategory(cat);
  181. saveCategory();
  182. }
  183. /**
  184. * Add new Holon Object to a Category.
  185. *
  186. * @param cat
  187. * Category
  188. * @param obj
  189. * New Object Name
  190. * @param ele
  191. * Array of Elements
  192. * @param img
  193. * 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 Transformer to a Category.
  202. *
  203. * @param cat
  204. * Category
  205. * @param obj
  206. * New Object Name
  207. */
  208. public void addTransformer(Category cat, String obj) {
  209. categoryController.addNewHolonTransformer(cat, obj, "/Images/transformer-1.png");
  210. }
  211. /**
  212. * Add new Holon Switch to a Category.
  213. *
  214. * @param cat
  215. * Category
  216. * @param obj
  217. * New Object Name
  218. * @throws IOException
  219. */
  220. public void addSwitch(Category cat, String obj) throws IOException {
  221. categoryController.addNewHolonSwitch(cat, obj, "/Images/switch-on.png");
  222. saveCategory();
  223. }
  224. /**
  225. * delete a given Category.
  226. *
  227. * @param cat
  228. * the Category
  229. * @throws IOException
  230. */
  231. public void deleteCategory(String cat) throws IOException {
  232. categoryController.deleteCategory(cat);
  233. saveCategory();
  234. }
  235. /**
  236. * Delete an Object from a Category.
  237. *
  238. * @param cat
  239. * the Category
  240. * @param obj
  241. * the Object
  242. * @throws IOException
  243. */
  244. public void delObjectCategory(String cat, String obj) throws IOException {
  245. categoryController.deleteObject(cat, obj);
  246. saveCategory();
  247. }
  248. /**
  249. * deletes a selectedObject.
  250. *
  251. * @param obj
  252. * Cpsobject
  253. */
  254. public void deleteSelectedObject(AbstractCpsObject obj) {
  255. objectController.deleteSelectedObject(obj);
  256. }
  257. /**
  258. * add an Object to selectedObject.
  259. *
  260. * @param obj
  261. * AbstractCpsobject
  262. */
  263. public void addSelectedObject(AbstractCpsObject obj) {
  264. objectController.addSelectedObject(obj);
  265. }
  266. /* Operations for Canvas */
  267. /**
  268. * Add an edge to the Canvas.
  269. *
  270. * @param edge
  271. * the edge
  272. */
  273. public void addEdgeOnCanvas(CpsEdge edge) {
  274. canvasController.addEdgeOnCanvas(edge);
  275. try {
  276. autoSave();
  277. } catch (IOException e) {
  278. // TODO Auto-generated catch block
  279. e.printStackTrace();
  280. }
  281. }
  282. /**
  283. * Removes an Edge from the Canvas.
  284. *
  285. * @param edge
  286. * the edge to remove
  287. */
  288. public void removeEdgesOnCanvas(CpsEdge edge) {
  289. canvasController.removeEdgesOnCanvas(edge);
  290. try {
  291. autoSave();
  292. } catch (IOException e) {
  293. // TODO Auto-generated catch block
  294. e.printStackTrace();
  295. }
  296. }
  297. /**
  298. * Set the selected Edge.
  299. *
  300. * @param edge
  301. * that is selected
  302. */
  303. public void setSelecteEdge(CpsEdge edge) {
  304. model.setSelectedEdge(edge);
  305. }
  306. /**
  307. * Add a new Object.
  308. *
  309. * @param object
  310. * the Object
  311. */
  312. public void addObjectCanvas(AbstractCpsObject object) {
  313. canvasController.addNewObject(object);
  314. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  315. if (!(object instanceof CpsNode)) {
  316. try {
  317. autoSave();
  318. } catch (IOException e) {
  319. // TODO Auto-generated catch block
  320. e.printStackTrace();
  321. }
  322. }
  323. }
  324. /**
  325. * Returns the ID of the selected Object 0 = no Object is selected.
  326. *
  327. * @param id
  328. * the ID of the selected Object
  329. */
  330. public void setSelectedObjectID(int id) {
  331. objectController.setSelectedObjectID(id);
  332. }
  333. /**
  334. * Deletes an CpsObject on the Canvas and its connections.
  335. *
  336. * @param obj
  337. * AbstractCpsObject
  338. * @param save
  339. */
  340. public void delCanvasObject(AbstractCpsObject obj, boolean save) {
  341. canvasController.deleteObjectOnCanvas(obj);
  342. calculateStateForCurrentTimeStep();
  343. if (obj instanceof CpsUpperNode)
  344. canvasController.bfsNodeCleaner((CpsUpperNode) obj);
  345. if (save)
  346. try {
  347. autoSave();
  348. } catch (IOException e) {
  349. // TODO Auto-generated catch block
  350. e.printStackTrace();
  351. }
  352. }
  353. /* Operations for Objects and Elements */
  354. /**
  355. * Add a new Element into a Object on the Canvas.
  356. *
  357. * @param id
  358. * the Object ID
  359. * @param ele
  360. * the Name of the Element
  361. * @param amount
  362. * the Amount
  363. * @param energy
  364. * the Energy
  365. */
  366. public void addElementCanvasObject(int id, String ele, int amount, float energy) {
  367. objectController.addNewElementIntoCanvasObject(id, ele, amount, energy);
  368. }
  369. /**
  370. * Add a new Element into a Object in Category.
  371. *
  372. * @param catName
  373. * the Category
  374. * @param objName
  375. * the Object
  376. * @param eleName
  377. * the Element Name
  378. * @param amount
  379. * the amount
  380. * @param energy
  381. * the Energy
  382. */
  383. public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
  384. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
  385. }
  386. /**
  387. * deletes a Element from a given Canvas Object.
  388. *
  389. * @param id
  390. * the ID
  391. * @param elementid
  392. * the Element ID
  393. */
  394. public void deleteElementCanvas(int id, int elementid) {
  395. objectController.deleteElementInCanvas(id, elementid);
  396. }
  397. /**
  398. * deletes a Element from a given Object.
  399. *
  400. * @param obj
  401. * the Oject
  402. * @param ele
  403. * the Element
  404. */
  405. public void deleteElementCanvas(HolonObject obj, HolonElement ele) {
  406. objectController.deleteElement(obj, ele);
  407. }
  408. /* Global Operations */
  409. /**
  410. * Add a SubNetColor.
  411. *
  412. * @param c
  413. * the Color
  414. */
  415. public void addSubNetColor(Color c) {
  416. globalController.addSubNetColor(c);
  417. }
  418. /**
  419. * Returns SCALE.
  420. *
  421. * @return SCALE
  422. */
  423. public int getScale() {
  424. return globalController.getScale();
  425. }
  426. /**
  427. * Returns SCALE Divided by 2.
  428. *
  429. * @return SCALE Divided by 2
  430. */
  431. public int getScaleDiv2() {
  432. return globalController.getScaleDiv2();
  433. }
  434. /**
  435. * Changes the value of SCALE and SCALEDIV2.
  436. *
  437. * @param s
  438. * Scale
  439. */
  440. public void setScale(int s) {
  441. globalController.setScale(s);
  442. }
  443. /**
  444. * sets the current Iteration.
  445. *
  446. * @param curit
  447. * the current Iteration
  448. */
  449. public void setCurIteration(int curit) {
  450. globalController.setCurIteration(curit);
  451. }
  452. /**
  453. * Writes the current State of the Modelling into a JSON File which can be
  454. * loaded.
  455. *
  456. * @param path
  457. * the Path
  458. *
  459. * @throws IOException
  460. * exception
  461. */
  462. public void saveFile(String path) throws IOException, ArchiveException {
  463. saveController.writeSave(path);
  464. }
  465. /**
  466. * Reads the the Save File and load the state into the Model.
  467. *
  468. * @param path
  469. * the Path
  470. * @throws IOException
  471. * exception
  472. * @throws ArchiveException
  473. */
  474. public void loadFile(String path) throws IOException, ArchiveException, ZipException {
  475. loadController.readSave(path);
  476. saveCategory();
  477. autoSave();
  478. }
  479. /**
  480. * Reads the Json File from Autosave
  481. *
  482. * @param path
  483. * @throws IOException
  484. */
  485. public void loadAutoSave(String path) throws IOException {
  486. loadController.readJson(path);
  487. }
  488. /**
  489. * Init the CategoryListener.
  490. *
  491. * @param catLis
  492. * the CategoryListener
  493. */
  494. public void initListener(CategoryListener catLis) {
  495. categoryController.addCategoryListener(catLis);
  496. }
  497. /**
  498. * calculates the flow of the edges and the supply for objects for the
  499. * current Timestep.
  500. */
  501. public void calculateStateForCurrentTimeStep() {
  502. // simulationManager.reset();
  503. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  504. }
  505. /**
  506. * calculates the flow of the edges and the supply for objects.
  507. *
  508. * @param x
  509. * current Iteration
  510. */
  511. public void calculateStateForTimeStep(int x) {
  512. // simulationManager.reset();
  513. simulationManager.calculateStateForTimeStep(x);
  514. }
  515. /**
  516. * resets the whole State of the simulation including a reset of all Edges
  517. * to the default "is working" state
  518. */
  519. public void resetSimulation() {
  520. setIsSimRunning(false);
  521. simulationManager.resetSimulation();
  522. }
  523. /**
  524. * Set the Canvas.
  525. *
  526. * @param can
  527. * the Canvas
  528. */
  529. public void setCanvas(MyCanvas can) {
  530. simulationManager.setCanvas(can);
  531. }
  532. /**
  533. * make an autosave.
  534. *
  535. * @throws IOException
  536. * Exception
  537. */
  538. public void autoSave() throws IOException {
  539. autoSaveController.increaseAutoSaveNr();
  540. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  541. if (autoSaveController.allowed()) {
  542. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  543. .delete();
  544. }
  545. }
  546. public void saveCategory() throws IOException {
  547. saveController.writeCategory(categoryDir + "Category.json");
  548. }
  549. /**
  550. * Returns the undo save.
  551. *
  552. * @return the undo save
  553. */
  554. public String getUndoSave() {
  555. autoSaveController.decreaseAutoSaveNr();
  556. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  557. autoSaveController.increaseAutoSaveNr();
  558. }
  559. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  560. }
  561. /**
  562. * Returns the redo save.
  563. *
  564. * @return the redo save
  565. */
  566. public String getRedoSave() {
  567. autoSaveController.increaseAutoSaveNr();
  568. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  569. autoSaveController.decreaseAutoSaveNr();
  570. }
  571. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  572. }
  573. /**
  574. * Getter for Model.
  575. *
  576. * @return the Model
  577. */
  578. public Model getModel() {
  579. return model;
  580. }
  581. /**
  582. * get the Simulation Manager.
  583. *
  584. * @return the Simulation Manager
  585. */
  586. public SimulationManager getSimManager() {
  587. return simulationManager;
  588. }
  589. /**
  590. * Getter for selected CpsObject.
  591. *
  592. * @param text
  593. * String the Text
  594. * @param color
  595. * the color of the Text
  596. * @param p
  597. * size of the Text
  598. * @param bold
  599. * bold or not
  600. * @param italic
  601. * italic or not
  602. * @param nl
  603. * new line or not
  604. *
  605. */
  606. public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
  607. consoleController.addTextToConsole(text, color, p, bold, italic, nl);
  608. }
  609. /**
  610. * Print Text on the console in black and font size 12.
  611. *
  612. * @param text
  613. * String the Text
  614. */
  615. public void addTextToConsole(String text) {
  616. consoleController.addTextToConsole(text);
  617. }
  618. /**
  619. * Clears the console.
  620. */
  621. public void clearConsole() {
  622. consoleController.clearConsole();
  623. }
  624. /**
  625. * Set the timerSpeed.
  626. *
  627. * @param t
  628. * interval in ms
  629. */
  630. public void setTimerSpeed(int t) {
  631. globalController.setTimerSpeed(t);
  632. }
  633. /**
  634. * Set the Canvas X Size.
  635. *
  636. * @param canvasX
  637. * the cANVAS_X to set
  638. */
  639. public void setCanvasX(int canvasX) {
  640. globalController.setCanvasX(canvasX);
  641. }
  642. /**
  643. * Set the Canvas Y Size.
  644. *
  645. * @param canvasY
  646. * the cANVAS_Y to set
  647. */
  648. public void setCanvasY(int canvasY) {
  649. globalController.setCanvasY(canvasY);
  650. }
  651. public void setMaxCapacity(float cap) {
  652. globalController.setMaxCapacity(cap);
  653. }
  654. /**
  655. * Set the Algorithm.
  656. *
  657. * @param obj
  658. * the Algorithm
  659. */
  660. public void setAlgorithm(Object obj) {
  661. multiPurposeController.setAlgorithm(obj);
  662. }
  663. /**
  664. * Run the Algorithm.
  665. */
  666. public void runAlgorithm(Model model, Control controller) {
  667. if (model.getAlgorithm() != null) {
  668. ((CpsAlgorithm) model.getAlgorithm()).runAlgorithm(model, controller);
  669. }
  670. }
  671. // ========================= MANAGING TRACKED OBJECTS ====================
  672. public void setTrackingObj(ArrayList<AbstractCpsObject> objArr) {
  673. statsController.setTrackingObj(objArr);
  674. }
  675. public ArrayList<AbstractCpsObject> getTrackingObj() {
  676. return statsController.getTrackingObj();
  677. }
  678. public void addTrackingObj(AbstractCpsObject obj) {
  679. statsController.addTrackingObj(obj);
  680. }
  681. public void removeTrackingObj(AbstractCpsObject obj) {
  682. statsController.removeTrackingObj(obj);
  683. }
  684. // ========================== MANAGING TRACKED OBJECTS END ================
  685. /**
  686. * Controlling Nodes of Nodes
  687. */
  688. public void addUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
  689. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  690. try {
  691. autoSave();
  692. } catch (IOException e) {
  693. // TODO Auto-generated catch block
  694. e.printStackTrace();
  695. }
  696. }
  697. public void delUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {
  698. nodeController.undoUpperNode(node, upperNode);
  699. try {
  700. autoSave();
  701. } catch (IOException e) {
  702. // TODO Auto-generated catch block
  703. e.printStackTrace();
  704. }
  705. }
  706. public void addObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  707. nodeController.addObjectInUpperNode(object, upperNode);
  708. try {
  709. autoSave();
  710. } catch (IOException e) {
  711. // TODO Auto-generated catch block
  712. e.printStackTrace();
  713. }
  714. }
  715. public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  716. nodeController.deleteObjectInUpperNode(object, upperNode);
  717. if (object instanceof CpsUpperNode)
  718. canvasController.bfsNodeCleaner((CpsUpperNode) object);
  719. try {
  720. autoSave();
  721. } catch (IOException e) {
  722. // TODO Auto-generated catch block
  723. e.printStackTrace();
  724. }
  725. }
  726. public void addEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  727. nodeController.addEdge(edge, upperNode);
  728. try {
  729. autoSave();
  730. } catch (IOException e) {
  731. // TODO Auto-generated catch block
  732. e.printStackTrace();
  733. }
  734. }
  735. public void delEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  736. nodeController.deleteEdge(edge, upperNode);
  737. try {
  738. autoSave();
  739. } catch (IOException e) {
  740. // TODO Auto-generated catch block
  741. e.printStackTrace();
  742. }
  743. }
  744. public void connectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  745. nodeController.connectNodes(edge, upperNode);
  746. try {
  747. autoSave();
  748. } catch (IOException e) {
  749. // TODO Auto-generated catch block
  750. e.printStackTrace();
  751. }
  752. }
  753. public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  754. nodeController.disconnectNodes(edge, upperNode);
  755. try {
  756. autoSave();
  757. } catch (IOException e) {
  758. // TODO Auto-generated catch block
  759. e.printStackTrace();
  760. }
  761. }
  762. /**
  763. * Get the number of HolonObjects in the given List
  764. *
  765. * @param list
  766. */
  767. public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
  768. return objectController.getNumberHolonObjects(list);
  769. }
  770. /**
  771. * Get the number of HolonObjects with the given state in the given List
  772. *
  773. * @param list
  774. * @param state
  775. */
  776. public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
  777. return objectController.getNumberStateObjects(list, state);
  778. }
  779. /**
  780. * Changes the value of HolonBodySCALE
  781. *
  782. * @param s
  783. * HolonBodyScale
  784. */
  785. public void setHolonBodyScale(int s) {
  786. globalController.setHolonBodyScale(s);
  787. }
  788. /**
  789. * Returns HolonBodySCALE.
  790. *
  791. * @return SCALE
  792. */
  793. public int getHolonBodyScale() {
  794. return globalController.getHolonBodyScale();
  795. }
  796. /**
  797. * Sets the ID of the selected HolonBody
  798. *
  799. * @param i
  800. * ID of the selected HolonBody
  801. */
  802. public void addSelectedHolonBody(int i) {
  803. objectController.addSelectedHolonBody(i);
  804. }
  805. /**
  806. * Copy all Selected Objects.
  807. */
  808. public void copy(CpsUpperNode upperNode) {
  809. clipboardController.copy(upperNode);
  810. }
  811. public void paste(CpsUpperNode upperNode, Point point)
  812. throws JsonParseException, UnsupportedFlavorException, IOException {
  813. clipboardController.paste(upperNode, point);
  814. }
  815. public void cut(CpsUpperNode upperNode) {
  816. clipboardController.cut(upperNode);
  817. }
  818. public void getObjectsInDepth() {
  819. clipboardController.getObjectsInDepth();
  820. }
  821. public float getTotalProduction(ArrayList<AbstractCpsObject> arrayList) {
  822. return holonCanvasController.getTotalProduction(arrayList);
  823. }
  824. public float getTotalConsumption(ArrayList<AbstractCpsObject> arrayList) {
  825. return holonCanvasController.getTotalConsumption(arrayList);
  826. }
  827. public int getTotalElements(ArrayList<AbstractCpsObject> arrayList) {
  828. return holonCanvasController.getTotalElements(arrayList);
  829. }
  830. public int getTotalProducers(ArrayList<AbstractCpsObject> arrayList) {
  831. return holonCanvasController.getTotalProducers(arrayList);
  832. }
  833. public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
  834. return holonCanvasController.getActiveElements(arrayList);
  835. }
  836. /**
  837. * Set the Background Image;
  838. *
  839. * @param imagePath
  840. * Image Path
  841. * @param mode
  842. * Image Mode
  843. * @param width
  844. * Image custom width
  845. * @param height
  846. * Image custom height
  847. */
  848. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  849. canvasController.setBackgroundImage(imagePath, mode, width, height);
  850. }
  851. public void setFlexiblePane(FlexiblePane fp) {
  852. simulationManager.setFlexiblePane(fp);
  853. }
  854. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  855. model.setGraphTable(gT);
  856. }
  857. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  858. return model.getGraphTable();
  859. }
  860. /**
  861. * Sets if the Simulation is running
  862. */
  863. public void setIsSimRunning(boolean isRunning) {
  864. globalController.setIsSimRunning(isRunning);
  865. }
  866. /**
  867. * Sets showConsoleLog.
  868. * @param showConsoleLog
  869. */
  870. public void setShowConsoleLog(boolean showConsoleLog) {
  871. globalController.setShowConsoleLog(showConsoleLog);
  872. }
  873. }