Class Graphics

java.lang.Object
smile.plot.swing.Graphics

public class Graphics extends Object
Graphics 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
    Graphics(smile.plot.swing.Projection projection)
    Constructor.
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Clear the restriction of the draw area.
    void
    Restrict the draw area to the valid base coordinate space.
    void
    drawLine(double[]... coord)
    Draw poly line.
    void
    drawLineBaseRatio(double[]... coord)
    Draw poly line.
    void
    drawPoint(char dot, double... coord)
    Draw a dot with given pattern.
    void
    drawPoint(double... coord)
    Draw a dot.
    void
    drawPolygon(double[]... coord)
    Draw polygon.
    void
    drawRect(double[] topLeft, double[] rightBottom)
    Draw the outline of the specified rectangle.
    void
    drawRectBaseRatio(double[] topLeft, double[] rightBottom)
    Draw the outline of the specified rectangle.
    void
    drawText(String label, double[] coord)
    Draw a string.
    void
    drawText(String label, double[] coord, double rotation)
    Draw a string with given rotation angle.
    void
    drawText(String label, double[] coord, double horizontalReference, double verticalReference)
    Draw a string with given reference point.
    void
    drawText(String label, double[] coord, double horizontalReference, double verticalReference, double rotation)
    Draw a string with given reference point and rotation angle.
    void
    drawTextBaseRatio(String label, double[] coord)
    Draw a string with given rotation angle.
    void
    drawTextBaseRatio(String label, double[] coord, double rotation)
    Draw a string with given rotation angle.
    void
    drawTextBaseRatio(String label, double[] coord, double horizontalReference, double verticalReference)
    Draw a string with given reference point.
    void
    drawTextBaseRatio(String label, double[] coord, double horizontalReference, double verticalReference, double rotation)
    Draw a string with given reference point and rotation angle.
    void
    fillPolygon(double[]... coord)
    Fill polygon.
    void
    fillPolygon(float alpha, double[]... coord)
    Fill polygon.
    void
    fillRect(double[] topLeft, double[] rightBottom)
    Fill the specified rectangle.
    void
    fillRectBaseRatio(double[] topLeft, double[] rightBottom)
    Fill the specified rectangle.
    Get the current color.
    Get the current font.
    Returns the Java2D graphics object.
    double[]
    Returns the lower bounds of coordinate space.
    Get the current paint object.
    smile.plot.swing.Projection
    Returns the projection object.
    Get the current stroke.
    double[]
    Returns the upper bounds of coordinate space.
    void
    Reset projection object when the PlotCanvas size changed.
    void
    rotate(double x, double y)
    Rotate the 3D view based on the changes on mouse position.
    setColor(Color color)
    Set the color.
    setFont(Font font)
    Set the font.
    void
    setGraphics(Graphics2D g2d, int width, int height)
    Set the Java2D graphics object.
    setPaint(Paint paint)
    Set the paint object.
    setStroke(Stroke stroke)
    Set the stroke.

    Methods inherited from class java.lang.Object

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

    • Graphics

      public Graphics(smile.plot.swing.Projection projection)
      Constructor.
  • Method Details

    • resetProjection

      public void resetProjection()
      Reset projection object when the PlotCanvas size changed.
    • getProjection

      public smile.plot.swing.Projection getProjection()
      Returns the projection object.
    • getGraphics

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

      public void setGraphics(Graphics2D g2d, int width, int height)
      Set the Java2D graphics object.
    • getLowerBound

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

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

      public Font getFont()
      Get the current font.
    • setFont

      public Graphics setFont(Font font)
      Set the font.
    • getColor

      public Color getColor()
      Get the current color.
    • setColor

      public Graphics setColor(Color color)
      Set the color.
    • getPaint

      public Paint getPaint()
      Get the current paint object.
    • setPaint

      public Graphics setPaint(Paint paint)
      Set the paint object.
    • getStroke

      public Stroke getStroke()
      Get the current stroke.
    • setStroke

      public Graphics setStroke(Stroke stroke)
      Set the stroke.
    • clip

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

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

      public void drawText(String label, double[] coord)
      Draw a string. Reference point is the center of string. The coordinates are logical coordinates.
    • drawText

      public void drawText(String label, double[] coord, double rotation)
      Draw 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.
    • drawText

      public void drawText(String label, 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 coordinates are logical coordinates.
    • drawText

      public void drawText(String label, 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, (0, 1) is upper left, etc. The angle of rotation is in radians. The coordinates are logical coordinates.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String label, 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.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String label, 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.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String label, 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.
    • drawTextBaseRatio

      public void drawTextBaseRatio(String label, 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.
    • drawLine

      public void drawLine(double[]... coord)
      Draw poly line. The coordinates are in logical coordinates.
    • drawLineBaseRatio

      public void drawLineBaseRatio(double[]... coord)
      Draw poly line. The logical coordinates are proportional to the base coordinates.
    • drawPoint

      public void drawPoint(double... coord)
      Draw a dot. The coordinates are in logical coordinates.
    • drawPoint

      public void drawPoint(char dot, double... coord)
      Draw a dot with given pattern. The coordinates are in logical coordinates.
      Parameters:
      dot - the pattern of dot:
      • . : 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
    • drawPolygon

      public void drawPolygon(double[]... coord)
      Draw polygon. The coordinates are in logical coordinates.
    • fillPolygon

      public void fillPolygon(double[]... coord)
      Fill polygon. The coordinates are in logical coordinates.
    • fillPolygon

      public void fillPolygon(float alpha, double[]... coord)
      Fill 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].
    • drawRect

      public void drawRect(double[] topLeft, double[] rightBottom)
      Draw the outline of the specified rectangle.
    • drawRectBaseRatio

      public void drawRectBaseRatio(double[] topLeft, double[] rightBottom)
      Draw the outline of the specified rectangle. The logical coordinates are proportional to the base coordinates.
    • fillRect

      public void fillRect(double[] topLeft, double[] rightBottom)
      Fill the specified rectangle.
    • fillRectBaseRatio

      public void fillRectBaseRatio(double[] topLeft, double[] rightBottom)
      Fill the specified rectangle. The logical coordinates are proportional to the base coordinates.
    • rotate

      public void rotate(double x, double y)
      Rotate 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.