public class ReactionRenderer extends AbstractRenderer<IReaction> implements IRenderer<IReaction>
IChemModel
s, IReaction
s, and
IAtomContainer
s. The chem object
is converted into a 'diagram' made up of IRenderingElement
s. It takes
an IDrawVisitor
to do the drawing of the generated diagram. Various
display properties can be set using the RendererModel
.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 hereto 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 is zoom 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.
cachedDiagram, drawCenter, fontManager, generators, modelCenter, rendererModel, transform
Constructor and Description |
---|
ReactionRenderer(List<IGenerator<IAtomContainer>> generators,
IFontManager fontManager)
A renderer that generates diagrams using the specified
generators and manages fonts with the supplied font manager.
|
ReactionRenderer(List<IGenerator<IAtomContainer>> generators,
List<IGenerator<IReaction>> reactionGenerators,
IFontManager fontManager)
A renderer that draws
IReaction s with the passed IGenerator
for both IAtomContainer and IReaction content. |
ReactionRenderer(RendererModel rendererModel,
List<IGenerator<IAtomContainer>> generators,
IFontManager fontManager) |
Modifier and Type | Method and Description |
---|---|
Rectangle |
calculateDiagramBounds(IReaction reaction)
Given a
IChemObject , 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.
|
IRenderingElement |
generateDiagram(IReaction reaction)
The main method of the renderer, that uses each of the generators
to create a different set of
IRenderingElement s grouped
together into a tree. |
List<IGenerator<IReaction>> |
getGenerators()
Returns a
List of IGenerator s for this renderer. |
Rectangle |
paint(IReaction reaction,
IDrawVisitor drawVisitor)
Paint an IChemObject.
|
void |
paint(IReaction reaction,
IDrawVisitor drawVisitor,
Rectangle2D bounds,
boolean resetCenter)
Paint a reaction.
|
void |
setScale(IReaction reaction)
Set the scale for an IReaction.
|
void |
setup(IReaction reaction,
Rectangle screen)
Setup the transformations necessary to draw this Reaction.
|
calculateScreenBounds, convertToDiagramBounds, getBounds, getDrawCenter, getModelCenter, getRenderer2DModel, paint, repaint, setDrawCenter, setModelCenter, setup, setupTransformNatural, setupTransformToFit, setZoom, setZoomToFit, shift, shiftDrawCenter, toModelCoordinates, toScreenCoordinates
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getRenderer2DModel, setZoom, shiftDrawCenter, toModelCoordinates, toScreenCoordinates
public ReactionRenderer(List<IGenerator<IAtomContainer>> generators, IFontManager fontManager)
generators
- a list of classes that implement the IGenerator interfacefontManager
- a class that manages mappings between zoom and font sizespublic ReactionRenderer(RendererModel rendererModel, List<IGenerator<IAtomContainer>> generators, IFontManager fontManager)
public ReactionRenderer(List<IGenerator<IAtomContainer>> generators, List<IGenerator<IReaction>> reactionGenerators, IFontManager fontManager)
IReaction
s with the passed IGenerator
for both IAtomContainer
and IReaction
content.generators
- a list of classes that implement the IGenerator
interfacereactionGenerators
- a list of IGenerator
related to IReaction
sfontManager
- a class that manages mappings between zoom and font sizespublic void setup(IReaction reaction, Rectangle screen)
public void setScale(IReaction reaction)
public Rectangle paint(IReaction reaction, IDrawVisitor drawVisitor)
public void paint(IReaction reaction, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter)
public Rectangle calculateDiagramBounds(IReaction reaction)
IChemObject
, calculates the bounding rectangle in screen
space.calculateDiagramBounds
in interface IRenderer<IReaction>
reaction
- the IChemObject
to draw.public double calculateScaleForBondLength(double modelBondLength)
calculateScaleForBondLength
in class AbstractRenderer<IReaction>
modelBondLength
- the wanted model bond length in screen lengthpublic IRenderingElement generateDiagram(IReaction reaction)
IRenderingElement
s grouped
together into a tree.generateDiagram
in interface IRenderer<IReaction>
generateDiagram
in class AbstractRenderer<IReaction>
reaction
- the object of type T to drawIRenderingElement
spublic List<IGenerator<IReaction>> getGenerators()
List
of IGenerator
s for this renderer.getGenerators
in interface IRenderer<IReaction>
Copyright © 2021. All rights reserved.