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.
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'.
|
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. |
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. |
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.
|
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.
|
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 valuepublic 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 drawspublic Rectangle shift(Rectangle screenBounds, Rectangle diagramBounds)
screenBounds
- the bounds of the screendiagramBounds
- the bounds of the diagram