source: src/main/java/genius/gui/panels/ExtendedCheckboxPanel.java@ 346

Last change on this file since 346 was 30, checked in by dimitrios, 6 years ago

Additions to uncertainty framework to support tournament configuration and command line running

File size: 2.0 KB
Line 
1package genius.gui.panels;
2
3
4
5import java.awt.BorderLayout;
6import java.awt.event.MouseEvent;
7import java.awt.event.MouseListener;
8
9import javax.swing.JCheckBox;
10import javax.swing.JLabel;
11import javax.swing.JPanel;
12
13import genius.core.listener.Listener;
14
15/** Another implementation of the CheckBox Panel. Uses Swing's JCheckBox. Works only with mouse at the moment
16 * @author dimtsi
17 *
18 */
19public class ExtendedCheckboxPanel extends JPanel{
20
21 private JLabel label;
22 private JCheckBox checkBox;
23 private BooleanModel model;
24
25 /**
26 *
27 * @param text
28 * the text for the label
29 * @param boolModel
30 * the boolean model
31 */
32 public ExtendedCheckboxPanel(final String text, final BooleanModel boolModel) {
33 this.model = boolModel;
34
35 setLayout(new BorderLayout());
36 label = new JLabel(text);
37 checkBox = new JCheckBox();
38 enable1();
39
40 // connect the box to the model,
41
42 add(label, BorderLayout.CENTER);
43 add(checkBox, BorderLayout.EAST);
44
45 checkBox.addMouseListener(new MouseListener() {
46
47 @Override
48 public void mouseClicked(MouseEvent arg0) {
49 model.setValue(checkBox.isSelected());
50 }
51
52
53 @Override
54 public void mouseEntered(MouseEvent arg0) {
55 // TODO Auto-generated method stub
56
57 }
58
59 @Override
60 public void mouseExited(MouseEvent arg0) {
61 // TODO Auto-generated method stub
62
63 }
64
65 @Override
66 public void mousePressed(MouseEvent arg0) {
67 // TODO Auto-generated method stub
68
69 }
70
71 @Override
72 public void mouseReleased(MouseEvent arg0) {
73 // TODO Auto-generated method stub
74
75 }
76 });
77
78 model.addListener(new Listener<Boolean>() {
79
80 @Override
81 public void notifyChange(Boolean data) {
82 checkBox.setSelected(data);
83 enable1();
84 }
85 });
86 }
87 /**
88 * Update enabled-ness of panel. Just calling enable() doesn nothing?
89 */
90 private void enable1() {
91 boolean enabled = !model.isLocked();
92 checkBox.setEnabled(enabled);
93 label.setEnabled(enabled);
94 }
95
96 public JCheckBox getCheckBox() {
97 return checkBox;
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.