public abstract class AbstractRenderer<T extends IChemObject> extends Object
The base class for all renderers, handling the core aspects of rendering
such as the location of the model in 'model space' and the location on
the screen to draw the model. It also holds a reference to the list of
IGenerator
instances that are used to create the diagram. These
generators are accessed through the generateDiagram method.
The terminology 'model space' and 'screen space' refer to the coordinate systems for the model and the drawing, respectively. So the 2D points for atoms in the model might be 1 unit apart (roughly representing Ångstrom, perhaps) but the circles in the diagram that represent those atoms might be 10 pixels apart on screen. Therefore screen space will be 10 times model space for this example.
The abstract method calculateScaleForBondLength(double)
is
needed to determine the scale. For the model example just given, this would
return '10.0' for an input of '10.0', as that is the scale for that desired
bond length.
Modifier and Type | Field and Description |
---|---|
protected IRenderingElement |
cachedDiagram
Used when repainting an unchanged model.
|
protected javax.vecmath.Point2d |
drawCenter
The center of the desired position on screen to draw.
|
protected IFontManager |
fontManager
Font managers change the font size depending on the zoom.
|
protected List<IGenerator<T>> |
generators
Generators for diagram elements.
|
protected javax.vecmath.Point2d |
modelCenter
The center point of the model (IAtomContainer, IAtomContainerSet, etc).
|
protected RendererModel |
rendererModel
The renderer model is final as it is not intended to be replaced.
|
protected AffineTransform |
transform
Converts between model coordinates and screen coordinates.
|
Constructor and Description |
---|
AbstractRenderer(RendererModel rendererModel) |
Modifier and Type | Method and Description |
---|---|
abstract double |
calculateScaleForBondLength(double bondLength)
Calculate the scale to convert the model bonds into bonds of the length
supplied.
|
Rectangle |
calculateScreenBounds(Rectangle2D modelBounds)
Converts a bounding rectangle in 'model space' into the equivalent
bounds in 'screen space'.
|
protected Rectangle |
convertToDiagramBounds(Rectangle2D modelBounds)
Calculate the bounds of the diagram on screen, given the current scale,
zoom, and margin.
|
IRenderingElement |
generateDiagram(T object)
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. |
Rectangle2D |
getBounds(IRenderingElement element)
Given a rendering element, traverse the elements compute required bounds
to full display all elements.
|
javax.vecmath.Point2d |
getDrawCenter()
Get the position on screen that the diagram will be drawn.
|
javax.vecmath.Point2d |
getModelCenter()
Get the center of the model.
|
RendererModel |
getRenderer2DModel()
Get the
RendererModel used by this renderer, which provides
access to the various parameters used to generate and draw the diagram. |
protected void |
paint(IDrawVisitor drawVisitor,
IRenderingElement diagram)
The target method for paintChemModel, paintReaction, and paintMolecule.
|
void |
repaint(IDrawVisitor drawVisitor)
Repaint using the cached diagram.
|
void |
setDrawCenter(double modelX,
double modelY)
Set the point on the screen to draw the diagram.
|
void |
setModelCenter(double modelX,
double modelY)
Set the position of the center of the model.
|
protected void |
setup()
Creates the transform using the scale, zoom, drawCenter, and modelCenter.
|
protected void |
setupTransformNatural(Rectangle2D modelBounds)
Set the transform for a non-fit to screen paint.
|
protected void |
setupTransformToFit(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.
|
void |
setZoom(double zoom)
Set the zoom, where 1.0 is 100% zoom.
|
void |
setZoomToFit(double drawWidth,
double drawHeight,
double diagramWidth,
double diagramHeight)
Calculate and set the zoom factor needed to completely fit the diagram
onto the screen bounds.
|
Rectangle |
shift(Rectangle screenBounds,
Rectangle diagramBounds)
Determine the overlap of the diagram with the screen, and shift (if
necessary) the diagram draw center.
|
void |
shiftDrawCenter(double shiftX,
double shiftY)
Move the draw center by dx and dy.
|
javax.vecmath.Point2d |
toModelCoordinates(double screenX,
double screenY)
Convert a point in screen space into a point in model space.
|
javax.vecmath.Point2d |
toScreenCoordinates(double modelX,
double modelY)
Convert a point in model space into a point in screen space.
|
protected final RendererModel rendererModel
protected IFontManager fontManager
protected javax.vecmath.Point2d modelCenter
protected javax.vecmath.Point2d drawCenter
protected List<IGenerator<T extends IChemObject>> generators
protected IRenderingElement cachedDiagram
protected AffineTransform transform
public AbstractRenderer(RendererModel rendererModel)
public IRenderingElement generateDiagram(T object)
IRenderingElement
s grouped
together into a tree.object
- the object of type T to drawIRenderingElement
spublic abstract double calculateScaleForBondLength(double bondLength)
bondLength
- the desired length on screenpublic Rectangle calculateScreenBounds(Rectangle2D modelBounds)
modelBounds
- the bounds of the modelpublic javax.vecmath.Point2d toModelCoordinates(double screenX, double screenY)
screenX
- the screen x-coordinatescreenY
- the screen y-coordinatepublic javax.vecmath.Point2d toScreenCoordinates(double modelX, double modelY)
modelX
- the model x-coordinatemodelY
- the model y-coordinatepublic void setModelCenter(double modelX, double modelY)
modelX
- the x-coordinate of the model centermodelY
- the y-coordinate of the model centerpublic void setDrawCenter(double modelX, double modelY)
modelX
- the x-coordinate of the point to draw atmodelY
- the y-coordinate of the point to draw atpublic void setZoom(double zoom)
zoom
- the zoom as a double valueprotected void setup()
public RendererModel getRenderer2DModel()
RendererModel
used by this renderer, which provides
access to the various parameters used to generate and draw the diagram.public void shiftDrawCenter(double shiftX, double shiftY)
shiftX
- the x shiftshiftY
- the y shiftpublic javax.vecmath.Point2d getDrawCenter()
public javax.vecmath.Point2d getModelCenter()
public void setZoomToFit(double drawWidth, double drawHeight, double diagramWidth, double diagramHeight)
drawWidth
- the width of the area to draw ontodrawHeight
- the height of the area to draw ontodiagramWidth
- the width of the diagramdiagramHeight
- the height of the diagrampublic void repaint(IDrawVisitor drawVisitor)
drawVisitor
- the wrapper for the graphics object that drawsprotected void paint(IDrawVisitor drawVisitor, IRenderingElement diagram)
drawVisitor
- the visitor to draw withdiagram
- the IRenderingElement tree to renderprotected void setupTransformNatural(Rectangle2D modelBounds)
modelBounds
- the bounding box of the modelpublic Rectangle shift(Rectangle screenBounds, Rectangle diagramBounds)
screenBounds
- the bounds of the screendiagramBounds
- the bounds of the diagramprotected Rectangle convertToDiagramBounds(Rectangle2D modelBounds)
modelBounds
- the bounds in model space of the chem objectprotected void setupTransformToFit(Rectangle2D screenBounds, Rectangle2D modelBounds, double bondLength, boolean reset)
screenBounds
- the bounding box of the draw areamodelBounds
- the bounding box of the modelbondLength
- the average bond length of the modelreset
- if true, model center will be set to the modelBounds center
and the scale will be re-calculatedpublic Rectangle2D getBounds(IRenderingElement element)
Bounds
elements which act to specify the required bounds when adjunct labels
are considered.element
- a rendering elementCopyright © 2018. All Rights Reserved.