StatPanel2.java 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  1. package ui.view;
  2. import java.awt.Color;
  3. import java.awt.Component;
  4. import java.awt.Dimension;
  5. import java.awt.event.ActionEvent;
  6. import java.awt.event.ActionListener;
  7. import java.awt.event.ItemEvent;
  8. import java.awt.event.ItemListener;
  9. import java.util.ArrayList;
  10. import java.util.Hashtable;
  11. import java.util.Random;
  12. import javax.swing.Box;
  13. import javax.swing.BoxLayout;
  14. import javax.swing.JButton;
  15. import javax.swing.JComboBox;
  16. import javax.swing.JLabel;
  17. import javax.swing.JMenuItem;
  18. import javax.swing.JPanel;
  19. import javax.swing.JPopupMenu;
  20. import javax.swing.JScrollPane;
  21. import javax.swing.JSplitPane;
  22. import javax.swing.JTextField;
  23. import javax.swing.JTree;
  24. import javax.swing.border.EmptyBorder;
  25. import javax.swing.border.LineBorder;
  26. import javax.swing.event.DocumentEvent;
  27. import javax.swing.event.DocumentListener;
  28. import javax.swing.event.TreeSelectionEvent;
  29. import javax.swing.event.TreeSelectionListener;
  30. import javax.swing.tree.DefaultMutableTreeNode;
  31. import javax.swing.tree.DefaultTreeModel;
  32. import DataSets.GraphDataSet;
  33. import DataSets.PropertyDataSet;
  34. import classes.AbstractCpsObject;
  35. import classes.CpsUpperNode;
  36. import classes.HolonObject;
  37. import classes.HolonSwitch;
  38. import classes.TrackedDataSet;
  39. import interfaces.GraphListener;
  40. import ui.controller.Control;
  41. public class StatPanel2 extends JSplitPane implements GraphListener {
  42. public static final String MAIN_GRID = "Main Grid";
  43. public static final String HOLON = "Holons";
  44. // Property Strings
  45. public static final String TOT_PROD_HOLON = "total Holon Production";
  46. public static final String TOT_CONS_HOLON = "total Holon Consumption";
  47. public static final String SUPPLIED_OBJ = "Percentage of supplied Objects";
  48. public static final String NOT_SUPPLIED_OBJ = "Percentage of not supplied Objects";
  49. public static final String PART_SUPPLIED_OBJ = "Percentage of partially supplied Objects";
  50. public static final String NR_SUBNETS = "Nr. of Subnets";
  51. public static final String NR_CLOSED_SWITCHES = "Nr. of closed Switches";
  52. public static final String AVG_OBJ_IN_HOLONS = "Average amount of Objects in Holons";
  53. public static final String AVG_ELEM_IN_HOLONS = "Average amount of Elements in Holons";
  54. public static final String AVG_PRODS_IN_HOLONS ="Average amount of Producers in Holons";
  55. public static final String AVG_CONS_ENERGY_IN_HOLONS = "Average consumed Energy";
  56. public static final String AVG_WASTED_ENERGY_HOLONS = "Average wasted Energy";
  57. public static final String NR_BROKEN_EDGES = "Amount of broken Edges";
  58. public static final String PROD_CONS_RATIO = "Producer/Consumer Ratio";
  59. public static final String AVG_CLOSED_SW_HOLON = "Average of closed Switches per Holon";
  60. public static final String AVG_ACTIVE_ELEMENTS_HOLON = "Average of active Elements per Holon";
  61. public static final String AVG_INACTIVE_ELEMENTS_HOLON = "Average of inactive Elements per Holon";
  62. public static final String AVG_PRODUCTION_HOLON = "Average Production per Holon";
  63. public static final String TOT_PROD_OBJ = "total Production";
  64. public static final String TOT_CONS_OBJ = "total Consumption";
  65. public static final String NR_ACTIVE_ELEMENTS = "active Elements";
  66. public static final String SW_ACTIVE = "active";
  67. public static final String TOT_PROD_GRID = "total Grid Production";
  68. public static final String TOT_CONS_GRID = "total Grid Consumption";
  69. private DefaultTreeModel treeModel;
  70. private DefaultMutableTreeNode objectsNode;
  71. private DefaultMutableTreeNode mainGrid;
  72. private DefaultMutableTreeNode holonNode;
  73. private DefaultMutableTreeNode switchesNode;
  74. private DefaultMutableTreeNode groupNode;
  75. private Hashtable<String, GraphDataSet> objectHashtable;
  76. private Hashtable<String, StatisticGraphPanel> graphHashtable;
  77. private Hashtable<String, PropertyDataSet> holonHashtable;
  78. private Hashtable<String, Integer> propValTable;
  79. //contains information about a selected property
  80. private PropertyDataSet currentProperty = new PropertyDataSet();
  81. private Control controller;
  82. private JPanel graphPanel;
  83. //WindowBuilder Components
  84. private JTree objectTree;
  85. private JTextField graphNrTxtField;
  86. private JTextField redField;
  87. private JTextField greenField;
  88. private JTextField blueField;
  89. private JPanel colorPanel;
  90. private JComboBox colorComboBox;
  91. private JLabel showObjectlbl;
  92. private JLabel showPropertylbl;
  93. private JButton btnAdd;
  94. public StatPanel2(Control cont) {
  95. setBorder(null);
  96. setMaximumSize(new Dimension(0, 0));
  97. setPreferredSize(new Dimension(0, 0));
  98. setMinimumSize(new Dimension(0, 0));
  99. this.setDividerLocation(180);
  100. setContinuousLayout(true);
  101. this.controller = cont;
  102. objectHashtable = new Hashtable<String, GraphDataSet>();
  103. graphHashtable = new Hashtable<String, StatisticGraphPanel>();
  104. controller.setGraphTable(graphHashtable);
  105. holonHashtable = new Hashtable<String, PropertyDataSet>();
  106. holonHashtable.put(TOT_PROD_HOLON, new PropertyDataSet());
  107. holonHashtable.put(TOT_CONS_HOLON, new PropertyDataSet());
  108. holonHashtable.put(SUPPLIED_OBJ, new PropertyDataSet());
  109. holonHashtable.put(NOT_SUPPLIED_OBJ, new PropertyDataSet());
  110. holonHashtable.put(PART_SUPPLIED_OBJ, new PropertyDataSet());
  111. holonHashtable.put(NR_SUBNETS, new PropertyDataSet());
  112. holonHashtable.put(NR_CLOSED_SWITCHES, new PropertyDataSet());
  113. holonHashtable.put(AVG_OBJ_IN_HOLONS, new PropertyDataSet());
  114. holonHashtable.put(AVG_ELEM_IN_HOLONS, new PropertyDataSet());
  115. holonHashtable.put(AVG_PRODS_IN_HOLONS, new PropertyDataSet());
  116. holonHashtable.put(AVG_CONS_ENERGY_IN_HOLONS, new PropertyDataSet());
  117. holonHashtable.put(AVG_WASTED_ENERGY_HOLONS, new PropertyDataSet());
  118. holonHashtable.put(NR_BROKEN_EDGES, new PropertyDataSet());
  119. holonHashtable.put(PROD_CONS_RATIO, new PropertyDataSet());
  120. holonHashtable.put(AVG_CLOSED_SW_HOLON, new PropertyDataSet());
  121. holonHashtable.put(AVG_ACTIVE_ELEMENTS_HOLON, new PropertyDataSet());
  122. holonHashtable.put(AVG_INACTIVE_ELEMENTS_HOLON, new PropertyDataSet());
  123. holonHashtable.put(AVG_PRODUCTION_HOLON, new PropertyDataSet());
  124. //propValTable associates the Strings to the numbers
  125. propValTable = new Hashtable<String, Integer>();
  126. propValTable.put(TOT_PROD_OBJ, TrackedDataSet.PRODUCTION);
  127. propValTable.put(TOT_CONS_OBJ, TrackedDataSet.CONSUMPTION);
  128. propValTable.put(NR_ACTIVE_ELEMENTS, TrackedDataSet.ACTIVATED_ELEMENTS);
  129. propValTable.put(SW_ACTIVE, TrackedDataSet.ON_OFF);
  130. propValTable.put(TOT_PROD_HOLON, TrackedDataSet.TOTAL_PRODUCTION);
  131. propValTable.put(TOT_CONS_HOLON, TrackedDataSet.TOTAL_CONSUMPTION);
  132. propValTable.put(SUPPLIED_OBJ, TrackedDataSet.PERCENT_SUPPLIED);
  133. propValTable.put(NOT_SUPPLIED_OBJ, TrackedDataSet.PERCENT_NOT_SUPPLIED);
  134. propValTable.put(PART_SUPPLIED_OBJ, TrackedDataSet.PERCENT_PARTIAL_SUPPLIED);
  135. propValTable.put(TOT_PROD_GRID, TrackedDataSet.GROUP_PRODUCTION);
  136. propValTable.put(TOT_CONS_GRID, TrackedDataSet.GROUP_CONSUMPTION);
  137. propValTable.put(NR_SUBNETS, TrackedDataSet.AMOUNT_HOLONS);
  138. propValTable.put(NR_CLOSED_SWITCHES, TrackedDataSet.AMOUNT_CLOSED_SWITCHES);
  139. propValTable.put(AVG_OBJ_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_OBJECTS_IN_HOLONS);
  140. propValTable.put(AVG_ELEM_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_ELEMENTS_IN_HOLONS);
  141. propValTable.put(AVG_PRODS_IN_HOLONS, TrackedDataSet.AVG_AMOUNT_PRODUCERS_IN_HOLONS);
  142. propValTable.put(AVG_CONS_ENERGY_IN_HOLONS, TrackedDataSet.AVG_CONSUMED_ENERGY_IN_HOLONS);
  143. propValTable.put(AVG_WASTED_ENERGY_HOLONS, TrackedDataSet.AVG_WASTED_ENERGY_IN_HOLONS);
  144. propValTable.put(NR_BROKEN_EDGES, TrackedDataSet.AMOUNT_BROKEN_EDGES);
  145. propValTable.put(PROD_CONS_RATIO, TrackedDataSet.RATIO_PRODUCERS_CONSUMERS);
  146. propValTable.put(AVG_CLOSED_SW_HOLON, TrackedDataSet.AVG_AMOUNT_CLOSED_SWITCHES_IN_HOLONS);
  147. propValTable.put(AVG_ACTIVE_ELEMENTS_HOLON, TrackedDataSet.AVG_AMOUNT_ACTIVE_ELEMENTS_IN_HOLONS);
  148. propValTable.put(AVG_INACTIVE_ELEMENTS_HOLON, TrackedDataSet.AVG_AMOUNT_INACTIVE_ELEMENTS_IN_HOLONS);
  149. propValTable.put(AVG_PRODUCTION_HOLON, TrackedDataSet.AVG_PRODUCED_ENERGY_IN_HOLONS);
  150. JScrollPane graphScrollPane = new JScrollPane();
  151. graphScrollPane.setBorder(null);
  152. setRightComponent(graphScrollPane);
  153. graphPanel = new JPanel();
  154. graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
  155. graphPanel.revalidate();
  156. graphPanel.updateUI();
  157. graphScrollPane.setViewportView(graphPanel);
  158. JSplitPane splitPane = new JSplitPane();
  159. splitPane.setBorder(null);
  160. splitPane.setPreferredSize(new Dimension(0, 0));
  161. splitPane.setMinimumSize(new Dimension(0, 0));
  162. splitPane.setMaximumSize(new Dimension(0, 0));
  163. splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT);
  164. setLeftComponent(splitPane);
  165. //========================== TREE STRUCTURE ===============================//
  166. JScrollPane treeScrollPane = new JScrollPane();
  167. treeScrollPane.setBorder(null);
  168. objectTree = new JTree();
  169. objectTree.setBorder(new EmptyBorder(0, 0, 0, 0));
  170. treeModel = (DefaultTreeModel) objectTree.getModel();
  171. DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
  172. mainGrid = new DefaultMutableTreeNode(MAIN_GRID);
  173. mainGrid.add(new DefaultMutableTreeNode(TOT_PROD_HOLON));
  174. mainGrid.add(new DefaultMutableTreeNode(TOT_CONS_HOLON));
  175. mainGrid.add(new DefaultMutableTreeNode(SUPPLIED_OBJ));
  176. mainGrid.add(new DefaultMutableTreeNode(NOT_SUPPLIED_OBJ));
  177. mainGrid.add(new DefaultMutableTreeNode(PART_SUPPLIED_OBJ));
  178. mainGrid.add(new DefaultMutableTreeNode(NR_SUBNETS));
  179. mainGrid.add(new DefaultMutableTreeNode(PROD_CONS_RATIO));
  180. mainGrid.add(new DefaultMutableTreeNode(NR_BROKEN_EDGES));
  181. mainGrid.add(new DefaultMutableTreeNode(NR_CLOSED_SWITCHES));
  182. holonNode = new DefaultMutableTreeNode(HOLON);
  183. holonNode.add(new DefaultMutableTreeNode(AVG_OBJ_IN_HOLONS));
  184. holonNode.add(new DefaultMutableTreeNode(AVG_ELEM_IN_HOLONS));
  185. holonNode.add(new DefaultMutableTreeNode(AVG_WASTED_ENERGY_HOLONS));
  186. holonNode.add(new DefaultMutableTreeNode(AVG_CONS_ENERGY_IN_HOLONS));
  187. holonNode.add(new DefaultMutableTreeNode(AVG_PRODS_IN_HOLONS));
  188. holonNode.add(new DefaultMutableTreeNode(AVG_CLOSED_SW_HOLON));
  189. holonNode.add(new DefaultMutableTreeNode(AVG_ACTIVE_ELEMENTS_HOLON));
  190. holonNode.add(new DefaultMutableTreeNode(AVG_INACTIVE_ELEMENTS_HOLON));
  191. holonNode.add(new DefaultMutableTreeNode(AVG_PRODUCTION_HOLON));
  192. objectsNode = new DefaultMutableTreeNode("Objects");
  193. objectsNode.add(new DefaultMutableTreeNode("empty"));
  194. switchesNode = new DefaultMutableTreeNode("Switches");
  195. switchesNode.add(new DefaultMutableTreeNode("empty"));
  196. groupNode = new DefaultMutableTreeNode("Groups");
  197. groupNode.add(new DefaultMutableTreeNode("empty"));
  198. treeModel.setRoot(root);
  199. root.add(mainGrid);
  200. root.add(holonNode);
  201. root.add(objectsNode);
  202. root.add(switchesNode);
  203. root.add(groupNode);
  204. objectTree.setModel(treeModel);
  205. treeScrollPane.setViewportView(objectTree);
  206. JPopupMenu popupMenu = new JPopupMenu();
  207. addPopup(objectTree, popupMenu);
  208. JMenuItem mntmUntrack = new JMenuItem("Untrack");
  209. mntmUntrack.addActionListener(new ActionListener() {
  210. public void actionPerformed(ActionEvent e) {
  211. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
  212. .getLastSelectedPathComponent();
  213. if (selectedNode.getLevel() == 2 && !selectedNode.getParent().toString().equals("whole Holon")) {
  214. String object = selectedNode.toString();
  215. controller.removeTrackingObj(objectHashtable.get(object).getObject());
  216. }
  217. }
  218. });
  219. popupMenu.add(mntmUntrack);
  220. objectTree.addTreeSelectionListener(new TreeSelectionListener() {
  221. @Override
  222. public void valueChanged(TreeSelectionEvent e) {
  223. resetFields();
  224. showObjectlbl.setText("...");
  225. //showPropertylbl.setText("...");
  226. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
  227. .getLastSelectedPathComponent();
  228. if (selectedNode == null) {
  229. return;
  230. } else {
  231. if (selectedNode.getLevel() == 0) {
  232. disableFields();
  233. }
  234. if (selectedNode.getLevel() == 1) {
  235. disableFields();
  236. currentProperty = null;
  237. graphNrTxtField.setText("");
  238. showObjectlbl.setText(selectedNode.toString());
  239. }
  240. if (selectedNode.getLevel() == 2) {
  241. if (((DefaultMutableTreeNode) selectedNode.getParent()).toString().equals(MAIN_GRID)
  242. || ((DefaultMutableTreeNode) selectedNode.getParent()).toString().equals(HOLON)) {
  243. enableFields();
  244. String object = selectedNode.getParent().toString();
  245. String property = selectedNode.toString();
  246. currentProperty = holonHashtable.get(property);
  247. Color color = currentProperty.getColor();
  248. redField.setText(Integer.toString(color.getRed()));
  249. greenField.setText(Integer.toString(color.getGreen()));
  250. blueField.setText(Integer.toString(color.getBlue()));
  251. showPropertylbl.setText(property);
  252. showObjectlbl.setText(object);
  253. graphNrTxtField.setText(currentProperty.getAssignedGraph());
  254. colorPanel.setBackground(color);
  255. } else {
  256. disableFields();
  257. currentProperty = null;
  258. graphNrTxtField.setText("");
  259. showObjectlbl.setText(selectedNode.toString());
  260. }
  261. }
  262. if (selectedNode.getLevel() == 3) {
  263. enableFields();
  264. String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
  265. String property = selectedNode.toString();
  266. currentProperty = objectHashtable.get(object).getPropertytTable().get(property);
  267. Color color = currentProperty.getColor();
  268. redField.setText(Integer.toString(color.getRed()));
  269. greenField.setText(Integer.toString(color.getGreen()));
  270. blueField.setText(Integer.toString(color.getBlue()));
  271. showObjectlbl.setText(object);
  272. showPropertylbl.setText(property);
  273. graphNrTxtField.setText(currentProperty.getAssignedGraph());
  274. colorPanel.setBackground(color);
  275. }
  276. }
  277. }
  278. });
  279. splitPane.setLeftComponent(treeScrollPane);
  280. repaintTree();
  281. //=========================== TREE STRUCTURE END ==========================//
  282. //================= COLOR COMBOBOX ===========================//
  283. colorComboBox = new JComboBox();
  284. colorComboBox.addItem("");
  285. colorComboBox.addItem("Red");
  286. colorComboBox.addItem("Blue");
  287. colorComboBox.addItem("Green");
  288. colorComboBox.addItem("Yellow");
  289. colorComboBox.addItem("Orange");
  290. colorComboBox.addItem("Cyan");
  291. colorComboBox.addItem("Magenta");
  292. colorComboBox.addItem("Pink");
  293. colorComboBox.addItem("Gray");
  294. colorComboBox.addItem("Random");
  295. colorComboBox.addItemListener(new ItemListener() {
  296. @Override
  297. public void itemStateChanged(ItemEvent e) {
  298. String colorName = (String) colorComboBox.getSelectedItem();
  299. Color tmpColor = Color.WHITE;
  300. switch (colorName) {
  301. case "":
  302. tmpColor = currentProperty.getColor();
  303. break;
  304. case "Red":
  305. tmpColor = Color.RED;
  306. colorChanged(tmpColor);
  307. break;
  308. case "Blue":
  309. tmpColor = Color.BLUE;
  310. colorChanged(tmpColor);
  311. break;
  312. case "Green":
  313. tmpColor = Color.GREEN;
  314. colorChanged(tmpColor);
  315. break;
  316. case "Yellow":
  317. tmpColor = Color.YELLOW;
  318. colorChanged(tmpColor);
  319. break;
  320. case "Orange":
  321. tmpColor = Color.ORANGE;
  322. colorChanged(tmpColor);
  323. break;
  324. case "Cyan":
  325. tmpColor = Color.CYAN;
  326. colorChanged(tmpColor);
  327. break;
  328. case "Magenta":
  329. tmpColor = Color.MAGENTA;
  330. colorChanged(tmpColor);
  331. break;
  332. case "Pink":
  333. tmpColor = Color.PINK;
  334. colorChanged(tmpColor);
  335. break;
  336. case "Gray":
  337. tmpColor = Color.GRAY;
  338. colorChanged(tmpColor);
  339. break;
  340. case "Random":
  341. Random rdm = new Random();
  342. tmpColor = new Color(rdm.nextInt(255), rdm.nextInt(255), rdm.nextInt(255));
  343. }
  344. redField.setText(Integer.toString(tmpColor.getRed()));
  345. greenField.setText(Integer.toString(tmpColor.getGreen()));
  346. blueField.setText(Integer.toString(tmpColor.getBlue()));
  347. }
  348. });
  349. // ==================== COLORBOX END ==========================//
  350. // ====================RED TEXTFIELD===========================//
  351. redField = new JTextField();
  352. redField.setColumns(10);
  353. redField.getDocument().addDocumentListener(new DocumentListener() {
  354. /*
  355. * if textField for Red changes, changes will applied in the
  356. * DataStructure "currentProperty" if Value is legit
  357. */
  358. @Override
  359. public void insertUpdate(DocumentEvent e) {
  360. int tmp = -1;
  361. try {
  362. tmp = Integer.parseInt(redField.getText());
  363. } catch (NumberFormatException e1) {
  364. }
  365. if (tmp > -1 && tmp <= 255) {
  366. if (currentProperty != null) {
  367. Color oldColor = currentProperty.getColor();
  368. Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
  369. currentProperty.setColor(color);
  370. colorChanged(color);
  371. }
  372. }
  373. }
  374. @Override
  375. public void removeUpdate(DocumentEvent e) {
  376. int tmp = -1;
  377. try {
  378. tmp = Integer.parseInt(redField.getText());
  379. } catch (NumberFormatException e1) {
  380. }
  381. if (tmp > -1 && tmp <= 255) {
  382. if (currentProperty != null) {
  383. Color oldColor = currentProperty.getColor();
  384. Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
  385. currentProperty.setColor(color);
  386. colorChanged(color);
  387. }
  388. }
  389. }
  390. @Override
  391. public void changedUpdate(DocumentEvent e) {
  392. }
  393. });
  394. // ======================RED TEXTFIELD END==========================//
  395. // ======================GREEN TEXTFIELD============================//
  396. greenField = new JTextField();
  397. greenField.setColumns(10);
  398. greenField.getDocument().addDocumentListener(new DocumentListener() {
  399. /*
  400. * if textField for Red changes, changes will applied in the
  401. * DataStructure "currentProperty" if Value is legit
  402. */
  403. @Override
  404. public void insertUpdate(DocumentEvent e) {
  405. int tmp = -1;
  406. try {
  407. tmp = Integer.parseInt(greenField.getText());
  408. } catch (NumberFormatException e1) {
  409. }
  410. if (tmp > -1 && tmp <= 255) {
  411. if (currentProperty != null) {
  412. Color oldColor = currentProperty.getColor();
  413. Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
  414. currentProperty.setColor(color);
  415. colorChanged(color);
  416. }
  417. }
  418. }
  419. @Override
  420. public void removeUpdate(DocumentEvent e) {
  421. int tmp = -1;
  422. try {
  423. tmp = Integer.parseInt(greenField.getText());
  424. } catch (NumberFormatException e1) {
  425. }
  426. if (tmp > -1 && tmp <= 255) {
  427. if (currentProperty != null) {
  428. Color oldColor = currentProperty.getColor();
  429. Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
  430. currentProperty.setColor(color);
  431. colorChanged(color);
  432. }
  433. }
  434. }
  435. @Override
  436. public void changedUpdate(DocumentEvent e) {
  437. }
  438. });
  439. // ======================GREEN TEXTFIELD END========================//
  440. // ======================BLUE TEXTFIELD=============================//
  441. blueField = new JTextField();
  442. blueField.setColumns(10);
  443. blueField.getDocument().addDocumentListener(new DocumentListener() {
  444. /*
  445. * if textField for Red changes, changes will applied in the
  446. * DataStructure "currentProperty" if Value is legit
  447. */
  448. @Override
  449. public void insertUpdate(DocumentEvent e) {
  450. int tmp = -1;
  451. try {
  452. tmp = Integer.parseInt(blueField.getText());
  453. } catch (NumberFormatException e1) {
  454. }
  455. if (tmp > -1 && tmp <= 255) {
  456. if (currentProperty != null) {
  457. Color oldColor = currentProperty.getColor();
  458. Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
  459. currentProperty.setColor(color);
  460. colorChanged(color);
  461. }
  462. }
  463. }
  464. @Override
  465. public void removeUpdate(DocumentEvent e) {
  466. int tmp = -1;
  467. try {
  468. tmp = Integer.parseInt(blueField.getText());
  469. } catch (NumberFormatException e1) {
  470. }
  471. if (tmp > -1 && tmp <= 255) {
  472. if (currentProperty != null) {
  473. Color oldColor = currentProperty.getColor();
  474. Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
  475. currentProperty.setColor(color);
  476. colorChanged(color);
  477. }
  478. }
  479. }
  480. @Override
  481. public void changedUpdate(DocumentEvent e) {
  482. }
  483. });
  484. // ======================BLUE TEXTFIELD END=========================//
  485. // ======================GRAPH NR TEXTFIELD=========================//
  486. graphNrTxtField = new JTextField();
  487. graphNrTxtField.setColumns(10);
  488. graphNrTxtField.getDocument().addDocumentListener(new DocumentListener() {
  489. /*
  490. * if textField for Red changes, changes will applied in the
  491. * DataStructure "currentProperty" if Value is legit
  492. */
  493. @Override
  494. public void insertUpdate(DocumentEvent e) {
  495. if (currentProperty != null) {
  496. currentProperty.setGraph(graphNrTxtField.getText());
  497. }
  498. }
  499. @Override
  500. public void removeUpdate(DocumentEvent e) {
  501. if (currentProperty != null) {
  502. currentProperty.setGraph(graphNrTxtField.getText());
  503. }
  504. }
  505. @Override
  506. public void changedUpdate(DocumentEvent e) {
  507. }
  508. });
  509. // ======================= GRAPH NR TEXTFIELD END==================//
  510. //======================== ADD BUTTON =============================//
  511. JButton btnAdd = new JButton("Add");
  512. btnAdd.addActionListener(new ActionListener() {
  513. public void actionPerformed(ActionEvent e) {
  514. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode) objectTree
  515. .getLastSelectedPathComponent();
  516. if (selectedNode == null) {
  517. return;
  518. } else {
  519. if (selectedNode.getLevel() == 3 || (selectedNode.getLevel() == 2 &&
  520. (selectedNode.getParent().toString().equals(HOLON) || selectedNode.getParent().toString().equals(MAIN_GRID) ))) {
  521. StatisticGraphPanel tmp = null;
  522. if (graphNrTxtField.getText().length() > 0) {
  523. if (!graphHashtable.containsKey(graphNrTxtField.getText())
  524. && graphNrTxtField.getText().length() > 0) {
  525. tmp = new StatisticGraphPanel(controller.getModel(), controller,
  526. graphNrTxtField.getText(), graphHashtable);
  527. graphPanel.add(tmp);
  528. graphPanel.add(Box.createRigidArea(new Dimension(50, 50)));
  529. graphPanel.revalidate();
  530. graphPanel.updateUI();
  531. graphHashtable.put(graphNrTxtField.getText(), tmp);
  532. }
  533. String object = ((DefaultMutableTreeNode) selectedNode.getParent()).toString();
  534. String property = selectedNode.toString();
  535. AbstractCpsObject absCps = null;
  536. if(!object.equals(MAIN_GRID) && !object.equals(HOLON)){
  537. GraphDataSet dataSet = objectHashtable.get(object);
  538. absCps = dataSet.getObject();
  539. }
  540. TrackedDataSet tds = new TrackedDataSet(absCps, propValTable.get(property),
  541. currentProperty.getColor());
  542. graphHashtable.get(graphNrTxtField.getText()).addObjec(tds);
  543. }
  544. }
  545. }
  546. }
  547. });
  548. //============================== ADD BUTTON END ==============================//
  549. //=========================== WINDOWBUILDER COMPONENTS ====================//
  550. JScrollPane scrollPane = new JScrollPane();
  551. scrollPane.setBorder(null);
  552. splitPane.setRightComponent(scrollPane);
  553. JPanel editPanel = new JPanel();
  554. //editPanel.setBounds(0,0,600,600);
  555. editPanel.setPreferredSize(new Dimension(170, 210));
  556. //scrollPane.setBounds(0,0,600,600);
  557. scrollPane.setViewportView(editPanel);
  558. editPanel.setLayout(null);
  559. JLabel lblObject = new JLabel("Object(s):");
  560. lblObject.setBounds(10, 11, 59, 20);
  561. editPanel.add(lblObject);
  562. showObjectlbl = new JLabel("...");
  563. showObjectlbl.setBounds(69, 11, 101, 20);
  564. editPanel.add(showObjectlbl);
  565. JLabel lblProperty = new JLabel("Property:");
  566. lblProperty.setBounds(10, 36, 59, 20);
  567. editPanel.add(lblProperty);
  568. showPropertylbl = new JLabel("...");
  569. showPropertylbl.setBounds(69, 36, 101, 20);
  570. editPanel.add(showPropertylbl);
  571. JLabel lblGraph = new JLabel("Graph:");
  572. lblGraph.setBounds(10, 61, 49, 23);
  573. editPanel.add(lblGraph);
  574. graphNrTxtField.setColumns(10);
  575. graphNrTxtField.setBounds(69, 61, 101, 23);
  576. editPanel.add(graphNrTxtField);
  577. JLabel lblColor = new JLabel("Color:");
  578. lblColor.setBounds(10, 95, 49, 23);
  579. editPanel.add(lblColor);
  580. colorComboBox.setBounds(69, 95, 101, 23);
  581. editPanel.add(colorComboBox);
  582. JLabel lblR = new JLabel("R");
  583. lblR.setBounds(10, 139, 11, 14);
  584. editPanel.add(lblR);
  585. redField.setColumns(10);
  586. redField.setBounds(22, 136, 37, 20);
  587. editPanel.add(redField);
  588. JLabel lblG = new JLabel("G");
  589. lblG.setBounds(68, 139, 11, 14);
  590. editPanel.add(lblG);
  591. greenField.setColumns(10);
  592. greenField.setBounds(79, 136, 37, 20);
  593. editPanel.add(greenField);
  594. JLabel lblB = new JLabel("B");
  595. lblB.setBounds(126, 139, 10, 14);
  596. editPanel.add(lblB);
  597. blueField.setColumns(10);
  598. blueField.setBounds(133, 136, 37, 20);
  599. editPanel.add(blueField);
  600. colorPanel = new JPanel();
  601. colorPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
  602. colorPanel.setBackground(Color.WHITE);
  603. colorPanel.setBounds(10, 164, 59, 38);
  604. editPanel.add(colorPanel);
  605. btnAdd.setBounds(10, 213, 59, 23);
  606. editPanel.add(btnAdd);
  607. splitPane.setDividerLocation(220);
  608. //============================= WINDOWBUILDER COMPONENTS END =================//
  609. }
  610. //=============================== END CONSTRUCTOR ==============================//
  611. //=============================== METHODS ======================================//
  612. @Override
  613. public void repaintTree() {
  614. treeModel.reload();
  615. }
  616. @Override
  617. public void addTrackedObject(ArrayList<AbstractCpsObject> hlList) {
  618. objectsNode.removeAllChildren();
  619. switchesNode.removeAllChildren();
  620. groupNode.removeAllChildren();
  621. objectHashtable.clear();
  622. if (hlList.size() > 0 && hlList != null) {
  623. for (AbstractCpsObject abs : hlList) {
  624. String name = abs.getName() + " " + abs.getId();
  625. DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(name);
  626. Hashtable<String, PropertyDataSet> tmpHash = new Hashtable<String, PropertyDataSet>();
  627. //HolonObjects
  628. if(abs instanceof HolonObject){
  629. tmp.add(new DefaultMutableTreeNode(TOT_PROD_OBJ));
  630. tmp.add(new DefaultMutableTreeNode(TOT_CONS_OBJ));
  631. tmp.add(new DefaultMutableTreeNode(NR_ACTIVE_ELEMENTS));
  632. tmpHash.put(TOT_PROD_OBJ, new PropertyDataSet());
  633. tmpHash.put(TOT_CONS_OBJ, new PropertyDataSet());
  634. tmpHash.put(NR_ACTIVE_ELEMENTS, new PropertyDataSet());
  635. objectsNode.add(tmp);
  636. }
  637. //HolonSwitches
  638. if(abs instanceof HolonSwitch){
  639. tmp.add(new DefaultMutableTreeNode(SW_ACTIVE));
  640. tmpHash.put(SW_ACTIVE, new PropertyDataSet());
  641. switchesNode.add(tmp);
  642. }
  643. //NodesOfNodes
  644. if(abs instanceof CpsUpperNode){
  645. tmp.add(new DefaultMutableTreeNode(TOT_PROD_GRID));
  646. tmp.add(new DefaultMutableTreeNode(TOT_CONS_GRID));
  647. tmpHash.put(TOT_PROD_GRID, new PropertyDataSet());
  648. tmpHash.put(TOT_CONS_GRID, new PropertyDataSet());
  649. groupNode.add(tmp);
  650. }
  651. GraphDataSet gS = new GraphDataSet(abs, tmpHash);
  652. objectHashtable.put(name, gS);
  653. }
  654. }
  655. if(objectsNode.getChildCount() == 0){
  656. objectsNode.add(new DefaultMutableTreeNode("empty"));
  657. }
  658. if(switchesNode.getChildCount() == 0){
  659. switchesNode.add(new DefaultMutableTreeNode("empty"));
  660. }
  661. if(groupNode.getChildCount() == 0){
  662. groupNode.add(new DefaultMutableTreeNode("empty"));
  663. }
  664. }
  665. public void colorChanged(Color color) {
  666. colorPanel.setBackground(color);
  667. }
  668. public void resetFields() {
  669. colorPanel.setBackground(Color.WHITE);
  670. redField.setText("");
  671. greenField.setText("");
  672. blueField.setText("");
  673. colorComboBox.setSelectedIndex(0);
  674. }
  675. public void disableFields() {
  676. redField.setEnabled(false);
  677. greenField.setEnabled(false);
  678. blueField.setEnabled(false);
  679. graphNrTxtField.setEnabled(false);
  680. colorComboBox.setEnabled(false);
  681. colorPanel.setBackground(Color.LIGHT_GRAY);
  682. }
  683. public void enableFields() {
  684. redField.setEnabled(true);
  685. greenField.setEnabled(true);
  686. blueField.setEnabled(true);
  687. graphNrTxtField.setEnabled(true);
  688. colorComboBox.setEnabled(true);
  689. colorPanel.setBackground(Color.WHITE);
  690. }
  691. public void repaintGraphs() {
  692. for (StatisticGraphPanel sg : graphHashtable.values()) {
  693. sg.calcMaximum();
  694. sg.addValues();
  695. sg.repaint();
  696. }
  697. }
  698. private static void addPopup(Component component, final JPopupMenu popup) {
  699. }
  700. }