Class AbstractAWTDrawVisitor
- java.lang.Object
-
- org.openscience.cdk.renderer.visitor.AbstractAWTDrawVisitor
-
- All Implemented Interfaces:
IRenderingVisitor
,IDrawVisitor
- Direct Known Subclasses:
AWTDrawVisitor
public abstract class AbstractAWTDrawVisitor extends Object implements IDrawVisitor
Partial implementation of theIDrawVisitor
interface for the AWT widget toolkit, allowing molecules to be rendered with toolkits based on AWT, like the Java reference graphics platform Swing.- Source code:
- main
- Belongs to CDK module:
- renderawt
-
-
Field Summary
Fields Modifier and Type Field Description protected AffineTransform
transform
This is initially null, and must be set in the setTransform method!
-
Constructor Summary
Constructors Constructor Description AbstractAWTDrawVisitor()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected Point
getTextBasePoint(String text, double xCoord, double yCoord, Graphics2D graphics)
Calculates the base point where text should be rendered, as text in Java is typically placed using the left-lower corner point in screen coordinates.protected Rectangle2D
getTextBounds(String text, double xCoord, double yCoord, Graphics2D graphics)
Calculates the boundaries of a text string in screen coordinates.protected Rectangle2D
getTextBounds(String text, Graphics2D g2)
Obtain the exact bounding box of thetext
in the provided graphics environment.void
setTransform(AffineTransform transform)
Sets a new affine transformation to convert world coordinates into screen coordinates.void
transformPoint(double[] xy)
int[]
transformPoint(double xCoord, double yCoord)
Transforms a point according to the current affine transformation, converting a world coordinate into a screen coordinate.-
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.visitor.IDrawVisitor
setFontManager, setRendererModel
-
Methods inherited from interface org.openscience.cdk.renderer.elements.IRenderingVisitor
visit
-
-
-
-
Field Detail
-
transform
protected AffineTransform transform
This is initially null, and must be set in the setTransform method!
-
-
Method Detail
-
transformPoint
public int[] transformPoint(double xCoord, double yCoord)
Transforms a point according to the current affine transformation, converting a world coordinate into a screen coordinate.- Parameters:
xCoord
- x-coordinate of the world point to transformyCoord
- y-coordinate of the world point to transform- Returns:
- the transformed screen coordinate
-
transformPoint
public void transformPoint(double[] xy)
-
getTextBounds
protected Rectangle2D getTextBounds(String text, double xCoord, double yCoord, Graphics2D graphics)
Calculates the boundaries of a text string in screen coordinates.- Parameters:
text
- the text stringxCoord
- the world x-coordinate of where the text should be placedyCoord
- the world y-coordinate of where the text should be placedgraphics
- the graphics to which the text is provided as output- Returns:
- the screen coordinates
-
getTextBasePoint
protected Point getTextBasePoint(String text, double xCoord, double yCoord, Graphics2D graphics)
Calculates the base point where text should be rendered, as text in Java is typically placed using the left-lower corner point in screen coordinates. However, because the Java coordinate system is inverted in the y-axis with respect to scientific coordinate systems (Java has 0,0 in the top left corner, while in science we have 0,0 in the lower left corner), some special action is needed, involving the size of the text.- Parameters:
text
- the text stringxCoord
- the world x-coordinate of where the text should be placedyCoord
- the world y-coordinate of where the text should be placedgraphics
- the graphics to which the text is provided as output- Returns:
- the screen coordinates
-
getTextBounds
protected Rectangle2D getTextBounds(String text, Graphics2D g2)
Obtain the exact bounding box of thetext
in the provided graphics environment.- Parameters:
text
- the text to obtain the bounds ofg2
- the graphic environment- Returns:
- bounds of the text
- See Also:
TextLayout
-
setTransform
public void setTransform(AffineTransform transform)
Sets a new affine transformation to convert world coordinates into screen coordinates.- Specified by:
setTransform
in interfaceIRenderingVisitor
- Parameters:
transform
- the newAffineTransform
.
-
-