view src/samer/maths/VectorTrace.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
/*
 *	VectorPlotter.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 java.util.*;
import java.awt.*;
import java.awt.event.*;
import samer.core.*;
import samer.core.util.*;
import samer.core.Agent.*;
import samer.tools.*;
import java.awt.image.IndexColorModel;

/**
	A Viewer that draws multiple traces: one for each element of a vector
  */

public class VectorTrace extends Trace
{
	private Vec			vec;
	private Renderer		R;
	private int[]			old;
	private Color[]		cols;

	public VectorTrace(Vec v)
	{
		IndexColorModel cmod=(IndexColorModel)Shell.get("colormap",ImageSourceBase.GREY);
		R=(Renderer)Shell.get("renderer",Renderer.LINE);

		int N=v.size(), M=cmod.getMapSize();
		cols=new Color[N];
		old=new int[N];
		vec=v;

		for (int i=0; i<N; i++) cols[i]=new Color(cmod.getRGB(i%M));
	}

	protected void realized() { super.realized(); attach(); }

	public void run()
	{
		super.run();
		Vec.Iterator it=vec.iterator();
		int	i,j;

		for (i=0; it.more(); i++) {
			j=height-map.toInt(it.next());
			graphics.setColor(cols[i]);
			R.draw(graphics,x1,x2,old[i],j,j0);
			old[i]=j;
		}
	}
	// .............. Agent bits ..............................

	public void getCommands(Registry r)
	{
		super.getCommands(r);
		r.group(); r.add("line").add("fill").add("fill3d").add("steps");
	}

	public void execute(String c, Environment env) throws Exception
	{
		if      (c.equals("line"))		{ R=Renderer.LINE; }
		else if (c.equals("fill"))		{ R=Renderer.FILL; }
		else if (c.equals("fill3d"))	{ R=Renderer.FILL3D; }
		else if (c.equals("steps"))	{ R=Renderer.STEPS; }
		else super.execute(c,env);
	}
}