Control.java 24 KB

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