Control.java 25 KB

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