source: java/main/src/main/java/com/framsticks/gui/controls/CheckBoxControl.java @ 193

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

  • Property svn:eol-style set to native
File size: 1.4 KB
Line 
1package com.framsticks.gui.controls;
2
3import java.awt.Dimension;
4import java.awt.event.ActionEvent;
5import java.awt.event.ActionListener;
6
7import javax.swing.JCheckBox;
8
9import org.apache.logging.log4j.Logger;
10import org.apache.logging.log4j.LogManager;
11
12import com.framsticks.gui.Gui;
13import com.framsticks.params.types.BooleanParam;
14
15@SuppressWarnings("serial")
16public 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}
Note: See TracBrowser for help on using the repository browser.