On Fri, May 15, 2009 at 4:59 PM, Sean Luke <[log in to unmask]> wrote:
> Mark Coletti wrote:
>> I have Valuable objects stored in a SparseGrid2D object ... I would like
>> to use a ColorMap similarly as one would with a
>> FastObjectGridPortrayal2D to render these SparseGrid2D objects...
> 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.
By default my objects are rendered as gray ovals; I merely wish to
change the color of these ovals by the returned doubleValue() from
these objects. As I understand it ValuePortrayal2D is only good for
double or int grids. My objects are in a _sparse_ grid.
> 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);
I think we're missing some context here. I've created a draw() for a
sub-class of SparseGridPortrayal2D in which I try to do exactly that,
not a subclass of, say, OvalPortrayal2D. Alas, 'object' in my context
is the entire sparse grid and not the individual object.
It might be nice if there existed an over-ridable 'drawObject(Object)'
which is, in turn, called by draw() for the grid level objects.
(I.e., sort of a Visitor design pattern for grid portrayals.) Then I
could do something like the above each time the object is rendered.
It seems that your draw() is for a sub-class of a simple object
portrayal? And, if so, that my object should subclass from that?
Which is icky because now I'm mixing in rendering state into an object
when it's not necessarily going to be be used in a graphics context.
(I.e. not run from a GUI.)