Control.java 23 KB

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