org.biojava.bio.chromatogram.graphic
Class ChromatogramGraphic

java.lang.Object
  extended byorg.biojava.bio.chromatogram.graphic.ChromatogramGraphic
All Implemented Interfaces:
java.lang.Cloneable

public class ChromatogramGraphic
extends java.lang.Object
implements java.lang.Cloneable

Encapsulates a configurable method for drawing a Chromatogram into a graphics context.

Author:
Rhett Sutphin (UI CBCB)

Nested Class Summary
static class ChromatogramGraphic.Option
          A typesafe enumeration of the options available for configuring the behavior of a ChromatogramGraphic instance.
 
Field Summary
protected  boolean callboxesValid
           
protected  java.util.Map colors
          The map containing the colors for drawing traces.
protected  boolean drawableCallboxesValid
           
protected  java.util.Map fillColors
          The map containing the fill colors for callboxes.
protected  java.util.Map options
          The map containing the ChromatogramGraphic.Options and values for this instance.
protected  boolean subpathsValid
           
 
Constructor Summary
ChromatogramGraphic()
          Default constructor with no Chromatogram.
ChromatogramGraphic(Chromatogram c)
          Creates a new ChromatogramGraphic, initially displaying the given chromatogram.
 
Method Summary
 java.lang.Object clone()
          Performs a partial deep copy and invalidates regenerable structures
 void drawTo(java.awt.Graphics2D g2)
          Draws the chromatogram onto the provided graphics context.
protected  void generateCallboxes()
          Precomputes the Rectangle2Ds that are the in-memory representation of the callboxes.
protected  void generateDrawableCallboxes(java.awt.geom.AffineTransform shapeTx)
          Precomputes the callboxes in screen coordinates.
protected  void generateSubpaths()
          Precomputes the GeneralPaths used to draw the traces.
 java.awt.Color getBaseColor(Symbol b)
          Returns the color that will be used to draw the trace for the given DNA symbol.
 java.awt.Color getBaseFillColor(Symbol b)
          Returns the color that will be used to fill in the callboxes for calls with the given symbol.
 java.awt.geom.Rectangle2D getCallboxBounds(int index)
          Returns the screen-coordinate bounds of the callbox for a given call.
 java.awt.geom.Rectangle2D getCallboxBounds(int index, boolean boundsOnScreen)
          Returns the bounds of the callbox for a given call.
 int getCallboxCount()
          Returns the number of callboxes, regenerating them if necessary.
 int getCallContaining(float x)
          Synonym for getCallContaining(float, boolean) with pointOnScreen=true.
 int getCallContaining(float x, boolean xOnScreen)
          Same as getCallContaining(Point2D, boolean), except that only the x-coordinate of the point is specified.
 int getCallContaining(java.awt.geom.Point2D point)
          Synonym for getCallContaining(Point2D, boolean) with pointOnScreen=true.
 int getCallContaining(java.awt.geom.Point2D point, boolean pointOnScreen)
          Returns the 0-based index of the call containing a given point.
 Chromatogram getChromatogram()
          Accessor for the in-use chromatogram.
 float getFloatOption(ChromatogramGraphic.Option opt)
          Helper method for converting a Number-valued option into a float primitive.
 int getHeight()
          Returns the height of the whole graphic (in pixels).
 float getHorizontalScale()
          Returns the in-use horizontal scale factor.
 int getIntOption(ChromatogramGraphic.Option opt)
          Helper method for converting a Number-valued option into an int primitive.
 java.awt.geom.AffineTransform getInvTransform()
          Returns a new AffineTransform describing the transformation from output space to chromatogram space.
 java.lang.Object getOption(ChromatogramGraphic.Option opt)
          Returns the current value for the specified option.
 int getRenderedWidth()
          Returns the width of the graphic as it will be rendered.
 int getRenderedWidth(float horizontalScale)
          Returns the width of the graphic as it would be rendered with the specified horizontal scale.
 java.awt.geom.AffineTransform getTransform()
          Returns a new AffineTransform describing the transformation from chromatogram coordinates to output coordinates.
 void getTransformAndConcat(java.awt.geom.AffineTransform target)
          Concatenates the chromatogram-to-output transform to the provided given AffineTransform.
 float getVerticalScale()
          Returns the in use vertical scale factor.
 int getWidth()
          Returns the width of the whole graphic (in pixels).
 boolean optionIsTrue(ChromatogramGraphic.Option opt)
          Helper method for converting a Boolean-valued option into a boolean primitive.
 void setBaseColor(Symbol b, java.awt.Color c)
          Maps a color to a DNA symbol.
 void setChromatogram(Chromatogram c)
          Sets the chromatogram to draw.
 void setHeight(int h)
          Sets the height (in pixels).
 void setHorizontalScale(float hs)
          Sets the horizontal scale (proportional).
 void setOption(ChromatogramGraphic.Option opt, java.lang.Object value)
          Sets a new value for the specified option.
 void setVerticalScale(float vs)
          Sets the vertical scale (proportional).
 void setWidth(int w)
          Sets the width of the whole graphic (in pixels).
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

subpathsValid

protected boolean subpathsValid

callboxesValid

protected boolean callboxesValid

drawableCallboxesValid

protected boolean drawableCallboxesValid

options

protected java.util.Map options
The map containing the ChromatogramGraphic.Options and values for this instance.


colors

protected java.util.Map colors
The map containing the colors for drawing traces. Keys are DNA Symbols.


fillColors

protected java.util.Map fillColors
The map containing the fill colors for callboxes. Keys are DNA Symbols.

Constructor Detail

ChromatogramGraphic

public ChromatogramGraphic()
Default constructor with no Chromatogram.


ChromatogramGraphic

public ChromatogramGraphic(Chromatogram c)
Creates a new ChromatogramGraphic, initially displaying the given chromatogram.

Method Detail

generateSubpaths

protected void generateSubpaths()
Precomputes the GeneralPaths used to draw the traces.


generateCallboxes

protected void generateCallboxes()
Precomputes the Rectangle2Ds that are the in-memory representation of the callboxes. These rectangles are used for drawing (via generateDrawableCallboxes) as well as queries (e.g., getCallContaining(java.awt.geom.Point2D, boolean)).


generateDrawableCallboxes

protected void generateDrawableCallboxes(java.awt.geom.AffineTransform shapeTx)
Precomputes the callboxes in screen coordinates.

Parameters:
shapeTx - the transform to apply to the callboxes to move them into screen space.

getChromatogram

public Chromatogram getChromatogram()
Accessor for the in-use chromatogram.

Returns:
the chromatogram that a call to drawTo(java.awt.Graphics2D) will draw

setChromatogram

public void setChromatogram(Chromatogram c)
Sets the chromatogram to draw.

Parameters:
c - the new chromatogram
See Also:
ChromatogramGraphic.Option.WIDTH_IS_AUTHORITATIVE, ChromatogramGraphic.Option.HEIGHT_IS_AUTHORITATIVE

getWidth

public int getWidth()
Returns the width of the whole graphic (in pixels).


getHeight

public int getHeight()
Returns the height of the whole graphic (in pixels).


getHorizontalScale

public float getHorizontalScale()
Returns the in-use horizontal scale factor. The "units" of this value are (trace samples) / pixel. For example, a horizontal scale of 1.0 means that there will be one pixel horizontally for each trace sample.


getVerticalScale

public float getVerticalScale()
Returns the in use vertical scale factor. The "units" of this value are (trace value bins) / pixel. For example, a vertical scale of 1.0 means that there will be one pixel vertically for each value in the range [0, getChromatogram().getMax()].


getRenderedWidth

public int getRenderedWidth()
Returns the width of the graphic as it will be rendered. This means that the ChromatogramGraphic.Option.FROM_TRACE_SAMPLE and ChromatogramGraphic.Option.TO_TRACE_SAMPLE bounds are taken into account.


getRenderedWidth

public int getRenderedWidth(float horizontalScale)
Returns the width of the graphic as it would be rendered with the specified horizontal scale. The ChromatogramGraphic.Option.FROM_TRACE_SAMPLE and ChromatogramGraphic.Option.TO_TRACE_SAMPLE bounds are taken into account.


setHeight

public void setHeight(int h)
Sets the height (in pixels). This will also change the vertical scale.

Parameters:
h - the desired height in pixels
See Also:
ChromatogramGraphic.Option.HEIGHT_IS_AUTHORITATIVE

setVerticalScale

public void setVerticalScale(float vs)
Sets the vertical scale (proportional). This will also change the height.

Parameters:
vs - the desired vertical scale. See getVerticalScale() for semantics.
See Also:
ChromatogramGraphic.Option.HEIGHT_IS_AUTHORITATIVE

setWidth

public void setWidth(int w)
Sets the width of the whole graphic (in pixels). This will also change the horizontal scale.

Parameters:
w - the desired width in pixels
See Also:
ChromatogramGraphic.Option.WIDTH_IS_AUTHORITATIVE

setHorizontalScale

public void setHorizontalScale(float hs)
Sets the horizontal scale (proportional). This will also change the width.

Parameters:
hs - the desired vertical scale. See getHorizontalScale() for semantics.
See Also:
ChromatogramGraphic.Option.WIDTH_IS_AUTHORITATIVE

getBaseColor

public java.awt.Color getBaseColor(Symbol b)
Returns the color that will be used to draw the trace for the given DNA symbol.

Parameters:
b - the symbol
Returns:
the color, or null if none is set

getBaseFillColor

public java.awt.Color getBaseFillColor(Symbol b)
Returns the color that will be used to fill in the callboxes for calls with the given symbol.

Parameters:
b - the symbol
Returns:
the color, or null if none is set

setBaseColor

public void setBaseColor(Symbol b,
                         java.awt.Color c)
Maps a color to a DNA symbol. The color as specified will be used for to draw the trace for the symbol (if any). The fill color for calls to the symbol will be derived from the trace color.

Parameters:
b - the symbol
c - the color

getCallboxCount

public int getCallboxCount()
Returns the number of callboxes, regenerating them if necessary. This should almost always equal getChromatogram().getSequenceLength()

Returns:
the number of callboxes

getCallboxBounds

public java.awt.geom.Rectangle2D getCallboxBounds(int index)
Returns the screen-coordinate bounds of the callbox for a given call.

Parameters:
index - the callbox for which to get the bounds 0-based.

getCallboxBounds

public java.awt.geom.Rectangle2D getCallboxBounds(int index,
                                                  boolean boundsOnScreen)
Returns the bounds of the callbox for a given call.

Parameters:
index - the callbox for which to get the bounds 0-based.
boundsOnScreen - determines the coordinate system of the returned bounds
Returns:
the bounds of the callbox in screen coordinates if boundsOnScreen is true, otherwise the bounds of the callbox in chromatogram coordinates

getCallContaining

public int getCallContaining(java.awt.geom.Point2D point,
                             boolean pointOnScreen)
Returns the 0-based index of the call containing a given point. The point may be either in screen space or chromatogram space, scale-wise. If the point is in screen space, the caller must translate the point such that if it is, for instance, from a mouse click, a click on the upper-left corner of the graphic would be (0,0).

Parameters:
point - the point to search for
pointOnScreen - if true, the point will be treated as though it is in screen space. Otherwise, it will be considered to be in chromatogram space.
Returns:
the 0-based index of the callbox which contains the point

getCallContaining

public int getCallContaining(java.awt.geom.Point2D point)
Synonym for getCallContaining(Point2D, boolean) with pointOnScreen=true.


getCallContaining

public int getCallContaining(float x,
                             boolean xOnScreen)
Same as getCallContaining(Point2D, boolean), except that only the x-coordinate of the point is specified.

Parameters:
x - the x-coordinate to search for
xOnScreen - whether the coordinate in screen space or chromatogram space

getCallContaining

public int getCallContaining(float x)
Synonym for getCallContaining(float, boolean) with pointOnScreen=true.


getTransform

public java.awt.geom.AffineTransform getTransform()
Returns a new AffineTransform describing the transformation from chromatogram coordinates to output coordinates.


getTransformAndConcat

public void getTransformAndConcat(java.awt.geom.AffineTransform target)
Concatenates the chromatogram-to-output transform to the provided given AffineTransform.


getInvTransform

public java.awt.geom.AffineTransform getInvTransform()
Returns a new AffineTransform describing the transformation from output space to chromatogram space. Should be much more efficient than getTransform().createInverse()


drawTo

public void drawTo(java.awt.Graphics2D g2)
Draws the chromatogram onto the provided graphics context.


setOption

public void setOption(ChromatogramGraphic.Option opt,
                      java.lang.Object value)
Sets a new value for the specified option. Be sure that the value is appropriate per the documentation, or you'll induce a ClassCastException somewhere else.

See Also:
ChromatogramGraphic.Option

getOption

public java.lang.Object getOption(ChromatogramGraphic.Option opt)
Returns the current value for the specified option.

See Also:
ChromatogramGraphic.Option

optionIsTrue

public boolean optionIsTrue(ChromatogramGraphic.Option opt)
                     throws java.lang.ClassCastException
Helper method for converting a Boolean-valued option into a boolean primitive.

Parameters:
opt - the ChromatogramGraphic.Option to convert
Throws:
java.lang.ClassCastException - when the option isn't Boolean-valued

getFloatOption

public float getFloatOption(ChromatogramGraphic.Option opt)
                     throws java.lang.ClassCastException
Helper method for converting a Number-valued option into a float primitive.

Parameters:
opt - the ChromatogramGraphic.Option to convert
Throws:
java.lang.ClassCastException - when the option isn't Number-valued

getIntOption

public int getIntOption(ChromatogramGraphic.Option opt)
                 throws java.lang.ClassCastException
Helper method for converting a Number-valued option into an int primitive.

Parameters:
opt - the ChromatogramGraphic.Option to convert
Throws:
java.lang.ClassCastException - when the option isn't Number-valued

clone

public java.lang.Object clone()
Performs a partial deep copy and invalidates regenerable structures