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 the IDrawVisitor 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 Details

    • transform

      protected AffineTransform transform
      This is initially null, and must be set in the setTransform method!
  • Constructor Details

    • AbstractAWTDrawVisitor

      public AbstractAWTDrawVisitor()
  • Method Details

    • 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 transform
      yCoord - 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 string
      xCoord - the world x-coordinate of where the text should be placed
      yCoord - the world y-coordinate of where the text should be placed
      graphics - 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 string
      xCoord - the world x-coordinate of where the text should be placed
      yCoord - the world y-coordinate of where the text should be placed
      graphics - 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 the text in the provided graphics environment.
      Parameters:
      text - the text to obtain the bounds of
      g2 - the graphic environment
      Returns:
      bounds of the text
      See Also:
    • setTransform

      public void setTransform(AffineTransform transform)
      Sets a new affine transformation to convert world coordinates into screen coordinates.
      Specified by:
      setTransform in interface IRenderingVisitor
      Parameters:
      transform - the new AffineTransform.