GUI.java 78 KB

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