Control.java 21 KB

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