Control.java 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972
  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. if (obj instanceof CpsUpperNode)
  348. canvasController.bfsNodeCleaner((CpsUpperNode) obj);
  349. if (save)
  350. try {
  351. autoSave();
  352. } catch (IOException e) {
  353. // TODO Auto-generated catch block
  354. e.printStackTrace();
  355. }
  356. }
  357. /* Operations for Objects and Elements */
  358. /**
  359. * Add a new Element into a Object on the Canvas.
  360. *
  361. * @param id
  362. * the Object ID
  363. * @param ele
  364. * the Name of the Element
  365. * @param amount
  366. * the Amount
  367. * @param energy
  368. * the Energy
  369. */
  370. public void addElementCanvasObject(int id, String ele, int amount, float energy) {
  371. objectController.addNewElementIntoCanvasObject(id, ele, amount, energy);
  372. }
  373. /**
  374. * Add a new Element into a Object in Category.
  375. *
  376. * @param catName
  377. * the Category
  378. * @param objName
  379. * the Object
  380. * @param eleName
  381. * the Element Name
  382. * @param amount
  383. * the amount
  384. * @param energy
  385. * the Energy
  386. */
  387. public void addElementCategoryObject(String catName, String objName, String eleName, int amount, float energy) {
  388. objectController.addNewElementIntoCategoryObject(catName, objName, eleName, amount, energy);
  389. }
  390. /**
  391. * deletes a Element from a given Canvas Object.
  392. *
  393. * @param id
  394. * the ID
  395. * @param elementid
  396. * the Element ID
  397. */
  398. public void deleteElementCanvas(int id, int elementid) {
  399. objectController.deleteElementInCanvas(id, elementid);
  400. }
  401. /* Global Operations */
  402. /**
  403. * Add a SubNetColor.
  404. *
  405. * @param c
  406. * the Color
  407. */
  408. public void addSubNetColor(Color c) {
  409. globalController.addSubNetColor(c);
  410. }
  411. /**
  412. * Returns SCALE.
  413. *
  414. * @return SCALE
  415. */
  416. public int getScale() {
  417. return globalController.getScale();
  418. }
  419. /**
  420. * Returns SCALE Divided by 2.
  421. *
  422. * @return SCALE Divided by 2
  423. */
  424. public int getScaleDiv2() {
  425. return globalController.getScaleDiv2();
  426. }
  427. /**
  428. * Changes the value of SCALE and SCALEDIV2.
  429. *
  430. * @param s
  431. * Scale
  432. */
  433. public void setScale(int s) {
  434. globalController.setScale(s);
  435. }
  436. /**
  437. * sets the current Iteration.
  438. *
  439. * @param curit
  440. * the current Iteration
  441. */
  442. public void setCurIteration(int curit) {
  443. globalController.setCurIteration(curit);
  444. }
  445. /**
  446. * Writes the current State of the Modelling into a JSON File which can be
  447. * loaded.
  448. *
  449. * @param path
  450. * the Path
  451. *
  452. * @throws IOException
  453. * exception
  454. */
  455. public void saveFile(String path) throws IOException, ArchiveException {
  456. saveController.writeSave(path);
  457. }
  458. /**
  459. * Reads the the Save File and load the state into the Model.
  460. *
  461. * @param path
  462. * the Path
  463. * @throws IOException
  464. * exception
  465. * @throws ArchiveException
  466. */
  467. public void loadFile(String path) throws IOException, ArchiveException, ZipException {
  468. loadController.readSave(path);
  469. saveCategory();
  470. autoSave();
  471. }
  472. /**
  473. * Reads the Json File from Autosave
  474. *
  475. * @param path
  476. * @throws IOException
  477. */
  478. public void loadAutoSave(String path) throws IOException {
  479. loadController.readJson(path);
  480. }
  481. /**
  482. * Init the CategoryListener.
  483. *
  484. * @param catLis
  485. * the CategoryListener
  486. */
  487. public void initListener(CategoryListener catLis) {
  488. categoryController.addCategoryListener(catLis);
  489. }
  490. /**
  491. * calculates the flow of the edges and the supply for objects for the
  492. * current Timestep.
  493. */
  494. public void calculateStateForCurrentTimeStep() {
  495. // simulationManager.reset();
  496. simulationManager.calculateStateForTimeStep(model.getCurIteration());
  497. }
  498. /**
  499. * calculates the flow of the edges and the supply for objects.
  500. *
  501. * @param x
  502. * current Iteration
  503. */
  504. public void calculateStateForTimeStep(int x) {
  505. // simulationManager.reset();
  506. simulationManager.calculateStateForTimeStep(x);
  507. }
  508. /**
  509. * resets the whole State of the simulation including a reset of all Edges
  510. * to the default "is working" state
  511. */
  512. public void resetSimulation() {
  513. setIsSimRunning(false);
  514. simulationManager.resetSimulation();
  515. }
  516. /**
  517. * Set the Canvas.
  518. *
  519. * @param can
  520. * the Canvas
  521. */
  522. public void setCanvas(MyCanvas can) {
  523. simulationManager.setCanvas(can);
  524. }
  525. /**
  526. * make an autosave.
  527. *
  528. * @throws IOException
  529. * Exception
  530. */
  531. public void autoSave() throws IOException {
  532. autoSaveController.increaseAutoSaveNr();
  533. saveController.writeAutosave(autosaveDir + rand + autoSaveController.getAutoSaveNr());
  534. if (autoSaveController.allowed()) {
  535. new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr() - globalController.getNumbersOfSaves()))
  536. .delete();
  537. }
  538. }
  539. public void saveCategory() throws IOException {
  540. saveController.writeCategory(categoryDir + "Category.json");
  541. }
  542. /**
  543. * Returns the undo save.
  544. *
  545. * @return the undo save
  546. */
  547. public String getUndoSave() {
  548. autoSaveController.decreaseAutoSaveNr();
  549. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  550. autoSaveController.increaseAutoSaveNr();
  551. }
  552. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  553. }
  554. /**
  555. * Returns the redo save.
  556. *
  557. * @return the redo save
  558. */
  559. public String getRedoSave() {
  560. autoSaveController.increaseAutoSaveNr();
  561. if (!new File(autosaveDir + rand + (autoSaveController.getAutoSaveNr())).exists()) {
  562. autoSaveController.decreaseAutoSaveNr();
  563. }
  564. return autosaveDir + rand + (autoSaveController.getAutoSaveNr());
  565. }
  566. /**
  567. * Getter for Model.
  568. *
  569. * @return the Model
  570. */
  571. public Model getModel() {
  572. return model;
  573. }
  574. /**
  575. * get the Simulation Manager.
  576. *
  577. * @return the Simulation Manager
  578. */
  579. public SimulationManager getSimManager() {
  580. return simulationManager;
  581. }
  582. /**
  583. * Getter for selected CpsObject.
  584. *
  585. * @param text
  586. * String the Text
  587. * @param color
  588. * the color of the Text
  589. * @param p
  590. * size of the Text
  591. * @param bold
  592. * bold or not
  593. * @param italic
  594. * italic or not
  595. * @param nl
  596. * new line or not
  597. *
  598. */
  599. public void addTextToConsole(String text, Color color, int p, boolean bold, boolean italic, boolean nl) {
  600. consoleController.addTextToConsole(text, color, p, bold, italic, nl);
  601. }
  602. /**
  603. * Print Text on the console in black and font size 12.
  604. *
  605. * @param text
  606. * String the Text
  607. */
  608. public void addTextToConsole(String text) {
  609. consoleController.addTextToConsole(text);
  610. }
  611. /**
  612. * Clears the console.
  613. */
  614. public void clearConsole() {
  615. consoleController.clearConsole();
  616. }
  617. /**
  618. * Set the timerSpeed.
  619. *
  620. * @param t
  621. * interval in ms
  622. */
  623. public void setTimerSpeed(int t) {
  624. globalController.setTimerSpeed(t);
  625. }
  626. /**
  627. * Set the Canvas X Size.
  628. *
  629. * @param canvasX
  630. * the cANVAS_X to set
  631. */
  632. public void setCanvasX(int canvasX) {
  633. globalController.setCanvasX(canvasX);
  634. }
  635. /**
  636. * Set the Canvas Y Size.
  637. *
  638. * @param canvasY
  639. * the cANVAS_Y to set
  640. */
  641. public void setCanvasY(int canvasY) {
  642. globalController.setCanvasY(canvasY);
  643. }
  644. public void setMaxCapacity(float cap) {
  645. globalController.setMaxCapacity(cap);
  646. }
  647. /**
  648. * Set the Algorithm.
  649. *
  650. * @param obj
  651. * the Algorithm
  652. */
  653. public void setAlgorithm(Object obj) {
  654. multiPurposeController.setAlgorithm(obj);
  655. }
  656. /**
  657. * Run the Algorithm.
  658. */
  659. public void runAlgorithm(Model model, Control controller) {
  660. if (model.getAlgorithm() != null) {
  661. ((CpsAlgorithm) model.getAlgorithm()).runAlgorithm(model, controller);
  662. }
  663. }
  664. // ========================= MANAGING TRACKED OBJECTS ====================
  665. public void setTrackingObj(ArrayList<AbstractCpsObject> objArr) {
  666. statsController.setTrackingObj(objArr);
  667. }
  668. public ArrayList<AbstractCpsObject> getTrackingObj() {
  669. return statsController.getTrackingObj();
  670. }
  671. public void addTrackingObj(AbstractCpsObject obj) {
  672. statsController.addTrackingObj(obj);
  673. }
  674. public void removeTrackingObj(AbstractCpsObject obj) {
  675. statsController.removeTrackingObj(obj);
  676. }
  677. // ========================== MANAGING TRACKED OBJECTS END ================
  678. /**
  679. * Controlling Nodes of Nodes
  680. */
  681. public void addUpperNode(String nodeName, CpsUpperNode upperNode, ArrayList<AbstractCpsObject> toGroup) {
  682. nodeController.doUpperNode(nodeName, upperNode, toGroup);
  683. try {
  684. autoSave();
  685. } catch (IOException e) {
  686. // TODO Auto-generated catch block
  687. e.printStackTrace();
  688. }
  689. }
  690. public void delUpperNode(CpsUpperNode node, CpsUpperNode upperNode) {
  691. nodeController.undoUpperNode(node, upperNode);
  692. try {
  693. autoSave();
  694. } catch (IOException e) {
  695. // TODO Auto-generated catch block
  696. e.printStackTrace();
  697. }
  698. }
  699. public void addObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  700. nodeController.addObjectInUpperNode(object, upperNode);
  701. try {
  702. autoSave();
  703. } catch (IOException e) {
  704. // TODO Auto-generated catch block
  705. e.printStackTrace();
  706. }
  707. }
  708. public void delObjUpperNode(AbstractCpsObject object, CpsUpperNode upperNode) {
  709. nodeController.deleteObjectInUpperNode(object, upperNode);
  710. if (object instanceof CpsUpperNode)
  711. canvasController.bfsNodeCleaner((CpsUpperNode) object);
  712. try {
  713. autoSave();
  714. } catch (IOException e) {
  715. // TODO Auto-generated catch block
  716. e.printStackTrace();
  717. }
  718. }
  719. public void addEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  720. nodeController.addEdge(edge, upperNode);
  721. try {
  722. autoSave();
  723. } catch (IOException e) {
  724. // TODO Auto-generated catch block
  725. e.printStackTrace();
  726. }
  727. }
  728. public void delEdgeUpperNode(CpsEdge edge, CpsUpperNode upperNode) {
  729. nodeController.deleteEdge(edge, upperNode);
  730. try {
  731. autoSave();
  732. } catch (IOException e) {
  733. // TODO Auto-generated catch block
  734. e.printStackTrace();
  735. }
  736. }
  737. public void connectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  738. nodeController.connectNodes(edge, upperNode);
  739. try {
  740. autoSave();
  741. } catch (IOException e) {
  742. // TODO Auto-generated catch block
  743. e.printStackTrace();
  744. }
  745. }
  746. public void disconnectNodes(CpsEdge edge, CpsUpperNode upperNode) {
  747. nodeController.disconnectNodes(edge, upperNode);
  748. try {
  749. autoSave();
  750. } catch (IOException e) {
  751. // TODO Auto-generated catch block
  752. e.printStackTrace();
  753. }
  754. }
  755. /**
  756. * Get the number of HolonObjects in the given List
  757. *
  758. * @param list
  759. */
  760. public int getNumberHolonObjects(ArrayList<AbstractCpsObject> list) {
  761. return objectController.getNumberHolonObjects(list);
  762. }
  763. /**
  764. * Get the number of HolonObjects with the given state in the given List
  765. *
  766. * @param list
  767. * @param state
  768. */
  769. public int getNumberStateObjects(ArrayList<AbstractCpsObject> list, int state) {
  770. return objectController.getNumberStateObjects(list, state);
  771. }
  772. /**
  773. * Changes the value of HolonBodySCALE
  774. *
  775. * @param s
  776. * HolonBodyScale
  777. */
  778. public void setHolonBodyScale(int s) {
  779. globalController.setHolonBodyScale(s);
  780. }
  781. /**
  782. * Returns HolonBodySCALE.
  783. *
  784. * @return SCALE
  785. */
  786. public int getHolonBodyScale() {
  787. return globalController.getHolonBodyScale();
  788. }
  789. /**
  790. * Sets the ID of the selected HolonBody
  791. *
  792. * @param i
  793. * ID of the selected HolonBody
  794. */
  795. public void addSelectedHolonBody(int i) {
  796. objectController.addSelectedHolonBody(i);
  797. }
  798. /**
  799. * Copy all Selected Objects.
  800. */
  801. public void copy(CpsUpperNode upperNode) {
  802. clipboardController.copy(upperNode);
  803. }
  804. public void paste(CpsUpperNode upperNode, Point point)
  805. throws JsonParseException, UnsupportedFlavorException, IOException {
  806. clipboardController.paste(upperNode, point);
  807. }
  808. public void cut(CpsUpperNode upperNode) {
  809. clipboardController.cut(upperNode);
  810. }
  811. public void getObjectsInDepth() {
  812. clipboardController.getObjectsInDepth();
  813. }
  814. public float getTotalProduction(ArrayList<AbstractCpsObject> arrayList) {
  815. return holonCanvasController.getTotalProduction(arrayList);
  816. }
  817. public float getTotalConsumption(ArrayList<AbstractCpsObject> arrayList) {
  818. return holonCanvasController.getTotalConsumption(arrayList);
  819. }
  820. public int getTotalElements(ArrayList<AbstractCpsObject> arrayList) {
  821. return holonCanvasController.getTotalElements(arrayList);
  822. }
  823. public int getTotalProducers(ArrayList<AbstractCpsObject> arrayList) {
  824. return holonCanvasController.getTotalProducers(arrayList);
  825. }
  826. public int getActiveElements(ArrayList<AbstractCpsObject> arrayList) {
  827. return holonCanvasController.getActiveElements(arrayList);
  828. }
  829. /**
  830. * Set the Background Image;
  831. *
  832. * @param imagePath
  833. * Image Path
  834. * @param mode
  835. * Image Mode
  836. * @param width
  837. * Image custom width
  838. * @param height
  839. * Image custom height
  840. */
  841. public void setBackgroundImage(String imagePath, int mode, int width, int height) {
  842. canvasController.setBackgroundImage(imagePath, mode, width, height);
  843. }
  844. public void setFlexiblePane(FlexiblePane fp) {
  845. simulationManager.setFlexiblePane(fp);
  846. }
  847. public void setGraphTable(Hashtable<String, StatisticGraphPanel> gT) {
  848. model.setGraphTable(gT);
  849. }
  850. public Hashtable<String, StatisticGraphPanel> getGraphTable() {
  851. return model.getGraphTable();
  852. }
  853. /**
  854. * Sets if the Simulation is running
  855. */
  856. public void setIsSimRunning(boolean isRunning) {
  857. globalController.setIsSimRunning(isRunning);
  858. }
  859. /**
  860. * Sets showConsoleLog.
  861. *
  862. * @param showConsoleLog
  863. */
  864. public void setShowConsoleLog(boolean showConsoleLog) {
  865. globalController.setShowConsoleLog(showConsoleLog);
  866. }
  867. }