001: /*
002: #IFNDEF ALT_LICENSE
003: ThinWire(R) RIA Ajax Framework
004: Copyright (C) 2003-2007 Custom Credit Systems
005:
006: This library is free software; you can redistribute it and/or modify it under
007: the terms of the GNU Lesser General Public License as published by the Free
008: Software Foundation; either version 2.1 of the License, or (at your option) any
009: later version.
010:
011: This library is distributed in the hope that it will be useful, but WITHOUT ANY
012: WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
013: PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
014:
015: You should have received a copy of the GNU Lesser General Public License along
016: with this library; if not, write to the Free Software Foundation, Inc., 59
017: Temple Place, Suite 330, Boston, MA 02111-1307 USA
018:
019: Users who would rather have a commercial license, warranty or support should
020: contact the following company who invented, built and supports the technology:
021:
022: Custom Credit Systems, Richardson, TX 75081, USA.
023: email: info@thinwire.com ph: +1 (888) 644-6405
024: http://www.thinwire.com
025: #ENDIF
026: [ v1.2_RC2 ]
027: */
028: package thinwire.ui;
029:
030: /**
031: * A CheckBox is a screen element that can either be checked or cleared, and operates independently of other elements.
032: * <p>
033: * <b>Example:</b> <br>
034: * <img src="doc-files/CheckBox-1.png"> <br>
035: *
036: * <pre>
037: * final CheckBox cb = new CheckBox("I am checked!");
038: * cb.setChecked(true);
039: * cb.setBounds(20, 20, 150, 30);
040: * cb.addPropertyChangeListener(CheckBox.PROPERTY_CHECKED, new PropertyChangeListener() {
041: * public void propertyChange(PropertyChangeEvent pce) {
042: * if (pce.getNewValue() == Boolean.TRUE) {
043: * cb.setText("I am checked");
044: * } else {
045: * cb.setText("I am unchecked");
046: * }
047: * }
048: * });
049: *
050: * Dialog d = new Dialog("CheckBox Test");
051: * d.setBounds(20, 20, 200, 100);
052: * d.getChildren().add(cb);
053: * d.setVisible(true);
054: * </pre>
055: *
056: * </p>
057: * <p>
058: * <b>Keyboard Navigation:</b><br>
059: * <table border="1">
060: * <tr>
061: * <td>KEY</td>
062: * <td>RESPONSE</td>
063: * <td>NOTE</td>
064: * </tr>
065: * <tr>
066: * <td>Space</td>
067: * <td>Fires PropertyChangeEvent( propertyName = CheckBox.PROPERTY_CHECKED )</td>
068: * <td>Only if the component has focus.</td>
069: * </tr>
070: * </table>
071: * </p>
072: * @author Joshua J. Gertzen
073: */
074: public class CheckBox extends AbstractTextComponent implements
075: CheckedComponent {
076: public static final String PROPERTY_CHECKED = "checked";
077:
078: private boolean checked;
079:
080: /**
081: * Constructs a new CheckBox with no text.
082: */
083: public CheckBox() {
084: this (null);
085: }
086:
087: /**
088: * Constructs a new CheckBox with the specified text.
089: * @param text the text to display on the right side of the CheckBox.
090: */
091: public CheckBox(String text) {
092: this (text, false);
093: }
094:
095: /**
096: * Constructs a new CheckBox with the specified text and initial checked state.
097: * @param text the text to display on the right side of the CheckBox.
098: * @param checked the initial checked state
099: */
100: public CheckBox(String text, boolean checked) {
101: setText(text);
102: setChecked(checked);
103: }
104:
105: public boolean isChecked() {
106: return checked;
107: }
108:
109: public void setChecked(boolean checked) {
110: boolean oldChecked = this.checked;
111: this.checked = checked;
112: firePropertyChange(this, PROPERTY_CHECKED, oldChecked, checked);
113: }
114: }
|