splitPane.java 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618
  1. package ui.view;
  2. import javax.swing.JSplitPane;
  3. import javax.swing.JScrollPane;
  4. import javax.swing.JPanel;
  5. import java.util.ArrayList;
  6. import java.util.Hashtable;
  7. import java.util.Random;
  8. import javax.swing.GroupLayout;
  9. import javax.swing.GroupLayout.Alignment;
  10. import javax.swing.JLabel;
  11. import javax.swing.LayoutStyle.ComponentPlacement;
  12. import javax.swing.event.DocumentEvent;
  13. import javax.swing.event.DocumentListener;
  14. import javax.swing.event.TreeSelectionEvent;
  15. import javax.swing.event.TreeSelectionListener;
  16. import javax.swing.tree.DefaultMutableTreeNode;
  17. import javax.swing.tree.DefaultTreeModel;
  18. import javax.swing.tree.MutableTreeNode;
  19. import javax.swing.tree.TreeNode;
  20. import DataSets.GraphDataSet;
  21. import DataSets.PropertyDataSet;
  22. import classes.HolonObject;
  23. import interfaces.GraphListener;
  24. import ui.controller.Control;
  25. import javax.swing.JTextField;
  26. import javax.swing.JComboBox;
  27. import javax.swing.JButton;
  28. import javax.swing.JTree;
  29. import java.awt.Color;
  30. import java.awt.event.ActionEvent;
  31. import java.awt.event.ActionListener;
  32. import java.awt.event.ItemEvent;
  33. import java.awt.event.ItemListener;
  34. import javax.swing.border.CompoundBorder;
  35. import javax.swing.border.LineBorder;
  36. import javax.swing.JPopupMenu;
  37. import java.awt.Component;
  38. import java.awt.Dimension;
  39. import java.awt.event.MouseAdapter;
  40. import java.awt.event.MouseEvent;
  41. import javax.swing.JMenuItem;
  42. import javax.swing.BorderFactory;
  43. import javax.swing.Box;
  44. import javax.swing.BoxLayout;
  45. import java.awt.FlowLayout;
  46. import java.awt.BorderLayout;
  47. public class splitPane extends JSplitPane implements GraphListener {
  48. private JTextField graphNrTxtField;
  49. private JTextField redField;
  50. private JTextField greenField;
  51. private JTextField blueField;
  52. private JTree objectTree;
  53. private DefaultTreeModel treeModel;
  54. private DefaultMutableTreeNode objectsNode;
  55. private DefaultMutableTreeNode wholeHolon;
  56. private Hashtable<String, GraphDataSet> objectHashtable;
  57. private JPanel colorPanel;
  58. private PropertyDataSet currentProperty = new PropertyDataSet();
  59. private JComboBox colorComboBox;
  60. private Control controller;
  61. private JPanel graphPanel;
  62. JLabel showObjectlbl;
  63. JLabel showPropertylbl;
  64. public splitPane(Control cont) {
  65. //this.rightComponent
  66. this.controller = cont;
  67. objectHashtable = new Hashtable<String, GraphDataSet>();
  68. JScrollPane dataPane = new JScrollPane();
  69. setLeftComponent(dataPane);
  70. JPanel panel = new JPanel();
  71. dataPane.setViewportView(panel);
  72. JScrollPane treeScrollPane = new JScrollPane();
  73. JLabel lblObject = new JLabel("Object(s):");
  74. showObjectlbl = new JLabel("...");
  75. JLabel lblProperty = new JLabel("Property:");
  76. showPropertylbl = new JLabel("...");
  77. JLabel lblGraph = new JLabel("Graph:");
  78. JLabel lblColor = new JLabel("Color:");
  79. colorComboBox = new JComboBox();
  80. colorComboBox.addItem("");
  81. colorComboBox.addItem("Red");
  82. colorComboBox.addItem("Blue");
  83. colorComboBox.addItem("Green");
  84. colorComboBox.addItem("Yellow");
  85. colorComboBox.addItem("Orange");
  86. colorComboBox.addItem("Cyan");
  87. colorComboBox.addItem("Magenta");
  88. colorComboBox.addItem("Pink");
  89. colorComboBox.addItem("Gray");
  90. colorComboBox.addItem("Random");
  91. colorComboBox.addItemListener(new ItemListener(){
  92. @Override
  93. public void itemStateChanged(ItemEvent e) {
  94. String colorName = (String) colorComboBox.getSelectedItem();
  95. Color tmpColor = Color.WHITE;
  96. switch(colorName){
  97. case "" : tmpColor = currentProperty.getColor();
  98. break;
  99. case "Red": tmpColor = Color.RED;
  100. colorChanged(tmpColor);
  101. break;
  102. case "Blue":tmpColor = Color.BLUE;
  103. colorChanged(tmpColor);
  104. break;
  105. case "Green":tmpColor = Color.GREEN;
  106. colorChanged(tmpColor);
  107. break;
  108. case "Yellow":tmpColor = Color.YELLOW;
  109. colorChanged(tmpColor);
  110. break;
  111. case "Orange":tmpColor = Color.ORANGE;
  112. colorChanged(tmpColor);
  113. break;
  114. case "Cyan":tmpColor = Color.CYAN;
  115. colorChanged(tmpColor);
  116. break;
  117. case "Magenta":tmpColor = Color.MAGENTA;
  118. colorChanged(tmpColor);
  119. break;
  120. case "Pink":tmpColor = Color.PINK;
  121. colorChanged(tmpColor);
  122. break;
  123. case "Gray":tmpColor = Color.GRAY;
  124. colorChanged(tmpColor);
  125. break;
  126. case "Random":Random rdm = new Random();
  127. tmpColor = new Color(rdm.nextInt(255),rdm.nextInt(255),rdm.nextInt(255));
  128. }
  129. redField.setText(Integer.toString(tmpColor.getRed()));
  130. greenField.setText(Integer.toString(tmpColor.getGreen()));
  131. blueField.setText(Integer.toString(tmpColor.getBlue()));
  132. }
  133. });
  134. //====================GRAPH NR TEXTFIELD======================//
  135. graphNrTxtField = new JTextField();
  136. graphNrTxtField.setColumns(10);
  137. graphNrTxtField.getDocument().addDocumentListener(new DocumentListener(){
  138. /*
  139. * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
  140. * if Value is legit
  141. */
  142. @Override
  143. public void insertUpdate(DocumentEvent e) {
  144. if(currentProperty != null){
  145. currentProperty.setGraph(graphNrTxtField.getText());
  146. }
  147. }
  148. @Override
  149. public void removeUpdate(DocumentEvent e) {
  150. if(currentProperty != null){
  151. currentProperty.setGraph(graphNrTxtField.getText());
  152. }
  153. }
  154. @Override
  155. public void changedUpdate(DocumentEvent e) {
  156. }
  157. });
  158. //====================GRAPH NR TEXTFIELD END==================//
  159. //====================RED TEXTFIELD===========================//
  160. redField = new JTextField();
  161. redField.setColumns(10);
  162. redField.getDocument().addDocumentListener(new DocumentListener(){
  163. /*
  164. * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
  165. * if Value is legit
  166. */
  167. @Override
  168. public void insertUpdate(DocumentEvent e) {
  169. int tmp = -1;
  170. try{
  171. tmp = Integer.parseInt(redField.getText());
  172. }catch(NumberFormatException e1){
  173. }
  174. if(tmp > -1 && tmp <= 255){
  175. if(currentProperty != null){
  176. Color oldColor = currentProperty.getColor();
  177. Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
  178. currentProperty.setColor(color);
  179. colorChanged(color);
  180. }
  181. }
  182. }
  183. @Override
  184. public void removeUpdate(DocumentEvent e) {
  185. int tmp = -1;
  186. try{
  187. tmp = Integer.parseInt(redField.getText());
  188. }catch(NumberFormatException e1){
  189. }
  190. if(tmp > -1 && tmp <= 255){
  191. if(currentProperty != null){
  192. Color oldColor = currentProperty.getColor();
  193. Color color = new Color(tmp, oldColor.getGreen(), oldColor.getBlue());
  194. currentProperty.setColor(color);
  195. colorChanged(color);
  196. }
  197. }
  198. }
  199. @Override
  200. public void changedUpdate(DocumentEvent e) {
  201. }
  202. });
  203. //======================RED TEXTFIELD END==========================//
  204. //======================GREEN TEXTFIELD============================//
  205. greenField = new JTextField();
  206. greenField.setColumns(10);
  207. greenField.getDocument().addDocumentListener(new DocumentListener(){
  208. /*
  209. * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
  210. * if Value is legit
  211. */
  212. @Override
  213. public void insertUpdate(DocumentEvent e) {
  214. int tmp = -1;
  215. try{
  216. tmp = Integer.parseInt(greenField.getText());
  217. }catch(NumberFormatException e1){
  218. }
  219. if(tmp > -1 && tmp <= 255){
  220. if(currentProperty != null){
  221. Color oldColor = currentProperty.getColor();
  222. Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
  223. currentProperty.setColor(color);
  224. colorChanged(color);
  225. }
  226. }
  227. }
  228. @Override
  229. public void removeUpdate(DocumentEvent e) {
  230. int tmp = -1;
  231. try{
  232. tmp = Integer.parseInt(greenField.getText());
  233. }catch(NumberFormatException e1){
  234. }
  235. if(tmp > -1 && tmp <= 255){
  236. if(currentProperty != null){
  237. Color oldColor = currentProperty.getColor();
  238. Color color = new Color(oldColor.getRed(), tmp, oldColor.getBlue());
  239. currentProperty.setColor(color);
  240. colorChanged(color);
  241. }
  242. }
  243. }
  244. @Override
  245. public void changedUpdate(DocumentEvent e) {
  246. }
  247. });
  248. //======================GREEN TEXTFIELD END========================//
  249. //======================BLUE TEXTFIELD=============================//
  250. blueField = new JTextField();
  251. blueField.setColumns(10);
  252. blueField.getDocument().addDocumentListener(new DocumentListener(){
  253. /*
  254. * if textField for Red changes, changes will applied in the DataStructure "currentProperty"
  255. * if Value is legit
  256. */
  257. @Override
  258. public void insertUpdate(DocumentEvent e) {
  259. int tmp = -1;
  260. try{
  261. tmp = Integer.parseInt(blueField.getText());
  262. }catch(NumberFormatException e1){
  263. }
  264. if(tmp > -1 && tmp <= 255){
  265. if(currentProperty != null){
  266. Color oldColor = currentProperty.getColor();
  267. Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
  268. currentProperty.setColor(color);
  269. colorChanged(color);
  270. }
  271. }
  272. }
  273. @Override
  274. public void removeUpdate(DocumentEvent e) {
  275. int tmp = -1;
  276. try{
  277. tmp = Integer.parseInt(blueField.getText());
  278. }catch(NumberFormatException e1){
  279. }
  280. if(tmp > -1 && tmp <= 255){
  281. if(currentProperty != null){
  282. Color oldColor = currentProperty.getColor();
  283. Color color = new Color(oldColor.getRed(), oldColor.getGreen(), tmp);
  284. currentProperty.setColor(color);
  285. colorChanged(color);
  286. }
  287. }
  288. }
  289. @Override
  290. public void changedUpdate(DocumentEvent e) {
  291. }
  292. });
  293. //======================BLUE TEXTFIELD END=========================//
  294. JLabel lblR = new JLabel("R:");
  295. JLabel lblG = new JLabel("G:");
  296. JLabel lblB = new JLabel("B:");
  297. JButton btnAdd = new JButton("Add");
  298. btnAdd.addActionListener(new ActionListener() {
  299. public void actionPerformed(ActionEvent e) {
  300. /*
  301. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
  302. if(selectedNode == null){
  303. return;
  304. }else{
  305. if(selectedNode.getLevel() == 3){
  306. }
  307. }
  308. */
  309. StatisticGraphPanel tmp = new StatisticGraphPanel(controller.getModel(), controller, graphNrTxtField.getText());
  310. tmp.setPreferredSize(new Dimension(280,120));
  311. tmp.setMaximumSize(new Dimension(1000,120));
  312. tmp.setMinimumSize(new Dimension(100,45));
  313. tmp.setBorder(new LineBorder(new Color(0, 0, 0), 1));
  314. graphPanel.add(tmp);
  315. graphPanel.add(Box.createRigidArea(new Dimension(50,50)));
  316. graphPanel.revalidate();
  317. graphPanel.updateUI();
  318. }
  319. });
  320. colorPanel = new JPanel();
  321. colorPanel.setBorder(new LineBorder(new Color(0, 0, 0)));
  322. colorPanel.setBackground(Color.WHITE);
  323. GroupLayout gl_panel = new GroupLayout(panel);
  324. gl_panel.setHorizontalGroup(
  325. gl_panel.createParallelGroup(Alignment.LEADING)
  326. .addGroup(gl_panel.createSequentialGroup()
  327. .addContainerGap()
  328. .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING, false)
  329. .addComponent(treeScrollPane, Alignment.LEADING)
  330. .addGroup(Alignment.LEADING, gl_panel.createSequentialGroup()
  331. .addGroup(gl_panel.createParallelGroup(Alignment.LEADING)
  332. .addComponent(lblGraph)
  333. .addComponent(lblObject)
  334. .addComponent(lblProperty)
  335. .addComponent(lblColor)
  336. .addGroup(gl_panel.createSequentialGroup()
  337. .addComponent(lblR)
  338. .addPreferredGap(ComponentPlacement.RELATED)
  339. .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
  340. .addComponent(colorPanel, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  341. .addComponent(redField, GroupLayout.DEFAULT_SIZE, 37, Short.MAX_VALUE))))
  342. .addPreferredGap(ComponentPlacement.RELATED)
  343. .addGroup(gl_panel.createParallelGroup(Alignment.LEADING, false)
  344. .addComponent(showObjectlbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  345. .addComponent(showPropertylbl, GroupLayout.DEFAULT_SIZE, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  346. .addComponent(colorComboBox, 0, GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
  347. .addComponent(graphNrTxtField)
  348. .addGroup(gl_panel.createSequentialGroup()
  349. .addGroup(gl_panel.createParallelGroup(Alignment.TRAILING)
  350. .addComponent(btnAdd)
  351. .addGroup(gl_panel.createSequentialGroup()
  352. .addComponent(lblG)
  353. .addPreferredGap(ComponentPlacement.RELATED)
  354. .addComponent(greenField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))
  355. .addPreferredGap(ComponentPlacement.RELATED)
  356. .addComponent(lblB)
  357. .addPreferredGap(ComponentPlacement.RELATED)
  358. .addComponent(blueField, GroupLayout.PREFERRED_SIZE, 37, GroupLayout.PREFERRED_SIZE)))))
  359. .addGap(32))
  360. );
  361. gl_panel.setVerticalGroup(
  362. gl_panel.createParallelGroup(Alignment.LEADING)
  363. .addGroup(gl_panel.createSequentialGroup()
  364. .addContainerGap()
  365. .addComponent(treeScrollPane, GroupLayout.PREFERRED_SIZE, 174, GroupLayout.PREFERRED_SIZE)
  366. .addPreferredGap(ComponentPlacement.RELATED)
  367. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  368. .addComponent(lblObject, GroupLayout.PREFERRED_SIZE, 14, GroupLayout.PREFERRED_SIZE)
  369. .addComponent(showObjectlbl))
  370. .addPreferredGap(ComponentPlacement.RELATED)
  371. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  372. .addComponent(lblProperty)
  373. .addComponent(showPropertylbl))
  374. .addPreferredGap(ComponentPlacement.RELATED)
  375. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  376. .addComponent(lblGraph)
  377. .addComponent(graphNrTxtField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  378. .addPreferredGap(ComponentPlacement.RELATED)
  379. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  380. .addComponent(lblColor)
  381. .addComponent(colorComboBox, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  382. .addGap(18)
  383. .addGroup(gl_panel.createParallelGroup(Alignment.BASELINE)
  384. .addComponent(lblR)
  385. .addComponent(redField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  386. .addComponent(lblG)
  387. .addComponent(greenField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE)
  388. .addComponent(lblB)
  389. .addComponent(blueField, GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE, GroupLayout.PREFERRED_SIZE))
  390. .addPreferredGap(ComponentPlacement.RELATED)
  391. .addComponent(colorPanel, GroupLayout.PREFERRED_SIZE, 33, GroupLayout.PREFERRED_SIZE)
  392. .addPreferredGap(ComponentPlacement.RELATED)
  393. .addComponent(btnAdd)
  394. .addContainerGap(35, Short.MAX_VALUE))
  395. );
  396. objectTree = new JTree();
  397. treeModel = (DefaultTreeModel)objectTree.getModel();
  398. DefaultMutableTreeNode root = new DefaultMutableTreeNode("Statistics");
  399. wholeHolon = new DefaultMutableTreeNode("whole Holon");
  400. wholeHolon.add(new DefaultMutableTreeNode("total Production"));
  401. wholeHolon.add(new DefaultMutableTreeNode("total Consumption"));
  402. wholeHolon.add(new DefaultMutableTreeNode("Percentage of Supplied Objects"));
  403. wholeHolon.add(new DefaultMutableTreeNode("Percentage of not Supplied Objects"));
  404. wholeHolon.add(new DefaultMutableTreeNode("Percentage of partially Supplied Objects"));
  405. objectsNode = new DefaultMutableTreeNode("Objects");
  406. DefaultMutableTreeNode defaultNode = new DefaultMutableTreeNode("empty");
  407. objectsNode.add(defaultNode);
  408. treeModel.setRoot(root);
  409. root.add(wholeHolon);
  410. root.add(objectsNode);
  411. objectTree.setModel(treeModel);
  412. treeScrollPane.setViewportView(objectTree);
  413. JPopupMenu popupMenu = new JPopupMenu();
  414. addPopup(objectTree, popupMenu);
  415. JMenuItem mntmUntrack = new JMenuItem("Untrack");
  416. mntmUntrack.addActionListener(new ActionListener() {
  417. public void actionPerformed(ActionEvent e) {
  418. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
  419. if(selectedNode.getLevel() == 2 && !selectedNode.getParent().toString().equals("whole Holon")){
  420. String object = selectedNode.toString();
  421. controller.removeTrackingObj((HolonObject)objectHashtable.get(object).getObject());
  422. }
  423. }
  424. });
  425. popupMenu.add(mntmUntrack);
  426. objectTree.addTreeSelectionListener(new TreeSelectionListener(){
  427. @Override
  428. public void valueChanged(TreeSelectionEvent e) {
  429. resetFields();
  430. showObjectlbl.setText("...");
  431. showPropertylbl.setText("...");
  432. DefaultMutableTreeNode selectedNode = (DefaultMutableTreeNode)objectTree.getLastSelectedPathComponent();
  433. if(selectedNode == null){
  434. return;
  435. }else{
  436. if(selectedNode.getLevel() == 0){
  437. disableFields();
  438. }
  439. if(selectedNode.getLevel() == 1){
  440. disableFields();
  441. currentProperty = null;
  442. showObjectlbl.setText(selectedNode.toString());
  443. }
  444. if(selectedNode.getLevel() == 2){
  445. if(((DefaultMutableTreeNode)selectedNode.getParent()).toString().equals("whole Holon")){
  446. enableFields();
  447. showPropertylbl.setText(selectedNode.toString());
  448. showObjectlbl.setText(selectedNode.getParent().toString());
  449. }else{
  450. disableFields();
  451. currentProperty = null;
  452. showObjectlbl.setText(selectedNode.toString());
  453. }
  454. }
  455. if(selectedNode.getLevel() == 3){
  456. enableFields();
  457. String object = ((DefaultMutableTreeNode)selectedNode.getParent()).toString();
  458. String property = selectedNode.toString();
  459. currentProperty = objectHashtable.get(object).getPropertytTable().get(property);
  460. Color color = currentProperty.getColor();
  461. redField.setText(Integer.toString(color.getRed()));
  462. greenField.setText(Integer.toString(color.getGreen()));
  463. blueField.setText(Integer.toString(color.getBlue()));
  464. showObjectlbl.setText(object);
  465. showPropertylbl.setText(property);
  466. graphNrTxtField.setText(currentProperty.getAssignedGraph());
  467. colorPanel.setBackground(color);
  468. }
  469. }
  470. }
  471. });
  472. panel.setLayout(gl_panel);
  473. JScrollPane graphScrollPane = new JScrollPane();
  474. setRightComponent(graphScrollPane);
  475. graphPanel = new JPanel();
  476. graphPanel.setLayout(new BoxLayout(graphPanel, BoxLayout.Y_AXIS));
  477. graphPanel.revalidate();
  478. graphPanel.updateUI();
  479. graphScrollPane.setViewportView(graphPanel);
  480. repaintGraph();
  481. }
  482. @Override
  483. public void repaintGraph() {
  484. treeModel.reload();
  485. }
  486. @Override
  487. public void addTrackedObject(ArrayList<HolonObject> hlList) {
  488. objectsNode.removeAllChildren();
  489. objectHashtable.clear();
  490. if(hlList.size() > 0 && hlList != null){
  491. for(HolonObject hO : hlList){
  492. Hashtable<String, PropertyDataSet> tmpHash = new Hashtable<String, PropertyDataSet>();
  493. String name = hO.getName() + " " + hO.getID();
  494. DefaultMutableTreeNode tmp = new DefaultMutableTreeNode(name);
  495. tmp.add(new DefaultMutableTreeNode("total Production"));
  496. tmp.add(new DefaultMutableTreeNode("total Consumption"));
  497. tmp.add(new DefaultMutableTreeNode("number of activated Elements"));
  498. tmpHash.put("total Production", new PropertyDataSet());
  499. tmpHash.put("total Consumption", new PropertyDataSet());
  500. tmpHash.put("number of activated Elements", new PropertyDataSet());
  501. GraphDataSet gS = new GraphDataSet(hO, tmpHash);
  502. objectHashtable.put(name, gS);
  503. objectsNode.add(tmp);
  504. }
  505. }else{
  506. objectsNode.add(new DefaultMutableTreeNode("empty"));
  507. }
  508. }
  509. public void colorChanged(Color color){
  510. colorPanel.setBackground(color);
  511. }
  512. public void resetFields(){
  513. colorPanel.setBackground(Color.WHITE);
  514. redField.setText("");
  515. greenField.setText("");
  516. blueField.setText("");
  517. //graphNrTxtField.setText("");
  518. colorComboBox.setSelectedIndex(0);
  519. }
  520. public void disableFields(){
  521. redField.setEnabled(false);
  522. greenField.setEnabled(false);
  523. blueField.setEnabled(false);
  524. graphNrTxtField.setEnabled(false);
  525. colorComboBox.setEnabled(false);
  526. colorPanel.setBackground(Color.LIGHT_GRAY);
  527. }
  528. public void enableFields(){
  529. redField.setEnabled(true);
  530. greenField.setEnabled(true);
  531. blueField.setEnabled(true);
  532. graphNrTxtField.setEnabled(true);
  533. colorComboBox.setEnabled(true);
  534. colorPanel.setBackground(Color.WHITE);
  535. }
  536. private static void addPopup(Component component, final JPopupMenu popup) {
  537. component.addMouseListener(new MouseAdapter() {
  538. public void mousePressed(MouseEvent e) {
  539. if (e.isPopupTrigger()) {
  540. showMenu(e);
  541. }
  542. }
  543. public void mouseReleased(MouseEvent e) {
  544. if (e.isPopupTrigger()) {
  545. showMenu(e);
  546. }
  547. }
  548. private void showMenu(MouseEvent e) {
  549. popup.show(e.getComponent(), e.getX(), e.getY());
  550. }
  551. });
  552. }
  553. }