view src/samer/core_/util/VariableViewer.java @ 8:5e3cbbf173aa tip

Reorganise some more
author samer
date Fri, 05 Apr 2019 22:41:58 +0100
parents bf79fb79ee13
children
line wrap: on
line source
/*
 *	VariableViewer.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.util;
import	samer.core.*;
import	java.util.*;

/** A VariableViewer is a BaseViewer that provides Agent commands
	for saving and restoring its Variable. It also sets the BaseViewer's
	label using the name of the Variable.
*/

public class VariableViewer extends BaseViewer implements Agent
{
	protected Variable variable;

	/** Construct a VariableViewer for the given Variable, setting the
		viewer's label to the default provided by variable.getLabel().
	 */
	protected VariableViewer(Variable v) {
		super(v); variable = v;
		setText(v.getLabel());
		exposeCommands(this);
	}

	// ............. Agent bits .................

	/** Reports the following commands: "save" and "restore". */
	public void getCommands(Agent.Registry r) { r.add("store").add("restore"); }

	/** Handles the commands "save" and "restore" using
		Variable.save() and Variable.load(). */
	public void execute(String cmd, Environment env) throws Exception
	{
		if      (cmd.equals("store"))		{ variable.save(Shell.env()); }
		else if (cmd.equals("restore"))	{ variable.load(Shell.env()); }
		//else if (cmd.equals("full name")) {
		//	env.add(variable.getNode().fullName());
		//}
	}

	/** A utility layout manager provided for VariableViewers to use.
		(See VLayout class) */
	protected static final VLayout	layout = new VLayout(1,6);
}