source: src/main/java/genius/gui/panels/RadioButtonPanel.java

Last change on this file was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.0 KB
Line 
1package genius.gui.panels;
2
3import java.awt.BorderLayout;
4import java.awt.event.MouseEvent;
5import java.awt.event.MouseListener;
6
7import javax.swing.JLabel;
8import javax.swing.JPanel;
9import javax.swing.JRadioButton;
10
11import genius.core.listener.Listener;
12
13/**
14 * Panel showing a checkbox with a title and value. This panel supports a
15 * BooleanModel (you can't with the default {@link Checkbox}).
16 */
17@SuppressWarnings("serial")
18public class RadioButtonPanel extends JPanel{
19
20 private JLabel label;
21 private JRadioButton button;
22 private BooleanModel model;
23
24 /**
25 *
26 * @param text
27 * the text for the label
28 * @param boolModel
29 * the boolean model
30 */
31 public RadioButtonPanel(final String text, final BooleanModel boolModel) {
32 this.model = boolModel;
33
34 setLayout(new BorderLayout());
35 label = new JLabel(text);
36 button = new JRadioButton("");
37 enable1();
38
39 // connect the box to the model,
40 add(button, BorderLayout.WEST);
41 add(label, BorderLayout.CENTER);
42
43 button.addMouseListener(new MouseListener() {
44
45 @Override
46 public void mouseClicked(MouseEvent arg0) {
47 model.setValue(true);
48 }
49
50
51 @Override
52 public void mouseEntered(MouseEvent arg0) {
53 // TODO Auto-generated method stub
54
55 }
56
57 @Override
58 public void mouseExited(MouseEvent arg0) {
59 // TODO Auto-generated method stub
60
61 }
62
63 @Override
64 public void mousePressed(MouseEvent arg0) {
65 // TODO Auto-generated method stub
66
67 }
68
69 @Override
70 public void mouseReleased(MouseEvent arg0) {
71 // TODO Auto-generated method stub
72
73 }
74 });
75
76 model.addListener(new Listener<Boolean>() {
77
78 @Override
79 public void notifyChange(Boolean data) {
80 button.setSelected(data);
81 enable1();
82 }
83 });
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 button.setEnabled(enabled);
93 label.setEnabled(enabled);
94 }
95
96 public JRadioButton getButton() {
97 return button;
98 }
99
100}
Note: See TracBrowser for help on using the repository browser.