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: /*
025: * Created on 14.05.2003
026: *
027: * To change the template for this generated file go to
028: * Window>Preferences>Java>Code Generation>Code and Comments
029: */
030: package jacareto.editor;
031:
032: import jacareto.struct.StructureElement;
033: import jacareto.system.Environment;
034: import jacareto.test.JListTest;
035: import jacareto.toolkit.event.TextValueListener;
036:
037: import org.apache.regexp.RE;
038:
039: import java.awt.event.ActionEvent;
040: import java.awt.event.ActionListener;
041:
042: import javax.swing.JButton;
043: import javax.swing.JLabel;
044: import javax.swing.JTextArea;
045: import javax.swing.event.DocumentEvent;
046:
047: /**
048: * This class is the editor class for <code>jacareto.test.JListTest</code> tests.
049: *
050: * @author Christoph Sauer
051: * @version 1.0
052: */
053: public class JListTestEditor extends JComponentTestEditor {
054: /** Which elements are selected. */
055: protected JTextArea selectedIndicesField;
056:
057: //The syntax check button
058: private JButton syntaxCheckButton;
059:
060: /**
061: * Creates an editor with the specified env.
062: *
063: * @param env the environment
064: */
065: public JListTestEditor(Environment env) {
066: super (env);
067:
068: // The selected indices label
069: c.gridx = 0;
070: c.gridy += 1;
071: c.gridwidth = 1;
072:
073: JLabel selectedIndicesLabel = new JLabel(language
074: .getString("Tests.JListTest.SelectedIndices")
075: + ":");
076: editorPanel.add(selectedIndicesLabel, c);
077:
078: // The selected index textfield
079: c.gridx = 1;
080: selectedIndicesField = new JTextArea("", 1, 40);
081: selectedIndicesField.getDocument().addDocumentListener(
082: new TextValueListener() {
083: public void textValueChanged(DocumentEvent e) {
084: if (isUpdateOnChange && (getElement() != null)) {
085: // setting the selectedIndicesString value
086: ((JListTest) getElement())
087: .setTargetSelectedIndicesString(selectedIndicesField
088: .getText());
089: }
090: }
091: });
092: editorPanel.add(selectedIndicesField, c);
093: selectedIndicesLabel.setLabelFor(selectedIndicesField);
094:
095: // The regexp syntax check button
096: c.gridx = 1;
097: c.gridy++;
098: c.gridwidth = 2;
099: syntaxCheckButton = new JButton(language
100: .getString("Editors.JListTestEditor.SyntaxCheck"));
101: syntaxCheckButton.addActionListener(new ActionListener() {
102: public void actionPerformed(ActionEvent e) {
103: String targetSelectedIndicesString = selectedIndicesField
104: .getText();
105:
106: try {
107: // this RE matches (int)(,int)* and blanks
108: // note that carriage returns are not matched
109: RE regexp = new RE(
110: "([:blank:]*([0-9]+)([:blank:]*,[:blank:]*([0-9]+))*[:blank:]*|[:blank:]*)");
111: regexp.match(targetSelectedIndicesString);
112:
113: String insideParens = regexp.getParen(1);
114:
115: if (!targetSelectedIndicesString
116: .equals(insideParens)) {
117: logger
118: .info(language
119: .getString("Editors.JListTestEditor.Msg.SyntaxError"));
120: } else {
121: logger
122: .info(language
123: .getString("Editors.JListTestEditor.Msg.SyntaxOk"));
124: }
125: } catch (Throwable t) {
126: t.printStackTrace();
127: }
128: }
129: });
130: editorPanel.add(syntaxCheckButton, c);
131: }
132:
133: /**
134: * @see jacareto.editor.Editor#handlesElement(jacareto.struct.StructureElement)
135: */
136: public boolean handlesElement(StructureElement element) {
137: return (element != null) && (element instanceof JListTest);
138: }
139:
140: /**
141: * @see jacareto.editor.Editor#setElement(jacareto.struct.StructureElement)
142: */
143: public void setElement(StructureElement element) {
144: super .setElement(element);
145:
146: JListTest test = (JListTest) element;
147:
148: //building a string from the int array of selected indices
149: String selectedIndices = test.getTargetSelectedIndicesString();
150:
151: //String selectedIndicesArray = test.getTargetSelectedIndicesString();
152: selectedIndicesField.setText(selectedIndices);
153: }
154: }
|