GUI.java 78 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248
  1. package ui.view;
  2. import java.awt.BorderLayout;
  3. import java.awt.Color;
  4. import java.awt.Component;
  5. import java.awt.Cursor;
  6. import java.awt.Dimension;
  7. import java.awt.HeadlessException;
  8. import java.awt.Image;
  9. import java.awt.Point;
  10. import java.awt.Toolkit;
  11. import java.awt.datatransfer.UnsupportedFlavorException;
  12. import java.awt.event.ActionEvent;
  13. import java.awt.event.ActionListener;
  14. import java.awt.event.ComponentAdapter;
  15. import java.awt.event.ComponentEvent;
  16. import java.awt.event.KeyEvent;
  17. import java.awt.event.MouseAdapter;
  18. import java.awt.event.MouseEvent;
  19. import java.beans.PropertyChangeEvent;
  20. import java.beans.PropertyChangeListener;
  21. import java.io.File;
  22. import java.io.IOException;
  23. import java.util.ArrayList;
  24. import java.util.Timer;
  25. import java.util.TimerTask;
  26. import javax.swing.AbstractAction;
  27. import javax.swing.ActionMap;
  28. import javax.swing.BoxLayout;
  29. import javax.swing.DefaultComboBoxModel;
  30. import javax.swing.ImageIcon;
  31. import javax.swing.InputMap;
  32. import javax.swing.JButton;
  33. import javax.swing.JComboBox;
  34. import javax.swing.JComponent;
  35. import javax.swing.JDialog;
  36. import javax.swing.JFileChooser;
  37. import javax.swing.JFrame;
  38. import javax.swing.JLabel;
  39. import javax.swing.JMenu;
  40. import javax.swing.JMenuBar;
  41. import javax.swing.JMenuItem;
  42. import javax.swing.JOptionPane;
  43. import javax.swing.JPanel;
  44. import javax.swing.JPopupMenu;
  45. import javax.swing.JScrollPane;
  46. import javax.swing.JSlider;
  47. import javax.swing.JSplitPane;
  48. import javax.swing.JTabbedPane;
  49. import javax.swing.JTable;
  50. import javax.swing.JTextField;
  51. import javax.swing.JToolBar;
  52. import javax.swing.JTree;
  53. import javax.swing.KeyStroke;
  54. import javax.swing.SwingUtilities;
  55. import javax.swing.border.LineBorder;
  56. import javax.swing.event.ChangeEvent;
  57. import javax.swing.event.ChangeListener;
  58. import javax.swing.filechooser.FileNameExtensionFilter;
  59. import javax.swing.table.DefaultTableModel;
  60. import javax.swing.table.TableCellEditor;
  61. import javax.swing.table.TableCellRenderer;
  62. import javax.swing.tree.DefaultMutableTreeNode;
  63. import javax.swing.tree.DefaultTreeModel;
  64. import javax.swing.tree.TreeCellRenderer;
  65. import org.apache.commons.compress.archivers.ArchiveException;
  66. import com.google.gson.JsonParseException;
  67. import classes.AbstractCpsObject;
  68. import classes.Category;
  69. import classes.CpsUpperNode;
  70. import classes.HolonElement;
  71. import classes.HolonObject;
  72. import classes.HolonSwitch;
  73. import classes.HolonTransformer;
  74. import classes.IdCounter;
  75. import classes.IdCounterElem;
  76. import interfaces.CategoryListener;
  77. import ui.controller.Control;
  78. import ui.controller.UpdateController;
  79. import ui.model.Model;
  80. /**
  81. * Graphical User Interface.
  82. *
  83. * @author Gruppe14
  84. *
  85. * @param <E>
  86. * Generic
  87. */
  88. public class GUI<E> implements CategoryListener {
  89. // for doubleclick
  90. private boolean click = false;
  91. private JFrame frmCyberPhysical;
  92. private final SimulationMenu simMenu;
  93. private JTabbedPane tabTemp; // tabbedPane or tabbedPane2
  94. private final JMenuBar menuBar = new JMenuBar();
  95. private final JMenu mnNewMenu = new JMenu("File");
  96. private final JMenu mnNewMenuEdit = new JMenu("Edit");
  97. private final JMenu mnNewMenuOptions = new JMenu("Options");
  98. private final JMenu mnNewMenuView = new JMenu("View");
  99. private final JMenu mnHelp = new JMenu("Help");
  100. private final JMenuItem mntmOpen = new JMenuItem("Open");
  101. private final JMenuItem mntmNew = new JMenuItem("New");
  102. private final JMenuItem mntmSave = new JMenuItem("Save");
  103. private final JMenuItem aboutUs = new JMenuItem("About Us");
  104. private final JMenuItem canvasSize = new JMenuItem("View Size");
  105. private final JMenuItem background = new JMenuItem("Background Image");
  106. private final JSplitPane splitPane = new JSplitPane();
  107. private final JSplitPane splitPane1 = new JSplitPane();
  108. private final JSplitPane splitPaneCanvasConsole = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  109. private final JScrollPane canvasSP = new JScrollPane();
  110. private final JScrollPane scrollPane1 = new JScrollPane();
  111. // private final JScrollPane holonSP = new JScrollPane();
  112. private final JTabbedPane tabbedPane = new JTabbedPane(JTabbedPane.TOP);
  113. private final JTabbedPane tabbedPane2 = new JTabbedPane(JTabbedPane.TOP);
  114. private final JButton splitButton = new JButton("Split View Test");
  115. private JSplitPane tempSplit;
  116. private boolean initSplit = true;
  117. private final JPanel panelTapped_SimMenu = new JPanel();
  118. private JPopupMenu popmenuEdit = new JPopupMenu();
  119. private JMenuItem editItem = new JMenuItem("Edit Object");
  120. private String catOfObjToBeEdited;
  121. private final JScrollPane statTab = new JScrollPane();
  122. private FlexiblePane flexPane;
  123. private StatPanel2 statSplitPane;
  124. private JScrollPane statScrollPane;
  125. private UpperNodeCanvas unc;
  126. private JPanel contentPane;
  127. private final JLabel maxGraph = new JLabel("100%");
  128. private final JLabel medGraph = new JLabel("50%");
  129. private final JLabel minGraph = new JLabel("0%");
  130. private final JLabel elementGraph = new JLabel("None ");
  131. private final ArrayList<HolonElement> selectedElements = new ArrayList<HolonElement>();
  132. private String holonEleNamesDisplayed = "None ";
  133. private final JTree tree = new JTree();
  134. /******************************************
  135. ************* Right Container*************
  136. ******************************************
  137. * Right Container: here comes the information about the HolonObject, such
  138. * as HolonElements Information, Properties and Consumption/Production
  139. * graph.
  140. **/
  141. private final JSplitPane splitHolonElPro = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  142. private final JSplitPane splitGraphHolonEl = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
  143. // In this section are all the Holonelements that correspond to the clicked
  144. // HolonObject with consumption/production, name and amount.
  145. // Model for single or multi selection
  146. private final JPanel scrollElements = new JPanel();
  147. private JScrollPane tableHolonElementScrollPane = new JScrollPane();
  148. // In this section are all the properties that correspond to the clicked
  149. // HolonObject, such as connections, name, Type, etc.
  150. // Table for Properties --> Cell with (0,1) is editable by CpsObjt and
  151. // Cell(3,1) is editable by Edges
  152. private JTable tableProperties = new JTable() {
  153. private static final long serialVersionUID = 1L;
  154. @Override
  155. public TableCellRenderer getCellRenderer(int row, int column) {
  156. if (getValueAt(row, column) instanceof Boolean) {
  157. return super.getDefaultRenderer(Boolean.class);
  158. } else {
  159. return super.getCellRenderer(row, column);
  160. }
  161. }
  162. @Override
  163. public TableCellEditor getCellEditor(int row, int column) {
  164. if (getValueAt(row, column) instanceof Boolean) {
  165. return super.getDefaultEditor(Boolean.class);
  166. } else {
  167. return super.getCellEditor(row, column);
  168. }
  169. }
  170. };
  171. private JPanel graphLabel = new JPanel();
  172. private final JScrollPane scrollProperties = new JScrollPane();
  173. // In this section is the graph for the selected HolonElement of the clicked
  174. // HolonObject
  175. private JTable tableGraph = new JTable();
  176. private DefaultTableModel tableModelGraph = new DefaultTableModel();
  177. private final JScrollPane scrollGraph = new JScrollPane();
  178. private Model model;
  179. private final Control controller;
  180. // Pop up Windows
  181. private AddObjectPopUp addObjectPopUP;
  182. private AboutUsPopUp aboutUsPopUp;
  183. private AddElementPopUp addElementPopUp;
  184. private final JPanel panel = new JPanel();
  185. private final JPanel panelHolonEl = new JPanel();
  186. private final JComboBox comboBox = new JComboBox();
  187. // private final JComboBox comboBoxGraph = new JComboBox();
  188. // Buttons
  189. private final JButton btnAdd = new JButton("+");
  190. private final JButton btnDel = new JButton("-");
  191. private final JButton btnAddHolEL = new JButton("+");
  192. private final JButton btnDelHolEL = new JButton("-");
  193. private final JButton resetGraphBtn = new JButton("Reset");
  194. private final JToolBar toolBar = new JToolBar();
  195. private final JToolBar toolBarHolonEl = new JToolBar();
  196. private final JToolBar toolBarGraph = new JToolBar();
  197. // private final Languages languages = new Languages();
  198. // Languages
  199. private final JMenuItem englishBtn = new JMenuItem("EN");
  200. private final JMenuItem spanishBtn = new JMenuItem("ES");
  201. private final JMenuItem germanBtn = new JMenuItem("DE");
  202. private final JMenuItem czechBtn = new JMenuItem("CZ");
  203. private final JMenuItem chineseBtn = new JMenuItem("ZH");
  204. // variables
  205. private boolean dragging = false;
  206. private String actualObjectClicked;
  207. private Image img = null;
  208. private AbstractCpsObject tempCps = null;
  209. private int yValueElements = 0;
  210. private Console console = new Console();
  211. private MyCanvas canvas;
  212. private HolonCanvas holonCanvas;
  213. private UnitGraph unitGraph;
  214. private final JSplitPane splitPane3 = new JSplitPane();
  215. private final JSlider sizeSlider = new JSlider();
  216. private final JLabel lblImageSize = new JLabel(Languages.getLanguage()[94]);
  217. // Time Stuff
  218. private TimePanel timePanel;
  219. // Coord for all Cells with text
  220. private int yThis;
  221. private int xThis;
  222. // Coord for all Cells with boolean values (checkbox)
  223. private int yBTis;
  224. private int xBThis;
  225. // Coord for the Edit-Modus in the PropertieTable
  226. private int yProThis;
  227. private int xProThis;
  228. private AbstractCpsObject temp = null;
  229. private final JMenuItem mntmUndo = new JMenuItem("Undo");
  230. private final JMenuItem mntmRedo = new JMenuItem("Redo");
  231. private final JMenuItem mntmEditEdges = new JMenuItem("Edit Edges");
  232. private final JMenuItem mntmFindReplace = new JMenuItem("Find/ Replace");
  233. private final JMenuItem mntmEditShowedInformation = new JMenuItem("Edit showed Information");
  234. private final JMenuItem mntmResetCategory = new JMenuItem("Reset Categories");
  235. private final JMenu mnLanguage = new JMenu("Language");
  236. private String[] columnNamesMulti = { "Object", "Nr.", "Device", "Energy", "Flexibility", "Quantity", "Activated",
  237. "Flex. activated" };
  238. private String[] columnNamesSingle = { "Nr.", "Device", "Energy", "Flexibility", "Quantity", "Activated",
  239. "Flex. activated" };
  240. private ArrayList<PropertyTable> tables = new ArrayList<PropertyTable>();
  241. private String[] comboBoxCat = { "Category", "Object", "Switch" };
  242. private String warningText = "Warning";
  243. private String saveBeforeNew = "Do you want to save your current data?";
  244. private String eraseCategory = "Do you really want to delete the Category ";
  245. private String selectObjBeforeErase = "Please select a Category or an Object in order to delete something.";
  246. private UpdateController updCon;
  247. private final JSplitPane splitPane_1 = new JSplitPane();
  248. private final JSlider holonBodySizeSlider = new JSlider();
  249. private final JLabel lblHolonBodySize = new JLabel("HolonBody SIze");
  250. /**
  251. * Create the application.
  252. *
  253. * @param control
  254. * the Controller
  255. */
  256. public GUI(Control control) {
  257. this.controller = control;
  258. this.model = control.getModel();
  259. statSplitPane = new StatPanel2(controller);
  260. model.addGraphListener(statSplitPane);
  261. statScrollPane = new JScrollPane(statSplitPane);
  262. this.unitGraph = new UnitGraph(model, control);
  263. this.canvas = new MyCanvas(model, control, unitGraph);
  264. this.holonCanvas = new HolonCanvas(model, control);
  265. control.initListener(this);
  266. controller.setCanvas(canvas);
  267. model.setConsole(console);
  268. simMenu = new SimulationMenu(model, control);
  269. initialize();
  270. updateCategories(model.getCategories());
  271. updCon = new UpdateController(model, controller);
  272. }
  273. /**
  274. * Initialize the contents of the frame.
  275. */
  276. @SuppressWarnings({ "serial", "unchecked" })
  277. private void initialize() {
  278. frmCyberPhysical = new JFrame();
  279. frmCyberPhysical.setTitle("Cyber Physical Systems Model");
  280. frmCyberPhysical.setBounds(100, 100, 1000, 800);
  281. frmCyberPhysical.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
  282. frmCyberPhysical.addWindowListener(new java.awt.event.WindowAdapter() {
  283. @Override
  284. public void windowClosing(java.awt.event.WindowEvent windowEvent) {
  285. if (JOptionPane.showConfirmDialog(frmCyberPhysical, Languages.getLanguage()[88],
  286. "Cyber Physical Systems Model", JOptionPane.YES_NO_OPTION,
  287. JOptionPane.QUESTION_MESSAGE) == JOptionPane.YES_OPTION) {
  288. controller.deleteDirectory(new File(System.getProperty("user.home") + "/HolonGUI/Autosave"));
  289. System.exit(0);
  290. }
  291. }
  292. });
  293. contentPane = (JPanel) frmCyberPhysical.getContentPane();
  294. int condition = JComponent.WHEN_IN_FOCUSED_WINDOW;
  295. InputMap inputMap = contentPane.getInputMap(condition);
  296. ActionMap actionMap = contentPane.getActionMap();
  297. String cntrlZDown = "controlZ";
  298. inputMap.put(KeyStroke.getKeyStroke("control Z"), cntrlZDown);
  299. actionMap.put(cntrlZDown, new AbstractAction() {
  300. private static final long serialVersionUID = 1L;
  301. @Override
  302. public void actionPerformed(ActionEvent e) {
  303. try {
  304. controller.loadAutoSave(controller.getUndoSave());
  305. canvas.repaint();
  306. unitGraph.update(model.getObjectsOnCanvas());
  307. } catch (IOException eex) {
  308. // TODO Auto-generated catch block
  309. eex.printStackTrace();
  310. }
  311. }
  312. });
  313. String cntrlYDown = "controlY";
  314. inputMap.put(KeyStroke.getKeyStroke("control Y"), cntrlYDown);
  315. actionMap.put(cntrlYDown, new AbstractAction() {
  316. private static final long serialVersionUID = 1L;
  317. @Override
  318. public void actionPerformed(ActionEvent e) {
  319. try {
  320. controller.loadAutoSave(controller.getRedoSave());
  321. canvas.repaint();
  322. unitGraph.update(model.getObjectsOnCanvas());
  323. } catch (IOException ex) {
  324. // TODO Auto-generated catch block
  325. ex.printStackTrace();
  326. }
  327. }
  328. });
  329. String cntrlADown = "controlA";
  330. inputMap.put(KeyStroke.getKeyStroke("control A"), cntrlADown);
  331. actionMap.put(cntrlADown, new AbstractAction() {
  332. private static final long serialVersionUID = 1L;
  333. @Override
  334. public void actionPerformed(ActionEvent e) {
  335. if (tabbedPane.getMousePosition() != null) {
  336. tabTemp = tabbedPane;
  337. } else {
  338. tabTemp = tabbedPane2;
  339. }
  340. model.getSelectedCpsObjects().clear();
  341. // Uppernode Canvas?
  342. if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  343. .getComponent(0) instanceof UpperNodeCanvas) {
  344. UpperNodeCanvas uNC = (UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  345. .getComponent(0);
  346. for (AbstractCpsObject cps : uNC.upperNode.getNodes()) {
  347. controller.addSelectedObject(cps);
  348. }
  349. uNC.repaint();
  350. // or Canvas?
  351. } else if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  352. .getComponent(0) instanceof MyCanvas) {
  353. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  354. controller.addSelectedObject(cps);
  355. }
  356. canvas.repaint();
  357. }
  358. }
  359. });
  360. String delDown = "delete";
  361. inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0, false), delDown);
  362. actionMap.put(delDown, new AbstractAction() {
  363. private static final long serialVersionUID = 1L;
  364. @Override
  365. public void actionPerformed(ActionEvent e) {
  366. // Uppernode Canvas?
  367. if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
  368. .getComponent(0) instanceof UpperNodeCanvas) {
  369. UpperNodeCanvas uNC = (UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent())
  370. .getViewport().getComponent(0);
  371. for (AbstractCpsObject cps : model.getSelectedCpsObjects()) {
  372. if (uNC.upperNode.getNodes().contains(cps)) {
  373. controller.delObjUpperNode(cps, uNC.upperNode);
  374. // Remove UpperNodeTab if UpperNode deleted
  375. if (cps instanceof CpsUpperNode) {
  376. for (int i = 4; i < tabbedPane.getTabCount(); i++) {
  377. if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
  378. .getComponent(0)).upperNode.getId() == cps.getId()) {
  379. tabbedPane.remove(i);
  380. i = tabbedPane.getTabCount();
  381. }
  382. }
  383. }
  384. }
  385. }
  386. uNC.repaint();
  387. // or Canvas?
  388. } else if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
  389. .getComponent(0) instanceof MyCanvas) {
  390. boolean save = false;
  391. for (int j = 0; j < model.getSelectedCpsObjects().size(); j++) {
  392. AbstractCpsObject cps = model.getSelectedCpsObjects().get(j);
  393. if (j < model.getSelectedCpsObjects().size() - 1)
  394. save = true;
  395. controller.delCanvasObject(cps, save);
  396. // Remove UpperNodeTab if UpperNode deleted
  397. if (cps instanceof CpsUpperNode) {
  398. for (int i = 4; i < tabbedPane.getTabCount(); i++) {
  399. if (((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i)).getViewport()
  400. .getComponent(0)).upperNode.getId() == cps.getId()) {
  401. tabbedPane.remove(i);
  402. i = tabbedPane.getTabCount();
  403. }
  404. }
  405. }
  406. }
  407. canvas.repaint();
  408. }
  409. model.getSelectedCpsObjects().clear();
  410. unitGraph.empty();
  411. }
  412. });
  413. String cntrlFDown = "controlF";
  414. inputMap.put(KeyStroke.getKeyStroke("control F"), cntrlFDown);
  415. actionMap.put(cntrlFDown, new AbstractAction() {
  416. private static final long serialVersionUID = 1L;
  417. @Override
  418. public void actionPerformed(ActionEvent e) {
  419. SearchPopUp dialog = new SearchPopUp(controller, canvas);
  420. dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  421. dialog.setVisible(true);
  422. }
  423. });
  424. String cntrlCDown = "controlC";
  425. inputMap.put(KeyStroke.getKeyStroke("control C"), cntrlCDown);
  426. actionMap.put(cntrlCDown, new AbstractAction() {
  427. private static final long serialVersionUID = 1L;
  428. @Override
  429. public void actionPerformed(ActionEvent e) {
  430. if (tabbedPane.getMousePosition() != null) {
  431. tabTemp = tabbedPane;
  432. } else {
  433. tabTemp = tabbedPane2;
  434. }
  435. if (!model.getSelectedCpsObjects().isEmpty()) {
  436. if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  437. .getComponent(0) instanceof UpperNodeCanvas)
  438. controller.copy(((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  439. .getComponent(0)).upperNode);
  440. else
  441. controller.copy(null);
  442. if (!model.getClipboradObjects().isEmpty()) {
  443. canvas.itemPaste.setEnabled(true);
  444. }
  445. }
  446. }
  447. });
  448. String cntrlVDown = "controlV";
  449. inputMap.put(KeyStroke.getKeyStroke("control V"), cntrlVDown);
  450. actionMap.put(cntrlVDown, new AbstractAction() {
  451. private static final long serialVersionUID = 1L;
  452. @Override
  453. public void actionPerformed(ActionEvent e) {
  454. try {
  455. tabTemp = null;
  456. if (tabbedPane.getMousePosition() != null) {
  457. tabTemp = tabbedPane;
  458. } else {
  459. if (!initSplit) {
  460. tabTemp = tabbedPane2;
  461. }
  462. }
  463. if (tabTemp != null && ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  464. .getComponent(0) instanceof UpperNodeCanvas) {
  465. controller.paste(
  466. ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  467. .getComponent(0)).upperNode,
  468. ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  469. .getComponent(0)).getMousePosition());
  470. } else {
  471. controller.paste(null, canvas.getMousePosition());
  472. unitGraph.update(model.getSelectedCpsObjects());
  473. }
  474. } catch (HeadlessException | JsonParseException | UnsupportedFlavorException | IOException e1) {
  475. // TODO Auto-generated catch block
  476. JLabel message = new JLabel("The Clipboard information cannot be pasted into Application.");
  477. JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
  478. }
  479. canvas.repaint();
  480. }
  481. });
  482. String cntrlXDown = "controlX";
  483. inputMap.put(KeyStroke.getKeyStroke("control X"), cntrlXDown);
  484. actionMap.put(cntrlXDown, new AbstractAction() {
  485. private static final long serialVersionUID = 1L;
  486. @Override
  487. public void actionPerformed(ActionEvent e) {
  488. if (tabbedPane.getMousePosition() != null) {
  489. tabTemp = tabbedPane;
  490. } else {
  491. tabTemp = tabbedPane2;
  492. }
  493. if (!model.getSelectedCpsObjects().isEmpty()) {
  494. if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  495. .getComponent(0) instanceof UpperNodeCanvas)
  496. controller.cut(((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  497. .getComponent(0)).upperNode);
  498. else
  499. controller.cut(null);
  500. if (!model.getClipboradObjects().isEmpty()) {
  501. canvas.itemPaste.setEnabled(true);
  502. }
  503. canvas.repaint();
  504. }
  505. }
  506. });
  507. frmCyberPhysical.setJMenuBar(menuBar);
  508. frmCyberPhysical.setIconImage(new ImageIcon(this.getClass().getResource("/Images/Dummy_House.png")).getImage()
  509. .getScaledInstance(30, 30, Image.SCALE_SMOOTH));
  510. menuBar.add(mnNewMenu);
  511. mnNewMenu.add(mntmNew);
  512. mnNewMenu.add(mntmOpen);
  513. mnNewMenu.add(mntmSave);
  514. menuBar.add(mnNewMenuEdit);
  515. mnNewMenuEdit.add(mntmUndo);
  516. mnNewMenuEdit.add(mntmRedo);
  517. mnLanguage.add(englishBtn);
  518. englishBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagEN.png").getImage().getScaledInstance(20,
  519. 20, java.awt.Image.SCALE_SMOOTH)));
  520. mnLanguage.add(spanishBtn);
  521. spanishBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagES.png").getImage().getScaledInstance(20,
  522. 20, java.awt.Image.SCALE_SMOOTH)));
  523. mnLanguage.add(germanBtn);
  524. germanBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagDE.png").getImage().getScaledInstance(20,
  525. 20, java.awt.Image.SCALE_SMOOTH)));
  526. // mnLanguage.add(czechBtn);
  527. // czechBtn.setIcon(new ImageIcon(new
  528. // ImageIcon("res/Button_Images/FlagCZ.png").getImage().getScaledInstance(20,
  529. // 20, java.awt.Image.SCALE_SMOOTH)));
  530. mnLanguage.add(chineseBtn);
  531. chineseBtn.setIcon(new ImageIcon(new ImageIcon("res/Button_Images/FlagZH.png").getImage().getScaledInstance(20,
  532. 20, java.awt.Image.SCALE_SMOOTH)));
  533. mntmFindReplace.addActionListener(new ActionListener() {
  534. public void actionPerformed(ActionEvent e) {
  535. try {
  536. SearchPopUp dialog = new SearchPopUp(controller, canvas);
  537. dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  538. dialog.setVisible(true);
  539. } catch (Exception ex) {
  540. ex.printStackTrace();
  541. }
  542. }
  543. });
  544. mnNewMenuEdit.add(mntmFindReplace);
  545. mntmEditShowedInformation.addActionListener(new ActionListener() {
  546. public void actionPerformed(ActionEvent e) {
  547. try {
  548. ShowedInformationPopUp dialog = new ShowedInformationPopUp(canvas, contentPane);
  549. dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  550. dialog.setVisible(true);
  551. } catch (Exception ex) {
  552. ex.printStackTrace();
  553. }
  554. }
  555. });
  556. mnNewMenuEdit.add(mntmEditShowedInformation);
  557. menuBar.add(mnNewMenuOptions);
  558. mntmEditEdges.addActionListener(new ActionListener() {
  559. public void actionPerformed(ActionEvent e) {
  560. EditEdgesPopUp edgePopUp = new EditEdgesPopUp();
  561. edgePopUp.setCanvas(canvas);
  562. edgePopUp.setController(controller);
  563. edgePopUp.setVisible(true);
  564. }
  565. });
  566. mnNewMenuOptions.add(mntmEditEdges);
  567. mnNewMenuOptions.add(mntmResetCategory);
  568. mntmResetCategory.addActionListener(new ActionListener() {
  569. @Override
  570. public void actionPerformed(ActionEvent e) {
  571. ArrayList<Category> cat = model.getCategories();
  572. try {
  573. while (!cat.isEmpty()) {
  574. controller.deleteCategory(cat.get(0).getName());
  575. }
  576. controller.resetCategorys();
  577. } catch (Exception e2) {
  578. // TODO: handle exception
  579. }
  580. tree.repaint();
  581. }
  582. });
  583. menuBar.add(mnNewMenuView);
  584. mnNewMenuView.add(canvasSize);
  585. canvasSize.addActionListener(new ActionListener() {
  586. @Override
  587. public void actionPerformed(ActionEvent e) {
  588. JPanel myPanel = new JPanel();
  589. JTextField field1 = new JTextField("" + canvas.getWidth() + "");
  590. JTextField field2 = new JTextField("" + canvas.getHeight() + "");
  591. myPanel.add(field1);
  592. myPanel.add(field2);
  593. JOptionPane.showMessageDialog(null, myPanel);
  594. controller.setCanvasX(Integer.parseInt(field1.getText()));
  595. controller.setCanvasY(Integer.parseInt(field2.getText()));
  596. canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  597. canvas.repaint();
  598. }
  599. });
  600. mnNewMenuView.add(splitPane3);
  601. sizeSlider.setMinimum(15);
  602. sizeSlider.setMaximum(115);
  603. sizeSlider.addChangeListener(new ChangeListener() {
  604. @Override
  605. public void stateChanged(ChangeEvent e) {
  606. controller.setScale(sizeSlider.getValue());
  607. if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
  608. .getComponent(0) instanceof UpperNodeCanvas) {
  609. ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getSelectedComponent()).getViewport().getComponent(0))
  610. .repaint();
  611. } else {
  612. canvas.repaint();
  613. }
  614. if (!initSplit && ((JScrollPane) tabbedPane2.getSelectedComponent()).getViewport()
  615. .getComponent(0) instanceof UpperNodeCanvas) {
  616. ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getSelectedComponent()).getViewport().getComponent(0))
  617. .repaint();
  618. } else {
  619. canvas.repaint();
  620. }
  621. }
  622. });
  623. mnNewMenuView.add(canvasSize);
  624. mnNewMenuView.add(background);
  625. background.addActionListener(new ActionListener() {
  626. @Override
  627. public void actionPerformed(ActionEvent e) {
  628. if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
  629. .getComponent(0) instanceof MyCanvas) {
  630. BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller, canvas, null);
  631. backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  632. backgroundDialog.setVisible(true);
  633. } else if (((JScrollPane) tabbedPane.getSelectedComponent()).getViewport()
  634. .getComponent(0) instanceof UpperNodeCanvas) {
  635. UpperNodeCanvas uNodeCanvas = (UpperNodeCanvas) (((JScrollPane) tabbedPane.getSelectedComponent())
  636. .getViewport().getComponent(0));
  637. BackgroundPopUp backgroundDialog = new BackgroundPopUp(model, controller, null,
  638. uNodeCanvas.upperNode);
  639. backgroundDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
  640. backgroundDialog.setVisible(true);
  641. uNodeCanvas.repaint();
  642. }
  643. }
  644. });
  645. splitPane3.setRightComponent(sizeSlider);
  646. splitPane3.setLeftComponent(lblImageSize);
  647. mnNewMenuView.add(splitPane_1);
  648. holonBodySizeSlider.setValue(100);
  649. holonBodySizeSlider.setMinimum(1);
  650. holonBodySizeSlider.addChangeListener(new ChangeListener() {
  651. @Override
  652. public void stateChanged(ChangeEvent e) {
  653. controller.setHolonBodyScale(holonBodySizeSlider.getValue());
  654. tree.setRowHeight(50);
  655. canvas.repaint();
  656. }
  657. });
  658. splitPane_1.setRightComponent(holonBodySizeSlider);
  659. splitPane_1.setLeftComponent(lblHolonBodySize);
  660. menuBar.add(mnHelp);
  661. mnHelp.add(aboutUs);
  662. // Testing
  663. menuBar.add(splitButton);
  664. // Split View
  665. splitButton.addActionListener(new ActionListener() {
  666. @Override
  667. public void actionPerformed(ActionEvent e) {
  668. if (panelTapped_SimMenu
  669. .getComponent(panelTapped_SimMenu.getComponentCount() - 1) instanceof JSplitPane) {
  670. initSplit = true;
  671. Component tempC = tabbedPane2.getSelectedComponent();
  672. tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
  673. tabbedPane2.removeAll();
  674. panelTapped_SimMenu
  675. .remove(panelTapped_SimMenu.getComponent(panelTapped_SimMenu.getComponentCount() - 1));
  676. panelTapped_SimMenu.add(tabbedPane);
  677. } else {
  678. for (int i = 0; i < tabbedPane.getTabCount(); i++) {
  679. tabbedPane2.addTab(tabbedPane.getTitleAt(i), null);
  680. if (i >= 4) {
  681. // tabbedPane2.setTabComponentAt(tabbedPane.getTabCount()
  682. // - 1,
  683. // new ButtonTabComponent(tabbedPane, tabbedPane2));
  684. }
  685. }
  686. if (tabbedPane.getSelectedComponent() == statScrollPane) {
  687. tabbedPane.setComponentAt(0, null);
  688. tabbedPane2.setComponentAt(0, canvasSP);
  689. tabbedPane2.setSelectedIndex(0);
  690. } else {
  691. tabbedPane.setComponentAt(1, null);
  692. tabbedPane2.setComponentAt(1, statScrollPane);
  693. tabbedPane2.setSelectedIndex(1);
  694. }
  695. tempSplit = new JSplitPane();
  696. tempSplit.setBorder(null);
  697. tempSplit.setRightComponent(tabbedPane2);
  698. tempSplit.setLeftComponent(tabbedPane);
  699. tempSplit.setDividerLocation(tabbedPane.getWidth() / 2);
  700. tempSplit.setResizeWeight(0.9);
  701. panelTapped_SimMenu.remove(tabbedPane);
  702. panelTapped_SimMenu.add(tempSplit);
  703. initSplit = false;
  704. }
  705. contentPane.updateUI();
  706. }
  707. });
  708. tabbedPane.addChangeListener(new ChangeListener() {
  709. @Override
  710. public void stateChanged(ChangeEvent e) {
  711. if (tabbedPane.getSelectedComponent() == null) {
  712. Component tempC = tabbedPane2.getSelectedComponent();
  713. tabbedPane2.setComponentAt(tabbedPane.getSelectedIndex(), null);
  714. tabbedPane.setComponentAt(tabbedPane.getSelectedIndex(), tempC);
  715. tempC = tabbedPane.getComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()));
  716. tabbedPane.setComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()), null);
  717. tabbedPane2.setComponentAt((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()), tempC);
  718. tabbedPane2.setSelectedIndex((tabbedPane.getSelectedIndex() + 1) % (tabbedPane.getTabCount()));
  719. contentPane.updateUI();
  720. }
  721. }
  722. });
  723. tabbedPane2.addChangeListener(new ChangeListener() {
  724. @Override
  725. public void stateChanged(ChangeEvent e) {
  726. if (tabbedPane2.getSelectedComponent() == null && !initSplit) {
  727. Component tempC = tabbedPane.getComponentAt(tabbedPane2.getSelectedIndex());
  728. tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), null);
  729. tabbedPane2.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
  730. for (int i = 0; i < tabbedPane.getTabCount(); i++) {
  731. if (tabbedPane2.getComponentAt(i) != null && tabbedPane2.getComponentAt(i) != tempC) {
  732. tempC = tabbedPane2.getComponentAt(i);
  733. tabbedPane2.setComponentAt(i, null);
  734. tabbedPane.setComponentAt(i, tempC);
  735. break;
  736. }
  737. }
  738. if (tabbedPane.getSelectedIndex() == tabbedPane2.getSelectedIndex()) {
  739. tabbedPane.setSelectedIndex((tabbedPane2.getSelectedIndex() + 1) % tabbedPane.getTabCount());
  740. }
  741. contentPane.updateUI();
  742. }
  743. }
  744. });
  745. mnNewMenuOptions.add(mnLanguage);
  746. canvas.setBackground(Color.WHITE);
  747. canvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  748. holonCanvas.setBackground(Color.WHITE);
  749. holonCanvas.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  750. /********************
  751. * RIGHT CONTAINER (INFORMATION)
  752. **********************/
  753. // Set up of the HolonElements section
  754. // Two different Models: Multi for multi-selection mode and Single for
  755. // single-selection mode (CPS-Object)
  756. model.getMultiTable().setColumnIdentifiers(columnNamesMulti);
  757. model.getSingleTable().setColumnIdentifiers(columnNamesSingle);
  758. model.getTableHolonElement().setBorder(null);
  759. model.getTableHolonElement().setFillsViewportHeight(true);
  760. model.getTableHolonElement().setCellSelectionEnabled(true);
  761. model.getTableHolonElement().setColumnSelectionAllowed(true);
  762. tableHolonElementScrollPane.setViewportView(model.getTableHolonElement());
  763. scrollElements.setLayout(new BorderLayout(0, 0));
  764. scrollElements.add(panelHolonEl, BorderLayout.NORTH);
  765. scrollElements.add(tableHolonElementScrollPane);
  766. panelHolonEl.setLayout(new BoxLayout(panelHolonEl, BoxLayout.X_AXIS));
  767. toolBarHolonEl.add(btnAddHolEL);
  768. toolBarHolonEl.add(btnDelHolEL);
  769. toolBarHolonEl.setFloatable(false);
  770. panelHolonEl.add(toolBarHolonEl);
  771. // Set up of the Properties section
  772. tableProperties.setModel(model.getPropertyTable());
  773. tableProperties.setFillsViewportHeight(true);
  774. tableProperties.setCellSelectionEnabled(true);
  775. tableProperties.setColumnSelectionAllowed(true);
  776. scrollProperties.setViewportView(tableProperties);
  777. // Set up of the Graph section
  778. tableGraph.setModel(tableModelGraph);
  779. tableGraph.setFillsViewportHeight(true);
  780. tableGraph.setCellSelectionEnabled(true);
  781. tableGraph.setColumnSelectionAllowed(true);
  782. scrollGraph.setViewportView(unitGraph);
  783. graphLabel.setLayout(new BorderLayout(0, 10));
  784. graphLabel.add(maxGraph, BorderLayout.NORTH);
  785. graphLabel.add(medGraph, BorderLayout.CENTER);
  786. graphLabel.add(minGraph, BorderLayout.SOUTH);
  787. toolBarGraph.add(elementGraph);
  788. toolBarGraph.add(resetGraphBtn);
  789. toolBarGraph.setFloatable(false);
  790. scrollGraph.setRowHeaderView(graphLabel);
  791. scrollGraph.setColumnHeaderView(toolBarGraph);
  792. tables.add(model.getSingleTable());
  793. tables.add(model.getMultiTable());
  794. /***********************
  795. * HolonElement Table Actions
  796. **********************/
  797. /*
  798. * Add HolonElement to given HolonObject
  799. */
  800. btnAddHolEL.addActionListener(new ActionListener() {
  801. public void actionPerformed(ActionEvent arg0) {
  802. if (model.getSelectedCpsObjects().size() == 1) {
  803. AbstractCpsObject tempCpsObject = updCon.getActualCps();
  804. if (tempCpsObject != null && tempCpsObject.getClass() == HolonObject.class
  805. && tempCpsObject.getId() != 0) {
  806. addElementPopUp = new AddElementPopUp();
  807. addElementPopUp.setActualCps(updCon.getActualCps());
  808. addElementPopUp.setVisible(true);
  809. HolonElement ele = addElementPopUp.getElement();
  810. if (ele != null) {
  811. controller.addElementCanvasObject(tempCpsObject.getId(), ele.getEleName(), ele.getAmount(),
  812. ele.getEnergy());
  813. }
  814. updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
  815. updCon.refreshTableProperties(model.getPropertyTable());
  816. controller.calculateStateForTimeStep(model.getCurIteration());
  817. contentPane.updateUI();
  818. }
  819. }
  820. }
  821. });
  822. /*
  823. * Delete the chosen HolonElement of the selected HolonObject,
  824. * Multi-Selection for CpsObjects as well as for HolonElements possible
  825. */
  826. btnDelHolEL.addActionListener(new ActionListener() {
  827. public void actionPerformed(ActionEvent arg0) {
  828. // For Single Selection of CpsObject
  829. if (model.getSelectedCpsObjects().size() == 1) {
  830. if (updCon.getActualCps().getClass() == HolonObject.class) {
  831. HolonObject obj = (HolonObject) updCon.getActualCps();
  832. for (HolonElement e : selectedElements) {
  833. controller.deleteElementCanvas(obj.getId(), e.getId());
  834. updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
  835. updCon.refreshTableProperties(model.getPropertyTable());
  836. controller.calculateStateForTimeStep(model.getCurIteration());
  837. contentPane.updateUI();
  838. // Names displayed in graph are not updated
  839. }
  840. model.getEleToDelete().clear();
  841. selectedElements.clear();
  842. }
  843. // For MultiSelection of CpsObject
  844. } else if (model.getSelectedCpsObjects().size() > 1) {
  845. for (Integer i : model.getEleToDelete().keySet()) {
  846. for (HolonElement e : model.getEleToDelete().get(i)) {
  847. controller.deleteElementCanvas(i, e.getId());
  848. }
  849. }
  850. updCon.refreshTableHolonElement(model.getMultiTable(), model.getSingleTable());
  851. updCon.refreshTableProperties(model.getPropertyTable());
  852. model.getEleToDelete().clear();
  853. selectedElements.clear();
  854. }
  855. updCon.refreshTableProperties(model.getPropertyTable());
  856. elementGraph.setText(Languages.getLanguage()[25]);
  857. holonEleNamesDisplayed = Languages.getLanguage()[25];
  858. }
  859. });
  860. /*
  861. * Communication between HolonElement Table and displayed Graph and
  862. * Properties, as well as selection of different HolonElements
  863. */
  864. model.getTableHolonElement().addMouseListener(new MouseAdapter() {
  865. public void mousePressed(MouseEvent e) {
  866. HolonObject obj = null;
  867. if (model.getSelectedCpsObjects().size() == 1
  868. && model.getSelectedCpsObjects().get(0) instanceof HolonObject) {
  869. obj = (HolonObject) updCon.getActualCps();
  870. }
  871. yValueElements = e.getY();
  872. HolonElement ele = null;
  873. // Search for current clicked HolonElement
  874. if (model.getSelectedCpsObjects().size() == 1) {
  875. ele = updCon.getActualHolonElement(obj, yValueElements, 0, tables);
  876. } else {
  877. ele = updCon.getActualHolonElement(null, yValueElements, 0, tables);
  878. }
  879. // Multi-Selection of HolonElements through control button +
  880. // mouse click
  881. if (e.isControlDown() && ele != null) {
  882. if (!selectedElements.contains(ele)) {
  883. selectedElements.add(ele);
  884. if (!holonEleNamesDisplayed.equals(Languages.getLanguage()[25])) {
  885. holonEleNamesDisplayed = holonEleNamesDisplayed + "; " + ele.getEleName() + " ";
  886. } else {
  887. holonEleNamesDisplayed = ele.getEleName() + " ";
  888. }
  889. unitGraph.repaintWithNewElement(selectedElements);
  890. }
  891. updCon.getActualHolonElement(null, yValueElements, 2, tables);
  892. } // if no control-button pressed but a HolonElement choose
  893. else if (ele != null) {
  894. selectedElements.clear();
  895. selectedElements.add(ele);
  896. updCon.getActualHolonElement(null, yValueElements, 1, tables);
  897. holonEleNamesDisplayed = ele.getEleName() + " ";
  898. unitGraph.repaintWithNewElement(selectedElements);
  899. } // If any empty space is clicked
  900. else {
  901. elementGraph.setText(Languages.getLanguage()[25]);
  902. unitGraph.empty();
  903. }
  904. // if any HolonElement is double-clicked --> Edit-Mode started
  905. // for selected HolonElement
  906. if (e.getClickCount() == 2) {
  907. yThis = e.getY();
  908. xThis = e.getX();
  909. }
  910. // for single click and empty slot
  911. if (e.getClickCount() == 1 && ele == null) {
  912. selectedElements.clear();
  913. holonEleNamesDisplayed = Languages.getLanguage()[25];
  914. }
  915. elementGraph.setText(holonEleNamesDisplayed);
  916. yBTis = e.getY();
  917. xBThis = e.getX();
  918. }
  919. });
  920. /*
  921. * Triggered every time a change is made
  922. */
  923. model.getTableHolonElement().addPropertyChangeListener(new PropertyChangeListener() {
  924. @Override
  925. public void propertyChange(PropertyChangeEvent evt) {
  926. try {
  927. int yMouse = yThis;
  928. int yBMouse = yBTis;
  929. int selectedValueY = (int) Math.floor(yMouse / 16);
  930. int selectedValueBY = (int) Math.floor(yBMouse / 16);
  931. // for multi-selection mode
  932. if (model.getSelectedCpsObjects().size() > 1) {
  933. int selectedValueX = (int) Math.floor(xThis / (model.getTableHolonElement().getWidth() / 8));
  934. int selectedValueBX = (int) Math.floor(xBThis / (model.getTableHolonElement().getWidth() / 8));
  935. if (updCon.getHolonObj(yMouse, model.getMultiTable()) != null) {
  936. // For active column (boolean with a checkbox)
  937. if (selectedValueBX == 6) {
  938. HolonElement eleBTemp = updCon.getActualHolonElement(null, yBMouse, 0, tables);
  939. String newBStuff = model.getMultiTable().getValueAt(selectedValueBY, selectedValueBX)
  940. .toString();
  941. Boolean bTemp = Boolean.parseBoolean(newBStuff);
  942. eleBTemp.setActive(bTemp);
  943. }
  944. // For activeFlex column (boolean with a checkbox)
  945. else if (selectedValueBX == 7) {
  946. HolonElement eleBTemp = updCon.getActualHolonElement(null, yBMouse, 0, tables);
  947. String newBStuff = model.getMultiTable().getValueAt(selectedValueBY, selectedValueBX)
  948. .toString();
  949. Boolean bTemp = Boolean.parseBoolean(newBStuff);
  950. eleBTemp.setActiveFlex(bTemp);
  951. } else {
  952. // Update of HolonElement
  953. HolonElement eleTemp = updCon.getActualHolonElement(null, yMouse, 0, tables);
  954. String newStuff = model.getMultiTable().getValueAt(selectedValueY, selectedValueX)
  955. .toString();
  956. // Name update
  957. if (selectedValueX == 2) {
  958. eleTemp.setEleName(newStuff);
  959. }
  960. // Energy Update
  961. else if (selectedValueX == 3) {
  962. Float ftemp = Float.parseFloat(newStuff);
  963. eleTemp.setEnergy(ftemp);
  964. }
  965. // Flexibility
  966. else if (selectedValueX == 4) {
  967. Float ftemp = Float.parseFloat(newStuff);
  968. eleTemp.setFlexibility(ftemp);
  969. }
  970. // Amount of Elements update
  971. else if (selectedValueX == 5) {
  972. Integer iTemp = Integer.parseInt(newStuff);
  973. eleTemp.setAmount(iTemp);
  974. }
  975. }
  976. }
  977. } // For single-selection mode
  978. else if (model.getSelectedCpsObjects().size() == 1) {
  979. int selectedValueX = (int) Math.floor(xThis / (model.getTableHolonElement().getWidth() / 7));
  980. int selectedValueBX = (int) Math.floor(xBThis / (model.getTableHolonElement().getWidth() / 7));
  981. if (updCon.getActualCps() != null && updCon.getActualCps().getClass() == HolonObject.class) {
  982. // For active column (boolean with a checkbox)
  983. if (selectedValueBX == 5) {
  984. HolonElement eleBTemp = updCon
  985. .getActualHolonElement((HolonObject) updCon.getActualCps(), yBMouse, 0, tables);
  986. String newBStuff = model.getSingleTable().getValueAt(selectedValueBY, selectedValueBX)
  987. .toString();
  988. Boolean bTemp = Boolean.parseBoolean(newBStuff);
  989. eleBTemp.setActive(bTemp);
  990. } // For activeFlex column (boolean with a checkbox)
  991. else if (selectedValueBX == 6) {
  992. HolonElement eleBTemp = updCon
  993. .getActualHolonElement((HolonObject) updCon.getActualCps(), yBMouse, 0, tables);
  994. String newBStuff = model.getSingleTable().getValueAt(selectedValueBY, selectedValueBX)
  995. .toString();
  996. Boolean bTemp = Boolean.parseBoolean(newBStuff);
  997. eleBTemp.setActiveFlex(bTemp);
  998. } else {
  999. // Update of HolonElement
  1000. HolonElement eleTemp = updCon.getActualHolonElement((HolonObject) updCon.getActualCps(),
  1001. yMouse, 0, tables);
  1002. String newStuff = model.getSingleTable().getValueAt(selectedValueY, selectedValueX)
  1003. .toString();
  1004. // Name update
  1005. if (selectedValueX == 1) {
  1006. eleTemp.setEleName(newStuff);
  1007. } // Energy Update
  1008. else if (selectedValueX == 2) {
  1009. Float ftemp = Float.parseFloat(newStuff);
  1010. eleTemp.setEnergy(ftemp);
  1011. } // Flexibility
  1012. else if (selectedValueX == 3) {
  1013. Float ftemp = Float.parseFloat(newStuff);
  1014. eleTemp.setFlexibility(ftemp);
  1015. }
  1016. // Amount of Elements update
  1017. else if (selectedValueX == 4) {
  1018. Integer iTemp = Integer.parseInt(newStuff);
  1019. eleTemp.setAmount(iTemp);
  1020. }
  1021. }
  1022. }
  1023. }
  1024. updCon.refreshTableProperties(model.getPropertyTable());
  1025. model.getSingleTable().fireTableDataChanged();
  1026. controller.calculateStateForTimeStep(model.getCurIteration());
  1027. contentPane.updateUI();
  1028. unitGraph.repaint();
  1029. } catch (Exception e) {
  1030. }
  1031. }
  1032. });
  1033. /***********************
  1034. * HolonElement Properties Actions
  1035. **********************/
  1036. /*
  1037. * Update of the mouse coord for Edit-Mode
  1038. */
  1039. tableProperties.addMouseListener(new MouseAdapter() {
  1040. public void mousePressed(MouseEvent e) {
  1041. if (e.getClickCount() == 2) {
  1042. yProThis = e.getY();
  1043. xProThis = e.getX();
  1044. }
  1045. }
  1046. });
  1047. /*
  1048. * Update any change in the Property table
  1049. */
  1050. tableProperties.addPropertyChangeListener(new PropertyChangeListener() {
  1051. @Override
  1052. public void propertyChange(PropertyChangeEvent evt) {
  1053. try {
  1054. Object temp;
  1055. Object btemp;
  1056. Point mousePos = tableProperties.getMousePosition();
  1057. int selValueY = (int) Math.floor(yProThis / 16);
  1058. int selValueX = (int) Math.floor(xProThis / (tableProperties.getWidth() / 2));
  1059. if (updCon.getActualCps() != null && selValueX != 0) {
  1060. temp = model.getPropertyTable().getValueAt(selValueY, selValueX);
  1061. if (updCon.getActualCps() instanceof HolonSwitch) {
  1062. btemp = model.getPropertyTable().getValueAt(mousePos.y / tableProperties.getRowHeight(),
  1063. mousePos.x / (tableProperties.getWidth() / 2));
  1064. if (mousePos.y / tableProperties.getRowHeight() == 0) {
  1065. updCon.getActualCps().setName(btemp.toString());
  1066. } else if (mousePos.y / tableProperties.getRowHeight() == 2) {
  1067. Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
  1068. ((HolonSwitch) updCon.getActualCps()).setManualMode(bbTemp);
  1069. if (bbTemp) {
  1070. model.getPropertyTable().setCellEditable(3, 1, true);
  1071. } else {
  1072. model.getPropertyTable().setCellEditable(3, 1, false);
  1073. }
  1074. } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
  1075. if (((HolonSwitch) updCon.getActualCps()).getManualMode()) {
  1076. model.getPropertyTable().setCellEditable(3, 1, true);
  1077. Boolean bTemp = Boolean.parseBoolean(temp.toString());
  1078. ((HolonSwitch) updCon.getActualCps()).setManualState(bTemp);
  1079. }
  1080. }
  1081. } else if (updCon.getActualCps() instanceof CpsUpperNode) {
  1082. updCon.getActualCps().setName(temp.toString());
  1083. for (int index = 4; index < tabbedPane.getTabCount(); index++) {
  1084. UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponent(index))
  1085. .getViewport().getComponent(0));
  1086. if (unc.upperNode.getId() == updCon.getActualCps().getId()) {
  1087. tabbedPane.setTitleAt(index, unc.upperNode.getName());
  1088. tabbedPane.updateUI();
  1089. if (!initSplit) {
  1090. tabbedPane2.setTitleAt(index, unc.upperNode.getName());
  1091. tabbedPane2.updateUI();
  1092. }
  1093. }
  1094. }
  1095. } else if (updCon.getActualCps() instanceof HolonObject) {
  1096. updCon.getActualCps().setName(temp.toString());
  1097. }
  1098. } else {
  1099. temp = model.getPropertyTable().getValueAt(selValueY, selValueX);
  1100. btemp = model.getPropertyTable().getValueAt(mousePos.y / tableProperties.getRowHeight(),
  1101. mousePos.x / (tableProperties.getWidth() / 2));
  1102. if (selValueY == 2) {
  1103. Float ftemp;
  1104. if (Float.parseFloat(temp.toString()) >= 0.0) {
  1105. ftemp = Float.parseFloat(temp.toString());
  1106. } else {
  1107. ftemp = model.getSelectedEdge().getCapacity();
  1108. }
  1109. model.getSelectedEdge().setCapacity(ftemp);
  1110. } else if (mousePos.y / tableProperties.getRowHeight() == 3) {
  1111. Boolean bbTemp = Boolean.parseBoolean(btemp.toString());
  1112. model.getSelectedEdge().setState(bbTemp);
  1113. }
  1114. }
  1115. canvas.repaint();
  1116. } catch (Exception e) {
  1117. }
  1118. }
  1119. });
  1120. /***********************
  1121. * HolonElement Graph Actions
  1122. **********************/
  1123. /*
  1124. * Reset the graph of the selected HolonElement
  1125. */
  1126. resetGraphBtn.setBorder(new LineBorder(Color.BLACK));
  1127. resetGraphBtn.addActionListener(new ActionListener() {
  1128. public void actionPerformed(ActionEvent arg0) {
  1129. unitGraph.reset();
  1130. }
  1131. });
  1132. /*****************************
  1133. * RIGHT CONTAINER DONE
  1134. *****************************/
  1135. frmCyberPhysical.getContentPane().setLayout(new BorderLayout(0, 0));
  1136. TreeCellRenderer customRenderer = new TreeCellRenderer() {
  1137. @Override
  1138. public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded,
  1139. boolean leaf, int row, boolean hasFocus) {
  1140. JLabel label = new JLabel();
  1141. Image imgR = null;
  1142. if (leaf) {
  1143. for (Category cat : model.getCategories()) {
  1144. for (AbstractCpsObject cps : cat.getObjects()) {
  1145. if (value.toString().compareTo(cps.getObjName()) == 0) {
  1146. File checkPath = new File(cps.getImage());
  1147. if (checkPath.exists()) {
  1148. imgR = new ImageIcon(cps.getImage()).getImage().getScaledInstance(50, 50,
  1149. java.awt.Image.SCALE_SMOOTH);
  1150. } else {
  1151. imgR = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
  1152. .getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
  1153. }
  1154. if (imgR != null) {
  1155. label.setIcon(new ImageIcon(imgR));
  1156. }
  1157. label.setText(cps.getName());
  1158. }
  1159. }
  1160. }
  1161. }
  1162. tree.setRowHeight(50);
  1163. if (hasFocus) {
  1164. label.setForeground(new Color(0, 0, 255));
  1165. label.setOpaque(true);
  1166. }
  1167. if (label.getText().length() == 0) {
  1168. label.setText(value.toString());
  1169. if (value.toString().compareTo("Categories") != 0) {
  1170. label.setIcon(new ImageIcon(this.getClass().getResource("/Images/folder.png")));
  1171. }
  1172. }
  1173. return label;
  1174. }
  1175. };
  1176. tree.setCellRenderer(customRenderer);
  1177. tree.addMouseListener(new MouseAdapter() {
  1178. public void mouseReleased(MouseEvent e) {
  1179. try {
  1180. if (dragging) {
  1181. if (tabbedPane.getMousePosition() != null) {
  1182. tabTemp = tabbedPane;
  1183. } else {
  1184. tabTemp = tabbedPane2;
  1185. }
  1186. if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  1187. .getComponent(0) instanceof UpperNodeCanvas) {
  1188. UpperNodeCanvas unc = ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent())
  1189. .getViewport().getComponent(0));
  1190. int x = (int) unc.getMousePosition().getX();
  1191. int y = (int) unc.getMousePosition().getY();
  1192. if (x > unc.borderPos) {
  1193. AbstractCpsObject h = null;
  1194. if (tempCps instanceof HolonObject) {
  1195. h = new HolonObject(tempCps);
  1196. }
  1197. if (tempCps instanceof HolonSwitch) {
  1198. h = new HolonSwitch(tempCps);
  1199. }
  1200. if (tempCps instanceof HolonTransformer) {
  1201. h = new HolonTransformer(tempCps);
  1202. }
  1203. h.setPosition(x, y);
  1204. controller.addObjUpperNode(h, unc.upperNode);
  1205. unc.invalidate();
  1206. unc.repaint();
  1207. }
  1208. } else {
  1209. int x = (int) canvas.getMousePosition().getX();
  1210. int y = (int) canvas.getMousePosition().getY();
  1211. AbstractCpsObject h = null;
  1212. if (tempCps instanceof HolonObject) {
  1213. h = new HolonObject(tempCps);
  1214. }
  1215. if (tempCps instanceof HolonSwitch) {
  1216. h = new HolonSwitch(tempCps);
  1217. }
  1218. if (tempCps instanceof HolonTransformer) {
  1219. h = new HolonTransformer(tempCps);
  1220. }
  1221. h.setPosition(x, y);
  1222. controller.addObjectCanvas(h);
  1223. canvas.invalidate();
  1224. canvas.repaint();
  1225. }
  1226. controller.calculateStateForCurrentTimeStep();
  1227. contentPane.updateUI();
  1228. dragging = false;
  1229. }
  1230. } catch (Exception eex) {
  1231. }
  1232. frmCyberPhysical.setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
  1233. }
  1234. });
  1235. popmenuEdit.add(editItem);
  1236. editItem.setEnabled(false);
  1237. editItem.addActionListener(new ActionListener() {
  1238. @Override
  1239. public void actionPerformed(ActionEvent e) {
  1240. }
  1241. });
  1242. tree.addMouseListener(new MouseAdapter() {
  1243. public void mousePressed(MouseEvent e) {
  1244. try {
  1245. actualObjectClicked = tree.getPathForLocation(e.getX(), e.getY()).getLastPathComponent().toString();
  1246. // if an Object was selected, the porperties are shown in
  1247. // the table
  1248. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) tree
  1249. .getPathForLocation(e.getX(), e.getY()).getLastPathComponent();
  1250. if (selectedNode.getLevel() == 2) {
  1251. controller.searchCategoryObject(selectedNode.getParent().toString(), selectedNode.toString());
  1252. updCon.deleteRows(model.getSingleTable());
  1253. updCon.deleteRows(model.getMultiTable());
  1254. // if (selected instanceof HolonObject && selected !=
  1255. // null) {
  1256. // selected = (HolonObject) selected;
  1257. // fillElementTable(((HolonObject)
  1258. // selected).getElements());
  1259. // }
  1260. }
  1261. if (SwingUtilities.isRightMouseButton(e)) {
  1262. for (Category cat : model.getCategories()) {
  1263. for (AbstractCpsObject cps : cat.getObjects()) {
  1264. if (actualObjectClicked.compareTo(cps.getObjName()) == 0
  1265. && !(cps instanceof HolonSwitch)) {
  1266. editItem.setEnabled(true);
  1267. popmenuEdit.show(e.getComponent(), e.getX(), e.getY());
  1268. catOfObjToBeEdited = selectedNode.getParent().toString();
  1269. tempCps = cps;
  1270. }
  1271. }
  1272. }
  1273. } else {
  1274. for (Category cat : model.getCategories()) {
  1275. for (AbstractCpsObject cps : cat.getObjects()) {
  1276. if (actualObjectClicked.compareTo(cps.getObjName()) == 0) {
  1277. File checkPath = new File(cps.getImage());
  1278. if (checkPath.exists()) {
  1279. img = new ImageIcon(cps.getImage()).getImage().getScaledInstance(50, 50,
  1280. java.awt.Image.SCALE_SMOOTH);
  1281. } else {
  1282. img = new ImageIcon(this.getClass().getResource(cps.getImage())).getImage()
  1283. .getScaledInstance(50, 50, java.awt.Image.SCALE_SMOOTH);
  1284. }
  1285. tempCps = cps;
  1286. dragging = true;
  1287. Cursor cursor = Toolkit.getDefaultToolkit().createCustomCursor(img, new Point(0, 0),
  1288. "Image");
  1289. frmCyberPhysical.setCursor(cursor);
  1290. }
  1291. }
  1292. }
  1293. }
  1294. } catch (Exception eex) {
  1295. }
  1296. }
  1297. });
  1298. editItem.addActionListener(new ActionListener() {
  1299. @Override
  1300. public void actionPerformed(ActionEvent e) {
  1301. // Remove the selected Object object
  1302. addObjectPopUP = new AddObjectPopUp(true, tempCps, catOfObjToBeEdited);
  1303. addObjectPopUP.setCategory(catOfObjToBeEdited);
  1304. addObjectPopUP.setController(controller);
  1305. addObjectPopUP.setVisible(true);
  1306. }
  1307. });
  1308. scrollPane1.setViewportView(tree);
  1309. scrollPane1.setColumnHeaderView(panel);
  1310. panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
  1311. toolBar.setAlignmentX(Component.LEFT_ALIGNMENT);
  1312. toolBar.setFloatable(false);
  1313. panel.add(toolBar);
  1314. comboBox.setMaximumSize(new Dimension(100, 20));
  1315. toolBar.add(comboBox);
  1316. comboBox.setModel(new DefaultComboBoxModel(comboBoxCat));
  1317. // Add Buttonnew DefaultComboBoxModel(comboBoxCat)
  1318. btnAdd.addActionListener(new ActionListener() {
  1319. public void actionPerformed(ActionEvent arg0) {
  1320. Object nodeInfo = tree.getLastSelectedPathComponent();
  1321. String selectedOption = comboBox.getSelectedItem().toString();
  1322. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
  1323. try {
  1324. switch (selectedOption) {
  1325. case "Category":
  1326. String catName = JOptionPane.showInputDialog(Languages.getLanguage()[56]);
  1327. if (catName.length() != 0) {
  1328. controller.addCategory(catName);
  1329. }
  1330. break;
  1331. case "Object":
  1332. if (selectedNode == null) {
  1333. JOptionPane.showMessageDialog(new JFrame(),
  1334. Languages.getLanguage()[57] + selectedOption + ".");
  1335. }
  1336. if (selectedNode.getLevel() == 1) {
  1337. AbstractCpsObject tmp = new HolonObject("");
  1338. addObjectPopUP = new AddObjectPopUp(false, tmp, null);
  1339. addObjectPopUP.setVisible(true);
  1340. addObjectPopUP.setController(controller);
  1341. addObjectPopUP.setCategory(selectedNode.toString());
  1342. }
  1343. break;
  1344. default:
  1345. addObjectAction(selectedOption, selectedNode);
  1346. break;
  1347. }
  1348. } catch (Exception e) {
  1349. // TODO: handle exception
  1350. }
  1351. tree.repaint();
  1352. }
  1353. });
  1354. /**
  1355. * Pop up - About Us with some important information about the
  1356. * developers, source and programming stuff
  1357. */
  1358. aboutUs.addMouseListener(new MouseAdapter() {
  1359. @Override
  1360. public void mousePressed(MouseEvent e) {
  1361. aboutUsPopUp = new AboutUsPopUp();
  1362. aboutUsPopUp.setVisible(true);
  1363. }
  1364. });
  1365. /**
  1366. * Update of every interaction between the user and the canvas (only on
  1367. * the canvas). Basically the update of all the information concerning
  1368. * the clicked HolonObject. For multi-selection, the propertyTable would
  1369. * be disabled
  1370. */
  1371. canvas.addMouseListener(new MouseAdapter() {
  1372. @Override
  1373. public void mousePressed(MouseEvent e) {
  1374. }
  1375. @Override
  1376. public void mouseReleased(MouseEvent e) {
  1377. holonEleNamesDisplayed = Languages.getLanguage()[25];
  1378. // If any empty space is clicked
  1379. if (temp == null || temp.getId() != model.getSelectedObjectID()) {
  1380. unitGraph.empty();
  1381. elementGraph.setText(Languages.getLanguage()[25]);
  1382. }
  1383. temp = updCon.getActualCps();
  1384. // Erase old data in the PropertyTable
  1385. if (model.getPropertyTable().getRowCount() > 0) {
  1386. for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
  1387. model.getPropertyTable().removeRow(i);
  1388. }
  1389. }
  1390. if (e.isControlDown() && temp != null) {
  1391. if (model.getSelectedCpsObjects().contains(temp)) {
  1392. controller.deleteSelectedObject(temp);
  1393. } else {
  1394. controller.addSelectedObject(temp);
  1395. }
  1396. }
  1397. if (temp instanceof HolonSwitch) {
  1398. unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
  1399. unitGraph.fillArrayofBooleans();
  1400. }
  1401. // Write new data in the PropertyTable
  1402. updCon.paintProperties(temp);
  1403. // New Tab with NodeOfNode
  1404. if (doubleClick() && MouseEvent.BUTTON3 != e.getButton() && temp instanceof CpsUpperNode) {
  1405. openNewUpperNodeTab();
  1406. }
  1407. if (model.getSelectedCpsObjects().size() > 1) {
  1408. model.getTableHolonElement().setModel(model.getMultiTable());
  1409. } else if (model.getSelectedCpsObjects().size() == 1) {
  1410. model.getTableHolonElement().setModel(model.getSingleTable());
  1411. }
  1412. }
  1413. });
  1414. holonCanvas.addMouseListener(new MouseAdapter() {
  1415. @Override
  1416. public void mousePressed(MouseEvent e) {
  1417. unitGraph.empty();
  1418. elementGraph.setText(Languages.getLanguage()[25]);
  1419. if (model.getPropertyTable().getRowCount() > 0) {
  1420. for (int i = model.getPropertyTable().getRowCount() - 1; i > -1; i--) {
  1421. model.getPropertyTable().removeRow(i);
  1422. }
  1423. }
  1424. updCon.deleteRows(model.getMultiTable());
  1425. updCon.deleteRows(model.getSingleTable());
  1426. updCon.paintHolonBody(model.getSelectedHolonBody());
  1427. }
  1428. });
  1429. toolBar.add(btnAdd);
  1430. // Del Button
  1431. btnDel.addActionListener(new ActionListener() {
  1432. public void actionPerformed(ActionEvent arg0) {
  1433. Object nodeInfo = tree.getLastSelectedPathComponent();
  1434. if (nodeInfo != null) {
  1435. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) nodeInfo;
  1436. String nodeName = selectedNode.getUserObject().toString();
  1437. int depthOfNode = selectedNode.getLevel();
  1438. try {
  1439. switch (depthOfNode) {
  1440. case 1:
  1441. int dialogResult = JOptionPane.showConfirmDialog(null, eraseCategory + nodeName + "?",
  1442. warningText, JOptionPane.YES_NO_OPTION);
  1443. if (dialogResult == JOptionPane.YES_OPTION) {
  1444. controller.deleteCategory(nodeName);
  1445. }
  1446. break;
  1447. case 2:
  1448. DefaultMutableTreeNode parent = (DefaultMutableTreeNode) selectedNode.getParent();
  1449. controller.delObjectCategory(parent.getUserObject().toString(), nodeName);
  1450. break;
  1451. default:
  1452. JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
  1453. }
  1454. } catch (Exception e2) {
  1455. // TODO: handle exception
  1456. }
  1457. } else {
  1458. JOptionPane.showMessageDialog(new JFrame(), selectObjBeforeErase);
  1459. }
  1460. tree.repaint();
  1461. }
  1462. });
  1463. toolBar.add(btnDel);
  1464. frmCyberPhysical.getContentPane().add(splitPane);
  1465. mntmNew.addActionListener(new ActionListener() {
  1466. @Override
  1467. public void actionPerformed(ActionEvent arg0) {
  1468. if (model.getObjectsOnCanvas().size() != 0) {
  1469. int newWarning = JOptionPane.YES_NO_OPTION;
  1470. int dialogForNewWarning = JOptionPane.showConfirmDialog(null, saveBeforeNew, warningText,
  1471. newWarning);
  1472. if (dialogForNewWarning == JOptionPane.YES_OPTION) {
  1473. mntmSave.doClick();
  1474. }
  1475. }
  1476. model.getEdgesOnCanvas().removeAll(model.getEdgesOnCanvas());
  1477. model.getObjectsOnCanvas().removeAll(model.getObjectsOnCanvas());
  1478. controller.setSelectedObjectID(0);
  1479. controller.setSelecteEdge(null);
  1480. controller.setCurIteration(0);
  1481. unitGraph.empty();
  1482. elementGraph.setText(Languages.getLanguage()[25]);
  1483. canvas.tempCps = null;
  1484. canvas.repaint();
  1485. IdCounter.resetCounter();
  1486. IdCounterElem.resetCounter();
  1487. }
  1488. });
  1489. mntmOpen.addActionListener(new java.awt.event.ActionListener() {
  1490. @Override
  1491. public void actionPerformed(java.awt.event.ActionEvent evt) {
  1492. menuFileExitActionPerformed(evt);
  1493. }
  1494. private void menuFileExitActionPerformed(java.awt.event.ActionEvent evt) {
  1495. JFileChooser fileChooser = new JFileChooser();
  1496. JFrame test = new JFrame();
  1497. FileNameExtensionFilter holonFilter = new FileNameExtensionFilter("Holon Save File(*.holon)", "holon");
  1498. fileChooser.setFileFilter(holonFilter);
  1499. if (fileChooser.showOpenDialog(test) == JFileChooser.APPROVE_OPTION) {
  1500. File file = fileChooser.getSelectedFile();
  1501. try {
  1502. controller.loadFile(file.getAbsolutePath());
  1503. canvas.repaint();
  1504. unitGraph.update(model.getObjectsOnCanvas());
  1505. tree.repaint();
  1506. } catch (IOException | ArchiveException e) {
  1507. // TODO Auto-generated catch block
  1508. e.printStackTrace();
  1509. JLabel message = new JLabel("The savefile is corrupt and cannot be opened.");
  1510. JOptionPane.showMessageDialog(null, message, "", JOptionPane.ERROR_MESSAGE);
  1511. }
  1512. }
  1513. }
  1514. });
  1515. mntmSave.addActionListener(new java.awt.event.ActionListener() {
  1516. @Override
  1517. public void actionPerformed(java.awt.event.ActionEvent evt) {
  1518. menuSaveActionPerformed(evt);
  1519. }
  1520. private void menuSaveActionPerformed(java.awt.event.ActionEvent evt) {
  1521. JFileChooser fileChooser = new JFileChooser();
  1522. JFrame test = new JFrame();
  1523. FileNameExtensionFilter holonFilter = new FileNameExtensionFilter("Holon Save File(*.holon)", "holon");
  1524. fileChooser.setFileFilter(holonFilter);
  1525. if (fileChooser.showSaveDialog(test) == JFileChooser.APPROVE_OPTION) {
  1526. String file = fileChooser.getSelectedFile().getPath();
  1527. if (fileChooser.getFileFilter().equals(holonFilter)) {
  1528. if (!file.contains("."))
  1529. file += ".holon";
  1530. if (!file.endsWith(".holon")) {
  1531. String suffix = file.substring(file.lastIndexOf("."), file.length());
  1532. String[] options = new String[] { "keep .holon", "use " + suffix };
  1533. JLabel message = new JLabel(
  1534. "Are you sure to use the extension \"" + suffix + "\" instead of \".holon\"?");
  1535. int response = JOptionPane.showOptionDialog(null, message, "", JOptionPane.DEFAULT_OPTION,
  1536. JOptionPane.QUESTION_MESSAGE, null, options, options[1]);
  1537. if (response == 0)
  1538. file = file.replace(suffix, ".holon");
  1539. }
  1540. }
  1541. try {
  1542. controller.saveFile(new File(file).getAbsolutePath());
  1543. } catch (IOException | ArchiveException e) {
  1544. // TODO Auto-generated catch block
  1545. e.printStackTrace();
  1546. }
  1547. }
  1548. }
  1549. });
  1550. englishBtn.addActionListener(new ActionListener() {
  1551. @Override
  1552. public void actionPerformed(ActionEvent e) {
  1553. Languages.setLanguage(0);
  1554. refreshLanguages();
  1555. updCon.refreshTableProperties(model.getPropertyTable());
  1556. }
  1557. });
  1558. spanishBtn.addActionListener(new ActionListener() {
  1559. @Override
  1560. public void actionPerformed(ActionEvent e) {
  1561. Languages.setLanguage(1);
  1562. refreshLanguages();
  1563. updCon.refreshTableProperties(model.getPropertyTable());
  1564. }
  1565. });
  1566. germanBtn.addActionListener(new ActionListener() {
  1567. @Override
  1568. public void actionPerformed(ActionEvent e) {
  1569. Languages.setLanguage(2);
  1570. refreshLanguages();
  1571. updCon.refreshTableProperties(model.getPropertyTable());
  1572. }
  1573. });
  1574. czechBtn.addActionListener(new ActionListener() {
  1575. @Override
  1576. public void actionPerformed(ActionEvent e) {
  1577. Languages.setLanguage(3);
  1578. refreshLanguages();
  1579. updCon.refreshTableProperties(model.getPropertyTable());
  1580. }
  1581. });
  1582. chineseBtn.addActionListener(new ActionListener() {
  1583. @Override
  1584. public void actionPerformed(ActionEvent e) {
  1585. Languages.setLanguage(4);
  1586. refreshLanguages();
  1587. updCon.refreshTableProperties(model.getPropertyTable());
  1588. ;
  1589. }
  1590. });
  1591. mntmUndo.addActionListener(new java.awt.event.ActionListener() {
  1592. @Override
  1593. public void actionPerformed(java.awt.event.ActionEvent evt) {
  1594. menuUndoActionPerformed(evt);
  1595. }
  1596. private void menuUndoActionPerformed(java.awt.event.ActionEvent evt) {
  1597. try {
  1598. controller.loadAutoSave(controller.getUndoSave());
  1599. canvas.repaint();
  1600. ArrayList<HolonElement> tempList = new ArrayList<>();
  1601. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  1602. if (cps instanceof HolonObject) {
  1603. for (HolonElement h : ((HolonObject) cps).getElements()) {
  1604. tempList.add(h);
  1605. unitGraph.repaintWithNewElement(tempList);
  1606. unitGraph.fillArrayofValue();
  1607. tempList.remove(0);
  1608. }
  1609. } else if (cps instanceof HolonSwitch) {
  1610. unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
  1611. unitGraph.fillArrayofBooleans();
  1612. }
  1613. }
  1614. unitGraph.empty();
  1615. } catch (IOException e) {
  1616. // TODO Auto-generated catch block
  1617. e.printStackTrace();
  1618. }
  1619. }
  1620. });
  1621. mntmRedo.addActionListener(new java.awt.event.ActionListener() {
  1622. @Override
  1623. public void actionPerformed(java.awt.event.ActionEvent evt) {
  1624. menuRedoActionPerformed(evt);
  1625. }
  1626. private void menuRedoActionPerformed(java.awt.event.ActionEvent evt) {
  1627. try {
  1628. controller.loadAutoSave(controller.getRedoSave());
  1629. canvas.repaint();
  1630. ArrayList<HolonElement> tempList = new ArrayList<>();
  1631. for (AbstractCpsObject cps : model.getObjectsOnCanvas()) {
  1632. if (cps instanceof HolonObject) {
  1633. for (HolonElement h : ((HolonObject) cps).getElements()) {
  1634. tempList.add(h);
  1635. unitGraph.repaintWithNewElement(tempList);
  1636. unitGraph.fillArrayofValue();
  1637. tempList.remove(0);
  1638. }
  1639. } else if (cps instanceof HolonSwitch) {
  1640. unitGraph.repaintWithNewSwitch((HolonSwitch) cps);
  1641. unitGraph.fillArrayofBooleans();
  1642. }
  1643. }
  1644. unitGraph.empty();
  1645. } catch (IOException e) {
  1646. // TODO Auto-generated catch block
  1647. e.printStackTrace();
  1648. }
  1649. }
  1650. });
  1651. timePanel = new TimePanel(model, controller);
  1652. timePanel.setBorder(null);
  1653. ((JSlider) (timePanel.getComponent(1))).addChangeListener(new ChangeListener() {
  1654. @Override
  1655. public void stateChanged(ChangeEvent e) {
  1656. int i = model.getCurIteration();
  1657. controller.runAlgorithm(model, controller);
  1658. controller.calculateStateForTimeStep(i);
  1659. unitGraph.repaint();
  1660. statSplitPane.repaintGraphs();
  1661. contentPane.updateUI();
  1662. }
  1663. });
  1664. splitPane1.setMinimumSize(new Dimension(0, 25));
  1665. splitPane.setRightComponent(splitPane1);
  1666. splitPane.setDividerLocation(200);
  1667. splitPane1.setDividerLocation(500);
  1668. splitPaneCanvasConsole.setDividerLocation(550);
  1669. splitPaneCanvasConsole.setResizeWeight(0.9);
  1670. splitPane.setLeftComponent(scrollPane1);
  1671. splitPaneCanvasConsole.setLeftComponent(panelTapped_SimMenu);
  1672. tabbedPane.addTab("View", canvasSP);
  1673. tabbedPane.addTab("Statistics", statScrollPane);
  1674. tabbedPane.addTab("Holon", holonCanvas);
  1675. flexPane = new FlexiblePane(controller);
  1676. controller.setFlexiblePane(flexPane);
  1677. tabbedPane.addTab("Flexibility", flexPane);
  1678. splitPaneCanvasConsole.setRightComponent(console);
  1679. splitPane1.setLeftComponent(splitPaneCanvasConsole);
  1680. splitPane1.setRightComponent(splitHolonElPro);
  1681. splitPane1.setResizeWeight(0.9);
  1682. splitHolonElPro.setDividerLocation(400);
  1683. splitHolonElPro.setTopComponent(splitGraphHolonEl);
  1684. splitHolonElPro.setBottomComponent(scrollProperties);
  1685. splitGraphHolonEl.setDividerLocation(150);
  1686. splitGraphHolonEl.setTopComponent(scrollGraph);
  1687. splitGraphHolonEl.setBottomComponent(scrollElements);
  1688. canvasSP.setViewportView(canvas);
  1689. // holonSP.setViewportView(holonCanvas);
  1690. panelTapped_SimMenu.setLayout(new BorderLayout());
  1691. panelTapped_SimMenu.add(simMenu, BorderLayout.NORTH);
  1692. panelTapped_SimMenu.add(tabbedPane);
  1693. simMenu.setBackground(new Color(240, 240, 240));
  1694. panelTapped_SimMenu.setBorder(null);
  1695. tabbedPane.setBorder(null);
  1696. scrollProperties.setBorder(null);
  1697. scrollGraph.setBorder(null);
  1698. scrollElements.setBorder(null);
  1699. splitPane.setBorder(null);
  1700. splitPane1.setBorder(null);
  1701. splitPaneCanvasConsole.setBorder(null);
  1702. splitHolonElPro.setBorder(null);
  1703. splitGraphHolonEl.setBorder(null);
  1704. panelHolonEl.setBorder(null);
  1705. canvasSP.setBorder(null);
  1706. // holonSP.setBorder(null);
  1707. tableHolonElementScrollPane.setBorder(null);
  1708. frmCyberPhysical.getContentPane().add(timePanel, BorderLayout.SOUTH);
  1709. try {
  1710. controller.loadAutoSave(System.getProperty("user.home") + "/HolonGUI/Category/Category.json");
  1711. } catch (IOException e1) {
  1712. // TODO Auto-generated catch block
  1713. }
  1714. String autoPath = System.getProperty("user.home") + "/HolonGUI/Autosave/";
  1715. File dest = new File(autoPath);
  1716. if (dest.listFiles().length > 1) {
  1717. int dialogButton = JOptionPane.YES_NO_OPTION;
  1718. int dialogResult = JOptionPane.showConfirmDialog(null, "Old autosave file was found, should it be loaded?",
  1719. warningText, dialogButton);
  1720. if (dialogResult == JOptionPane.YES_OPTION) {
  1721. if (dest.exists()) {
  1722. model.setAutoSaveNr(dest.listFiles().length - 1);
  1723. mntmRedo.doClick();
  1724. } else {
  1725. JOptionPane.showMessageDialog(frmCyberPhysical, "Autosave could not be loaded.");
  1726. setUpAutoSave(dest);
  1727. }
  1728. } else {
  1729. setUpAutoSave(dest);
  1730. }
  1731. }
  1732. canvasSP.addComponentListener(new ComponentAdapter() {
  1733. @Override
  1734. public void componentResized(ComponentEvent e) {
  1735. controller.setCanvasX(Math.max(model.getCanvasX(), canvasSP.getViewport().getWidth()));
  1736. controller.setCanvasY(Math.max(model.getCanvasY(), canvasSP.getViewport().getHeight()));
  1737. canvas.repaint();
  1738. }
  1739. });
  1740. }
  1741. /**
  1742. * Sets up autosave if no old one is loaded at the beginning
  1743. *
  1744. * @param dest
  1745. * path to save-folder
  1746. */
  1747. public void setUpAutoSave(File dest) {
  1748. controller.deleteDirectory(dest);
  1749. dest.mkdirs();
  1750. try {
  1751. controller.autoSave();
  1752. } catch (IOException e1) {
  1753. // TODO Auto-generated catch block
  1754. e1.printStackTrace();
  1755. }
  1756. }
  1757. /**
  1758. * adds a specific object type to selected Category also handles input
  1759. * windows and illegal inputs.
  1760. *
  1761. * @param objType
  1762. * type of the Object
  1763. * @param selectedNode
  1764. * The selected Node
  1765. */
  1766. public void addObjectAction(String objType, DefaultMutableTreeNode selectedNode) {
  1767. if (selectedNode == null) {
  1768. JOptionPane.showMessageDialog(new JFrame(),
  1769. "Please select a Category first before adding " + objType + ".");
  1770. }
  1771. // if selected node is a directory for Categories
  1772. else {
  1773. if (selectedNode.getLevel() == 1) {
  1774. String objname = JOptionPane.showInputDialog("Please enter a Name for the " + objType);
  1775. Category cat = controller.searchCategory(selectedNode.getUserObject().toString());
  1776. if (objname.length() != 0) {
  1777. try {
  1778. switch (objType) {
  1779. case "Switch":
  1780. controller.addSwitch(cat, objname);
  1781. break;
  1782. }
  1783. } catch (Exception e) {
  1784. // TODO: handle exception
  1785. }
  1786. }
  1787. } else {
  1788. JOptionPane.showMessageDialog(new JFrame(),
  1789. "Objects can not be added to Objects. Please select a Category.");
  1790. }
  1791. }
  1792. }
  1793. /**
  1794. * reloads the Categories from Model.
  1795. *
  1796. * @param categories
  1797. * the current categories
  1798. */
  1799. public void updateCategories(final ArrayList<Category> categories) {
  1800. tree.setModel(new DefaultTreeModel(new DefaultMutableTreeNode("Categories") {
  1801. private static final long serialVersionUID = 1L;
  1802. {
  1803. DefaultMutableTreeNode node1;
  1804. for (Category c : categories) {
  1805. node1 = new DefaultMutableTreeNode(c.getName());
  1806. // kann eventuell umgeändert werden
  1807. for (AbstractCpsObject obj : c.getObjects()) {
  1808. node1.add(new DefaultMutableTreeNode(obj.getObjName()));
  1809. }
  1810. add(node1);
  1811. }
  1812. }
  1813. }));
  1814. }
  1815. /**
  1816. * When changes are made to the Categories.
  1817. *
  1818. * @param categories
  1819. * the Categories
  1820. */
  1821. public void onChange(ArrayList<Category> categories) {
  1822. DefaultTreeModel model = (DefaultTreeModel) tree.getModel();
  1823. updateCategories(categories);
  1824. model.reload();
  1825. }
  1826. /**
  1827. * Get the Frame.
  1828. *
  1829. * @return the Frame
  1830. */
  1831. public JFrame getFrmCyberPhysical() {
  1832. return frmCyberPhysical;
  1833. }
  1834. /**
  1835. * Adds a Popup.
  1836. *
  1837. * @param component
  1838. * Component
  1839. * @param popup
  1840. * PopupMenu
  1841. */
  1842. private static void addPopup(Component component, final JPopupMenu popup) {
  1843. component.addMouseListener(new MouseAdapter() {
  1844. public void mousePressed(MouseEvent e) {
  1845. if (e.isPopupTrigger()) {
  1846. showMenu(e);
  1847. }
  1848. }
  1849. public void mouseReleased(MouseEvent e) {
  1850. if (e.isPopupTrigger()) {
  1851. showMenu(e);
  1852. }
  1853. }
  1854. private void showMenu(MouseEvent e) {
  1855. popup.show(e.getComponent(), e.getX(), e.getY());
  1856. }
  1857. });
  1858. }
  1859. private void refreshLanguages() {
  1860. String[] tempArray = Languages.getLanguage();
  1861. // ToolBar
  1862. mnNewMenu.setText(tempArray[0]);
  1863. mntmNew.setText(tempArray[1]);
  1864. mntmOpen.setText(tempArray[2]);
  1865. mntmSave.setText(tempArray[3]);
  1866. mnNewMenuEdit.setText(tempArray[4]);
  1867. mntmUndo.setText(tempArray[5]);
  1868. mntmRedo.setText(tempArray[6]);
  1869. mntmFindReplace.setText(tempArray[7]);
  1870. mntmEditShowedInformation.setText(tempArray[8]);
  1871. mnNewMenuOptions.setText(tempArray[9]);
  1872. mntmResetCategory.setText(tempArray[10]);
  1873. mnNewMenuView.setText(tempArray[11]);
  1874. canvasSize.setText(tempArray[12]);
  1875. mnHelp.setText(tempArray[13]);
  1876. aboutUs.setText(tempArray[14]);
  1877. mntmEditEdges.setText(tempArray[15]);
  1878. mnLanguage.setText(tempArray[16]);
  1879. canvas.updateLanguages();
  1880. // Tables
  1881. for (int i = 0; i < columnNamesMulti.length; i++) {
  1882. columnNamesMulti[i] = tempArray[i + 17];
  1883. }
  1884. model.getMultiTable().setColumnIdentifiers(columnNamesMulti);
  1885. for (int i = 0; i < columnNamesSingle.length; i++) {
  1886. columnNamesSingle[i] = tempArray[i + 18];
  1887. }
  1888. model.getSingleTable().setColumnIdentifiers(columnNamesSingle);
  1889. model.colNames[0] = tempArray[23];
  1890. model.colNames[1] = tempArray[24];
  1891. model.getPropertyTable().setColumnIdentifiers(model.colNames);
  1892. // Graph
  1893. elementGraph.setText(tempArray[25]);
  1894. holonEleNamesDisplayed = tempArray[25];
  1895. resetGraphBtn.setText(tempArray[26]);
  1896. // Warning PopUps
  1897. warningText = tempArray[27];
  1898. saveBeforeNew = tempArray[28];
  1899. eraseCategory = tempArray[29];
  1900. selectObjBeforeErase = tempArray[30];
  1901. // SimMenu
  1902. simMenu.algoFolderButton.setText(Languages.getLanguage()[85]);
  1903. // TimePanel
  1904. timePanel.playBtn.setToolTipText(Languages.getLanguage()[89]);
  1905. timePanel.timeResetBtn.setToolTipText(Languages.getLanguage()[90]);
  1906. timePanel.timeForwardBtn.setToolTipText(Languages.getLanguage()[91]);
  1907. timePanel.timeBackwardBtn.setToolTipText(Languages.getLanguage()[92]);
  1908. timePanel.timeSlider.setToolTipText(Languages.getLanguage()[93]);
  1909. // Image Size Slider
  1910. lblImageSize.setText(Languages.getLanguage()[94]);
  1911. }
  1912. /**
  1913. * Checks if a double click was made.
  1914. *
  1915. * @return
  1916. *
  1917. * @return true if doublecklick, false if not
  1918. */
  1919. private boolean doubleClick() {
  1920. if (click) {
  1921. click = false;
  1922. return true;
  1923. } else {
  1924. click = true;
  1925. Timer t = new Timer("doubleclickTimer", false);
  1926. t.schedule(new TimerTask() {
  1927. @Override
  1928. public void run() {
  1929. click = false;
  1930. }
  1931. }, 350);
  1932. }
  1933. return false;
  1934. }
  1935. /*
  1936. * Open a new Tab with an UpperNodeCanvas
  1937. */
  1938. private void openNewUpperNodeTab() {
  1939. // is the uppernode on tabbedPane or tabbedPane2
  1940. if (tabbedPane.getMousePosition() != null) {
  1941. tabTemp = tabbedPane;
  1942. } else {
  1943. tabTemp = tabbedPane2;
  1944. }
  1945. if (((JScrollPane) tabTemp.getSelectedComponent()).getViewport().getComponent(0) instanceof MyCanvas) {
  1946. unc = new UpperNodeCanvas(model, controller, unitGraph, (CpsUpperNode) temp, "");
  1947. } else {
  1948. unc = new UpperNodeCanvas(model, controller, unitGraph, (CpsUpperNode) temp,
  1949. ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  1950. .getComponent(0)).path + " -> ");
  1951. }
  1952. unc.setShowedInformation(canvas.getShowedInformation());
  1953. // check if tab already open for clicked NodeOfNode
  1954. boolean dupl = false;
  1955. for (int i = 4; i < tabbedPane.getTabCount() && dupl == false; i++) {
  1956. if (tabbedPane.getComponentAt(i) != null && ((UpperNodeCanvas) ((JScrollPane) tabbedPane.getComponentAt(i))
  1957. .getViewport().getComponent(0)).upperNode.getId() == temp.getId()) {
  1958. dupl = true;
  1959. tabbedPane.setSelectedComponent(tabbedPane.getComponentAt(i));
  1960. }
  1961. if (!initSplit && tabbedPane2.getComponentAt(i) != null
  1962. && ((UpperNodeCanvas) ((JScrollPane) tabbedPane2.getComponentAt(i)).getViewport()
  1963. .getComponent(0)).upperNode.getId() == temp.getId()) {
  1964. dupl = true;
  1965. tabbedPane2.setSelectedComponent(tabbedPane2.getComponentAt(i));
  1966. }
  1967. }
  1968. if (!dupl) {
  1969. unc.setBorder(null);
  1970. unc.setBackground(Color.WHITE);
  1971. unc.setPreferredSize(new Dimension(model.getCanvasX(), model.getCanvasY()));
  1972. unc.addMouseListener(new MouseAdapter() {
  1973. @Override
  1974. public void mousePressed(MouseEvent e) {
  1975. unitGraph.empty();
  1976. holonEleNamesDisplayed = Languages.getLanguage()[25];
  1977. elementGraph.setText(holonEleNamesDisplayed);
  1978. if (tabbedPane.getMousePosition() != null) {
  1979. tabTemp = tabbedPane;
  1980. } else {
  1981. tabTemp = tabbedPane2;
  1982. }
  1983. temp = ((UpperNodeCanvas) ((JScrollPane) tabTemp.getSelectedComponent()).getViewport()
  1984. .getComponent(0)).tempCps;
  1985. if (doubleClick() && MouseEvent.BUTTON3 != e.getButton() && temp instanceof CpsUpperNode) {
  1986. openNewUpperNodeTab();
  1987. }
  1988. if (temp instanceof HolonSwitch) {
  1989. unitGraph.repaintWithNewSwitch((HolonSwitch) temp);
  1990. unitGraph.fillArrayofBooleans();
  1991. }
  1992. }
  1993. });
  1994. JScrollPane sp = new JScrollPane(unc);
  1995. sp.setBorder(null);
  1996. if (tabTemp == tabbedPane) {
  1997. tabbedPane.add(temp.getName(), sp);
  1998. tabbedPane.setSelectedComponent(sp);
  1999. tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1,
  2000. new ButtonTabComponent(tabbedPane, tabbedPane2));
  2001. if (!initSplit) {
  2002. tabbedPane2.add(temp.getName(), null);
  2003. // tabbedPane2.setTabComponentAt(tabbedPane2.getTabCount() -
  2004. // 1,
  2005. // new ButtonTabComponent(tabbedPane, tabbedPane2));
  2006. }
  2007. } else {
  2008. tabbedPane2.add(temp.getName(), sp);
  2009. Component tempC = tabbedPane2.getSelectedComponent();
  2010. tabbedPane2.setComponentAt(tabbedPane2.getSelectedIndex(), null);
  2011. tabbedPane.setComponentAt(tabbedPane2.getSelectedIndex(), tempC);
  2012. tabbedPane2.setSelectedComponent(sp);
  2013. // tabbedPane2.setTabComponentAt(tabbedPane2.getTabCount() - 1,
  2014. // new ButtonTabComponent(tabbedPane, tabbedPane2));
  2015. tabbedPane.add(temp.getName(), null);
  2016. tabbedPane.setTabComponentAt(tabbedPane.getTabCount() - 1,
  2017. new ButtonTabComponent(tabbedPane, tabbedPane2));
  2018. }
  2019. temp = null;
  2020. }
  2021. }
  2022. }