Package smile.plot.swing
Class Graphics
java.lang.Object
smile.plot.swing.Graphics
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
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Clear the restriction of the draw area.void
clip()
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
Draw a string.void
Draw a string with given rotation angle.void
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.getColor()
Get the current color.getFont()
Get the current font.Returns the Java2D graphics object.double[]
Returns the lower bounds of coordinate space.getPaint()
Get the current paint object.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.Set the color.Set the font.void
setGraphics
(Graphics2D g2d, int width, int height) Set the Java2D graphics object.Set the paint object.Set the stroke.
-
Constructor Details
-
Graphics
Constructor.
-
-
Method Details
-
resetProjection
public void resetProjection()Reset projection object when the PlotCanvas size changed. -
getProjection
Returns the projection object. -
getGraphics
Returns the Java2D graphics object. -
setGraphics
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
Get the current font. -
setFont
Set the font. -
getColor
Get the current color. -
setColor
Set the color. -
getPaint
Get the current paint object. -
setPaint
Set the paint object. -
getStroke
Get the current stroke. -
setStroke
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
Draw a string. Reference point is the center of string. The coordinates are logical coordinates. -
drawText
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
Draw a string with given rotation angle. Reference point is the center of string. The logical coordinates are proportional to the base coordinates. -
drawTextBaseRatio
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.
-