annotate 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
rev   line source
samer@0 1 /*
samer@0 2 * VariableViewer.java
samer@0 3 *
samer@0 4 * Copyright (c) 2000, Samer Abdallah, King's College London.
samer@0 5 * All rights reserved.
samer@0 6 *
samer@0 7 * This software is provided AS iS and WITHOUT ANY WARRANTY;
samer@0 8 * without even the implied warranty of MERCHANTABILITY or
samer@0 9 * FITNESS FOR A PARTICULAR PURPOSE.
samer@0 10 */
samer@0 11
samer@0 12 package samer.core.util;
samer@0 13 import samer.core.*;
samer@0 14 import java.util.*;
samer@0 15
samer@0 16 /** A VariableViewer is a BaseViewer that provides Agent commands
samer@0 17 for saving and restoring its Variable. It also sets the BaseViewer's
samer@0 18 label using the name of the Variable.
samer@0 19 */
samer@0 20
samer@0 21 public class VariableViewer extends BaseViewer implements Agent
samer@0 22 {
samer@0 23 protected Variable variable;
samer@0 24
samer@0 25 /** Construct a VariableViewer for the given Variable, setting the
samer@0 26 viewer's label to the default provided by variable.getLabel().
samer@0 27 */
samer@0 28 protected VariableViewer(Variable v) {
samer@0 29 super(v); variable = v;
samer@0 30 setText(v.getLabel());
samer@0 31 exposeCommands(this);
samer@0 32 }
samer@0 33
samer@0 34 // ............. Agent bits .................
samer@0 35
samer@0 36 /** Reports the following commands: "save" and "restore". */
samer@0 37 public void getCommands(Agent.Registry r) { r.add("store").add("restore"); }
samer@0 38
samer@0 39 /** Handles the commands "save" and "restore" using
samer@0 40 Variable.save() and Variable.load(). */
samer@0 41 public void execute(String cmd, Environment env) throws Exception
samer@0 42 {
samer@0 43 if (cmd.equals("store")) { variable.save(Shell.env()); }
samer@0 44 else if (cmd.equals("restore")) { variable.load(Shell.env()); }
samer@0 45 //else if (cmd.equals("full name")) {
samer@0 46 // env.add(variable.getNode().fullName());
samer@0 47 //}
samer@0 48 }
samer@0 49
samer@0 50 /** A utility layout manager provided for VariableViewers to use.
samer@0 51 (See VLayout class) */
samer@0 52 protected static final VLayout layout = new VLayout(1,6);
samer@0 53 }