Class DrawingUtilities
- java.lang.Object
- 
- com.inductiveautomation.ignition.client.util.gui.DrawingUtilities
 
- 
 public class DrawingUtilities extends java.lang.Object
- 
- 
Field SummaryFields Modifier and Type Field Description static java.awt.StrokeTHICK_LINEstatic java.awt.StrokeTHIN_LINEstatic doubleTWOPI
 - 
Constructor SummaryConstructors Constructor Description DrawingUtilities()
 - 
Method SummaryAll Methods Static Methods Concrete Methods Modifier and Type Method Description static doubleangle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y)Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.static doubleangle(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Returns the angle off horizontal created by the line connecting p1 and p2static doubleangle(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.static java.awt.geom.Point2DasPercentage(java.awt.geom.Point2D pt, java.awt.geom.Rectangle2D container, java.awt.geom.Point2D rv)static java.awt.geom.Rectangle2DasPercentage(java.awt.geom.Rectangle2D rect, java.awt.geom.Rectangle2D container, java.awt.geom.Rectangle2D rv)Calculates the position of rect inside container, returning the result as a rectangle where each value is a percentage of the container's size.static doublebottom(java.awt.geom.Rectangle2D rect)static doublebottom(java.awt.geom.Rectangle2D rect, double dY)Returns the y-position of the bottom side of the rectangle after translating it by dYstatic java.awt.geom.Point2DcenterPoint(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Find the center point on the line segment connecting the two pointsstatic java.awt.geom.Point2DcenterPoint(java.awt.geom.Rectangle2D rect)static java.awt.PointcenterPoint(java.awt.Rectangle rect)static java.awt.geom.Rectangle2Dcopy(java.awt.geom.Rectangle2D rect)static doubledist(double x1, double y1, double x2, double y2)Returns the distance between two pointsstatic floatdist(float x1, float y1, float x2, float y2)Returns the distance between two pointsstatic doubledist(java.awt.geom.Point2D a, java.awt.geom.Point2D b)Returns the distance between two pointsstatic doubledistSquared(double x1, double y1, double x2, double y2)static doubledistSquared(java.awt.geom.Point2D a, java.awt.geom.Point2D b)static doubledot(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)The dot-product of two vectors.static java.awt.Colorfade(java.awt.Color color, float alpha)static java.awt.image.BufferedImagegetScaledInstance(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint, boolean higherQuality)Convenience method that returns a scaled instance of the providedBufferedImage.static java.awt.geom.Rectangle2Dinset(java.awt.geom.Rectangle2D rect, double d)Insets a rectangle by the given amount.static java.awt.Insetsinsets(java.awt.Rectangle rect, java.awt.Insets insets)Converts a rectangle (x,y,w,h) into an insets that represents the coordinates of the rectangles edges (top=y, bottom=y+h, left=x, right=x+h)static Insets2Dinsets2D(java.awt.geom.Rectangle2D rect, Insets2D insets)static java.awt.geom.Point2D.Doublelocation(java.awt.geom.Rectangle2D rect)The location of the rectangle's x,y coords.static voidmakeRelative(java.awt.geom.Rectangle2D child, java.awt.geom.Rectangle2D parent)For two rectangles in the same coordinate space, make the child relative to the parent.static voidmoveRect(java.awt.geom.Rectangle2D rect, double dx, double dy)Moves a rectangle by an offset, like rect.x += dx; rect.y += dy;static booleannear(double value, double nearTo)Detects double proximity within 1 millionth, since double equality is not reliable.static booleannear(double value, double nearTo, double tolerance)Just like the other implementation of near, but with a custom specified tolerance.static booleannear(float value, float nearTo)Detects double proximity within 1 millionth, since float equality is not reliable.static booleannear(float value, float nearTo, float tolerance)Just like the other implementation of near, but with a custom specified tolerance.static booleannear(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double tolerance)Returns whether or not the two points' x and y coords are near each other within the specified tolerance.static booleannear(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2, double tolerance)Returns whether or not the rectangle's are near each other within the specified tolerance.static java.awt.geom.Point2DnearestPointInShape(java.awt.Shape shape, java.awt.geom.Point2D pt)Finds the nearest point on or inside the given shape.static java.awt.geom.Point2DnearestPointOnLine(double ax, double ay, double bx, double by, double px, double py, boolean clampToSegment, java.awt.geom.Point2D dest)Finds a point on the line that passes through A (ax,ay) and B(bx,by) that is nearest to the point P (px,py).static java.awt.geom.Point2DnearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p)static java.awt.geom.Point2DnearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, boolean clampToSegment)static java.awt.geom.Point2DnearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, java.awt.geom.Point2D dest)static java.awt.geom.Point2DnearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, java.awt.geom.Point2D dest, boolean clampToSegment)static java.awt.geom.Rectangle2Doutset(java.awt.geom.Rectangle2D rect, double d)static booleanpathsIntersect(java.awt.Shape path1, java.awt.Shape path2)Detects if the outlines of two shapes intersect or not.static java.awt.geom.Point2Dproject(java.awt.geom.Point2D pcts, java.awt.geom.Rectangle2D container, java.awt.geom.Point2D rv)static java.awt.geom.Rectangle2Dproject(java.awt.geom.Rectangle2D pcts, java.awt.geom.Rectangle2D container, java.awt.geom.Rectangle2D rv)Projects the rectangle of percentages into the container rectangle, storing the results in the rvstatic java.awt.geom.Rectangle2Drectangle(Insets2D insets, java.awt.geom.Rectangle2D r)static java.awt.Rectanglerectangle(java.awt.Insets insets, java.awt.Rectangle r)Performs the inverse operation ofinsets(Rectangle, Insets).static booleanrectangleContains(java.awt.geom.Rectangle2D rectangle, java.awt.Shape shape)static booleanrectangleIntersects(java.awt.geom.Rectangle2D rectangle, java.awt.Shape shape)static java.awt.geom.Point2Dreflect(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double mult)Consider the line segment p1,p2.static doubleright(java.awt.geom.Rectangle2D rect)static doubleright(java.awt.geom.Rectangle2D rect, double dX)Returns the x-position of the right-hand side of the rectangle after translating it by dXstatic voidrotate(double angle, double anchorX, double anchorY, java.awt.geom.Point2D point)static voidrotate(double angle, double anchorX, double anchorY, java.awt.geom.Point2D point, java.awt.geom.Point2D dest)static voidrotate(double angle, java.awt.geom.Point2D anchor, java.awt.geom.Point2D point)Rotates the point around the anchor, storing the results by altering the pointstatic voidrotate(double angle, java.awt.geom.Point2D anchor, java.awt.geom.Point2D point, java.awt.geom.Point2D dest)static intround(double d)Shortcut for (int)Math.round(d);static java.awt.Pointround(java.awt.geom.Point2D pt)static java.awt.Rectangleround(java.awt.geom.Rectangle2D rect)static java.awt.Rectangleround(java.awt.geom.Rectangle2D rect, java.awt.Rectangle rv)static java.awt.DimensionroundSize(java.awt.geom.Rectangle2D rect)static voidscale(java.awt.geom.Point2D p, double d)Scales a point by a value.static java.awt.geom.Point2DscaleOnLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double value)Returns a point on the line that joins p1 and p2.static voidsetHeight(java.awt.geom.Rectangle2D rect, double newHeight)static voidsetLocation(java.awt.geom.Rectangle2D rect, double x, double y)static voidsetWidth(java.awt.geom.Rectangle2D rect, double newWidth)static voidsetX(java.awt.geom.Rectangle2D rect, double newX)static voidsetY(java.awt.geom.Rectangle2D rect, double newY)static java.util.List<java.awt.geom.Point2D>simplifyPath(java.util.List<java.awt.geom.Point2D> points, float tolerance)Simplifies a basic poly-line to use fewer pointsstatic java.awt.geom.GeneralPathsmoothPath(java.util.List<java.awt.geom.Point2D> points, double smoothness)Turns a list of points representing a poly-line into a GeneralPath consisting of bezier curves.static java.awt.geom.GeneralPathsmoothPath(java.util.List<java.awt.geom.Point2D> points, double smoothness, boolean close)static java.awt.geom.Point2DsnapPointToAngle(java.awt.geom.Point2D center, double angle, java.awt.geom.Point2D desired)Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.static java.awt.geom.Point2DsnapPointToAngle(java.awt.geom.Point2D center, java.awt.geom.Point2D horizontalReference, double angle, java.awt.geom.Point2D desired)Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.static doublesq(double d)Square (d^2)static java.awt.geom.Point2Dsubtract(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)static java.awt.image.BufferedImagetoBufferedImage(java.awt.Image img)static java.lang.StringtoString(java.awt.geom.Rectangle2D rect)static voidunion(java.awt.Rectangle r1, java.awt.Rectangle r2, java.awt.Rectangle rv)Unions two rectangles, storing the result in rv, rather than creating a new rectangle
 
- 
- 
- 
Field Detail- 
THIN_LINEpublic static final java.awt.Stroke THIN_LINE 
 - 
THICK_LINEpublic static final java.awt.Stroke THICK_LINE 
 - 
TWOPIpublic static final double TWOPI - See Also:
- Constant Field Values
 
 
- 
 - 
Method Detail- 
getScaledInstancepublic static java.awt.image.BufferedImage getScaledInstance(java.awt.image.BufferedImage img, int targetWidth, int targetHeight, java.lang.Object hint, boolean higherQuality)Convenience method that returns a scaled instance of the providedBufferedImage. Implementation thanks to http://today.java.net/pub/a/today/2007/04/03/perils-of-image-getscaledinstance.html- Parameters:
- img- the original image to be scaled
- targetWidth- the desired width of the scaled instance, in pixels
- targetHeight- the desired height of the scaled instance, in pixels
- hint- one of the rendering hints that corresponds to- RenderingHints.KEY_INTERPOLATION(e.g.- RenderingHints.VALUE_INTERPOLATION_NEAREST_NEIGHBOR,- RenderingHints.VALUE_INTERPOLATION_BILINEAR,- RenderingHints.VALUE_INTERPOLATION_BICUBIC)
- higherQuality- if true, this method will use a multi-step scaling technique that provides higher quality than the usual one-step technique (only useful in downscaling cases, where- targetWidthor- targetHeightis smaller than the original dimensions, and generally only when the- BILINEARhint is specified)
- Returns:
- a scaled version of the original BufferedImage
 
 - 
toBufferedImagepublic static java.awt.image.BufferedImage toBufferedImage(java.awt.Image img) 
 - 
distpublic static double dist(java.awt.geom.Point2D a, java.awt.geom.Point2D b)Returns the distance between two points
 - 
fadepublic static java.awt.Color fade(java.awt.Color color, float alpha)
 - 
distpublic static double dist(double x1, double y1, double x2, double y2)Returns the distance between two points
 - 
distpublic static float dist(float x1, float y1, float x2, float y2)Returns the distance between two points
 - 
distSquaredpublic static double distSquared(java.awt.geom.Point2D a, java.awt.geom.Point2D b)
 - 
distSquaredpublic static double distSquared(double x1, double y1, double x2, double y2)
 - 
nearestPointOnLinepublic static java.awt.geom.Point2D nearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p)
 - 
nearestPointOnLinepublic static java.awt.geom.Point2D nearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, boolean clampToSegment)
 - 
nearestPointOnLinepublic static java.awt.geom.Point2D nearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, java.awt.geom.Point2D dest)
 - 
nearestPointOnLinepublic static java.awt.geom.Point2D nearestPointOnLine(java.awt.geom.Point2D a, java.awt.geom.Point2D b, java.awt.geom.Point2D p, java.awt.geom.Point2D dest, boolean clampToSegment)
 - 
nearestPointInShapepublic static java.awt.geom.Point2D nearestPointInShape(java.awt.Shape shape, java.awt.geom.Point2D pt)Finds the nearest point on or inside the given shape. If the point is already in the shape, this simply sets dest to pt. If not, then it uses a flattening path iterator to find the line segment with with the closest point.
 - 
nearestPointOnLinepublic static java.awt.geom.Point2D nearestPointOnLine(double ax, double ay, double bx, double by, double px, double py, boolean clampToSegment, java.awt.geom.Point2D dest)Finds a point on the line that passes through A (ax,ay) and B(bx,by) that is nearest to the point P (px,py).- Parameters:
- clampToSegment- true if you want the point to be on the segment between points A and B
 
 - 
sqpublic static double sq(double d) Square (d^2)
 - 
insetpublic static java.awt.geom.Rectangle2D inset(java.awt.geom.Rectangle2D rect, double d)Insets a rectangle by the given amount. Alters the given rectangle in-place
 - 
outsetpublic static java.awt.geom.Rectangle2D outset(java.awt.geom.Rectangle2D rect, double d)
 - 
rightpublic static double right(java.awt.geom.Rectangle2D rect) 
 - 
rightpublic static double right(java.awt.geom.Rectangle2D rect, double dX)Returns the x-position of the right-hand side of the rectangle after translating it by dX
 - 
bottompublic static double bottom(java.awt.geom.Rectangle2D rect) 
 - 
bottompublic static double bottom(java.awt.geom.Rectangle2D rect, double dY)Returns the y-position of the bottom side of the rectangle after translating it by dY
 - 
centerPointpublic static java.awt.Point centerPoint(java.awt.Rectangle rect) 
 - 
centerPointpublic static java.awt.geom.Point2D centerPoint(java.awt.geom.Rectangle2D rect) 
 - 
centerPointpublic static java.awt.geom.Point2D centerPoint(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Find the center point on the line segment connecting the two points
 - 
anglepublic static double angle(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)Returns the angle off horizontal created by the line connecting p1 and p2
 - 
anglepublic static double angle(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, java.awt.geom.Point2D p3)Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.
 - 
anglepublic static double angle(double p1x, double p1y, double p2x, double p2y, double p3x, double p3y)Uses the Math.atan2 to calculate the angle created by the three points, where p1 is the vertex near the angle to be determined.
 - 
subtractpublic static java.awt.geom.Point2D subtract(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
 - 
dotpublic static double dot(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)The dot-product of two vectors.
 - 
scalepublic static void scale(java.awt.geom.Point2D p, double d)Scales a point by a value. simply multiplies the x and y location by the multiplier.
 - 
scaleOnLinepublic static java.awt.geom.Point2D scaleOnLine(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double value)Returns a point on the line that joins p1 and p2. If value is 0.0, this will return p1, if value is 1.0, this will return p2.
 - 
insetspublic static java.awt.Insets insets(java.awt.Rectangle rect, java.awt.Insets insets)Converts a rectangle (x,y,w,h) into an insets that represents the coordinates of the rectangles edges (top=y, bottom=y+h, left=x, right=x+h)- Parameters:
- rect- Must not be null.
- insets- May be null, in which case a new Insets wil be instantiated and returned.
 
 - 
rectanglepublic static java.awt.Rectangle rectangle(java.awt.Insets insets, java.awt.Rectangle r)Performs the inverse operation ofinsets(Rectangle, Insets). Converts an insets representing rectangle edges into a Rectangle. If the insets has been turned "inside out" (e.g. top > bottom) it will be corrected automatically.
 - 
rectanglepublic static java.awt.geom.Rectangle2D rectangle(Insets2D insets, java.awt.geom.Rectangle2D r) 
 - 
copypublic static java.awt.geom.Rectangle2D copy(java.awt.geom.Rectangle2D rect) 
 - 
makeRelativepublic static void makeRelative(java.awt.geom.Rectangle2D child, java.awt.geom.Rectangle2D parent)For two rectangles in the same coordinate space, make the child relative to the parent. Like:child.x -= parent.x; child.y -= parent.y; 
 - 
setXpublic static void setX(java.awt.geom.Rectangle2D rect, double newX)
 - 
setYpublic static void setY(java.awt.geom.Rectangle2D rect, double newY)
 - 
setWidthpublic static void setWidth(java.awt.geom.Rectangle2D rect, double newWidth)
 - 
setHeightpublic static void setHeight(java.awt.geom.Rectangle2D rect, double newHeight)
 - 
toStringpublic static java.lang.String toString(java.awt.geom.Rectangle2D rect) 
 - 
moveRectpublic static void moveRect(java.awt.geom.Rectangle2D rect, double dx, double dy)Moves a rectangle by an offset, like rect.x += dx; rect.y += dy;
 - 
locationpublic static java.awt.geom.Point2D.Double location(java.awt.geom.Rectangle2D rect) The location of the rectangle's x,y coords.
 - 
setLocationpublic static void setLocation(java.awt.geom.Rectangle2D rect, double x, double y)
 - 
pathsIntersectpublic static boolean pathsIntersect(java.awt.Shape path1, java.awt.Shape path2)Detects if the outlines of two shapes intersect or not.
 - 
rectangleContainspublic static boolean rectangleContains(java.awt.geom.Rectangle2D rectangle, java.awt.Shape shape)
 - 
rectangleIntersectspublic static boolean rectangleIntersects(java.awt.geom.Rectangle2D rectangle, java.awt.Shape shape)
 - 
unionpublic static void union(java.awt.Rectangle r1, java.awt.Rectangle r2, java.awt.Rectangle rv)Unions two rectangles, storing the result in rv, rather than creating a new rectangle
 - 
snapPointToAnglepublic static java.awt.geom.Point2D snapPointToAngle(java.awt.geom.Point2D center, double angle, java.awt.geom.Point2D desired)Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.
 - 
snapPointToAnglepublic static java.awt.geom.Point2D snapPointToAngle(java.awt.geom.Point2D center, java.awt.geom.Point2D horizontalReference, double angle, java.awt.geom.Point2D desired)Snaps a point to a nearby point that is on a line aligned to a multiple of the given angle from the centerpoint.
 - 
nearpublic static boolean near(double value, double nearTo)Detects double proximity within 1 millionth, since double equality is not reliable. Implementation is:Math.abs(nearTo - value) < 0.000001d 
 - 
nearpublic static boolean near(double value, double nearTo, double tolerance)Just like the other implementation of near, but with a custom specified tolerance.
 - 
nearpublic static boolean near(float value, float nearTo)Detects double proximity within 1 millionth, since float equality is not reliable. Implementation is:Math.abs(nearTo - value) < 0.000001f 
 - 
nearpublic static boolean near(float value, float nearTo, float tolerance)Just like the other implementation of near, but with a custom specified tolerance.
 - 
nearpublic static boolean near(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double tolerance)Returns whether or not the two points' x and y coords are near each other within the specified tolerance.
 - 
nearpublic static boolean near(java.awt.geom.Rectangle2D r1, java.awt.geom.Rectangle2D r2, double tolerance)Returns whether or not the rectangle's are near each other within the specified tolerance.
 - 
roundpublic static java.awt.Rectangle round(java.awt.geom.Rectangle2D rect) 
 - 
roundpublic static java.awt.Rectangle round(java.awt.geom.Rectangle2D rect, java.awt.Rectangle rv)
 - 
roundpublic static int round(double d) Shortcut for (int)Math.round(d);
 - 
roundSizepublic static java.awt.Dimension roundSize(java.awt.geom.Rectangle2D rect) 
 - 
roundpublic static java.awt.Point round(java.awt.geom.Point2D pt) 
 - 
asPercentagepublic static java.awt.geom.Rectangle2D asPercentage(java.awt.geom.Rectangle2D rect, java.awt.geom.Rectangle2D container, java.awt.geom.Rectangle2D rv)Calculates the position of rect inside container, returning the result as a rectangle where each value is a percentage of the container's size. You can re-create rect by calling#project(Rectangle2D, Rectangle2D, Rectangle)with the return value of this function.- Parameters:
- rect- The rectangle in question
- container- The reference rectangle containing rect
- rv- The return value in which to store the result. May be null.
 
 - 
asPercentagepublic static java.awt.geom.Point2D asPercentage(java.awt.geom.Point2D pt, java.awt.geom.Rectangle2D container, java.awt.geom.Point2D rv)
 - 
projectpublic static java.awt.geom.Rectangle2D project(java.awt.geom.Rectangle2D pcts, java.awt.geom.Rectangle2D container, java.awt.geom.Rectangle2D rv)Projects the rectangle of percentages into the container rectangle, storing the results in the rv
 - 
projectpublic static java.awt.geom.Point2D project(java.awt.geom.Point2D pcts, java.awt.geom.Rectangle2D container, java.awt.geom.Point2D rv)
 - 
rotatepublic static void rotate(double angle, double anchorX, double anchorY, java.awt.geom.Point2D point)
 - 
rotatepublic static void rotate(double angle, java.awt.geom.Point2D anchor, java.awt.geom.Point2D point)Rotates the point around the anchor, storing the results by altering the point
 - 
rotatepublic static void rotate(double angle, java.awt.geom.Point2D anchor, java.awt.geom.Point2D point, java.awt.geom.Point2D dest)
 - 
rotatepublic static void rotate(double angle, double anchorX, double anchorY, java.awt.geom.Point2D point, java.awt.geom.Point2D dest)
 - 
simplifyPathpublic static java.util.List<java.awt.geom.Point2D> simplifyPath(java.util.List<java.awt.geom.Point2D> points, float tolerance)Simplifies a basic poly-line to use fewer points- Parameters:
- points- The list of points that make up the line
- tolerance- The tolerance of how "simple" to make the line. Zero means no simplification. A value in the high tens will simplify quite a bit.
 
 - 
reflectpublic static java.awt.geom.Point2D reflect(java.awt.geom.Point2D p1, java.awt.geom.Point2D p2, double mult)Consider the line segment p1,p2. This will return a homothetical point on the reflected segment. A multiplier of 1.0 will return the symmetrical point.
 - 
smoothPathpublic static java.awt.geom.GeneralPath smoothPath(java.util.List<java.awt.geom.Point2D> points, double smoothness)Turns a list of points representing a poly-line into a GeneralPath consisting of bezier curves. Thanks to http://www.efg2.com/Lab/Graphics/Jean-YvesQueinecBezierCurves.htm- Parameters:
- smoothness- A double from zero to 1.5. Zero will make straight segments, higher numbers will make a curvier path.
 
 - 
smoothPathpublic static java.awt.geom.GeneralPath smoothPath(java.util.List<java.awt.geom.Point2D> points, double smoothness, boolean close)
 
- 
 
-