001: /*
002: * Jacareto Copyright (c) 2002-2005
003: * Applied Computer Science Research Group, Darmstadt University of
004: * Technology, Institute of Mathematics & Computer Science,
005: * Ludwigsburg University of Education, and Computer Based
006: * Learning Research Group, Aachen University. All rights reserved.
007: *
008: * Jacareto is free software; you can redistribute it and/or
009: * modify it under the terms of the GNU General Public
010: * License as published by the Free Software Foundation; either
011: * version 2 of the License, or (at your option) any later version.
012: *
013: * Jacareto 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 GNU
016: * General Public License for more details.
017: *
018: * You should have received a copy of the GNU General Public
019: * License along with Jacareto; if not, write to the Free
020: * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
021: *
022: */
023:
024: package jacareto.test;
025:
026: import jacareto.comp.Components;
027: import jacareto.system.Environment;
028:
029: import java.awt.Component;
030:
031: //import javax.swing.JSpinner;
032:
033: /**
034: * A JSpinner test.
035: *
036: * @author <a href="mailto:cspannagel@web.de">Uwe A. Kraemer</a>
037: * @version 1.0
038: */
039: public class JSpinnerTest extends JComponentTest {
040: Object spinnerValue;
041:
042: /**
043: * DOCUMENT ME!
044: *
045: * @param env
046: * @param componentName
047: * @param isIgnoring
048: * @param isCorrecting
049: * @param hasFocus DOCUMENT ME!
050: * @param isEnabled DOCUMENT ME!
051: * @param value DOCUMENT ME!
052: */
053: public JSpinnerTest(Environment env, String componentName,
054: boolean isIgnoring, boolean isCorrecting, boolean hasFocus,
055: boolean isEnabled, Object value) {
056: super (env, componentName, isIgnoring, isCorrecting, hasFocus,
057: isEnabled);
058: setSpinnerValue(value);
059: }
060:
061: /**
062: * DOCUMENT ME!
063: *
064: * @param env
065: * @param components
066: * @param component
067: */
068: public JSpinnerTest(Environment env, Components components,
069: Component component) {
070: super (env, components, component);
071: }
072:
073: /**
074: *
075: */
076: public JSpinnerTest() {
077: this (null, "", false, false, false, false, null);
078: }
079:
080: /**
081: * Evaluates the test. Should return <code>false</code> if the test fails, otherwise
082: * <code>true</code>. If the test has failed, the error message can be retrieved. by calling
083: * the method {@link #getEvaluationMessage()}. If {@link #isCorrecting()} returns
084: * <code>true</code>, after the test the fields (or whatever) of the component will be set to
085: * the right values in case of a failure. If {@link #isIgnoring()} returns <code>true</code>,
086: * the behavior of this method is exactly the same as in the opposite case, except it always
087: * returns <code>true</code>.
088: *
089: * @param components the components instance
090: *
091: * @return <code>true</code> if all is ok, otherwise <code>false</code>
092: */
093: public boolean evaluate(Components components) {
094: boolean result = true;
095:
096: //Since JSpinner is new to Java in JDK 1.4, this class is commented
097:
098: /* JSpinner spinner = null;
099:
100: //get the JSpinner object
101: Component component = components.getComponent (getComponentName());
102: if (component == null) {
103: setEvaluationMessage (language.getString ("Test.Failure.NoComponent"));
104: return false;
105: }
106: if (! (component instanceof JSpinner)) {
107: setEvaluationMessage (language.getString ("Test.Failure.WrongComponentType"));
108: return false;
109: }
110: spinner = (JSpinner) component;
111:
112: //Let's check if the spinner's value is correct
113: if (! (spinner.getValue().equals(getSpinnerValue())))
114: {
115: result = false;
116: }
117: setEvaluationMessage (language.getString ("JSpinnerTest.Failure.WrongValue"));
118:
119: //If the isCorrecting flag is set, let's set the correct values
120: if (isCorrecting()) {
121: spinner.setValue(getSpinnerValue());
122: }
123: */
124: return result;
125: }
126:
127: /**
128: * Returns a String which describes the content of the recordable shortly.
129: *
130: * @return a string with a short description of the recordable
131: */
132: public String toShortString() {
133: return getElementName();
134: }
135:
136: /**
137: * Returns the name of the recordable.
138: *
139: * @return the name
140: */
141: public String getElementName() {
142: return language.getString("Tests.JSliderTest.Name");
143: }
144:
145: /**
146: * Returns a description of the recordable.
147: *
148: * @return the description
149: */
150: public String getElementDescription() {
151: return language.getString("Tests.JSliderTest.Description");
152: }
153:
154: /**
155: * DOCUMENT ME!
156: *
157: * @return Object
158: */
159: public Object getSpinnerValue() {
160: return spinnerValue;
161: }
162:
163: /**
164: * DOCUMENT ME!
165: *
166: * @param object
167: */
168: public void setSpinnerValue(Object object) {
169: spinnerValue = object;
170: }
171:
172: protected void setEvaluationMessage(String evaluationMessage) {
173: super .setEvaluationMessage(getComponentName() + ": "
174: + evaluationMessage);
175: }
176: }
|