Mercurial > hg > jslab
diff src/samer/core_/util/VariableViewer.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/samer/core_/util/VariableViewer.java Tue Jan 17 17:50:20 2012 +0000 @@ -0,0 +1,53 @@ +/* + * 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); +}