Control.java 21 KB

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