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.Test;
029: import jacareto.toolkit.event.TextValueListener;
030:
031: import java.awt.Component;
032: import java.awt.GridBagConstraints;
033: import java.awt.GridBagLayout;
034: import java.awt.event.ActionEvent;
035: import java.awt.event.ActionListener;
036:
037: import javax.swing.JCheckBox;
038: import javax.swing.JLabel;
039: import javax.swing.JPanel;
040: import javax.swing.JTextField;
041: import javax.swing.border.EmptyBorder;
042: import javax.swing.event.DocumentEvent;
043:
044: /**
045: * An editor for a test.
046: *
047: * @author <a href="mailto:cspannagel@web.de">Christian Spannagel</a>
048: * @version 1.21
049: */
050: public class TestEditor extends Editor {
051: /** The editor's component. */
052: protected JPanel editorPanel;
053:
054: /** The editor panel's constraints. */
055: protected GridBagConstraints c;
056:
057: /** The field for the component's name. */
058: protected JTextField componentField;
059:
060: /** The checkbock for the correcting value. */
061: protected JCheckBox chkCorrect;
062:
063: /** The checkbox for the ignoring value. */
064: protected JCheckBox chkIgnore;
065:
066: /** The structure element. */
067: private StructureElement element;
068:
069: /**
070: * Creates a new test editor.
071: *
072: * @param env the environment.
073: */
074: public TestEditor(Environment env) {
075: super (env);
076:
077: // The panel
078: editorPanel = new JPanel();
079: editorPanel.setBorder(new EmptyBorder(10, 10, 10, 10));
080: editorPanel.setLayout(new GridBagLayout());
081:
082: // The component field label
083: c = new GridBagConstraints();
084: c.gridx = 0;
085: c.gridy = 0;
086: c.weightx = 40;
087: c.ipadx = 5;
088: c.ipady = 5;
089: c.anchor = GridBagConstraints.WEST;
090:
091: JLabel componentFieldLabel = new JLabel(language
092: .getString("Tests.Test.ComponentName")
093: + ":");
094: editorPanel.add(componentFieldLabel, c);
095:
096: // The component field.
097: c.gridx = 1;
098: c.weightx = 60;
099: componentField = new JTextField("", 20);
100: componentField.getDocument().addDocumentListener(
101: new TextValueListener() {
102: public void textValueChanged(DocumentEvent e) {
103: if (isUpdateOnChange && (getElement() != null)) {
104: ((Test) getElement())
105: .setComponentName(componentField
106: .getText());
107: }
108: }
109: });
110: editorPanel.add(componentField, c);
111: componentFieldLabel.setLabelFor(componentField);
112:
113: // The correct checkbox
114: c.gridx = 0;
115: c.gridy++;
116: c.gridwidth = 2;
117: chkCorrect = new JCheckBox(language
118: .getString("Tests.Test.Correcting"));
119: chkCorrect.addActionListener(new ActionListener() {
120: public void actionPerformed(ActionEvent e) {
121: if (isUpdateOnChange && (getElement() != null)) {
122: ((Test) getElement()).setCorrecting(chkCorrect
123: .isSelected());
124: }
125: }
126: });
127: editorPanel.add(chkCorrect, c);
128:
129: // The ignore checkbox
130: c.gridx = 0;
131: c.gridy++;
132: chkIgnore = new JCheckBox(language
133: .getString("Tests.Test.Ignoring"));
134: chkIgnore.addActionListener(new ActionListener() {
135: public void actionPerformed(ActionEvent e) {
136: if (isUpdateOnChange && (getElement() != null)) {
137: ((Test) getElement()).setIgnoring(chkIgnore
138: .isSelected());
139: }
140: }
141: });
142: editorPanel.add(chkIgnore, c);
143: }
144:
145: /**
146: * Returns whether this editor is responsible for a given structure element. This editor is
147: * responsible for all test recordables.
148: *
149: * @param element the structure element
150: *
151: * @return <code>true</code> if <i>element</i> is a test and not <code>null</code>, otherwise
152: * <code>false</code>
153: */
154: public boolean handlesElement(StructureElement element) {
155: return (element != null) && (element instanceof Test);
156: }
157:
158: /**
159: * Returns the actual structure element to be edited.
160: *
161: * @return DOCUMENT ME!
162: */
163: public StructureElement getElement() {
164: return element;
165: }
166:
167: /**
168: * Sets the structure element to edit.
169: *
170: * @param element DOCUMENT ME!
171: */
172: public void setElement(StructureElement element) {
173: this .element = element;
174:
175: Test test = (Test) element;
176: componentField.setText(test.getComponentName());
177: chkCorrect.setSelected(test.isCorrecting());
178: chkIgnore.setSelected(test.isIgnoring());
179: }
180:
181: /**
182: * Returns the component of the editor.
183: *
184: * @return the editor component
185: */
186: public Component getComponent() {
187: return editorPanel;
188: }
189: }
|