samer@0: /* samer@0: * VariableViewer.java samer@0: * samer@0: * Copyright (c) 2000, Samer Abdallah, King's College London. samer@0: * All rights reserved. samer@0: * samer@0: * This software is provided AS iS and WITHOUT ANY WARRANTY; samer@0: * without even the implied warranty of MERCHANTABILITY or samer@0: * FITNESS FOR A PARTICULAR PURPOSE. samer@0: */ samer@0: samer@0: package samer.core.util; samer@0: import samer.core.*; samer@0: import java.util.*; samer@0: samer@0: /** A VariableViewer is a BaseViewer that provides Agent commands samer@0: for saving and restoring its Variable. It also sets the BaseViewer's samer@0: label using the name of the Variable. samer@0: */ samer@0: samer@0: public class VariableViewer extends BaseViewer implements Agent samer@0: { samer@0: protected Variable variable; samer@0: samer@0: /** Construct a VariableViewer for the given Variable, setting the samer@0: viewer's label to the default provided by variable.getLabel(). samer@0: */ samer@0: protected VariableViewer(Variable v) { samer@0: super(v); variable = v; samer@0: setText(v.getLabel()); samer@0: exposeCommands(this); samer@0: } samer@0: samer@0: // ............. Agent bits ................. samer@0: samer@0: /** Reports the following commands: "save" and "restore". */ samer@0: public void getCommands(Agent.Registry r) { r.add("store").add("restore"); } samer@0: samer@0: /** Handles the commands "save" and "restore" using samer@0: Variable.save() and Variable.load(). */ samer@0: public void execute(String cmd, Environment env) throws Exception samer@0: { samer@0: if (cmd.equals("store")) { variable.save(Shell.env()); } samer@0: else if (cmd.equals("restore")) { variable.load(Shell.env()); } samer@0: //else if (cmd.equals("full name")) { samer@0: // env.add(variable.getNode().fullName()); samer@0: //} samer@0: } samer@0: samer@0: /** A utility layout manager provided for VariableViewers to use. samer@0: (See VLayout class) */ samer@0: protected static final VLayout layout = new VLayout(1,6); samer@0: }