GUI.java 78 KB

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