org.biojava.bio.gui.sequence
Class PairwiseDiagonalRenderer

java.lang.Object
  extended by org.biojava.utils.AbstractChangeable
      extended by org.biojava.bio.gui.sequence.PairwiseDiagonalRenderer
All Implemented Interfaces:
Serializable, PairwiseSequenceRenderer, Changeable

public class PairwiseDiagonalRenderer
extends AbstractChangeable
implements PairwiseSequenceRenderer, Serializable

PairwiseDiagonalRenderer renders a region of similarity between two sequences as a straight line. The effect produced is similar to a dotplot. This implementation requires that these regions be represented by SimilarityPairFeatures.

Drawing outside the visible area using a range of valid doubles may cause Java to hang (Sun JDK 1.3.1 on Linux, Compaq JDK 1.3.1 on Tru64, but not Sun JDK 1.4.0-beta2-b77 on Linux). I got round this by manual clipping of the lines to the clip area. The code uses an implementation of the Cohen-Sutherland line-clipping algorithm which clips lines to within a rectangle.

The clipping code is taken from Computer Graphics for Java Programmers by Leen Ammeraal (1998, ISBN 0-471-98142-7) and cosmetically altered to support Java2D objects. Any bugs introduced are my responsibility.

Since:
1.2
Author:
Keith James, Leen Ammeraal
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from interface org.biojava.bio.gui.sequence.PairwiseSequenceRenderer
PairwiseSequenceRenderer.PairwiseRendererForwarder
 
Field Summary
protected  Line2D.Float line
          line is the line to be drawn for each feature.
protected  Paint outline
          outline is the line colour.
static ChangeType OUTLINE
          Constant OUTLINE indicating a change to the fill of the features.
 
Constructor Summary
PairwiseDiagonalRenderer()
          Creates a new PairwiseDiagonalRenderer which will draw black lines.
PairwiseDiagonalRenderer(Paint outline)
          Creates a new PairwiseDiagonalRenderer which will draw lines using the specified Paint.
 
Method Summary
 Paint getOutline()
          getOutline returns the colour used to draw the lines.
 void paint(Graphics2D g2, PairwiseRenderContext context)
          paint renders the feature as a simple line.
 SequenceViewerEvent processMouseEvent(PairwiseRenderContext context, MouseEvent me, List path)
          processMouseEvent acts on a mouse gesture.
 void setOutline(Paint outline)
          setOutline sets the the colour used to draw the lines.
 
Methods inherited from class org.biojava.utils.AbstractChangeable
addChangeListener, addChangeListener, generateChangeSupport, getChangeSupport, hasListeners, hasListeners, isUnchanging, removeChangeListener, removeChangeListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

OUTLINE

public static final ChangeType OUTLINE
Constant OUTLINE indicating a change to the fill of the features.


line

protected Line2D.Float line
line is the line to be drawn for each feature.


outline

protected Paint outline
outline is the line colour.

Constructor Detail

PairwiseDiagonalRenderer

public PairwiseDiagonalRenderer()
Creates a new PairwiseDiagonalRenderer which will draw black lines.


PairwiseDiagonalRenderer

public PairwiseDiagonalRenderer(Paint outline)
Creates a new PairwiseDiagonalRenderer which will draw lines using the specified Paint.

Parameters:
outline - a Paint.
Method Detail

paint

public void paint(Graphics2D g2,
                  PairwiseRenderContext context)
paint renders the feature as a simple line.

Specified by:
paint in interface PairwiseSequenceRenderer
Parameters:
g2 - a Graphics2D.
context - a PairwiseRenderContext.

getOutline

public Paint getOutline()
getOutline returns the colour used to draw the lines.

Returns:
a Paint.

setOutline

public void setOutline(Paint outline)
                throws ChangeVetoException
setOutline sets the the colour used to draw the lines.

Parameters:
outline - a Paint.
Throws:
ChangeVetoException - if an error occurs.

processMouseEvent

public SequenceViewerEvent processMouseEvent(PairwiseRenderContext context,
                                             MouseEvent me,
                                             List path)
processMouseEvent acts on a mouse gesture. The target object is a FeatureHolder containing the features on the primary sequence which contain the mouse pointer.

Specified by:
processMouseEvent in interface PairwiseSequenceRenderer
Parameters:
context - a PairwiseRenderContext.
me - a MouseEvent.
path - a List.
Returns:
a SequenceViewerEvent.