2
* FreeMind - A Program for creating and viewing Mindmaps Copyright (C)
3
* 2000-2006 Joerg Mueller, Daniel Polansky, Christian Foltin and others.
5
* See COPYING for Details
7
* This program is free software; you can redistribute it and/or modify it under
8
* the terms of the GNU General Public License as published by the Free Software
9
* Foundation; either version 2 of the License, or (at your option) any later
12
* This program is distributed in the hope that it will be useful, but WITHOUT
13
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
14
* FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
17
* You should have received a copy of the GNU General Public License along with
18
* this program; if not, write to the Free Software Foundation, Inc., 59 Temple
19
* Place - Suite 330, Boston, MA 02111-1307, USA.
21
* Created on 25.02.2006
23
/* $Id: BooleanProperty.java,v 1.1.2.3.2.2 2007/08/05 20:33:12 christianfoltin Exp $ */
24
package freemind.common;
26
import java.awt.event.ItemEvent;
27
import java.awt.event.ItemListener;
28
import java.beans.PropertyChangeEvent;
29
import java.beans.PropertyChangeListener;
31
import javax.swing.JCheckBox;
32
import javax.swing.JLabel;
34
import com.jgoodies.forms.builder.DefaultFormBuilder;
36
public class BooleanProperty extends PropertyBean implements PropertyControl
38
static public final String FALSE_VALUE = "false";
40
static public final String TRUE_VALUE = "true";
43
protected String mFalseValue = FALSE_VALUE;
45
protected String mTrueValue = TRUE_VALUE;
51
JCheckBox mCheckBox = new JCheckBox();
54
public BooleanProperty(String description, String label)
57
this.description = description;
59
mCheckBox.addItemListener(new ItemListener(){
61
public void itemStateChanged(ItemEvent pE)
63
firePropertyChangeEvent();
67
public String getDescription()
72
public String getLabel()
77
public void setValue(String value)
80
|| !(value.toLowerCase().equals(mTrueValue) || value.toLowerCase()
81
.equals(mFalseValue)))
83
throw new IllegalArgumentException("Cannot set a boolean to "
86
mCheckBox.setSelected(value.toLowerCase().equals(mTrueValue));
89
public String getValue()
91
return mCheckBox.isSelected() ? mTrueValue : mFalseValue;
94
public void layout(DefaultFormBuilder builder, TextTranslator pTranslator)
96
JLabel label = builder.append(
97
pTranslator.getText(getLabel()),
99
label.setToolTipText(pTranslator.getText(getDescription()));
102
public void setEnabled(boolean pEnabled) {
103
mCheckBox.setEnabled(pEnabled);