Control.java 22 KB

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