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.JComboBoxTest;
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.JComboBoxTest</code> tests.
037: *
038: * @author <a href="mailto:csauer@gmx.net">Christoph Sauer</a>
039: * @version 1.0
040: */
041: public class JComboBoxTestEditor extends JComponentTestEditor {
042: /** Which element is selected. */
043: protected IntegerTextField selectedIndexField;
044:
045: /**
046: * Creates an editor with the specified env.
047: *
048: * @param env the environment
049: */
050: public JComboBoxTestEditor(Environment env) {
051: super (env);
052:
053: // The selected index label
054: c.gridx = 0;
055: c.gridy += 1;
056: c.gridwidth = 1;
057:
058: JLabel selectedIndexLabel = new JLabel(language
059: .getString("Tests.JComboBoxTest.SelectedIndex")
060: + ":");
061: editorPanel.add(selectedIndexLabel, c);
062:
063: // The selected index textfield
064: c.gridx = 1;
065: selectedIndexField = new IntegerTextField(0, 5);
066: selectedIndexField.getDocument().addDocumentListener(
067: new TextValueListener() {
068: public void textValueChanged(DocumentEvent e) {
069: if (isUpdateOnChange && (getElement() != null)) {
070: // does the textField contain text
071: if (!selectedIndexField.getText()
072: .equals("")) {
073: ((JComboBoxTest) getElement())
074: .setSelectedIndex(selectedIndexField
075: .getValue());
076: } else {
077: ((JComboBoxTest) getElement())
078: .setSelectedIndex(-1);
079: }
080: }
081: }
082: });
083: editorPanel.add(selectedIndexField, c);
084: selectedIndexLabel.setLabelFor(selectedIndexField);
085: }
086:
087: /**
088: * @see jacareto.editor.Editor#handlesElement(jacareto.struct.StructureElement)
089: */
090: public boolean handlesElement(StructureElement element) {
091: return (element != null) && (element instanceof JComboBoxTest);
092: }
093:
094: /**
095: * @see jacareto.editor.Editor#setElement(jacareto.struct.StructureElement)
096: */
097: public void setElement(StructureElement element) {
098: super .setElement(element);
099:
100: JComboBoxTest test = (JComboBoxTest) element;
101: selectedIndexField.setValue(test.getSelectedIndex());
102: }
103: }
|