[Biojava-l] New FeatureRenderers and demo

David Huen smh1008@cus.cam.ac.uk
Mon, 11 Jun 2001 22:59:08 +0100 (BST)


On 10 Jun 2001, Keith James wrote:

> In the demo you may notice features vanishing if entirely within 50
> pixels of the right edge of the SequencePanel. This seems to be due to
> arbitrary 50 pixel offset in SequencePanel interfering with the use of
> the rectangle returned by sequencePanel.getVisibleRect(). The renderer
> thinks they are outside the visible area and skips over them.
> 
> David, can we discuss alternatives to moving the graphics origin to
> fix the floating point rounding errors for very long sequences? Or if
> anyone else has any ideas?
> 
Dear Keith,
I think I have located the cause of the above.

getVisibleRect returns the visible rectangle of the component in component
space, ie. as a rectangle in which the topleft is rooted at (0,0).  All
drawing in SequencePanel occurs in a transformed space (see
SequencePanel.paintComponent()).  In this, a transform of the coordinate
space is applied such that the ultimate left edge of the sequence render
region (leftmost edge of SequenceRenderContext LESS minimum leader) falls
at the right edge of the leading border.  This is done so that if a
SequencePanel is implemented that has something rendered at the left edge
of the panel space is allocated for it.  This is independent of the the
minimum leader which is within the renderer area itself.

The net consequence of this transform is that the renderer coordinate
space and the component coordinate space are displaced relative to each
other.  The 50 pixel figure arises because the arbitrary coorection I make
puts the left edge of the render area at 50 pixels.  If the 50 in the
correction were reduced to 0.0, the coordinate spaces would match under
the current conditions (better make it slightly large than 0 otherwise the
smallest rounding error will cause Java to barf - it hates negative
coordinates somewhere).  But that actually doesn't solve your problem
because the first time someone uses the leading border, the problem will
return.  I suggest leaving that alone and using the solution given below.

I think you will need to either transform your Visible Rectangle to the
renderer coordinate space or alternatively, transform your objects
coordinates to component space so your test uses the same coordinate space
for the visibility test.  The former is easier and can be performed with
the methods in AffineTransform.  You can recover the current transform
from the Graphics2D object by getTransform().

Best wishes,
David Huen, Dept. of Genetics, Univ. of Cambridge