Class ChemModelRenderer
- java.lang.Object
-
- org.openscience.cdk.renderer.AbstractRenderer<IChemModel>
-
- org.openscience.cdk.renderer.ChemModelRenderer
-
- All Implemented Interfaces:
IRenderer<IChemModel>
public class ChemModelRenderer extends AbstractRenderer<IChemModel> implements IRenderer<IChemModel>
A general renderer forIChemModel
s,IReaction
s, andIAtomContainer
s. The chem object is converted into a 'diagram' made up ofIRenderingElement
s. It takes anIDrawVisitor
to do the drawing of the generated diagram. Various display properties can be set using theRendererModel
.This class has several usage patterns. For just painting fit-to-screen do:
renderer.paintMolecule(molecule, visitor, drawArea)
for painting at a scale determined by the bond length in the RendererModel:if (moleculeIsNew) { renderer.setup(molecule, drawArea); } Rectangle diagramSize = renderer.paintMolecule(molecule, visitor); // ...update scroll bars here
to paint at full screen size, but not resize with each change:if (moleculeIsNew) { renderer.setScale(molecule); Rectangle diagramBounds = renderer.calculateDiagramBounds(molecule); renderer.setZoomToFit(diagramBounds, drawArea); renderer.paintMolecule(molecule, visitor); } else { Rectangle diagramSize = renderer.paintMolecule(molecule, visitor); // ...update scroll bars here }
finally, if you are scrolling, and have not changed the diagram:renderer.repaint(visitor)
will just repaint the previously generated diagram, at the same scale.There are two sets of methods for painting IChemObjects - those that take a Rectangle that represents the desired draw area, and those that return a Rectangle that represents the actual draw area. The first are intended for drawing molecules fitted to the screen (where 'screen' means any drawing area) while the second type of method are for drawing bonds at the length defined by the
RendererModel
parameter bondLength.There are two numbers used to transform the model so that it fits on screen. The first is
scale
, which is used to map model coordinates to screen coordinates. The second iszoom
which is used to, well, zoom the on screen coordinates. If the diagram is fit-to-screen, then the ratio of the bounds when drawn using bondLength and the bounds of the screen is used as the zoom.So, if the bond length on screen is set to 40, and the average bond length of the model is 2 (unitless, but roughly Ångstrom scale) then the scale will be 20. If the model is 10 units wide, then the diagram drawn at 100% zoom will be 10 * 20 = 200 in width on screen. If the screen is 400 pixels wide, then fitting it to the screen will make the zoom 200%. Since the zoom is just a floating point number, 100% = 1 and 200% = 2.
- Author:
- maclean
- Source code:
- main
- Belongs to CDK module:
- renderextra
-
-
Field Summary
-
Fields inherited from class org.openscience.cdk.renderer.AbstractRenderer
cachedDiagram, drawCenter, fontManager, generators, modelCenter, rendererModel, transform
-
-
Constructor Summary
Constructors Constructor Description ChemModelRenderer(List<IGenerator<IAtomContainer>> generators, List<IGenerator<IReaction>> reactionGenerators, IFontManager fontManager)
ChemModelRenderer(List<IGenerator<IAtomContainer>> generators, IFontManager fontManager)
A renderer that generates diagrams using the specified generators and manages fonts with the supplied font manager.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Rectangle
calculateDiagramBounds(IChemModel model)
Given a chem model, calculates the bounding rectangle in screen space.double
calculateScaleForBondLength(double modelBondLength)
Given a bond length for a model, calculate the scale that will transform this length to the on screen bond length in RendererModel.List<IGenerator<IChemModel>>
getGenerators()
Returns aList
ofIGenerator
s for this renderer.Rectangle
paint(IChemModel chemModel, IDrawVisitor drawVisitor)
Paint an IChemModel using the IDrawVisitor at a scale determined by the bond length in RendererModel.void
paint(IChemModel chemModel, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter)
Paint a ChemModel.void
repaint(IDrawVisitor drawVisitor)
Repaint using the cached diagram.void
setScale(IChemModel chemModel)
Set the scale for an IChemModel.void
setup(IChemModel chemModel, Rectangle screen)
Setup the transformations necessary to draw this Chem Model.-
Methods inherited from class org.openscience.cdk.renderer.AbstractRenderer
calculateScreenBounds, convertToDiagramBounds, generateDiagram, getBounds, getDrawCenter, getModelCenter, getRenderer2DModel, paint, setDrawCenter, setModelCenter, setup, setupTransformNatural, setupTransformToFit, setZoom, setZoomToFit, shift, shiftDrawCenter, toModelCoordinates, toScreenCoordinates
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.openscience.cdk.renderer.IRenderer
generateDiagram, getRenderer2DModel, setZoom, shiftDrawCenter, toModelCoordinates, toScreenCoordinates
-
-
-
-
Constructor Detail
-
ChemModelRenderer
public ChemModelRenderer(List<IGenerator<IAtomContainer>> generators, IFontManager fontManager)
A renderer that generates diagrams using the specified generators and manages fonts with the supplied font manager.- Parameters:
generators
- a list of classes that implement the IGenerator interfacefontManager
- a class that manages mappings between zoom and font sizes
-
ChemModelRenderer
public ChemModelRenderer(List<IGenerator<IAtomContainer>> generators, List<IGenerator<IReaction>> reactionGenerators, IFontManager fontManager)
-
-
Method Detail
-
setup
public void setup(IChemModel chemModel, Rectangle screen)
Setup the transformations necessary to draw this Chem Model.- Specified by:
setup
in interfaceIRenderer<IChemModel>
- Parameters:
chemModel
-screen
-
-
setScale
public void setScale(IChemModel chemModel)
Set the scale for an IChemModel. It calculates the average bond length of the model and calculates the multiplication factor to transform this to the bond length that is set in the RendererModel.- Specified by:
setScale
in interfaceIRenderer<IChemModel>
- Parameters:
chemModel
-
-
paint
public Rectangle paint(IChemModel chemModel, IDrawVisitor drawVisitor)
Paint an IChemModel using the IDrawVisitor at a scale determined by the bond length in RendererModel.- Specified by:
paint
in interfaceIRenderer<IChemModel>
- Parameters:
chemModel
- the chem model to drawdrawVisitor
- the visitor used to draw with- Returns:
- the rectangular area that the diagram will occupy on screen
-
paint
public void paint(IChemModel chemModel, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter)
Paint a ChemModel.- Specified by:
paint
in interfaceIRenderer<IChemModel>
- Parameters:
chemModel
-drawVisitor
- the visitor that does the drawingbounds
- the bounds of the area to paint on.resetCenter
- if true, set the modelCenter to the center of the ChemModel's bounds.
-
repaint
public void repaint(IDrawVisitor drawVisitor)
Repaint using the cached diagram.- Overrides:
repaint
in classAbstractRenderer<IChemModel>
- Parameters:
drawVisitor
- the wrapper for the graphics object that draws
-
calculateDiagramBounds
public Rectangle calculateDiagramBounds(IChemModel model)
Given a chem model, calculates the bounding rectangle in screen space.- Specified by:
calculateDiagramBounds
in interfaceIRenderer<IChemModel>
- Parameters:
model
- the model to draw.- Returns:
- a rectangle in screen space.
-
calculateScaleForBondLength
public double calculateScaleForBondLength(double modelBondLength)
Given a bond length for a model, calculate the scale that will transform this length to the on screen bond length in RendererModel.- Specified by:
calculateScaleForBondLength
in classAbstractRenderer<IChemModel>
- Parameters:
modelBondLength
- the wanted model bond length in screen length- Returns:
- returns the scale that causes the drawn bond lengths in pixels to match the given model bond length
-
getGenerators
public List<IGenerator<IChemModel>> getGenerators()
Returns aList
ofIGenerator
s for this renderer.- Specified by:
getGenerators
in interfaceIRenderer<IChemModel>
- Returns:
- the list of generators for this renderer.
-
-