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

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

Initial import : Genius 9.0.0

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