Package org.biojava.bio.gui.sequence
Class HeadlessRenderContext
java.lang.Object
org.biojava.bio.gui.sequence.HeadlessRenderContext
- All Implemented Interfaces:
SwingConstants
,SequenceRenderContext
A stand-alone SequenceRenderContext to make it easy to render to an image.
This class makes it very easy to render sequence information into an arbitrary graphics object without the need to fuss about with AWT or Swing components. You chose the width of the image and the region of the sequence to render. It will calculate the scale factor to ensure that the whole region of the sequence fits into that width. You can then use the context to render any number of SequenceRenderer instances to any Graphics2D instance you want, for example, to an image that's to be written out by a servlet.
Example
HeadlessRenderContext ctxt = new HeadlessRenderContext( seq, // the sequence to render range, // a RangeLocation giving the block you want to render width // an int specifying the image width in pixles ); BufferedImage img = new BufferedImage( width, // image width (int) Math.ceil(seqRend.getDepth(ctxt), // calculated height BufferedImage.TYPE_INT_RGB // let's use RGB ); // set stuff up Graphics2D graph = img.createGraphics(); graph.setPaint(Color.WHITE); graph.fillRect(0, 0, img.getWidth(), img.getHeight()); // and now render the sequences sequenceRenderer.paint(graph, ctxt); // let's dump this out as a png ImageIO.write(image, "png", myFile);
- Since:
- 1.3
- Author:
- Matthew Pocock
-
Nested Class Summary
Nested classes/interfaces inherited from interface org.biojava.bio.gui.sequence.SequenceRenderContext
SequenceRenderContext.Border
-
Field Summary
Fields inherited from interface org.biojava.bio.gui.sequence.SequenceRenderContext
LAYOUT, REPAINT
Fields inherited from interface javax.swing.SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionint
Gets the direction in which this context expects sequences to be rendered - HORIZONTAL or VERTICAL.The features to render.getFont()
Gets the Font attribute of the SequenceRenderContext objectGets the LeadingBorder attribute of the SequenceRenderContext object.getRange()
The range of the SymbolList to render.double
getScale()
Gets the scale as pixels per SymbolThe SymbolList that is currently rendered by this SequenceRenderContext.Gets the TrailingBorder attribute of the SequenceRenderContext object.int
graphicsToSequence
(double d) Converts a graphical position into a sequence coordinate.int
graphicsToSequence
(Point2D point) Converts a graphical position into a sequence coordinate.double
sequenceToGraphics
(int i) Converts a sequence index into a graphical coordinate.
-
Constructor Details
-
HeadlessRenderContext
-
-
Method Details
-
getDirection
Description copied from interface:SequenceRenderContext
Gets the direction in which this context expects sequences to be rendered - HORIZONTAL or VERTICAL.- Specified by:
getDirection
in interfaceSequenceRenderContext
- Returns:
- The Direction value
-
getFeatures
Description copied from interface:SequenceRenderContext
The features to render.- Specified by:
getFeatures
in interfaceSequenceRenderContext
- Returns:
- a FeatureHolder with the Features to render
-
getFont
Description copied from interface:SequenceRenderContext
Gets the Font attribute of the SequenceRenderContext object- Specified by:
getFont
in interfaceSequenceRenderContext
- Returns:
- The Font value
-
getLeadingBorder
Description copied from interface:SequenceRenderContext
Gets the LeadingBorder attribute of the SequenceRenderContext object. This represents the space between the beginning of the rendering area and the beginning of the sequence.- Specified by:
getLeadingBorder
in interfaceSequenceRenderContext
- Returns:
- The LeadingBorder value
-
getRange
Description copied from interface:SequenceRenderContext
The range of the SymbolList to render.- Specified by:
getRange
in interfaceSequenceRenderContext
- Returns:
- the RangeLocation specifying which indices (inclusive) to render
-
getScale
Description copied from interface:SequenceRenderContext
Gets the scale as pixels per Symbol- Specified by:
getScale
in interfaceSequenceRenderContext
- Returns:
- The scale value
-
getSymbols
Description copied from interface:SequenceRenderContext
The SymbolList that is currently rendered by this SequenceRenderContext.- Specified by:
getSymbols
in interfaceSequenceRenderContext
- Returns:
- The Sequence value
-
getTrailingBorder
Description copied from interface:SequenceRenderContext
Gets the TrailingBorder attribute of the SequenceRenderContext object. This represents the space between the end of the sequence and the end of the rendering area.- Specified by:
getTrailingBorder
in interfaceSequenceRenderContext
- Returns:
- The TrailingBorder value
-
sequenceToGraphics
Description copied from interface:SequenceRenderContext
Converts a sequence index into a graphical coordinate. You will need to use this in conjunction with getDirection to correctly lay graphics out.- Specified by:
sequenceToGraphics
in interfaceSequenceRenderContext
- Parameters:
i
- Index within the sequence- Returns:
- Equivalent graphical position in pixels
-
graphicsToSequence
Description copied from interface:SequenceRenderContext
Converts a graphical position into a sequence coordinate. This will use getDirection to decide whether to use the x or y coordinate.- Specified by:
graphicsToSequence
in interfaceSequenceRenderContext
- Parameters:
point
- a point representing the position- Returns:
- the corresponding sequence index
-
graphicsToSequence
Description copied from interface:SequenceRenderContext
Converts a graphical position into a sequence coordinate. You will need to have used getDirection to decide whether to use the x or y coordinate.- Specified by:
graphicsToSequence
in interfaceSequenceRenderContext
- Parameters:
d
- A pixel position- Returns:
- The corresponding sequence index
-