Class AtomContainerRenderer
- All Implemented Interfaces:
IRenderer<IAtomContainer>
IAtomContainers. The chem object
is converted into a 'diagram' made up of IRenderingElements. 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 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 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.
- Author:
- maclean
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe default scale is used when the model is empty.Fields inherited from class AbstractRenderer
cachedDiagram, drawCenter, fontManager, generators, modelCenter, rendererModel, transformModifier and TypeFieldDescriptionprotected IRenderingElementUsed when repainting an unchanged model.protected javax.vecmath.Point2dThe center of the desired position on screen to draw.protected IFontManagerFont managers change the font size depending on the zoom.protected List<IGenerator<IAtomContainer>> Generators for diagram elements.protected javax.vecmath.Point2dThe center point of the model (IAtomContainer, IAtomContainerSet, etc).protected final RendererModelThe renderer model is final as it is not intended to be replaced.protected AffineTransformConverts between model coordinates and screen coordinates. -
Constructor Summary
ConstructorsConstructorDescriptionAtomContainerRenderer(List<IGenerator<IAtomContainer>> generators, IFontManager fontManager) A renderer that generates diagrams using the specified generators and manages fonts with the supplied font manager.AtomContainerRenderer(RendererModel rendererModel, List<IGenerator<IAtomContainer>> generators, IFontManager fontManager) -
Method Summary
Modifier and TypeMethodDescriptioncalculateDiagramBounds(IAtomContainer atomContainer) Given aIChemObject, calculates the bounding rectangle in screen space.doublecalculateScaleForBondLength(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.Returns aListofIGenerators for this renderer.paint(IAtomContainer atomContainer, IDrawVisitor drawVisitor) Paint an IChemObject.voidpaint(IAtomContainer atomContainer, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter) Paint a molecule (an IAtomContainer).voidreset()Reset the draw center and model center, and set the zoom to 100%.voidsetScale(IAtomContainer atomContainer) Set the scale for an IAtomContainer.voidsetup(IAtomContainer atomContainer, Rectangle screen) Setup the transformations necessary to draw this Atom Container.Methods inherited from class AbstractRenderer
calculateScreenBounds, convertToDiagramBounds, generateDiagram, getBounds, getDrawCenter, getModelCenter, getRenderer2DModel, paint, repaint, setDrawCenter, setModelCenter, setup, setupTransformNatural, setupTransformToFit, setZoom, setZoomToFit, shift, shiftDrawCenter, toModelCoordinates, toScreenCoordinatesModifier and TypeMethodDescriptioncalculateScreenBounds(Rectangle2D modelBounds) Converts a bounding rectangle in 'model space' into the equivalent bounds in 'screen space'.protected RectangleconvertToDiagramBounds(Rectangle2D modelBounds) Calculate the bounds of the diagram on screen, given the current scale, zoom, and margin.generateDiagram(IAtomContainer object) The main method of the renderer, that uses each of the generators to create a different set ofIRenderingElements grouped together into a tree.getBounds(IRenderingElement element) Given a rendering element, traverse the elements compute required bounds to full display all elements.javax.vecmath.Point2dGet the position on screen that the diagram will be drawn.javax.vecmath.Point2dGet the center of the model.Get theRendererModelused by this renderer, which provides access to the various parameters used to generate and draw the diagram.protected voidpaint(IDrawVisitor drawVisitor, IRenderingElement diagram) The target method for paintChemModel, paintReaction, and paintMolecule.voidrepaint(IDrawVisitor drawVisitor) Repaint using the cached diagram.voidsetDrawCenter(double modelX, double modelY) Set the point on the screen to draw the diagram.voidsetModelCenter(double modelX, double modelY) Set the position of the center of the model.protected voidsetup()Creates the transform using the scale, zoom, drawCenter, and modelCenter.protected voidsetupTransformNatural(Rectangle2D modelBounds) Set the transform for a non-fit to screen paint.protected voidsetupTransformToFit(Rectangle2D screenBounds, Rectangle2D modelBounds, double bondLength, boolean reset) Sets the transformation needed to draw the model on the canvas when the diagram needs to fit the screen.voidsetZoom(double zoom) Set the zoom, where 1.0 is 100% zoom.voidsetZoomToFit(double drawWidth, double drawHeight, double diagramWidth, double diagramHeight) Calculate and set the zoom factor needed to completely fit the diagram onto the screen bounds.Determine the overlap of the diagram with the screen, and shift (if necessary) the diagram draw center.voidshiftDrawCenter(double shiftX, double shiftY) Move the draw center by dx and dy.javax.vecmath.Point2dtoModelCoordinates(double screenX, double screenY) Convert a point in screen space into a point in model space.javax.vecmath.Point2dtoScreenCoordinates(double modelX, double modelY) Convert a point in model space into a point in screen space.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface IRenderer
generateDiagram, getRenderer2DModel, setZoom, shiftDrawCenter, toModelCoordinates, toScreenCoordinatesModifier and TypeMethodDescriptionInternal method to generate the intermediate format.Returns the drawing model, giving access to drawing parameters.voidsetZoom(double zoomFactor) Set a new zoom factor.voidshiftDrawCenter(double screenX, double screenY) Set a new drawing center in screen coordinates.javax.vecmath.Point2dtoModelCoordinates(double screenXTo, double screenYTo) Converts screen coordinates into model (or world) coordinates.javax.vecmath.Point2dtoScreenCoordinates(double screenXTo, double screenYTo) Converts model (or world) coordinates into screen coordinates.
-
Field Details
-
DEFAULT_SCALE
public static final double DEFAULT_SCALEThe default scale is used when the model is empty.- See Also:
-
-
Constructor Details
-
AtomContainerRenderer
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
-
AtomContainerRenderer
public AtomContainerRenderer(RendererModel rendererModel, List<IGenerator<IAtomContainer>> generators, IFontManager fontManager)
-
-
Method Details
-
setup
Setup the transformations necessary to draw this Atom Container.- Specified by:
setupin interfaceIRenderer<IAtomContainer>- Parameters:
atomContainer- the atom container to use in the setupscreen- the area to draw on
-
reset
public void reset()Reset the draw center and model center, and set the zoom to 100%. -
setScale
Set the scale for an IAtomContainer. 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:
setScalein interfaceIRenderer<IAtomContainer>- Parameters:
atomContainer- the atom container that will be drawn
-
paint
Paint an IChemObject.- Specified by:
paintin interfaceIRenderer<IAtomContainer>- Parameters:
atomContainer- the chem object to paintdrawVisitor- the class that visits the generated elements- Returns:
- the rectangular area where was drawn
-
paint
public void paint(IAtomContainer atomContainer, IDrawVisitor drawVisitor, Rectangle2D bounds, boolean resetCenter) Paint a molecule (an IAtomContainer).- Specified by:
paintin interfaceIRenderer<IAtomContainer>- Parameters:
atomContainer- the molecule to paintdrawVisitor- the visitor that does the drawingbounds- the bounds on the screenresetCenter- if true, set the draw center to be the center of bounds
-
calculateDiagramBounds
Given aIChemObject, calculates the bounding rectangle in screen space.- Specified by:
calculateDiagramBoundsin interfaceIRenderer<IAtomContainer>- Parameters:
atomContainer- theIChemObjectto 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:
calculateScaleForBondLengthin classAbstractRenderer<IAtomContainer>- Parameters:
modelBondLength- the average bond length of the model- Returns:
- the scale necessary to transform this to a screen bond
-
getGenerators
Returns aListofIGenerators for this renderer.- Specified by:
getGeneratorsin interfaceIRenderer<IAtomContainer>- Returns:
- the list of generators for this renderer.
-