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