com.xj.anylogic.engine.presentation
Class UtilitiesDrawing

java.lang.Object
  extended by com.xj.anylogic.engine.presentation.UtilitiesDrawing

public final class UtilitiesDrawing
extends java.lang.Object

This is a collection of static functions which could be useful for drawing.

Author:
XJ Technologies Company Ltd. www.anylogic.com

Method Summary
static boolean arcContains(double px, double py, double radiusX, double radiusY, double anglestart, double angle)
          Tests if the arc (pie type) with the given attributes contains the point with coordinates (x,y) relative to the arc center.
static boolean curveContains(double px, double py, int nPoints, double[] dx, double[] dy)
          Tests if the curve with given base points contains the point with coordinates (x,y) relative to the polyline first base point.
static void drawArc(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, double radiusx, double radiusy, double anglestart, double angle, double lineWidth, int lineStyle)
          Draws an arc.
static void drawCurve(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, int npoints, boolean manualControlPoints, double[] dx, double[] dy, boolean closed, double lineWidth, int lineStyle)
          Draws a curve as a sequence of cubic splines.
static void drawCurve(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, int npoints, double[] dx, double[] dy, boolean closed, double lineWidth, int lineStyle)
          Deprecated. use drawCurve(Panel, Graphics2D, AffineTransform, double, double, double, double, double, Color, Color, int, boolean, double[], double[], boolean, double, int)
static void drawImage(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, double width, double height, Presentable p, java.lang.String packagePrefix, java.lang.String filename)
          Draws an image.
static void drawLine(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color color, double dx, double dy, double width, int style)
          Draws a line.
static void drawOval(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, double radiusx, double radiusy, double lineWidth, int lineStyle)
          Draws an oval.
static void drawPixel(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, java.awt.Color color)
          Draws a pixel.
static void drawPolyLine(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, int npoints, double[] dx, double[] dy, boolean closed, double lineWidth, int lineStyle)
          Draws a polyline.
static void drawRectangle(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, double width, double height, double lineWidth, int lineStyle)
          Draws a rectangle.
static void drawRoundedRectangle(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color lineColor, java.awt.Color fillColor, double width, double height, double radius, double lineWidth, int lineStyle)
          Draws a rounded rectangle.
static void drawText(Panel panel, java.awt.Graphics2D g, java.awt.geom.AffineTransform xform, double x, double y, double rotation, double scalex, double scaley, java.awt.Color color, java.lang.String text, java.awt.Font font, int alignment)
          Draws a text.
static int getAdjustedFontSize(int original)
          Adjusts font size depending on the platform.
static java.awt.Font getDefaultFont()
          Returns the default font used in presentation graphics
static java.awt.Font getDefaultFont(int style)
          Returns the default font of a particular style
static java.awt.BasicStroke getDefaultStroke()
          Returns the Default stroke: solid line, width 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 4.0.
static java.awt.BasicStroke getThinnestStroke()
          Returns the thinnest possible stroke: solid line, width 0.0 CAP_SQUARE, JOIN_MITER, a miter limit of 10.0.
static boolean ovalContains(double px, double py, double radiusX, double radiusY)
          Tests if the oval with the given attributes contains the point with coordinates (x,y) relative to the oval center.
static boolean polyLineContains(double px, double py, int nPoints, double[] dx, double[] dy)
          Tests if the polygon with given base points contains the point with coordinates (x,y) relative to the polygon first base point.
static boolean rectangleContains(double px, double py, double width, double height)
          Tests if the rectangle with the given attributes contains the point with coordinates (x,y) relative to the rectangle "upper left" corner.
static boolean roundedRectangleContains(double px, double py, double width, double height, double radius)
          Tests if the rounded rectangle with the given attributes contains the point with coordinates (x,y) relative to the rectangle "upper left" corner.
static void setDefaultFonts()
          Deprecated. this method shouldn't be called by user and will be removed in the next release
static boolean textContains(double px, double py, java.lang.String text, java.awt.Font font, int alignment)
          Tests if a (possibly, multi-line) text with given font and alignment contains the point with coordinates (x,y) relative to the text base point (which is NOT the beginning of the baseline, but top left, right or center of text, depending on alignment).
static double transformX(double px, double py, double x, double y, double rotation, double scalex)
          Transforms the x coordinate of a given point according to the base coordinates, rotation and scale.
static double transformY(double px, double py, double x, double y, double rotation, double scaley)
          Transforms the y coordinate of a given point according to the base coordinates, rotation and scale.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getDefaultFont

public static java.awt.Font getDefaultFont()
Returns the default font used in presentation graphics


getDefaultFont

public static java.awt.Font getDefaultFont(int style)
Returns the default font of a particular style


getAdjustedFontSize

public static int getAdjustedFontSize(int original)
Adjusts font size depending on the platform. Is needed because Java 2D and Windows assume different screen resolutions, while Java 2D and e.g. Mac OS - same. Code taken from http://www.3rd-evolution.de/tkrammer/docs/java_font_size.html

Parameters:
original - the original font size
Returns:
the adjusted font size

getDefaultStroke

public static java.awt.BasicStroke getDefaultStroke()
Returns the Default stroke: solid line, width 1.0, CAP_SQUARE, JOIN_MITER, a miter limit of 4.0.

Returns:
the Default stroke

getThinnestStroke

public static java.awt.BasicStroke getThinnestStroke()
Returns the thinnest possible stroke: solid line, width 0.0 CAP_SQUARE, JOIN_MITER, a miter limit of 10.0.

Returns:
the Default stroke

setDefaultFonts

@Deprecated
public static void setDefaultFonts()
Deprecated. this method shouldn't be called by user and will be removed in the next release

Sets the default fonts used by AnyLogic with respect to the system default fonts. Is called after the look and feel is set.


arcContains

public static boolean arcContains(double px,
                                  double py,
                                  double radiusX,
                                  double radiusY,
                                  double anglestart,
                                  double angle)
Tests if the arc (pie type) with the given attributes contains the point with coordinates (x,y) relative to the arc center.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
radiusX - "horizontal" radius of the arc
radiusY - "vertical" radius of the arc
anglestart - the starting angle of the arc (0 means 12 o'clock) in radians, clockwise
angle - the angular extent of the arc in radians, clockwise
Returns:
true if the point is within the arc boundary, otherwise false

curveContains

public static boolean curveContains(double px,
                                    double py,
                                    int nPoints,
                                    double[] dx,
                                    double[] dy)
Tests if the curve with given base points contains the point with coordinates (x,y) relative to the polyline first base point.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
nPoints - the number of base points
dx - the array of (at least nPoints) base points x coordinates relative to the start point
dy - the array of (at least nPoints) base points y coordinates relative to the start point
Returns:
true if the point is within the curve boundary, otherwise false

drawArc

public static void drawArc(Panel panel,
                           java.awt.Graphics2D g,
                           java.awt.geom.AffineTransform xform,
                           double x,
                           double y,
                           double rotation,
                           double scalex,
                           double scaley,
                           java.awt.Color lineColor,
                           java.awt.Color fillColor,
                           double radiusx,
                           double radiusy,
                           double anglestart,
                           double angle,
                           double lineWidth,
                           int lineStyle)
Draws an arc.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the arc center
y - the y coordinate of the arc
rotation - the rotation of the arc (in radians) around its center
scalex - the scale of the arc along x axis
scaley - the scale of the arc along y axis
lineColor - line color of the arc
fillColor - fill color of the arc
radiusx - "horizontal" radius of the arc
radiusy - "vertical" radius of the arc
anglestart - the starting angle of the arc (0 means 12 o'clock) in radians, clockwise
angle - the anglular extent of the arc in radians, clockwise
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawCurve

@Deprecated
public static void drawCurve(Panel panel,
                                        java.awt.Graphics2D g,
                                        java.awt.geom.AffineTransform xform,
                                        double x,
                                        double y,
                                        double rotation,
                                        double scalex,
                                        double scaley,
                                        java.awt.Color lineColor,
                                        java.awt.Color fillColor,
                                        int npoints,
                                        double[] dx,
                                        double[] dy,
                                        boolean closed,
                                        double lineWidth,
                                        int lineStyle)
Deprecated. use drawCurve(Panel, Graphics2D, AffineTransform, double, double, double, double, double, Color, Color, int, boolean, double[], double[], boolean, double, int)


drawCurve

public static void drawCurve(Panel panel,
                             java.awt.Graphics2D g,
                             java.awt.geom.AffineTransform xform,
                             double x,
                             double y,
                             double rotation,
                             double scalex,
                             double scaley,
                             java.awt.Color lineColor,
                             java.awt.Color fillColor,
                             int npoints,
                             boolean manualControlPoints,
                             double[] dx,
                             double[] dy,
                             boolean closed,
                             double lineWidth,
                             int lineStyle)
Draws a curve as a sequence of cubic splines.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the curve start point
y - the y coordinate of the curve start point
rotation - the rotation of the curve (in radians) around its start point
scalex - the scale of the curve along x axis
scaley - the scale of the curve along y axis
lineColor - line color of the curve
fillColor - fill color of the curve
npoints - the number of points in the curve
dx - the array of curve base points x coordinates relative to the start point (if controlPointsIncluded == true, with control points, in triplets: p0x, p0c1x, p0c2x, p1x, p1c1x, p1c2x... )
dy - the array of curve base points y coordinates relative to the start point (if controlPointsIncluded == true, with control points, in triplets: p0y, p0c1y, p0c2y, p1y, p1c1y, p1c2y... )
manualControlPoints - if true curve is drawn using control points specified in the dx and dy arrays
closed - if true, the curve is drawn as closed
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawImage

public static void drawImage(Panel panel,
                             java.awt.Graphics2D g,
                             java.awt.geom.AffineTransform xform,
                             double x,
                             double y,
                             double rotation,
                             double scalex,
                             double scaley,
                             double width,
                             double height,
                             Presentable p,
                             java.lang.String packagePrefix,
                             java.lang.String filename)
Draws an image. Uses the panel's image cache. Note that the images are cached as BufferedImages with requested width and height, so it is not desirable to change it frequently.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the image
y - the y coordinate of the image
rotation - the rotation of the image (in radians) around its upper left corner
scalex - the scale of the image along x axis
scaley - the scale of the image along y axis
width - the requested width of the image, -1 for original width
height - the requested height of the image, -1 for original height
p - the presentable object owning the image
packagePrefix - the package name of original active object where this image is defined, formatted using '/' characters; with '/' character at the beginning
filename - the file name of the image, relative to the class of p

drawLine

public static void drawLine(Panel panel,
                            java.awt.Graphics2D g,
                            java.awt.geom.AffineTransform xform,
                            double x,
                            double y,
                            double rotation,
                            double scalex,
                            double scaley,
                            java.awt.Color color,
                            double dx,
                            double dy,
                            double width,
                            int style)
Draws a line.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the line start point
y - the y coordinate of the line start point
rotation - the rotation of the line (in radians) around its start point
scalex - the scale of the line along x axis
scaley - the scale of the line along y axis
color - color of the line
dx - the difference of x coordinates of the line end and start points
dy - the difference of y coordinates of the line end and start points
width - line width
style - line stroke style (solid, dotted, dashed)

drawOval

public static void drawOval(Panel panel,
                            java.awt.Graphics2D g,
                            java.awt.geom.AffineTransform xform,
                            double x,
                            double y,
                            double rotation,
                            double scalex,
                            double scaley,
                            java.awt.Color lineColor,
                            java.awt.Color fillColor,
                            double radiusx,
                            double radiusy,
                            double lineWidth,
                            int lineStyle)
Draws an oval.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the oval center
y - the y coordinate of the oval center
rotation - the rotation of the oval (in radians) around its center
scalex - the scale of the oval along x axis
scaley - the scale of the oval along y axis
lineColor - line color of the oval
fillColor - fill color of the oval
radiusx - "horizontal" radius of the oval
radiusy - "vertical" radius of the oval
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawPixel

public static void drawPixel(Panel panel,
                             java.awt.Graphics2D g,
                             java.awt.geom.AffineTransform xform,
                             double x,
                             double y,
                             java.awt.Color color)
Draws a pixel.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the pixel
y - the x coordinate of the pixel
color - color of the pixel

drawPolyLine

public static void drawPolyLine(Panel panel,
                                java.awt.Graphics2D g,
                                java.awt.geom.AffineTransform xform,
                                double x,
                                double y,
                                double rotation,
                                double scalex,
                                double scaley,
                                java.awt.Color lineColor,
                                java.awt.Color fillColor,
                                int npoints,
                                double[] dx,
                                double[] dy,
                                boolean closed,
                                double lineWidth,
                                int lineStyle)
Draws a polyline.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the polyline start point
y - the y coordinate of the polyline start point
rotation - the rotation of the polyline (in radians) around its start point
scalex - the scale of the polyline along x axis
scaley - the scale of the polyline along y axis
lineColor - line color of the polyline
fillColor - fill color of the polyline
npoints - the number of points in the polyline
dx - the array of (at least npoints) polyline points x coordinates relative to the start point
dy - the array of (at least npoints) polyline points y coordinates relative to the start point
closed - if true, the polyline is drawn as closed
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawRectangle

public static void drawRectangle(Panel panel,
                                 java.awt.Graphics2D g,
                                 java.awt.geom.AffineTransform xform,
                                 double x,
                                 double y,
                                 double rotation,
                                 double scalex,
                                 double scaley,
                                 java.awt.Color lineColor,
                                 java.awt.Color fillColor,
                                 double width,
                                 double height,
                                 double lineWidth,
                                 int lineStyle)
Draws a rectangle.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the rectangle
y - the y coordinate of the rectangle
rotation - the rotation of the rectangle (in radians) around its upper left corner
scalex - the scale of the rectangle along x axis
scaley - the scale of the rectangle along y axis
lineColor - line color of the rectangle
fillColor - fill color of the rectangle
width - width of the rectangle
height - height of the rectangle
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawRoundedRectangle

public static void drawRoundedRectangle(Panel panel,
                                        java.awt.Graphics2D g,
                                        java.awt.geom.AffineTransform xform,
                                        double x,
                                        double y,
                                        double rotation,
                                        double scalex,
                                        double scaley,
                                        java.awt.Color lineColor,
                                        java.awt.Color fillColor,
                                        double width,
                                        double height,
                                        double radius,
                                        double lineWidth,
                                        int lineStyle)
Draws a rounded rectangle.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the rounded rectangle
y - the y coordinate of the rounded rectangle
rotation - the rotation of the rounded rectangle (in radians) around its upper left corner
scalex - the scale of the rounded rectangle along x axis
scaley - the scale of the rounded rectangle along y axis
lineColor - line color of the rounded rectangle
fillColor - fill color of the rounded rectangle
width - width of the rounded rectangle
height - height of the rounded rectangle
radius - of corners of the rounded rectangle
lineWidth - line width
lineStyle - line stroke style (solid, dotted, dashed)

drawText

public static void drawText(Panel panel,
                            java.awt.Graphics2D g,
                            java.awt.geom.AffineTransform xform,
                            double x,
                            double y,
                            double rotation,
                            double scalex,
                            double scaley,
                            java.awt.Color color,
                            java.lang.String text,
                            java.awt.Font font,
                            int alignment)
Draws a text.

Parameters:
panel - the presentation panel
g - the graphics where the drawing takes place
xform - the "original" transform that must be restored before drawing
x - the x coordinate of the text start point
y - the y coordinate of the text start point (baseline - ascent)
rotation - the rotation of the text (in radians) around its start point
scalex - the scale of the text along x axis
scaley - the scale of the text along y axis
color - color of the text
text - the text string to be drawn
font - font to use
alignment - the alignment of the text

ovalContains

public static boolean ovalContains(double px,
                                   double py,
                                   double radiusX,
                                   double radiusY)
Tests if the oval with the given attributes contains the point with coordinates (x,y) relative to the oval center.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
radiusX - "horizontal" radius of the oval
radiusY - "vertical" radius of the oval
Returns:
true if the point is within the oval boundary, otherwise false

polyLineContains

public static boolean polyLineContains(double px,
                                       double py,
                                       int nPoints,
                                       double[] dx,
                                       double[] dy)
Tests if the polygon with given base points contains the point with coordinates (x,y) relative to the polygon first base point.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
nPoints - the number of base points
dx - the array of (at least nPoints) base points x coordinates relative to the start point
dy - the array of (at least nPoints) base points y coordinates relative to the start point
Returns:
true if the point is within the polygon boundary, otherwise false

rectangleContains

public static boolean rectangleContains(double px,
                                        double py,
                                        double width,
                                        double height)
Tests if the rectangle with the given attributes contains the point with coordinates (x,y) relative to the rectangle "upper left" corner.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
width - the width of the rectangle
height - the height of the rectangle
Returns:
true if the point is within the rectangle boundary, otherwise false

roundedRectangleContains

public static boolean roundedRectangleContains(double px,
                                               double py,
                                               double width,
                                               double height,
                                               double radius)
Tests if the rounded rectangle with the given attributes contains the point with coordinates (x,y) relative to the rectangle "upper left" corner.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
width - the width of the rounded rectangle
height - the height of the rounded rectangle
radius - the corner radius of the rounded rectangle
Returns:
true if the point is within the rounded rectangle boundary, otherwise false

textContains

public static boolean textContains(double px,
                                   double py,
                                   java.lang.String text,
                                   java.awt.Font font,
                                   int alignment)
Tests if a (possibly, multi-line) text with given font and alignment contains the point with coordinates (x,y) relative to the text base point (which is NOT the beginning of the baseline, but top left, right or center of text, depending on alignment).

Parameters:
px - the x coordinate of the point
text - the text
font - the text font
alignment - the text alignment
Returns:
true if the point is within the text area, otherwise false

transformX

public static double transformX(double px,
                                double py,
                                double x,
                                double y,
                                double rotation,
                                double scalex)
Transforms the x coordinate of a given point according to the base coordinates, rotation and scale.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
x - the base x coordinate
y - the base y coordinate
rotation - the base rotation
scalex - the base x scale
Returns:
the transformed x coordinate of the point

transformY

public static double transformY(double px,
                                double py,
                                double x,
                                double y,
                                double rotation,
                                double scaley)
Transforms the y coordinate of a given point according to the base coordinates, rotation and scale.

Parameters:
px - the x coordinate of the point
py - the y coordinate of the point
x - the base x coordinate
y - the base y coordinate
rotation - the base rotation
scaley - the base y scale
Returns:
the transformed y coordinate of the point


Copyright © 1991-2008 XJ Technlogies. All Rights Reserved.