MyCanvas.java 38 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172
  1. package ui.view;
  2. import java.awt.BasicStroke;
  3. import java.awt.Color;
  4. import java.awt.Graphics;
  5. import java.awt.Graphics2D;
  6. import java.awt.Image;
  7. import java.awt.Point;
  8. import java.awt.RenderingHints;
  9. import java.awt.datatransfer.UnsupportedFlavorException;
  10. import java.awt.event.ActionEvent;
  11. import java.awt.event.ActionListener;
  12. import java.awt.event.MouseEvent;
  13. import java.awt.event.MouseListener;
  14. import java.awt.event.MouseMotionListener;
  15. import java.awt.geom.Line2D;
  16. import java.io.File;
  17. import java.io.IOException;
  18. import java.util.ArrayList;
  19. import java.util.Timer;
  20. import java.util.TimerTask;
  21. import javax.swing.ImageIcon;
  22. import javax.swing.JLabel;
  23. import javax.swing.JMenuItem;
  24. import javax.swing.JOptionPane;
  25. import javax.swing.JPanel;
  26. import javax.swing.JPopupMenu;
  27. import javax.swing.JScrollPane;
  28. import javax.swing.JSplitPane;
  29. import javax.swing.JTabbedPane;
  30. import com.google.gson.JsonParseException;
  31. import classes.CpsEdge;
  32. import classes.CpsNode;
  33. import classes.CpsUpperNode;
  34. import classes.AbstractCpsObject;
  35. import classes.HolonElement;
  36. import classes.HolonObject;
  37. import classes.HolonSwitch;
  38. import classes.Position;
  39. import classes.SubNet;
  40. import ui.controller.Control;
  41. import ui.controller.UpdateController;
  42. import ui.model.Model;
  43. /**
  44. * This Class is the Canvas. All Objects will be visualized here
  45. *
  46. * @author Gruppe14
  47. */
  48. public class MyCanvas extends JPanel implements MouseListener, MouseMotionListener {
  49. private static final long serialVersionUID = 1L;
  50. private Image img = null; // Contains the image to draw on MyCanvas
  51. private int x = 0;
  52. private int y = 0;
  53. // edge Object Start Point
  54. private Model model;
  55. private final Control controller;
  56. Graphics2D g2; // For Painting
  57. private int cx, cy;
  58. private int sx, sy; // Mark Coords
  59. private float scalediv20;
  60. private Position unPos;
  61. private ArrayList<Position> savePos;
  62. private UpdateController updCon;
  63. ArrayList<HolonElement> dataSelected = new ArrayList<HolonElement>();
  64. ArrayList<AbstractCpsObject> tempSelected = new ArrayList<AbstractCpsObject>();
  65. private boolean[] showedInformation = new boolean[5];
  66. private boolean dragging = false; // for dragging
  67. private boolean dragged = false; // if an object/objects was/were dragged
  68. private boolean drawEdge = false; // for drawing edges
  69. public boolean click = false; // for double click
  70. private boolean doMark = false; // for double click
  71. public AbstractCpsObject tempCps = null;
  72. private CpsEdge edgeHighlight = null;
  73. // PopUpMenu
  74. private JPopupMenu popmenu = new JPopupMenu();
  75. private JMenuItem itemDelete = new JMenuItem(Languages.getLanguage()[98]);
  76. private JMenuItem itemCut = new JMenuItem(Languages.getLanguage()[95]);
  77. private JMenuItem itemCopy = new JMenuItem(Languages.getLanguage()[96]);
  78. public JMenuItem itemPaste = new JMenuItem(Languages.getLanguage()[97]);
  79. public JMenuItem itemGroup = new JMenuItem(Languages.getLanguage()[99]);
  80. public JMenuItem itemUngroup = new JMenuItem(Languages.getLanguage()[100]);
  81. public JMenuItem itemTrack = new JMenuItem(Languages.getLanguage()[101]);
  82. public JMenuItem itemUntrack = new JMenuItem(Languages.getLanguage()[102]);
  83. // Tooltip
  84. private boolean toolTip; // Tooltip on or off
  85. private Position toolTipPos = new Position(); // Tooltip Position
  86. private String toolTipText = "";
  87. private Point mousePosition = new Point(); // Mouse Position when
  88. // rightclicked
  89. // Animation Stuff
  90. javax.swing.Timer animT; // animation Timer
  91. private final int ANIMTIME = 500; // animation Time
  92. private ArrayList<AbstractCpsObject> animCps = null;
  93. private int animFPS = 60;
  94. private int animDuration = ANIMTIME; // animation Duration
  95. private int animDelay = 1000 / animFPS; // animation Delay
  96. private int animSteps = animDuration / animDelay; // animation Steps;
  97. // contains the value of the Capacity for new created Edges
  98. /**
  99. * Constructor.
  100. *
  101. * @param mod
  102. * the Model
  103. * @param control
  104. * the Controller
  105. * @param unitGraph
  106. */
  107. public MyCanvas(Model mod, Control control, UnitGraph unitGraph) {
  108. toolTip = false;
  109. this.controller = control;
  110. this.model = mod;
  111. scalediv20 = model.getScale() / 20;
  112. showedInformation[0] = true;
  113. showedInformation[1] = true;
  114. showedInformation[3] = false;
  115. showedInformation[4] = true;
  116. control.setMaxCapacity(10000);
  117. popmenu.add(itemCut);
  118. popmenu.add(itemCopy);
  119. popmenu.add(itemPaste);
  120. popmenu.add(itemDelete);
  121. popmenu.addSeparator();
  122. popmenu.add(itemGroup);
  123. popmenu.add(itemUngroup);
  124. popmenu.add(itemTrack);
  125. popmenu.add(itemUntrack);
  126. updCon = new UpdateController(mod, control);
  127. itemDelete.setEnabled(false);
  128. itemCut.setEnabled(false);
  129. itemCopy.setEnabled(false);
  130. itemPaste.setEnabled(true);
  131. itemGroup.setEnabled(false);
  132. itemUngroup.setEnabled(false);
  133. itemTrack.setEnabled(false);
  134. itemUntrack.setEnabled(false);
  135. itemCut.setText(Languages.getLanguage()[95]);
  136. itemGroup.addActionListener(new ActionListener() {
  137. @Override
  138. public void actionPerformed(ActionEvent e) {
  139. // calculate uppernode pos (taken from the controller)
  140. unPos = new Position(0, 0);
  141. animCps = new ArrayList<>();
  142. for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
  143. animCps.add(cps); // add to animation Cps ArrayList
  144. unPos.x += cps.getPosition().x;
  145. unPos.y += cps.getPosition().y;
  146. }
  147. unPos.x /= animCps.size();
  148. unPos.y /= animCps.size();
  149. // save old Position
  150. savePos = new ArrayList<>();
  151. for (int i = 0; i < animCps.size(); i++) {
  152. savePos.add(new Position(0, 0));
  153. savePos.get(i).x = animCps.get(i).getPosition().x;
  154. savePos.get(i).y = animCps.get(i).getPosition().y;
  155. }
  156. animT = new javax.swing.Timer(animDelay, new ActionListener() {
  157. @Override
  158. public void actionPerformed(ActionEvent e) {
  159. if (animDuration - animDelay > 0 && animCps.size() > 1) {
  160. for (int i = 0; i < animCps.size(); i++) {
  161. double x1 = animCps.get(i).getPosition().x - unPos.x;
  162. double y1 = animCps.get(i).getPosition().y - unPos.y;
  163. animCps.get(i).getPosition().x -= x1 / animSteps;
  164. animCps.get(i).getPosition().y -= y1 / animSteps;
  165. }
  166. repaint();
  167. animDuration -= animDelay;
  168. animSteps--;
  169. } else {
  170. animDuration = ANIMTIME;
  171. animSteps = animDuration / animDelay;
  172. animT.stop();
  173. for (int i = 0; i < animCps.size(); i++) {
  174. animCps.get(i).getPosition().x = savePos.get(i).x;
  175. animCps.get(i).getPosition().y = savePos.get(i).y;
  176. }
  177. controller.addUpperNode("NodeOfNode", null, animCps);
  178. controller.calculateStateForCurrentTimeStep();
  179. repaint();
  180. }
  181. }
  182. });
  183. animT.start();
  184. }
  185. });
  186. itemUngroup.addActionListener(new ActionListener() {
  187. @Override
  188. public void actionPerformed(ActionEvent e) {
  189. // save old Position
  190. JTabbedPane tabbedPane = (JTabbedPane) getParent().getParent().getParent();
  191. for (int i = 4; i < tabbedPane.getTabCount(); i++) {
  192. if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
  193. .getComponent(0)).upperNode.getId() == ((CpsUpperNode) tempCps).getId()) {
  194. tabbedPane.remove(i);
  195. break;
  196. }
  197. }
  198. savePos = new ArrayList<>();
  199. animCps = ((CpsUpperNode) tempCps).getNodes();
  200. controller.delUpperNode((CpsUpperNode) tempCps, null);
  201. for (int i = 0; i < animCps.size(); i++) {
  202. savePos.add(new Position(0, 0));
  203. savePos.get(i).x = animCps.get(i).getPosition().x;
  204. savePos.get(i).y = animCps.get(i).getPosition().y;
  205. }
  206. for (AbstractCpsObject cps : animCps) {
  207. int x = ((CpsUpperNode) tempCps).getPosition().x;
  208. int y = ((CpsUpperNode) tempCps).getPosition().y;
  209. cps.setPosition(new Position(x, y));
  210. }
  211. animT = new javax.swing.Timer(animDelay, new ActionListener() {
  212. @Override
  213. public void actionPerformed(ActionEvent e) {
  214. if (animDuration - animDelay >= 0) {
  215. for (int i = 0; i < animCps.size(); i++) {
  216. double x1 = animCps.get(i).getPosition().x - savePos.get(i).x;
  217. double y1 = animCps.get(i).getPosition().y - savePos.get(i).y;
  218. animCps.get(i).getPosition().x -= x1 / animSteps;
  219. animCps.get(i).getPosition().y -= y1 / animSteps;
  220. }
  221. repaint();
  222. animDuration -= animDelay;
  223. animSteps--;
  224. } else {
  225. animDuration = ANIMTIME;
  226. animSteps = animDuration / animDelay;
  227. animT.stop();
  228. for (int i = 0; i < animCps.size(); i++) {
  229. animCps.get(i).getPosition().x = savePos.get(i).x;
  230. animCps.get(i).getPosition().y = savePos.get(i).y;
  231. }
  232. controller.calculateStateForCurrentTimeStep();
  233. repaint();
  234. }
  235. }
  236. });
  237. animT.start();
  238. }
  239. });
  240. // adds the selected object(s) to the statistic panel
  241. itemTrack.addActionListener(new ActionListener() {
  242. @Override
  243. public void actionPerformed(ActionEvent e) {
  244. for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
  245. boolean found = false;
  246. if (controller.getTrackingObj() != null) {
  247. if (controller.getTrackingObj().contains(o)) {
  248. found = true;
  249. }
  250. }
  251. if (!found) {
  252. controller.addTrackingObj(o);
  253. if (o instanceof HolonObject) {
  254. ((HolonObject) o).updateTrackingInfo();
  255. }
  256. }
  257. if (model.getShowConsoleLog()) {
  258. controller.addTextToConsole("Tracking: ", Color.BLACK, 12, false, false, false);
  259. controller.addTextToConsole("" + o.getName(), Color.BLUE, 12, true, false, false);
  260. controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
  261. controller.addTextToConsole("" + o.getId(), Color.RED, 12, true, false, true);
  262. }
  263. }
  264. }
  265. });
  266. itemUntrack.addActionListener(new ActionListener() {
  267. @Override
  268. public void actionPerformed(ActionEvent e) {
  269. for (AbstractCpsObject o : model.getSelectedCpsObjects()) {
  270. if (o instanceof HolonObject) {
  271. boolean found = false;
  272. if (controller.getTrackingObj() != null) {
  273. for (AbstractCpsObject obj : controller.getTrackingObj()) {
  274. if (obj instanceof HolonObject) {
  275. if (obj.getId() == o.getId()) {
  276. found = true;
  277. }
  278. }
  279. }
  280. }
  281. if (found) {
  282. // Removed from tracking array and tracking
  283. // information reseted
  284. controller.removeTrackingObj((HolonObject) o);
  285. ((HolonObject) o).setTrackingProd(new float[100]);
  286. ((HolonObject) o).setTrackingCons(new float[100]);
  287. }
  288. if (model.getShowConsoleLog()) {
  289. controller.addTextToConsole("Untracking: ", Color.BLACK, 12, false, false, false);
  290. controller.addTextToConsole("" + o.getName(), Color.BLUE, 12, true, false, false);
  291. controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
  292. controller.addTextToConsole("" + o.getId(), Color.RED, 12, true, false, true);
  293. }
  294. }
  295. }
  296. }
  297. });
  298. itemDelete.addActionListener(new ActionListener() {
  299. @Override
  300. public void actionPerformed(ActionEvent e) {
  301. // Remove the selected Object objects
  302. boolean save = false;
  303. for (int j = 0; j < model.getSelectedCpsObjects().size(); j++) {
  304. AbstractCpsObject cps = model.getSelectedCpsObjects().get(j);
  305. if (j == model.getSelectedCpsObjects().size() - 1)
  306. save = true;
  307. controller.delCanvasObject(cps, save);
  308. controller.removeTrackingObj(cps);
  309. // Remove UpperNodeTab if UpperNode deleted
  310. if (cps instanceof CpsUpperNode) {
  311. boolean splitView = false;
  312. JSplitPane tempSplit = (JSplitPane) getParent().getParent().getParent().getParent();
  313. JTabbedPane tabbedPane;
  314. JTabbedPane tabbedPane2;
  315. // if SplitView is activated
  316. if (tempSplit.getLeftComponent() instanceof JTabbedPane
  317. && tempSplit.getRightComponent() instanceof JTabbedPane) {
  318. splitView = true;
  319. tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
  320. tabbedPane2 = (JTabbedPane) tempSplit.getRightComponent();
  321. } else {
  322. tabbedPane = (JTabbedPane) tempSplit.getLeftComponent();
  323. tabbedPane2 = null;
  324. }
  325. // Look if the uppernode is open in a Tab
  326. for (int i = 4; i < tabbedPane.getTabCount(); i++) {
  327. if (tabbedPane.getComponentAt(i) == null) {
  328. } else if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
  329. .getComponent(0)).upperNode.getId() == cps.getId()) {
  330. ((ButtonTabComponent) tabbedPane.getTabComponentAt(i)).removeTabs();
  331. break;
  332. }
  333. }
  334. // If SplitView is on and the view on
  335. // tabbedPane2 is the deleted upperNode
  336. try {
  337. if (tabbedPane2 != null
  338. && ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent())
  339. .getViewport().getComponent(0)).upperNode.getId() == cps.getId()) {
  340. ((ButtonTabComponent) tabbedPane.getTabComponentAt(tabbedPane2.getSelectedIndex()))
  341. .removeTabs();
  342. }
  343. } catch (Exception e2) {
  344. }
  345. }
  346. toolTip = false;
  347. }
  348. model.getSelectedCpsObjects().clear();
  349. tempCps = null;
  350. repaint();
  351. }
  352. });
  353. itemCut.addActionListener(new ActionListener() {
  354. @Override
  355. public void actionPerformed(ActionEvent e) {
  356. controller.cut(null);
  357. itemPaste.setEnabled(true);
  358. repaint();
  359. }
  360. });
  361. itemCopy.addActionListener(new ActionListener() {
  362. @Override
  363. public void actionPerformed(ActionEvent e) {
  364. controller.copy(null);
  365. itemPaste.setEnabled(true);
  366. repaint();
  367. }
  368. });
  369. itemPaste.addActionListener(new ActionListener() {
  370. @Override
  371. public void actionPerformed(ActionEvent e) {
  372. try {
  373. controller.paste(null, mousePosition);
  374. unitGraph.update(model.getSelectedCpsObjects());
  375. } catch (JsonParseException | UnsupportedFlavorException | IOException e1) {
  376. // TODO Auto-generated catch block
  377. JLabel message = new JLabel("The Clipboard information cannot be pastet into Application.");
  378. JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
  379. }
  380. repaint();
  381. }
  382. });
  383. this.addMouseListener(this);
  384. this.addMouseMotionListener(this);
  385. }
  386. /**
  387. * Paints all Components on the Canvas.
  388. *
  389. * @param g
  390. * Graphics
  391. */
  392. public void paintComponent(Graphics g) {
  393. String maxCap;
  394. super.paintComponent(g);
  395. // Rendering
  396. g2 = (Graphics2D) g;
  397. RenderingHints rh = new RenderingHints(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
  398. g2.setRenderingHints(rh);
  399. // Paint the Background
  400. if (!model.getCanvasImagePath().isEmpty()) {
  401. img = new ImageIcon(model.getCanvasImagePath()).getImage();
  402. switch (model.getCanvasImageMode()) {
  403. case BackgroundPopUp.IMAGE_PIXELS:
  404. g2.drawImage(img, 0, 0, img.getWidth(null), img.getHeight(null), null);
  405. break;
  406. case BackgroundPopUp.STRETCHED:
  407. g2.drawImage(img, 0, 0, model.getCanvasX(), model.getCanvasY(), null);
  408. break;
  409. case BackgroundPopUp.CUSTOM:
  410. g2.drawImage(img, 0, 0, model.getCanvasImageWidth(), model.getCanvasImageHeight(), null);
  411. break;
  412. default:
  413. break;
  414. }
  415. }
  416. // SubNet Coloring
  417. int i = 0;
  418. for (SubNet s : controller.getSimManager().getSubNets()) {
  419. if (model.getSubNetColors().size() - 1 < i) {
  420. controller.addSubNetColor(new Color((int) (Math.random() * 255), (int) (Math.random() * 255),
  421. (int) (Math.random() * 255)));
  422. }
  423. if (showedInformation[3]) {
  424. for (HolonObject cps : s.getObjects()) {
  425. cps.setBorderColor(model.getSubNetColors().get(i));
  426. }
  427. }
  428. i++;
  429. }
  430. // drawEdges that is being dragged
  431. if (drawEdge) {
  432. g2.setColor(Color.BLACK);
  433. g2.setStroke(new BasicStroke(2));
  434. g2.drawLine(tempCps.getPosition().x, tempCps.getPosition().y, x, y);
  435. }
  436. for (CpsEdge con : model.getEdgesOnCanvas()) {
  437. if (con.getA().getId() != model.getSelectedObjectID() && con.getB().getId() != model.getSelectedObjectID()
  438. && con != edgeHighlight) {
  439. if (con.getConnected() == 0) {
  440. if (con.getState()) {
  441. g2.setColor(Color.GREEN);
  442. if (con.getCapacity() != -1) {
  443. g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
  444. }
  445. } else {
  446. g2.setColor(Color.RED);
  447. g2.setStroke(new BasicStroke(2));
  448. }
  449. } else {
  450. g2.setColor(Color.DARK_GRAY);
  451. g2.setStroke(new BasicStroke(2));
  452. }
  453. g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
  454. con.getB().getPosition().y);
  455. if (con.getCapacity() == -1) {
  456. maxCap = Character.toString('\u221e');
  457. } else if (con.getCapacity() == -2) {
  458. maxCap = "???";
  459. } else {
  460. maxCap = String.valueOf(con.getCapacity());
  461. }
  462. if (showedInformation[0]) {
  463. if (con.getConnected() == 0 || con.getConnected() == 1) {
  464. g2.drawString(con.getFlow() + "/" + maxCap,
  465. (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
  466. (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
  467. } else {
  468. g2.drawString("not connected", (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
  469. (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
  470. }
  471. }
  472. }
  473. }
  474. // Highlighted Edge
  475. if (model.getSelectedObjectID() > 0 || !model.getSelectedCpsObjects().isEmpty() || !tempSelected.isEmpty()) {
  476. g2.setColor(Color.BLUE);
  477. for (CpsEdge con : model.getEdgesOnCanvas()) {
  478. if (con.getFlow() <= con.getCapacity()) {
  479. g2.setStroke(new BasicStroke(Math.min(((con.getFlow() / con.getCapacity() * 3) + 1), 4)));
  480. } else {
  481. g2.setStroke(new BasicStroke(2));
  482. }
  483. if (con.getA().getId() == model.getSelectedObjectID()
  484. || model.getSelectedCpsObjects().contains(con.getA()) || tempSelected.contains(con.getA())
  485. || con.getB().getId() == model.getSelectedObjectID()
  486. || model.getSelectedCpsObjects().contains(con.getB())
  487. || tempSelected.contains(con.getB()) && con != edgeHighlight) {
  488. g2.drawLine(con.getA().getPosition().x, con.getA().getPosition().y, con.getB().getPosition().x,
  489. con.getB().getPosition().y);
  490. if (con.getCapacity() == -1) {
  491. maxCap = Character.toString('\u221e');
  492. } else if (con.getCapacity() == -2) {
  493. maxCap = "???";
  494. } else {
  495. maxCap = String.valueOf(con.getCapacity());
  496. }
  497. if (showedInformation[0]) {
  498. if (con.getConnected() == 0 || con.getConnected() == 1) {
  499. g2.drawString(con.getFlow() + "/" + maxCap,
  500. (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
  501. (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
  502. } else {
  503. g2.drawString("not connected",
  504. (con.getA().getPosition().x + con.getB().getPosition().x) / 2,
  505. (con.getA().getPosition().y + con.getB().getPosition().y) / 2);
  506. }
  507. }
  508. }
  509. }
  510. } else if (edgeHighlight != null) {
  511. g2.setColor(Color.BLUE);
  512. if (edgeHighlight.getFlow() <= edgeHighlight.getCapacity()) {
  513. g2.setStroke(new BasicStroke(
  514. Math.min(((edgeHighlight.getFlow() / edgeHighlight.getCapacity() * 3) + 1), 4)));
  515. } else {
  516. g2.setStroke(new BasicStroke(2));
  517. }
  518. g2.drawLine(edgeHighlight.getA().getPosition().x, edgeHighlight.getA().getPosition().y,
  519. edgeHighlight.getB().getPosition().x, edgeHighlight.getB().getPosition().y);
  520. if (edgeHighlight.getCapacity() == -1) {
  521. maxCap = Character.toString('\u221e');
  522. } else if (edgeHighlight.getCapacity() == -2) {
  523. maxCap = "???";
  524. } else {
  525. maxCap = String.valueOf(edgeHighlight.getCapacity());
  526. }
  527. if (showedInformation[0]) {
  528. g2.drawString(edgeHighlight.getFlow() + "/" + maxCap,
  529. (edgeHighlight.getA().getPosition().x + edgeHighlight.getB().getPosition().x) / 2,
  530. (edgeHighlight.getA().getPosition().y + edgeHighlight.getB().getPosition().y) / 2);
  531. }
  532. }
  533. // Objects
  534. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  535. // Border Highlighting
  536. if (showedInformation[3]) {
  537. g2.setColor(cps.getBorderColor());
  538. if (g2.getColor() != Color.WHITE && !(cps instanceof CpsNode)) {
  539. g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20 - 3),
  540. (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20 - 3),
  541. (int) (controller.getScale() + ((scalediv20 + 3) * 2)),
  542. (int) (controller.getScale() + ((scalediv20 + 3) * 2)));
  543. }
  544. }
  545. // node image
  546. if (cps instanceof CpsNode && (cps == tempCps || model.getSelectedCpsObject() == cps
  547. || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps))) {
  548. img = new ImageIcon(this.getClass().getResource("/Images/node_selected.png")).getImage();
  549. } else {
  550. if (cps instanceof HolonSwitch) {
  551. if (((HolonSwitch) cps).getActiveAt()[model.getCurIteration()]) {
  552. ((HolonSwitch) cps).setAutoState(true);
  553. } else {
  554. ((HolonSwitch) cps).setAutoState(false);
  555. }
  556. }
  557. // Highlighting
  558. if ((cps == tempCps && model.getSelectedCpsObjects().size() == 0 && tempSelected.size() == 0)
  559. || model.getSelectedCpsObjects().contains(cps) || tempSelected.contains(cps)) {
  560. g2.setColor(Color.BLUE);
  561. g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
  562. (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
  563. (int) (controller.getScale() + (scalediv20 * 2)),
  564. (int) (controller.getScale() + (scalediv20 * 2)));
  565. if (showedInformation[1] && cps instanceof HolonObject) {
  566. g2.setColor(Color.BLACK);
  567. float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
  568. g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
  569. cps.getPosition().y - controller.getScaleDiv2() - 10);
  570. }
  571. } else if (cps instanceof HolonObject) {
  572. g2.setColor(((HolonObject) cps).getColor());
  573. g2.fillRect((int) (cps.getPosition().x - controller.getScaleDiv2() - scalediv20),
  574. (int) (cps.getPosition().y - controller.getScaleDiv2() - scalediv20),
  575. (int) (controller.getScale() + (scalediv20 * 2)),
  576. (int) (controller.getScale() + (scalediv20 * 2)));
  577. if (showedInformation[1]) {
  578. g2.setColor(Color.BLACK);
  579. float totalEnergy = ((HolonObject) cps).getCurrentEnergyAtTimeStep(model.getCurIteration());
  580. g2.drawString(Float.toString(totalEnergy), cps.getPosition().x - controller.getScaleDiv2(),
  581. cps.getPosition().y - controller.getScaleDiv2() - 10);
  582. }
  583. }
  584. // draw image
  585. File checkPath = new File(cps.getImage());
  586. if (checkPath.exists()) {
  587. img = new ImageIcon(cps.getImage()).getImage();
  588. } else {
  589. img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage();
  590. }
  591. }
  592. g2.drawImage(img, cps.getPosition().x - controller.getScaleDiv2(),
  593. cps.getPosition().y - controller.getScaleDiv2(), controller.getScale(), controller.getScale(),
  594. null);
  595. }
  596. // Dragged marker Highlighting
  597. if (doMark) {
  598. g2.setColor(Color.BLACK);
  599. g2.setStroke(new BasicStroke(1));
  600. if (sx > x && sy > y) {
  601. g2.drawRect(x, y, sx - x, sy - y);
  602. } else if (sx < x && sy < y) {
  603. g2.drawRect(sx, sy, x - sx, y - sy);
  604. } else if (sx >= x) {
  605. g2.drawRect(x, sy, sx - x, y - sy);
  606. } else if (sy >= y) {
  607. g2.drawRect(sx, y, x - sx, sy - y);
  608. }
  609. }
  610. // Tooltip
  611. if (toolTip) {
  612. g2.setColor(new Color(255, 225, 150));
  613. g2.setStroke(new BasicStroke(1));
  614. int textWidth = g.getFontMetrics().stringWidth(toolTipText) + 2; // Text
  615. // width
  616. // fixed x and y Position to the screen
  617. int fixXPos = toolTipPos.x - (textWidth >> 1) + model.getScaleDiv2();
  618. int fixYPos = toolTipPos.y;
  619. if (fixXPos < 0) {
  620. fixXPos = 0;
  621. } else if (fixXPos + textWidth + 1 > this.getWidth()) {
  622. fixXPos -= (fixXPos + textWidth + 1) - this.getWidth();
  623. }
  624. if (fixYPos + 16 > this.getHeight()) {
  625. fixYPos -= (fixYPos + 16) - this.getHeight();
  626. }
  627. g2.fillRect(fixXPos, fixYPos, textWidth, 15);
  628. g2.setColor(Color.BLACK);
  629. g2.drawRect(fixXPos, fixYPos, textWidth, 15);
  630. g2.drawString(toolTipText, fixXPos + 2, fixYPos + 12);
  631. }
  632. }
  633. @Override
  634. public void mouseClicked(MouseEvent e) {
  635. if (e.getButton() == e.BUTTON1) {
  636. if (model.getPropertyTable().getRowCount() > 0) {
  637. for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
  638. model.getPropertyTable().removeRow(i);
  639. }
  640. }
  641. updCon.paintProperties(tempCps);
  642. updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
  643. updCon.refreshTableProperties(model.getPropertyTable());
  644. }
  645. }
  646. @Override
  647. public void mouseEntered(MouseEvent e) {
  648. }
  649. @Override
  650. public void mouseExited(MouseEvent e) {
  651. }
  652. @Override
  653. public void mousePressed(MouseEvent e) {
  654. tempCps = null;
  655. dataSelected = null;
  656. edgeHighlight = null;
  657. controller.setSelecteEdge(null);
  658. // Object Selection
  659. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  660. cx = cps.getPosition().x - controller.getScaleDiv2();
  661. cy = cps.getPosition().y - controller.getScaleDiv2();
  662. if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
  663. tempCps = cps;
  664. if (model.getShowConsoleLog()) {
  665. controller.addTextToConsole("Selected: ", Color.BLACK, 12, false, false, false);
  666. controller.addTextToConsole("" + cps.getName(), Color.BLUE, 12, true, false, false);
  667. controller.addTextToConsole(", ID:", Color.BLACK, 12, false, false, false);
  668. controller.addTextToConsole("" + cps.getId(), Color.RED, 12, true, false, true);
  669. }
  670. dragging = true;
  671. if (e.isControlDown() && tempCps != null) {
  672. if (model.getSelectedCpsObjects().contains(tempCps)) {
  673. controller.deleteSelectedObject(tempCps);
  674. } else {
  675. controller.addSelectedObject(tempCps);
  676. }
  677. }
  678. // If drawing an Edge (CTRL down)
  679. if (tempCps.getClass() == HolonObject.class) {
  680. HolonObject tempObj = ((HolonObject) tempCps);
  681. dataSelected = tempObj.getElements();
  682. }
  683. if (e.isShiftDown()) {
  684. drawEdge = true;
  685. dragging = false;
  686. }
  687. }
  688. }
  689. // Edge Selection
  690. if (tempCps == null) {
  691. edgeHighlight = mousePositionOnEdge(x, y);
  692. controller.setSelecteEdge(edgeHighlight);
  693. controller.setSelectedObjectID(0);
  694. if (!e.isControlDown() && e.getButton() != MouseEvent.BUTTON3) {
  695. model.getSelectedCpsObjects().clear();
  696. }
  697. }
  698. if (edgeHighlight == null && tempCps == null) {
  699. sx = e.getX();
  700. sy = e.getY();
  701. doMark = true;
  702. }
  703. repaint();
  704. }
  705. @Override
  706. public void mouseReleased(MouseEvent e) {
  707. x = e.getX();
  708. y = e.getY();
  709. dragging = false;
  710. if (drawEdge) {
  711. drawEdge = false;
  712. drawDeleteEdge();
  713. }
  714. if (dragged == true) {
  715. try {
  716. controller.autoSave();
  717. } catch (IOException ex) {
  718. // TODO Auto-generated catch block
  719. ex.printStackTrace();
  720. }
  721. }
  722. if (!e.isControlDown() && dragged == false && tempCps != null && e.BUTTON3 != e.getButton()) {
  723. model.getSelectedCpsObjects().clear();
  724. controller.addSelectedObject(tempCps);
  725. }
  726. dragged = false;
  727. // Rightclick List
  728. if (e.getButton() == MouseEvent.BUTTON3) {
  729. if (e.getButton() == MouseEvent.BUTTON3 && tempCps != null) {
  730. itemDelete.setEnabled(true);
  731. itemCut.setEnabled(true);
  732. itemCopy.setEnabled(true);
  733. if (tempCps != null) {
  734. itemGroup.setEnabled(true);
  735. itemTrack.setEnabled(true);
  736. itemUntrack.setEnabled(true);
  737. }
  738. if (tempCps instanceof CpsUpperNode)
  739. itemUngroup.setEnabled(true);
  740. else
  741. itemUngroup.setEnabled(false);
  742. if (model.getSelectedCpsObjects().size() == 0) {
  743. controller.addSelectedObject(tempCps);
  744. }
  745. } else {
  746. itemCut.setEnabled(false);
  747. itemCopy.setEnabled(false);
  748. itemDelete.setEnabled(false);
  749. itemGroup.setEnabled(false);
  750. itemUngroup.setEnabled(false);
  751. itemTrack.setEnabled(false);
  752. itemUntrack.setEnabled(false);
  753. }
  754. mousePosition = this.getMousePosition();
  755. popmenu.show(e.getComponent(), e.getX(), e.getY());
  756. }
  757. if (doMark) {
  758. doMark = false;
  759. for (AbstractCpsObject cps : tempSelected) {
  760. if (!model.getSelectedCpsObjects().contains(cps)) {
  761. controller.addSelectedObject(cps);
  762. }
  763. }
  764. controller.getObjectsInDepth();
  765. tempSelected.clear();
  766. }
  767. if (doubleClick() && tempCps != null && tempCps instanceof HolonSwitch && MouseEvent.BUTTON3 != e.getButton()) {
  768. ((HolonSwitch) tempCps).switchState();
  769. }
  770. controller.calculateStateForTimeStep(model.getCurIteration());
  771. updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
  772. updCon.refreshTableProperties(model.getPropertyTable());
  773. repaint();
  774. }
  775. @Override
  776. public void mouseDragged(MouseEvent e) {
  777. // If Edge is drawn
  778. x = e.getX();
  779. y = e.getY();
  780. if (!model.getSelectedCpsObjects().contains(tempCps) && doMark == false) {
  781. model.getSelectedCpsObjects().clear();
  782. if (tempCps != null) {
  783. controller.addSelectedObject(tempCps);
  784. }
  785. }
  786. if (dragging) {
  787. try {
  788. dragged = true;
  789. float xDist, yDist; // Distance
  790. x = e.getX();
  791. y = e.getY();
  792. // Make sure its in bounds
  793. if (e.getX() < controller.getScaleDiv2())
  794. x = controller.getScaleDiv2();
  795. else if (e.getX() > this.getWidth() - controller.getScaleDiv2())
  796. x = this.getWidth() - controller.getScaleDiv2();
  797. if (e.getY() < controller.getScaleDiv2())
  798. y = controller.getScaleDiv2();
  799. else if (e.getY() > this.getHeight() - controller.getScaleDiv2())
  800. y = this.getHeight() - controller.getScaleDiv2();
  801. // Distance
  802. xDist = x - tempCps.getPosition().x;
  803. yDist = y - tempCps.getPosition().y;
  804. tempCps.setPosition(x, y); // Drag Position
  805. // ToolTipText Position and name
  806. toolTip = true;
  807. toolTipText = tempCps.getName() + ", " + tempCps.getId();
  808. toolTipPos.x = tempCps.getPosition().x - controller.getScaleDiv2();
  809. toolTipPos.y = tempCps.getPosition().y + controller.getScaleDiv2();
  810. // All Selected Objects
  811. for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
  812. if (cps != tempCps) {
  813. x = (int) (cps.getPosition().x + xDist);
  814. y = (int) (cps.getPosition().y + yDist);
  815. // Make sure its in bounds
  816. if (x <= controller.getScaleDiv2())
  817. x = controller.getScaleDiv2();
  818. else if (x > this.getWidth() - controller.getScaleDiv2())
  819. x = this.getWidth() - controller.getScaleDiv2();
  820. if (y <= controller.getScaleDiv2())
  821. y = controller.getScaleDiv2();
  822. else if (y > this.getHeight() - controller.getScaleDiv2())
  823. y = this.getHeight() - controller.getScaleDiv2();
  824. cps.setPosition(x, y);
  825. }
  826. }
  827. repaint();
  828. } catch (Exception eex) {
  829. }
  830. }
  831. // Mark Objects
  832. if (doMark) {
  833. tempSelected.clear();
  834. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  835. int x1 = sx, x2 = x, y1 = sy, y2 = y;
  836. if (sx >= x) {
  837. x1 = x;
  838. x2 = sx;
  839. }
  840. if (sy >= y) {
  841. y1 = y;
  842. y2 = sy;
  843. }
  844. if (x1 <= cps.getPosition().x + model.getScaleDiv2() && y1 <= cps.getPosition().y + model.getScaleDiv2()
  845. && x2 >= cps.getPosition().x && y2 >= cps.getPosition().y) {
  846. tempSelected.add(cps);
  847. }
  848. }
  849. }
  850. repaint();
  851. }
  852. @Override
  853. public void mouseMoved(MouseEvent e) {
  854. x = e.getX();
  855. y = e.getY();
  856. // Everytghing for the tooltip :)
  857. boolean on = false;
  858. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  859. cx = cps.getPosition().x - controller.getScaleDiv2();
  860. cy = cps.getPosition().y - controller.getScaleDiv2();
  861. if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy) {
  862. on = true;
  863. toolTipPos.x = cps.getPosition().x - controller.getScaleDiv2();
  864. toolTipPos.y = cps.getPosition().y + controller.getScaleDiv2();
  865. toolTipText = cps.getName() + ", " + cps.getId();
  866. }
  867. }
  868. if (on) {
  869. toolTip = true;
  870. } else {
  871. toolTip = false;
  872. }
  873. repaint();
  874. }
  875. /**
  876. * Draws or Deletes an Edge.
  877. */
  878. private void drawDeleteEdge() {
  879. if (getMousePosition() != null) {
  880. boolean node = true;
  881. boolean newEdge = true;
  882. boolean onEdge = true;
  883. boolean deleteNode = false;
  884. CpsEdge e = null;
  885. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  886. cx = cps.getPosition().x - controller.getScaleDiv2();
  887. cy = cps.getPosition().y - controller.getScaleDiv2();
  888. if (x - controller.getScale() <= cx && y - controller.getScale() <= cy && x >= cx && y >= cy
  889. && cps != tempCps) {
  890. node = false;
  891. onEdge = false;
  892. for (CpsEdge p : tempCps.getConnections()) {
  893. if ((p.getA() == tempCps && p.getB() == cps) || (p.getB() == tempCps && p.getA() == cps)) {
  894. newEdge = false;
  895. e = p;
  896. }
  897. }
  898. if (!newEdge) {
  899. controller.removeEdgesOnCanvas(e);
  900. // Node ohne Edge?
  901. if (e.getA().getClass() == CpsNode.class && e.getA().getConnections().isEmpty()) {
  902. tempCps = e.getA();
  903. deleteNode = true;
  904. }
  905. if (e.getB().getClass() == CpsNode.class && e.getB().getConnections().isEmpty()) {
  906. deleteNode = true;
  907. }
  908. }
  909. if (newEdge) {
  910. e = new CpsEdge(cps, tempCps, model.getMaxCapacity());
  911. controller.addEdgeOnCanvas(e);
  912. }
  913. }
  914. }
  915. // Edge auf eine Edge gezogen?
  916. if (onEdge) {
  917. CpsEdge p = mousePositionOnEdge(x, y);
  918. if (p != null) {
  919. CpsEdge e1 = null;
  920. CpsEdge e2 = null;
  921. node = false;
  922. CpsNode n = new CpsNode("Node");
  923. n.setPosition(x, y);
  924. controller.addObjectCanvas(n);
  925. AbstractCpsObject r, k;
  926. r = p.getA();
  927. k = p.getB();
  928. e = new CpsEdge(n, tempCps, model.getMaxCapacity());
  929. e1 = new CpsEdge(n, r, model.getMaxCapacity());
  930. e2 = new CpsEdge(n, k, model.getMaxCapacity());
  931. controller.removeEdgesOnCanvas(p);
  932. controller.addEdgeOnCanvas(e);
  933. controller.addEdgeOnCanvas(e1);
  934. controller.addEdgeOnCanvas(e2);
  935. }
  936. }
  937. // ins leere Gedragged
  938. if (node) {
  939. CpsNode n = new CpsNode("Node");
  940. n.setPosition(x, y);
  941. controller.addObjectCanvas(n);
  942. e = new CpsEdge(n, tempCps, model.getMaxCapacity());
  943. controller.addEdgeOnCanvas(e);
  944. }
  945. // Wenn ein Node ohne Connections da ist
  946. if (deleteNode) {
  947. controller.delCanvasObject(tempCps, true);
  948. tempCps = null;
  949. }
  950. }
  951. }
  952. /**
  953. * Checks if the mouse is on an Edge.
  954. *
  955. * @param x
  956. * Position of the Mouse
  957. * @param y
  958. * Position of the Mouse
  959. *
  960. * @return CpsEdge the Mouse is on, null if the mouse is not on an Edge
  961. */
  962. public CpsEdge mousePositionOnEdge(int x, int y) {
  963. x += controller.getScaleDiv2();
  964. y += controller.getScaleDiv2();
  965. int lx, ly, hx, hy;
  966. for (CpsEdge p : model.getEdgesOnCanvas()) {
  967. Line2D l = new Line2D.Float(p.getA().getPosition().x, p.getA().getPosition().y, p.getB().getPosition().x,
  968. p.getB().getPosition().y);
  969. if (p.getA().getPosition().x > p.getB().getPosition().x) {
  970. hx = p.getA().getPosition().x + model.getScaleDiv2() + 7;
  971. lx = p.getB().getPosition().x + model.getScaleDiv2() - 7;
  972. } else {
  973. lx = p.getA().getPosition().x + model.getScaleDiv2() - 7;
  974. hx = p.getB().getPosition().x + model.getScaleDiv2() + 7;
  975. }
  976. if (p.getA().getPosition().y > p.getB().getPosition().y) {
  977. hy = p.getA().getPosition().y + model.getScaleDiv2() + 7;
  978. ly = p.getB().getPosition().y + model.getScaleDiv2() - 7;
  979. } else {
  980. ly = p.getA().getPosition().y + model.getScaleDiv2() - 7;
  981. hy = p.getB().getPosition().y + model.getScaleDiv2() + 7;
  982. }
  983. // distance from a point to a line and between both Objects
  984. if (l.ptLineDistSq(x - model.getScaleDiv2(), y - model.getScaleDiv2()) < 20 && x > lx && x < hx && y > ly
  985. && y < hy) {
  986. return p;
  987. }
  988. }
  989. return null;
  990. }
  991. public void updateLanguages() {
  992. itemCut.setText(Languages.getLanguage()[95]);
  993. itemCopy.setText(Languages.getLanguage()[96]);
  994. itemPaste.setText(Languages.getLanguage()[97]);
  995. itemDelete.setText(Languages.getLanguage()[98]);
  996. itemGroup.setText(Languages.getLanguage()[99]);
  997. itemUngroup.setText(Languages.getLanguage()[100]);
  998. itemTrack.setText(Languages.getLanguage()[101]);
  999. itemUntrack.setText(Languages.getLanguage()[102]);
  1000. }
  1001. /**
  1002. * Checks if a double click was made.
  1003. *
  1004. * @return
  1005. *
  1006. * @return true if doublecklick, false if not
  1007. */
  1008. private boolean doubleClick() {
  1009. if (click) {
  1010. click = false;
  1011. return true;
  1012. } else {
  1013. click = true;
  1014. Timer t = new Timer("doubleclickTimer", false);
  1015. t.schedule(new TimerTask() {
  1016. @Override
  1017. public void run() {
  1018. click = false;
  1019. }
  1020. }, 500);
  1021. }
  1022. return false;
  1023. }
  1024. /**
  1025. * Set if Information should be shown.
  1026. *
  1027. * @param connection
  1028. * boolean for conecction
  1029. * @param object
  1030. * boolean for objects
  1031. * @param nodeOfnode
  1032. */
  1033. public void setShowedInformation(boolean connection, boolean object, boolean border, boolean nodeOfnode) {
  1034. showedInformation[0] = connection;
  1035. showedInformation[1] = object;
  1036. showedInformation[3] = border;
  1037. showedInformation[4] = nodeOfnode;
  1038. }
  1039. /**
  1040. * Returns if Information should be shown.
  1041. *
  1042. * @return Array of boolean [0] = connection, [1] = objects
  1043. */
  1044. public boolean[] getShowedInformation() {
  1045. return showedInformation;
  1046. }
  1047. /**
  1048. * set tooltIp
  1049. * @param bool
  1050. */
  1051. public void setToolTip(boolean bool){
  1052. this.toolTip = bool;
  1053. }
  1054. }