~ubuntu-branches/ubuntu/utopic/freemind/utopic

« back to all changes in this revision

Viewing changes to freemind/freemind/common/BooleanProperty.java

  • Committer: Bazaar Package Importer
  • Author(s): Benjamin Drung
  • Date: 2010-01-03 14:19:19 UTC
  • mfrom: (2.1.1 sid)
  • Revision ID: james.westby@ubuntu.com-20100103141919-m5az7dkicy21hqop
Tags: 0.9.0~rc6+dfsg-1ubuntu1
* Merge from Debian unstable (LP: #182927), remaining changes:
  - debian/copyright: add license/copyright for
    freemind/freemind/main/ExampleFileFilter.java

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * FreeMind - A Program for creating and viewing Mindmaps Copyright (C)
 
3
 * 2000-2006 Joerg Mueller, Daniel Polansky, Christian Foltin and others.
 
4
 * 
 
5
 * See COPYING for Details
 
6
 * 
 
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
 
10
 * version.
 
11
 * 
 
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
 
15
 * details.
 
16
 * 
 
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.
 
20
 * 
 
21
 * Created on 25.02.2006
 
22
 */
 
23
/* $Id: BooleanProperty.java,v 1.1.2.3.2.2 2007/08/05 20:33:12 christianfoltin Exp $ */
 
24
package freemind.common;
 
25
 
 
26
import java.awt.event.ItemEvent;
 
27
import java.awt.event.ItemListener;
 
28
import java.beans.PropertyChangeEvent;
 
29
import java.beans.PropertyChangeListener;
 
30
 
 
31
import javax.swing.JCheckBox;
 
32
import javax.swing.JLabel;
 
33
 
 
34
import com.jgoodies.forms.builder.DefaultFormBuilder;
 
35
 
 
36
public class BooleanProperty extends PropertyBean implements PropertyControl
 
37
{
 
38
    static public final String FALSE_VALUE = "false";
 
39
 
 
40
    static public final String TRUE_VALUE = "true";
 
41
 
 
42
 
 
43
    protected String mFalseValue = FALSE_VALUE;
 
44
 
 
45
    protected String mTrueValue = TRUE_VALUE;
 
46
 
 
47
    String    description;
 
48
 
 
49
    String    label;
 
50
 
 
51
    JCheckBox mCheckBox = new JCheckBox();
 
52
    /**
 
53
     */
 
54
    public BooleanProperty(String description, String label)
 
55
    {
 
56
        super();
 
57
        this.description = description;
 
58
        this.label = label;
 
59
        mCheckBox.addItemListener(new ItemListener(){
 
60
 
 
61
            public void itemStateChanged(ItemEvent pE)
 
62
            {
 
63
                firePropertyChangeEvent();
 
64
            }});
 
65
    }
 
66
 
 
67
    public String getDescription()
 
68
    {
 
69
        return description;
 
70
    }
 
71
 
 
72
    public String getLabel()
 
73
    {
 
74
        return label;
 
75
    }
 
76
 
 
77
    public void setValue(String value)
 
78
    {
 
79
        if (value == null
 
80
                || !(value.toLowerCase().equals(mTrueValue) || value.toLowerCase()
 
81
                        .equals(mFalseValue)))
 
82
        {
 
83
            throw new IllegalArgumentException("Cannot set a boolean to "
 
84
                    + value);
 
85
        }
 
86
        mCheckBox.setSelected(value.toLowerCase().equals(mTrueValue));
 
87
    }
 
88
 
 
89
    public String getValue()
 
90
    {
 
91
        return mCheckBox.isSelected() ? mTrueValue : mFalseValue;
 
92
    }
 
93
 
 
94
    public void layout(DefaultFormBuilder builder, TextTranslator pTranslator)
 
95
    {
 
96
        JLabel label = builder.append(
 
97
                pTranslator.getText(getLabel()),
 
98
                mCheckBox);
 
99
        label.setToolTipText(pTranslator.getText(getDescription()));
 
100
    }
 
101
 
 
102
    public void setEnabled(boolean pEnabled) {
 
103
        mCheckBox.setEnabled(pEnabled);
 
104
    }
 
105
 
 
106
}