splitPane.java 20 KB

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