Mercurial > hg > jslab
view src/samer/maths/MatrixAgent.java @ 0:bf79fb79ee13
Initial Mercurial check in.
author | samer |
---|---|
date | Tue, 17 Jan 2012 17:50:20 +0000 |
parents | |
children |
line wrap: on
line source
/* * MatrixAgent.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.maths; import samer.core.*; import samer.core.Agent.*; /** Provides a load of useful commands for dealing with a matrix. */ public class MatrixAgent extends Saver { private Matrix M; public MatrixAgent(Matrix m) { super(m,m.getNode()); M=m; } public void getCommands(Registry r) { r.add("zeros").add("identity").add("multiply"); r.group(); super.getCommands(r); r.group(); r.add("image").add("editor"); r.add("rowcolumn"); } public String toString() { return "MatrixAgent("+M+")"; } public void execute(String cmd, Environment env) throws Exception { if (cmd.equals("identity")) { M.identity(); M.changed(); } else if (cmd.equals("zeros")) { M.zero(); M.changed(); } else if (cmd.equals("multiply")) { double K=X._double(env.datum("factor"),1); M.timesEquals(K); M.changed(); } else if (cmd.equals("rowcolumn")) { new RowColumn(M); } else if (cmd.equals("plotter")) { pushNode("plotter"); Viewer vwr = new MatrixPlotter(M); Shell.expose(vwr, "window"); Shell.pop(); } else if (cmd.equals("image")) { pushNode("image"); Viewer vwr = new MatrixImage(M); Shell.expose(vwr, "window"); Shell.pop(); } else if(cmd.equals("editor")) { pushNode("editor"); Shell.expose((Viewer)(new MatrixImageEditor(M)),"window"); Shell.pop(); } else super.execute(cmd,env); } private void pushNode(String nm) { Shell.push(new Node(nm,M.getNode())); } } class MatrixImageEditor extends MatrixImage { MatEditor editor; public MatrixImageEditor(Matrix A) { super(A); editor = new MatEditor(A,this,A.observable(),this); } public void detach() { editor.detach(); super.detach(); } }