Class Renderer

java.lang.Object
smile.plot.swing.Renderer

public class Renderer extends Object
Renderer provides methods to draw graphical primitives in logical/mathematical coordinates. The mathematical coordinates are translated into Java2D coordinates based on suitable projection method. Both 2D and 3D shapes are supported.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Renderer(Projection projection)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clears the restriction of the draw area.
    void
    Restricts the draw area to the valid base coordinate space.
    void
    drawLine(double[]... coord)
    Draws poly line.
    void
    drawLineBaseRatio(double[]... coord)
    Draws poly line.
    void
    drawPoint(char mark, double... coord)
    Draws a point with given pattern.
    void
    drawPoint(double... coord)
    Draws a point.
    void
    drawPolygon(double[]... coord)
    Draws polygon.
    void
    drawRect(double[] topLeft, double[] rightBottom)
    Draws the outline of the specified rectangle.
    void
    drawRectBaseRatio(double[] topLeft, double[] rightBottom)
    Draws the outline of the specified rectangle.
    void
    drawText(String text, double[] coord)
    Draws a string.
    void
    drawText(String text, double[] coord, double rotation)
    Draws a string with given rotation angle.
    void
    drawText(String text, double[] coord, double horizontalReference, double verticalReference)
    Draws a string with given reference point.
    void
    drawText(String text, double[] coord, double horizontalReference, double verticalReference, double rotation)
    Draws a string with given reference point and rotation angle.
    void
    drawTextBaseRatio(String text, double[] coord)
    Draw a string with given rotation angle.
    void
    drawTextBaseRatio(String text, double[] coord, double rotation)
    Draw a string with given rotation angle.
    void
    drawTextBaseRatio(String text, double[] coord, double horizontalReference, double verticalReference)
    Draw a string with given reference point.
    void
    drawTextBaseRatio(String text, double[] coord, double horizontalReference, double verticalReference, double rotation)
    Draw a string with given reference point and rotation angle.
    void
    fillPolygon(double[]... coord)
    Fills polygon.
    void
    fillPolygon(float alpha, double[]... coord)
    Fills polygon.
    void
    fillRect(double[] topLeft, double[] rightBottom)
    Fills the specified rectangle.
    void
    fillRectBaseRatio(double[] topLeft, double[] rightBottom)
    Fills the specified rectangle.
    Gets the current color.
    Gets the current font.
    Returns the Java2D graphics object.
    double[]
    Returns the lower bounds of coordinate space.
    Gets the current paint object.
    Gets the current stroke.
    double[]
    Returns the upper bounds of coordinate space.
    Returns the projection object.
    void
    rotate(double x, double y)
    Rotates the 3D view based on the changes on mouse position.
    setColor(Color color)
    Sets the color.
    setFont(Font font)
    Sets the font.
    void
    Sets the Java2D graphics object.
    setPaint(Paint paint)
    Sets the paint object.
    setStroke(Stroke stroke)
    Sets the stroke.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • Renderer

      public Renderer(Projection projection)
      Constructor.
      Parameters:
      projection - the projection.
  • Method Details

    • projection

      public Projection projection()
      Returns the projection object.
      Returns:
      the projection object.
    • getGraphics

      public Graphics2D getGraphics()
      Returns the Java2D graphics object.
      Returns:
      the Java2D graphics object.
    • setGraphics

      public void setGraphics(Graphics2D g2d)
      Sets the Java2D graphics object.
      Parameters:
      g2d - Java2D graphics.
    • getLowerBound

      public double[] getLowerBound()
      Returns the lower bounds of coordinate space.
      Returns:
      the lower bounds of coordinate space.
    • getUpperBound

      public double[] getUpperBound()
      Returns the upper bounds of coordinate space.
      Returns:
      the upper bounds of coordinate space.
    • getFont

      public Font getFont()
      Gets the current font.
      Returns:
      the font.
    • setFont

      public Renderer setFont(Font font)
      Sets the font.
      Parameters:
      font - the font.
      Returns:
      this object.
    • getColor

      public Color getColor()
      Gets the current color.
      Returns:
      the color.
    • setColor

      public Renderer setColor(Color color)
      Sets the color.
      Parameters:
      color - the color.
      Returns:
      this object.
    • getPaint

      public Paint getPaint()
      Gets the current paint object.
      Returns:
      the paint.
    • setPaint

      public Renderer setPaint(Paint paint)
      Sets the paint object.
      Parameters:
      paint - the paint.
      Returns:
      this object.
    • getStroke

      public Stroke getStroke()
      Gets the current stroke.
      Returns:
      the stroke.
    • setStroke

      public Renderer setStroke(Stroke stroke)
      Sets the stroke.
      Parameters:
      stroke - the stroke.
      Returns:
      this object.
    • clip

      public void clip()
      Restricts the draw area to the valid base coordinate space.
    • clearClip

      public void clearClip()
      Clears the restriction of the draw area.
    • drawText

      public void drawText(String text, double[] coord)
      Draws a string. Reference point is the center of string. The coordinates are logical coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates.
    • drawText

      public void drawText(String text, double[] coord, double rotation)
      Draws a string with given rotation angle. Reference point is the center of string. The coordinates are logical coordinates. The angle of rotation is in radians.
      Parameters:
      text - the text.
      coord - the text coordinates.
      rotation - the rotation angel of text.
    • drawText

      public void drawText(String text, double[] coord, double horizontalReference, double verticalReference)
      Draws a string with given reference point. (0.5, 0.5) is center, (0, 0) is lower left, (0, 1) is upper left, etc. The coordinates are logical coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates.
      horizontalReference - the horizontal reference position of coordinates respected to dimension of text.
      verticalReference - the vertical reference position of coordinates respected to dimension of text.
    • drawText

      public void drawText(String text, double[] coord, double horizontalReference, double verticalReference, double rotation)
      Draws a string with given reference point and rotation angle. (0.5, 0.5) is center, (0, 0) is lower left, (0, 1) is upper left, etc. The angle of rotation is in radians. The coordinates are logical coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates.
      horizontalReference - the horizontal reference position of coordinates respected to dimension of text.
      verticalReference - the vertical reference position of coordinates respected to dimension of text.
      rotation - the rotation angel of text.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String text, double[] coord)
      Draw a string with given rotation angle. Reference point is the center of string. The logical coordinates are proportional to the base coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates in base ratio.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String text, double[] coord, double rotation)
      Draw a string with given rotation angle. Reference point is the center of string. The angle of rotation is in radians. The logical coordinates are proportional to the base coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates in base ratio.
      rotation - the rotation angel of text.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String text, double[] coord, double horizontalReference, double verticalReference)
      Draw a string with given reference point. (0.5, 0.5) is center, (0, 0) is lower left, (0, 1) is upper left, etc. The logical coordinates are proportional to the base coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates in base ratio.
      horizontalReference - the horizontal reference position of coordinates respected to dimension of text.
      verticalReference - the vertical reference position of coordinates respected to dimension of text.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String text, double[] coord, double horizontalReference, double verticalReference, double rotation)
      Draw a string with given reference point and rotation angle. (0.5, 0.5) is center, (0, 0) is lower left, (1, 0) is upper left, etc. The angle of rotation is in radians. The logical are proportional to the base coordinates.
      Parameters:
      text - the text.
      coord - the text coordinates in base ratio.
      horizontalReference - the horizontal reference position of coordinates respected to dimension of text.
      verticalReference - the vertical reference position of coordinates respected to dimension of text.
      rotation - the rotation angel of text.
    • drawLine

      public void drawLine(double[]... coord)
      Draws poly line. The coordinates are in logical coordinates.
      Parameters:
      coord - the line point coordinates.
    • drawLineBaseRatio

      public void drawLineBaseRatio(double[]... coord)
      Draws poly line. The logical coordinates are proportional to the base coordinates.
      Parameters:
      coord - the line point coordinates in base ratio.
    • drawPoint

      public void drawPoint(double... coord)
      Draws a point. The coordinates are in logical coordinates.
      Parameters:
      coord - the point coordinates.
    • drawPoint

      public void drawPoint(char mark, double... coord)
      Draws a point with given pattern. The coordinates are in logical coordinates.
      Parameters:
      mark - the pattern of point:
      • . : dot
      • + : cross
      • - : -
      • | : |
      • * : star
      • x : x
      • o : circle
      • O : large circle
      • @ : solid circle
      • # : large sollid circle
      • s : square
      • S : large square
      • q : solid square
      • Q : large solid square
      coord - the point coordinates.
    • drawPolygon

      public void drawPolygon(double[]... coord)
      Draws polygon. The coordinates are in logical coordinates.
      Parameters:
      coord - the polygon point coordinates.
    • fillPolygon

      public void fillPolygon(double[]... coord)
      Fills polygon. The coordinates are in logical coordinates.
      Parameters:
      coord - the polygon point coordinates.
    • fillPolygon

      public void fillPolygon(float alpha, double[]... coord)
      Fills polygon. The coordinates are in logical coordinates. This also supports basic alpha compositing rules for combining source and destination colors to achieve blending and transparency effects with graphics and images.
      Parameters:
      alpha - the constant alpha to be multiplied with the alpha of the source. alpha must be a floating point number in the inclusive range [0.0, 1.0].
      coord - the polygon point coordinates.
    • drawRect

      public void drawRect(double[] topLeft, double[] rightBottom)
      Draws the outline of the specified rectangle.
      Parameters:
      topLeft - the top left coordinates.
      rightBottom - the right bottom coordinates.
    • drawRectBaseRatio

      public void drawRectBaseRatio(double[] topLeft, double[] rightBottom)
      Draws the outline of the specified rectangle. The logical coordinates are proportional to the base coordinates.
      Parameters:
      topLeft - the top left coordinates in base ratio.
      rightBottom - the right bottom coordinates in base ratio.
    • fillRect

      public void fillRect(double[] topLeft, double[] rightBottom)
      Fills the specified rectangle.
      Parameters:
      topLeft - the top left coordinates.
      rightBottom - the right bottom coordinates.
    • fillRectBaseRatio

      public void fillRectBaseRatio(double[] topLeft, double[] rightBottom)
      Fills the specified rectangle. The logical coordinates are proportional to the base coordinates.
      Parameters:
      topLeft - the top left coordinates in base ratio.
      rightBottom - the right bottom coordinates in base ratio.
    • rotate

      public void rotate(double x, double y)
      Rotates the 3D view based on the changes on mouse position.
      Parameters:
      x - changes of mouse position on the x-axis.
      y - changes on mouse position on the y-axis.