Print

Print


Mark Coletti wrote:

> I have Valuable objects stored in a SparseGrid2D object.  These
> objects' doubleValue() members return values in [0,1].  I would like
> to use a ColorMap similarly as one would with a
> FastObjectGridPortrayal2D to render these SparseGrid2D objects
> accordingly.  After RTFM'ing I don't see a nice, clean way to do this.
>  The best I can do is to implement a draw() function, which seems like
> overkill.  Surely there is a quick an easy way to do this in MASON?

There SHOULD be a nice way to do rectangles cleanly -- ValuePortryal2D. 
  But that only works in limited circumstances and I need to make the 
class much more useful.

In the meantime, here's how to do it:

Override the draw() method of your simple portrayal like this:

public void draw(Object object, Graphics2D graphics, DrawInfo2D info)
	{
	paint = myColorMap.getColor(((Valuable)object).getValue());
	super.draw(object, graphics, info);
	}


Your map would either be stored an instance variable in a custom 
subclass of a simple portrayal, or you could do it as a closure, like this:


final SimpleColorMap myColorMap = new SimpleColorMap(....);

RectanglePortrayal2D myportrayal = new RectanglePortrayal2D()
	{
	public void draw(Object object,
		Graphics2D graphics, DrawInfo2D info)
		{
		paint = myColorMap.getColor(
				((Valuable)object).getValue());
		super.draw(object, graphics, info);
		}	
	};


Sean