com.mindfusion.diagramming
Class Utilities

java.lang.Object
  extended by com.mindfusion.diagramming.Utilities

public final class Utilities
extends java.lang.Object


Constructor Summary
Utilities()
           
 
Method Summary
static
<T extends java.awt.geom.Point2D>
T
add(T changed, double addX, double addY)
           
static
<T extends java.awt.geom.Point2D>
T
add(T changed, java.awt.geom.Point2D changeVector)
          Add (translate) the coordinates of one point with the coordinates of another
static void cartesianToPolar(java.awt.geom.Point2D coordCenter, java.awt.geom.Point2D point, java.awt.geom.Point2D result)
           
static
<T extends java.awt.geom.Point2D>
T
clone(T point)
           
static
<T extends java.awt.geom.Rectangle2D>
T
clone(T rect)
           
static java.lang.String concat(java.lang.String delimiter, java.lang.Object... objs)
          Joins array elements using the specified delimiter.
static double convert(double value, int valueMeasureUnit, int targetMeasureUnit)
          Convert value from valueMeasureUnit to targetMeasureUnit
static java.awt.geom.Rectangle2D deviceToDoc(java.awt.Graphics2D g, java.awt.Rectangle r)
           
static float distToLineSegment(java.awt.geom.Point2D pt, java.awt.geom.Point2D p1, java.awt.geom.Point2D p2)
          Calculates distance from the specified point to the specified line segment.
static java.awt.Rectangle docToDevice(java.awt.Graphics2D g, java.awt.geom.Rectangle2D r)
           
static void drawImage(java.awt.Graphics2D g, java.awt.Image image, java.awt.geom.Rectangle2D rect, int imageAlign, Diagram diagram)
           
static void drawImage(java.awt.Graphics2D g, java.awt.Image image, java.awt.geom.Rectangle2D rect, int imageAlign, Diagram diagram, double rotationAngle, java.awt.geom.Point2D pivot)
           
static
<T,D extends T>
java.lang.Iterable<D>
filter(java.lang.Iterable<T> unfiltered, java.lang.Class<D> desiredType)
          Creates Iterable that iterates only over the subset of the given Iterable that consist of elements of desired type Example: for (TableNode t: filter(diagram .getItems(), TableNode.class)) t.getRowCount();
static
<T,D extends T>
java.util.Iterator<D>
filter(java.util.Iterator<T> unfiltered, java.lang.Class<D> desiredType)
          Creates Iterator that iterates only over the subset of the given Iterator that consist of elements of desired type
static java.awt.Component findValidateRoot(javax.swing.JComponent c)
          Returns the ancestor component that acts as validate root
static java.awt.geom.Point2D getLocation(java.awt.geom.Rectangle2D rect)
           
static java.awt.geom.Dimension2D getSize(java.awt.geom.Rectangle2D rect)
           
static
<T extends java.awt.geom.Point2D>
boolean
lineIntersect(java.awt.geom.Point2D pA, java.awt.geom.Point2D pB, java.awt.geom.Point2D pC, java.awt.geom.Point2D pD, java.awt.geom.Point2D result)
          Calculates the intersection point of endless lines (pA, pB) and (pC, pD)
static double lineIntersectHorizontal(double y, java.awt.geom.Point2D pA, java.awt.geom.Point2D pB)
          Finds the x coordinate of the intersection point of the horizontal line at y and the line defined by points pA and pB.
static double lineIntersectVertical(double x, java.awt.geom.Point2D pA, java.awt.geom.Point2D pB)
          Finds the y coordinate of the intersection point of the vertical line at x and the line defined by points pA and pB.
static java.awt.geom.Point2D newPoint2D(double x, double y)
           
static java.awt.geom.Point2D newPoint2D(java.awt.geom.Point2D point)
           
static java.awt.geom.Point2D.Double newPointDouble(double x, double y)
           
static java.awt.geom.Point2D.Double newPointDouble(java.awt.geom.Point2D point)
           
static java.awt.geom.Point2D.Float newPointFloat()
           
static java.awt.geom.Point2D.Float newPointFloat(double x, double y)
           
static java.awt.geom.Point2D.Float newPointFloat(java.awt.geom.Point2D point)
           
static java.awt.geom.Rectangle2D newRectangle2D(double x, double y, double width, double height)
           
static java.awt.geom.Rectangle2D.Double newRectangleDouble(double x, double y, double width, double height)
           
static java.awt.geom.Rectangle2D.Double newRectangleDouble(java.awt.geom.Rectangle2D rc)
           
static java.awt.geom.Rectangle2D.Float newRectangleFloat(double x, double y, double width, double height)
           
static java.awt.geom.Rectangle2D.Float newRectangleFloat(java.awt.geom.Rectangle2D rc)
           
static java.awt.geom.Rectangle2D normalizeRect(java.awt.geom.Rectangle2D rc)
           
static boolean parse(java.lang.String pair, java.awt.geom.Point2D dest)
          Parses space separated numbers into Point2D
static void polarToCartesian(java.awt.geom.Point2D coordCenter, double a, double r, java.awt.geom.Point2D point)
           
static
<T extends java.awt.geom.Rectangle2D>
T
resize(T changed, double width, double height)
           
static void revalidateSynced(javax.swing.JComponent comp)
          Performs synchronized revalidation to ensure that layout is up to date after this method returns.
static
<T extends java.awt.geom.Point2D>
T
set(T changed, double x, double y)
           
static
<T extends java.awt.geom.Rectangle2D>
T
set(T changed, double x, double y)
           
static
<T extends java.awt.geom.Rectangle2D>
T
set(T changed, double x, double y, double width, double height)
           
static
<T extends java.awt.geom.Rectangle2D>
T
set(T changed, java.awt.geom.Rectangle2D src)
           
static
<T extends java.awt.geom.Rectangle2D>
T
setHeight(T changed, double height)
           
static
<T extends java.awt.geom.Point2D>
T
setLocation(T changed, java.awt.geom.Rectangle2D src)
           
static
<T extends java.awt.geom.Rectangle2D>
T
setWidth(T changed, double width)
           
static
<T extends java.awt.geom.Point2D>
T
setX(T changed, double x)
           
static
<T extends java.awt.geom.Rectangle2D>
T
setX(T changed, double x)
           
static
<T extends java.awt.geom.Point2D>
T
setY(T changed, double y)
           
static
<T extends java.awt.geom.Rectangle2D>
T
setY(T changed, double y)
           
static java.awt.Point subtract(java.awt.Point changed, java.awt.Point changeVector)
          Subtract the coordinates of one point from the coordinates of another
static
<T extends java.awt.geom.Rectangle2D>
T
translate(T changed, double addX, double addY)
           
static
<T extends java.awt.geom.Point2D>
T
translateX(T changed, double addX)
           
static
<T extends java.awt.geom.Rectangle2D>
T
translateX(T changed, double addX)
           
static
<T extends java.awt.geom.Point2D>
T
translateY(T changed, double addY)
           
static
<T extends java.awt.geom.Rectangle2D>
T
translateY(T changed, double addY)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Utilities

public Utilities()
Method Detail

docToDevice

public static java.awt.Rectangle docToDevice(java.awt.Graphics2D g,
                                             java.awt.geom.Rectangle2D r)

deviceToDoc

public static java.awt.geom.Rectangle2D deviceToDoc(java.awt.Graphics2D g,
                                                    java.awt.Rectangle r)

normalizeRect

public static java.awt.geom.Rectangle2D normalizeRect(java.awt.geom.Rectangle2D rc)

lineIntersectVertical

public static double lineIntersectVertical(double x,
                                           java.awt.geom.Point2D pA,
                                           java.awt.geom.Point2D pB)
Finds the y coordinate of the intersection point of the vertical line at x and the line defined by points pA and pB. If the lines do not intersect, result is undefined.

Returns:
The intersection point y coordinate.

lineIntersectHorizontal

public static double lineIntersectHorizontal(double y,
                                             java.awt.geom.Point2D pA,
                                             java.awt.geom.Point2D pB)
Finds the x coordinate of the intersection point of the horizontal line at y and the line defined by points pA and pB. If the lines do not intersect, result is undefined.

Returns:
The intersection point x coordinate.

lineIntersect

public static <T extends java.awt.geom.Point2D> boolean lineIntersect(java.awt.geom.Point2D pA,
                                                                      java.awt.geom.Point2D pB,
                                                                      java.awt.geom.Point2D pC,
                                                                      java.awt.geom.Point2D pD,
                                                                      java.awt.geom.Point2D result)
Calculates the intersection point of endless lines (pA, pB) and (pC, pD)

Type Parameters:
T -
Parameters:
pA -
pB -
pC -
pD -
result - the point that will receive the result if the lines intersect
Returns:
true if the lines intersect

distToLineSegment

public static float distToLineSegment(java.awt.geom.Point2D pt,
                                      java.awt.geom.Point2D p1,
                                      java.awt.geom.Point2D p2)
Calculates distance from the specified point to the specified line segment.


drawImage

public static void drawImage(java.awt.Graphics2D g,
                             java.awt.Image image,
                             java.awt.geom.Rectangle2D rect,
                             int imageAlign,
                             Diagram diagram)

drawImage

public static void drawImage(java.awt.Graphics2D g,
                             java.awt.Image image,
                             java.awt.geom.Rectangle2D rect,
                             int imageAlign,
                             Diagram diagram,
                             double rotationAngle,
                             java.awt.geom.Point2D pivot)

convert

public static double convert(double value,
                             int valueMeasureUnit,
                             int targetMeasureUnit)
Convert value from valueMeasureUnit to targetMeasureUnit

Parameters:
value - A double value that should be converted.
valueMeasureUnit - The source GraphicsUnit.
targetMeasureUnit - The target GraphicsUnit.
Returns:
The converted value.

polarToCartesian

public static void polarToCartesian(java.awt.geom.Point2D coordCenter,
                                    double a,
                                    double r,
                                    java.awt.geom.Point2D point)

cartesianToPolar

public static void cartesianToPolar(java.awt.geom.Point2D coordCenter,
                                    java.awt.geom.Point2D point,
                                    java.awt.geom.Point2D result)

subtract

public static java.awt.Point subtract(java.awt.Point changed,
                                      java.awt.Point changeVector)
Subtract the coordinates of one point from the coordinates of another

Parameters:
changed -
changeVector -
Returns:
the first parameter which holds the result

add

public static <T extends java.awt.geom.Point2D> T add(T changed,
                                                      java.awt.geom.Point2D changeVector)
Add (translate) the coordinates of one point with the coordinates of another

Parameters:
changed -
changeVector -
Returns:
the first parameter which holds the result

add

public static <T extends java.awt.geom.Point2D> T add(T changed,
                                                      double addX,
                                                      double addY)

translateX

public static <T extends java.awt.geom.Point2D> T translateX(T changed,
                                                             double addX)

translateY

public static <T extends java.awt.geom.Point2D> T translateY(T changed,
                                                             double addY)

set

public static <T extends java.awt.geom.Point2D> T set(T changed,
                                                      double x,
                                                      double y)

setX

public static <T extends java.awt.geom.Point2D> T setX(T changed,
                                                       double x)

setY

public static <T extends java.awt.geom.Point2D> T setY(T changed,
                                                       double y)

setLocation

public static <T extends java.awt.geom.Point2D> T setLocation(T changed,
                                                              java.awt.geom.Rectangle2D src)

getLocation

public static java.awt.geom.Point2D getLocation(java.awt.geom.Rectangle2D rect)

getSize

public static java.awt.geom.Dimension2D getSize(java.awt.geom.Rectangle2D rect)

set

public static <T extends java.awt.geom.Rectangle2D> T set(T changed,
                                                          double x,
                                                          double y,
                                                          double width,
                                                          double height)

set

public static <T extends java.awt.geom.Rectangle2D> T set(T changed,
                                                          double x,
                                                          double y)

set

public static <T extends java.awt.geom.Rectangle2D> T set(T changed,
                                                          java.awt.geom.Rectangle2D src)

setX

public static <T extends java.awt.geom.Rectangle2D> T setX(T changed,
                                                           double x)

setY

public static <T extends java.awt.geom.Rectangle2D> T setY(T changed,
                                                           double y)

setHeight

public static <T extends java.awt.geom.Rectangle2D> T setHeight(T changed,
                                                                double height)

setWidth

public static <T extends java.awt.geom.Rectangle2D> T setWidth(T changed,
                                                               double width)

resize

public static <T extends java.awt.geom.Rectangle2D> T resize(T changed,
                                                             double width,
                                                             double height)

translate

public static <T extends java.awt.geom.Rectangle2D> T translate(T changed,
                                                                double addX,
                                                                double addY)

translateX

public static <T extends java.awt.geom.Rectangle2D> T translateX(T changed,
                                                                 double addX)

translateY

public static <T extends java.awt.geom.Rectangle2D> T translateY(T changed,
                                                                 double addY)

clone

public static <T extends java.awt.geom.Point2D> T clone(T point)

clone

public static <T extends java.awt.geom.Rectangle2D> T clone(T rect)

newPointFloat

public static java.awt.geom.Point2D.Float newPointFloat()

newPointFloat

public static java.awt.geom.Point2D.Float newPointFloat(java.awt.geom.Point2D point)

newPointFloat

public static java.awt.geom.Point2D.Float newPointFloat(double x,
                                                        double y)

newPointDouble

public static java.awt.geom.Point2D.Double newPointDouble(java.awt.geom.Point2D point)

newPointDouble

public static java.awt.geom.Point2D.Double newPointDouble(double x,
                                                          double y)

newPoint2D

public static java.awt.geom.Point2D newPoint2D(java.awt.geom.Point2D point)

newPoint2D

public static java.awt.geom.Point2D newPoint2D(double x,
                                               double y)

newRectangleFloat

public static java.awt.geom.Rectangle2D.Float newRectangleFloat(double x,
                                                                double y,
                                                                double width,
                                                                double height)

newRectangleFloat

public static java.awt.geom.Rectangle2D.Float newRectangleFloat(java.awt.geom.Rectangle2D rc)

newRectangleDouble

public static java.awt.geom.Rectangle2D.Double newRectangleDouble(double x,
                                                                  double y,
                                                                  double width,
                                                                  double height)

newRectangleDouble

public static java.awt.geom.Rectangle2D.Double newRectangleDouble(java.awt.geom.Rectangle2D rc)

newRectangle2D

public static java.awt.geom.Rectangle2D newRectangle2D(double x,
                                                       double y,
                                                       double width,
                                                       double height)

findValidateRoot

public static java.awt.Component findValidateRoot(javax.swing.JComponent c)
Returns the ancestor component that acts as validate root

Parameters:
c - A JComponent whose validation root should be returned.
Returns:
A Component that is the validation root of c.

revalidateSynced

public static void revalidateSynced(javax.swing.JComponent comp)
Performs synchronized revalidation to ensure that layout is up to date after this method returns.


concat

public static java.lang.String concat(java.lang.String delimiter,
                                      java.lang.Object... objs)
Joins array elements using the specified delimiter.

Parameters:
delimiter - A character inserted between the array elements.
objs - The objects to be joined.
Returns:
A string containing the concatenated string representations of the objects.

parse

public static boolean parse(java.lang.String pair,
                            java.awt.geom.Point2D dest)
Parses space separated numbers into Point2D

Parameters:
pair - A string representation of the point coordinates.
dest - A Point2D object to which the parsed values are assigned.
Returns:
true if the string has been parsed successfully, otherwise false.

filter

public static <T,D extends T> java.lang.Iterable<D> filter(java.lang.Iterable<T> unfiltered,
                                                           java.lang.Class<D> desiredType)
Creates Iterable that iterates only over the subset of the given Iterable that consist of elements of desired type Example: for (TableNode t: filter(diagram .getItems(), TableNode.class)) t.getRowCount();

Parameters:
unfiltered - the collection of items that can be of different type.
desiredType - the class of the items in the collection to be returned.
Returns:
An iterator over the collection items of the desired type.

filter

public static <T,D extends T> java.util.Iterator<D> filter(java.util.Iterator<T> unfiltered,
                                                           java.lang.Class<D> desiredType)
Creates Iterator that iterates only over the subset of the given Iterator that consist of elements of desired type

Parameters:
unfiltered - the collection of items that can be of different type.
desiredType - the class of the items in the collection to be returned.
Returns:
An iterator over the collection items of the desired type.