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.editor;
025:
026: import jacareto.struct.StructureElement;
027: import jacareto.system.Environment;
028: import jacareto.test.JSliderTest;
029: import jacareto.toolkit.event.TextValueListener;
030: import jacareto.toolkit.swing.IntegerTextField;
031:
032: import javax.swing.JLabel;
033: import javax.swing.event.DocumentEvent;
034:
035: /**
036: * This class is the editor class for <code>jacareto.test.JSliderTest</code> tests.
037: *
038: * @author <a href="mailto:coch@rbg.informatik.tu-darmstadt.de">Carola Coch</a>
039: * @version 1.0
040: */
041: public class JSliderTestEditor extends JComponentTestEditor {
042: /** Contains the selected value to test it. */
043: protected IntegerTextField selectedValueField;
044:
045: /** Contains the lower bound to test it. */
046: protected IntegerTextField minValueField;
047:
048: /** Contains the upper bound to test it. */
049: protected IntegerTextField maxValueField;
050:
051: /**
052: * Creates an editor with the specified env.
053: *
054: * @param env the environment
055: */
056: public JSliderTestEditor(Environment env) {
057: super (env);
058:
059: // The selected value label
060: c.gridx = 0;
061: c.gridy += 1;
062: c.gridwidth = 1;
063:
064: JLabel selectedValueLabel = new JLabel(language
065: .getString("Tests.JSliderTest.SelectedValue")
066: + ":");
067: editorPanel.add(selectedValueLabel, c);
068:
069: // The selected value textfield
070: c.gridx = 1;
071: selectedValueField = new IntegerTextField(0, 5);
072: selectedValueField.getDocument().addDocumentListener(
073: new TextValueListener() {
074: public void textValueChanged(DocumentEvent e) {
075: if (isUpdateOnChange && (getElement() != null)) {
076: ((JSliderTest) getElement())
077: .setSliderValue(selectedValueField
078: .getValue());
079: }
080: }
081: });
082: editorPanel.add(selectedValueField, c);
083: selectedValueLabel.setLabelFor(selectedValueField);
084:
085: // The minimum label
086: c.gridx = 0;
087: c.gridy++;
088: c.gridwidth = 1;
089:
090: JLabel minValueLabel = new JLabel(language
091: .getString("Tests.JSliderTest.MinValue")
092: + ":");
093: editorPanel.add(minValueLabel, c);
094:
095: // The minimum value textfield
096: c.gridx = 1;
097: minValueField = new IntegerTextField(0, 5);
098: minValueField.getDocument().addDocumentListener(
099: new TextValueListener() {
100: public void textValueChanged(DocumentEvent e) {
101: if (isUpdateOnChange && (getElement() != null)) {
102: ((JSliderTest) getElement())
103: .setSliderMin(minValueField
104: .getValue());
105: }
106: }
107: });
108: editorPanel.add(minValueField, c);
109: minValueLabel.setLabelFor(minValueField);
110:
111: // The maximum label
112: c.gridx = 0;
113: c.gridy++;
114: c.gridwidth = 1;
115:
116: JLabel maxValueLabel = new JLabel(language
117: .getString("Tests.JSliderTest.MaxValue")
118: + ":");
119: editorPanel.add(maxValueLabel, c);
120:
121: // The maximum value textfield
122: c.gridx = 1;
123: maxValueField = new IntegerTextField(0, 5);
124: maxValueField.getDocument().addDocumentListener(
125: new TextValueListener() {
126: public void textValueChanged(DocumentEvent e) {
127: if (isUpdateOnChange && (getElement() != null)) {
128: ((JSliderTest) getElement())
129: .setSliderMax(maxValueField
130: .getValue());
131: }
132: }
133: });
134: editorPanel.add(maxValueField, c);
135: maxValueLabel.setLabelFor(maxValueField);
136: }
137:
138: /**
139: * @see jacareto.editor.Editor#handlesElement(jacareto.struct.StructureElement)
140: */
141: public boolean handlesElement(StructureElement element) {
142: return (element != null) && (element instanceof JSliderTest);
143: }
144:
145: /**
146: * @see jacareto.editor.Editor#setElement(jacareto.struct.StructureElement)
147: */
148: public void setElement(StructureElement element) {
149: super .setElement(element);
150:
151: JSliderTest test = (JSliderTest) element;
152: selectedValueField.setValue(test.getSliderValue());
153: minValueField.setValue(test.getSliderMin());
154: maxValueField.setValue(test.getSliderMax());
155: }
156: }
|