Mercurial > hg > jslab
view src/samer/maths/VGenerator.java @ 5:b67a33c44de7
Remove some crap, etc
author | samer |
---|---|
date | Fri, 05 Apr 2019 21:34:25 +0100 |
parents | bf79fb79ee13 |
children |
line wrap: on
line source
/* * 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.maths; import samer.core.*; import samer.core.types.*; import samer.core.util.*; import java.awt.*; import java.util.*; /** A Viewable random number generator. The Generator itself must expose any parameters it has, but this object allows the user to control what class of generator to use. */ public class VGenerator extends Viewable implements Agent, Generator { Generator gen; String desc; // description of the current generator public VGenerator(String nm) throws Exception { this(nm,new Zero()); } public VGenerator(String nm, Generator g) throws Exception { super(nm); setAgent(this); gen = g; Shell.registerViewable(this); } public double next() { return gen.next(); } public void next(double[] x) { gen.next(x); } public void dispose() { Shell.deregisterViewable(this); gen.dispose(); super.dispose(); } public Generator getGenerator() { return gen; } public void setGenerator(Generator g) { gen.dispose(); gen=g; changed(); } public Viewer getViewer() { return new UI(); } private class UI extends BaseViewer { UI() { super(VGenerator.this); update(VGenerator.this,null); } public void update(Observable o, Object arg) { super.update(o,arg); Shell.trace("VGenerator update to "+gen.toString()); setText(getLabel()+": "+gen.toString()); } } public void getCommands(Registry r) { r.add("set").add("next"); } public void execute(String cmd, Environment env) throws Exception { if (cmd.equals("set")) { Shell.push(getNode()); setGenerator((Generator)X.object(env.datum())); Shell.pop(); } else if (cmd.equals("next")) { env.add(new Double(gen.next())); } } }