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 java.util.Iterator;
032:
033: import javax.swing.JCheckBoxMenuItem;
034:
035: /**
036: * Test class for testing <code>java.swing.JCheckBoMenuItem</code> components. The following
037: * criteria are tested by this class:
038: *
039: * <ul>
040: * <li>
041: * <b>is selected</b> - testes if the check box menu item is selected
042: * </li>
043: * </ul>
044: *
045: *
046: * @author uak
047: * @version 1.0
048: */
049: public class JCheckBoxMenuItemTest extends JMenuItemTest {
050: /** Contains whether the check box menu item is expected to be selected */
051: private boolean isSelected;
052:
053: /**
054: * Creates a new test with the specified values.
055: *
056: * @param env env the environment
057: * @param componentName the name of the component
058: * @param isIgnoring if the test result should be ignored
059: * @param isCorrecting if the values of the component should be corrected when the test has
060: * failed
061: * @param hasFocus if the component has the focus
062: * @param isEnabled if the component is set enabled
063: * @param btnText the text on the button
064: * @param isArmed if the the component is "armed"
065: * @param isSelected if the the component is selected
066: */
067: public JCheckBoxMenuItemTest(Environment env, String componentName,
068: boolean isIgnoring, boolean isCorrecting, boolean hasFocus,
069: boolean isEnabled, String btnText, boolean isArmed,
070: boolean isSelected) {
071: super (env, componentName, isIgnoring, isCorrecting, hasFocus,
072: isEnabled, btnText, isArmed);
073: setSelected(isSelected);
074: }
075:
076: /**
077: * Creates a new test with the values of the given component and default values.
078: *
079: * @param env the environment.
080: * @param components the components instance
081: * @param component the component to test. Must be of type
082: * <code>javax.swing.JRadioButtonMenuItem</code>.
083: */
084: public JCheckBoxMenuItemTest(Environment env,
085: Components components, Component component) {
086: super (env, components, component);
087: setSelected(((JCheckBoxMenuItem) component).getState());
088: }
089:
090: /**
091: * Creates a new test with default values and no environment. The environment should be defined
092: * with the method {@link jacareto.system.EnvironmentMember#setEnvironment(Environment)}
093: * before environment instances will be accessed.
094: */
095: public JCheckBoxMenuItemTest() {
096: this (null, "", false, false, false, true, "", false, false);
097: }
098:
099: /**
100: * @see jacareto.test.Test#evaluate(jacareto.comp.Components)
101: */
102: public boolean evaluate(Components components) {
103: setLastIgnored(isIgnoring());
104: setLastResult(false);
105: setLastCorrected(false);
106:
107: JCheckBoxMenuItem menuItem = null;
108:
109: // get the pane with the componentName
110: Component component = components
111: .getComponent(getComponentName());
112:
113: if (component == null) {
114: setEvaluationMessage(language
115: .getString("Tests.Test.Failure.NoComponent"));
116:
117: return false;
118: }
119:
120: if (!(component instanceof JCheckBoxMenuItem)) {
121: setEvaluationMessage(language
122: .getString("Tests.Test.Failure.WrongComponentType"));
123:
124: return false;
125: }
126:
127: menuItem = (JCheckBoxMenuItem) component;
128:
129: if (doTest(menuItem)) {
130: boolean result = true;
131: Iterator childIter = childrenIterator();
132:
133: while (childIter.hasNext() && result) {
134: result &= evaluateChild((Test) childIter.next(),
135: components);
136: }
137:
138: setLastResult(result);
139:
140: return result;
141: }
142:
143: if (isCorrecting()) {
144: //appendToEvaluationMessage("\n" + language.getString("Test.Correct"));
145: correct(menuItem);
146: setLastCorrected(true);
147: }
148:
149: //if(isIgnoring()) appendToEvaluationMessage("\n" + language.getString("Test.Ignored"));
150: return false;
151: }
152:
153: /**
154: * @see jacareto.test.JComponentTest#doTest(java.awt.Component)
155: */
156: protected boolean doTest(Component component) {
157: if (super .doTest(component)) {
158: JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) component;
159:
160: // check if the menu's components are correct
161: if (menuItem.getState() != isSelected()) {
162: setEvaluationMessage(language
163: .getString("Tests.JCheckBoxMenuItemTest.Failure.WrongState")
164: + "\n"
165: + language
166: .getString("Tests.Test.Failure.Expected")
167: + ": "
168: + isSelected()
169: + "\n"
170: + language
171: .getString("Tests.Test.Failure.Expected")
172: + ": " + menuItem.getState());
173:
174: return false;
175: }
176: } else {
177: return false;
178: }
179:
180: return true;
181: }
182:
183: /**
184: * @see jacareto.test.JComponentTest#correct(java.awt.Component)
185: */
186: protected void correct(Component component) {
187: super .correct(component);
188:
189: JCheckBoxMenuItem menuItem = (JCheckBoxMenuItem) component;
190: menuItem.setSelected(isSelected());
191: appendToEvaluationMessage("\n"
192: + getElementName()
193: + ": "
194: + language
195: .getString("Tests.JCheckBoxMenuItemTest.Correct.Select"));
196: }
197:
198: /**
199: * @see jacareto.struct.StructureElement#getElementName()
200: */
201: public String getElementName() {
202: return language.getString("Tests.JCheckBoxMenuItemTest.Name");
203: }
204:
205: /**
206: * @see jacareto.struct.StructureElement#getElementDescription()
207: */
208: public String getElementDescription() {
209: return language
210: .getString("Tests.JCheckBoxMenuItemTest.Description");
211: }
212:
213: /**
214: * @see jacareto.struct.StructureElement#toShortString()
215: */
216: public String toShortString() {
217: return getElementName();
218: }
219:
220: /**
221: * DOCUMENT ME!
222: *
223: * @return <code>true</code> if the tested check box menu item is expected to be selected, if
224: * not <code>false</code>.
225: */
226: public boolean isSelected() {
227: return isSelected;
228: }
229:
230: /**
231: * DOCUMENT ME!
232: *
233: * @param b whether the tested check box menu item is expected to be selected.
234: */
235: public void setSelected(boolean b) {
236: isSelected = b;
237: }
238: }
|