splitPane.java 20 KB

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