001: /*
002: $Id: BooleanParameter.java,v 1.6 2005/02/14 12:06:19 vauclair Exp $
003:
004: Copyright (C) 2002-2005 Sebastien Vauclair
005:
006: This file is part of Extensible Java Profiler.
007:
008: Extensible Java Profiler is free software; you can redistribute it and/or
009: modify it under the terms of the GNU General Public License as published by
010: the Free Software Foundation; either version 2 of the License, or
011: (at your option) any later version.
012:
013: Extensible Java Profiler is distributed in the hope that it will be useful,
014: but WITHOUT ANY WARRANTY; without even the implied warranty of
015: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
016: GNU General Public License for more details.
017:
018: You should have received a copy of the GNU General Public License
019: along with Extensible Java Profiler; if not, write to the Free Software
020: Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
021: */
022:
023: package ejp.presenter.api.filters.parameters;
024:
025: import javax.swing.JCheckBox;
026:
027: import ejp.presenter.gui.Utils;
028:
029: /**
030: * A Boolean parameter, graphically represented as a check box.
031: *
032: * @author Sebastien Vauclair
033: * @version <code>$Revision: 1.6 $<br>$Date: 2005/02/14 12:06:19 $</code>
034: */
035: public class BooleanParameter extends AbstractParameter {
036: // ///////////////////////////////////////////////////////////////////////////
037: // COMPONENTS
038: // ///////////////////////////////////////////////////////////////////////////
039:
040: /**
041: * The check box.
042: */
043: protected final JCheckBox jcbValue;
044:
045: // ///////////////////////////////////////////////////////////////////////////
046: // CONSTRUCTOR
047: // ///////////////////////////////////////////////////////////////////////////
048:
049: /**
050: * Creates a new Boolean parameter instance.
051: *
052: * @param aName
053: * the parameter's name.
054: * @param aTitle
055: * text caption of active state.
056: * @param aToolTipText
057: * tool-tip text.
058: */
059: public BooleanParameter(String aName, String aTitle,
060: String aToolTipText) {
061: super (aName, aTitle, aToolTipText);
062:
063: jcbValue = new JCheckBox();
064: Utils.setCommonProperties(jcbValue);
065: addLine("Enabled", "Click to enable/disable.", jcbValue, null);
066: }
067:
068: // ///////////////////////////////////////////////////////////////////////////
069: // READ-ONLY
070: // ///////////////////////////////////////////////////////////////////////////
071:
072: /**
073: * Implementation of read-only activating.
074: *
075: * Locks the check box's state.
076: */
077: public void setReadOnly() {
078: jcbValue.setEnabled(false);
079: }
080:
081: // ///////////////////////////////////////////////////////////////////////////
082: // ACCESSORS
083: // ///////////////////////////////////////////////////////////////////////////
084:
085: /**
086: * Sets value from object.
087: *
088: * Wrapper to <code>setValue(Boolean)</code>.
089: */
090: public void setValue(Object aObject) throws ClassCastException {
091: setValue((Boolean) aObject);
092: }
093:
094: /**
095: * Sets parameter's state.
096: *
097: * Current state is holded by the check box.
098: *
099: * @param aValue
100: * new state.
101: */
102: public void setValue(Boolean aValue) {
103: jcbValue.setSelected(aValue.booleanValue());
104: }
105:
106: /**
107: * Sets value from text.
108: *
109: * The constructor <code>Boolean(String)</code> is used to parse the string
110: * to a Boolean value; refer to it for syntax definition.
111: */
112: public void setValueAsText(String aTextValue) {
113: setValue(new Boolean(aTextValue));
114: }
115:
116: /**
117: * Gets value as an object.
118: *
119: * @return a <code>Boolean</code> value.
120: */
121: public Object getValue() {
122: return new Boolean(getBooleanValue());
123: }
124:
125: /**
126: * Gets current value of the parameter.
127: *
128: * @return a <code>boolean</code> value.
129: */
130: public boolean getBooleanValue() {
131: return jcbValue.isSelected();
132: }
133:
134: /**
135: * Gets value as text.
136: *
137: * The method <code>Boolean.toString()</code> is used to generate text.
138: */
139: public String getValueAsText() {
140: return getValue().toString();
141: }
142: }
|