view src/samer/core_/viewers/StringViewer.java @ 5:b67a33c44de7

Remove some crap, etc
author samer
date Fri, 05 Apr 2019 21:34:25 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	StringViewer.java	
 *
 *	Copyright (c) 2000, Samer Abdallah, King's College London.
 *	All rights reserved.
 *
 *	This software is provided AS iS and WITHOUT ANY WARRANTY; 
 *	without even the implied warranty of MERCHANTABILITY or 
 *	FITNESS FOR A PARTICULAR PURPOSE.
 */

package	samer.core.viewers;
import	samer.core.util.*;
import	samer.core.types.*;
import	samer.core.*;
import	java.awt.*;
import	java.awt.event.*;
import	java.util.*;

public class StringViewer extends VariableViewer implements ActionListener, FocusListener
{
	TextField	t;

	public StringViewer(VString v) { this((Variable)v); }
	public StringViewer(Variable v) 
	{ 
		super(v); 

		setLayout(layout);
		t = new TextField(12); 
		t.addFocusListener(this);
		t.addActionListener(this);

		panel().add(t,"Center");
		update(null,null);

	}

	public void update(Observable o, Object source)
	{ 
		if (source!=this) { // &&&
			t.setText(variable.getModel().string());
		}
		super.update(o,source);
	}

	private void parseTextField()
	{
		variable.getModel().decode(t.getText()); 
		variable.changed(this); 
	}

	public void actionPerformed( ActionEvent e)
	{
		// set value and slider
		if (e.getSource()==t) parseTextField();
	}

	public void focusGained( FocusEvent e) {}
	public void focusLost( FocusEvent e) { parseTextField(); }
}