2 Launch4j (http://launch4j.sourceforge.net/)
3 Cross-platform Java application wrapper for creating Windows native executables.
5 Copyright (C) 2004, 2006 Grzegorz Kowal
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 * Created on Apr 30, 2005
25 package net.sf.launch4j.binding;
27 import java.awt.Color;
29 import javax.swing.JToggleButton;
31 import org.apache.commons.beanutils.PropertyUtils;
34 * Handles JToggleButton, JCheckBox
36 * @author Copyright (C) 2005 Grzegorz Kowal
38 public class JToggleButtonBinding implements Binding {
39 private final String _property;
40 private final JToggleButton _button;
41 private final boolean _defaultValue;
42 private final Color _validColor;
44 public JToggleButtonBinding(String property, JToggleButton button, boolean defaultValue) {
45 if (property == null || button == null) {
46 throw new NullPointerException();
48 if (property.equals("")) {
49 throw new IllegalArgumentException();
53 _defaultValue = defaultValue;
54 _validColor = _button.getBackground();
57 public String getProperty() {
61 public void clear(IValidatable bean) {
62 _button.setSelected(_defaultValue);
65 public void put(IValidatable bean) {
67 // String s = BeanUtils.getProperty(o, _property);
68 // _checkBox.setSelected("true".equals(s));
69 Boolean b = (Boolean) PropertyUtils.getProperty(bean, _property);
70 _button.setSelected(b != null && b.booleanValue());
71 } catch (Exception e) {
72 throw new BindingException(e);
76 public void get(IValidatable bean) {
78 PropertyUtils.setProperty(bean, _property, Boolean.valueOf(_button.isSelected()));
79 } catch (Exception e) {
80 throw new BindingException(e);
84 public void markValid() {
85 _button.setBackground(_validColor);
86 _button.requestFocusInWindow();
89 public void markInvalid() {
90 _button.setBackground(Binding.INVALID_COLOR);
93 public void setEnabled(boolean enabled) {
94 _button.setEnabled(enabled);