1 | package com.framsticks.gui.controls; |
---|
2 | |
---|
3 | import java.awt.Dimension; |
---|
4 | import java.awt.event.ActionEvent; |
---|
5 | import java.awt.event.ActionListener; |
---|
6 | |
---|
7 | import javax.swing.JCheckBox; |
---|
8 | |
---|
9 | import org.apache.logging.log4j.Logger; |
---|
10 | import org.apache.logging.log4j.LogManager; |
---|
11 | |
---|
12 | import com.framsticks.gui.Gui; |
---|
13 | import com.framsticks.params.types.BooleanParam; |
---|
14 | |
---|
15 | @SuppressWarnings("serial") |
---|
16 | public class CheckBoxControl extends ValueControl { |
---|
17 | |
---|
18 | private static final Logger log = LogManager.getLogger(CheckBoxControl.class.getName()); |
---|
19 | |
---|
20 | protected final JCheckBox checkBox; |
---|
21 | |
---|
22 | public CheckBoxControl(BooleanParam booleanParam) { |
---|
23 | super(booleanParam); |
---|
24 | checkBox = new JCheckBox(); |
---|
25 | checkBox.addActionListener(new ActionListener() { |
---|
26 | |
---|
27 | @Override |
---|
28 | public void actionPerformed(ActionEvent actionEvent) { |
---|
29 | log.debug("change to: {}", checkBox.isSelected()); |
---|
30 | notifyOfChange(); |
---|
31 | } |
---|
32 | }); |
---|
33 | this.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT)); |
---|
34 | Gui.addLeftToLabel(this, checkBox); |
---|
35 | } |
---|
36 | |
---|
37 | @Override |
---|
38 | public void pushValueToUserInterfaceImpl(Object value) { |
---|
39 | if (value == null) { |
---|
40 | return; |
---|
41 | } |
---|
42 | checkBox.setSelected((Boolean) value); |
---|
43 | } |
---|
44 | |
---|
45 | @Override |
---|
46 | public Object pullValueFromUserInterface() { |
---|
47 | return checkBox.isSelected(); |
---|
48 | } |
---|
49 | |
---|
50 | @Override |
---|
51 | public BooleanParam getParam() { |
---|
52 | return (BooleanParam) param; |
---|
53 | } |
---|
54 | |
---|
55 | @Override |
---|
56 | protected void updateEnabled(boolean enabled) { |
---|
57 | checkBox.setEnabled(enabled); |
---|
58 | } |
---|
59 | |
---|
60 | } |
---|