package org.uva.sea.ql.gui.widget;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JComponent;
import javax.swing.JTextField;

import org.uva.sea.ql.ast.Identifier;
import org.uva.sea.ql.evaluate.StringValue;
import org.uva.sea.ql.evaluate.Value;
import org.uva.sea.ql.gui.questionaire.State;

public class StringWidget extends Control{

	private JTextField textfield;
	
	public StringWidget(Identifier identifier, State state) {
		super(identifier, state);
		textfield = new JTextField();
		textfield.setText("empty");
		textfield.addActionListener(new ActionListener(){
			
			public void actionPerformed(ActionEvent e){
					setValue(textToStringValue());
			}
		
		});
		
	}

	@Override
	public JComponent UIElement() {
		return textfield;
	}

	@Override
	public void setEnabled(boolean isEnabled) {
		textfield.setEnabled(isEnabled);
	}

	public Value textToStringValue(){
		return new StringValue(textfield.getText());
	}
	@Override
	public void setValue(Value value) {
		textfield.setText(((StringValue) value).getValue());		
		setChanged();
		getState().putVariable(getIdentifier(), value);
		getState().notify(getIdentifier());
		
	}
	

}

@@ -553,39 +553,8 @@
 );%0D%0A
-%09%09textfield.setText(%22empty%22);%0D%0A
 %09%09te
@@ -705,24 +705,63 @@
 %0A%09%09%0D%0A%09%09%7D);%0D%0A
+%09%09setValue(new StringValue(%22empty%22));%0D%0A
 %09%09%0D%0A%09%7D%0D%0A%0D%0A%09@
@@ -1236,20 +1236,14 @@
 ());
-%0D%0A%09
 %09%0D%0A%09%7D%0D
-%0A%09%0D
 %0A%0D%0A%7D

Remove money, bugfixing, added typecheckertests