UC Berkeley Group for User Interface Research
Updated November 17, 2000

edu.berkeley.guir.lib.satin.objects
Class GraphicalObjectLib

java.lang.Object
  |
  +--edu.berkeley.guir.lib.satin.objects.GraphicalObjectLib
All Implemented Interfaces:
SatinConstants

public final class GraphicalObjectLib
extends Object
implements SatinConstants

Handy utilities for manipulating GraphicalObjects.

This software is distributed under the Berkeley Software License.

 Revisions:  - SATIN-v1.0-1.0.0, Oct 06 1998, JH
               Created class
             - SATIN-v2.1-1.0.0, Aug 11 2000, JH
               Touched for SATIN release
 

Since:
JDK 1.2
Version:
SATIN-v2.1-1.0.0, Aug 11 2000
Author:
Jason Hong ( jasonh@cs.berkeley.edu )

Inner classes inherited from class edu.berkeley.guir.lib.satin.SatinConstants
SatinConstants.ObjectPoolAffineTransform, SatinConstants.ObjectPoolPoint2D, SatinConstants.ObjectPoolPolygon2D, SatinConstants.ObjectPoolRectangle2D, SatinConstants.ObjectPoolStringBuffer, SatinConstants.UniqueAffineTransform, SatinConstants.UniquePoint2D, SatinConstants.UniquePolygon2D, SatinConstants.UniqueRectangle2D
 
Fields inherited from interface edu.berkeley.guir.lib.satin.SatinConstants
ABOVE, ALL, BAR, BELOW, clipboard, clprops, cmdqueue, cmdsubsys, CONTAINEDBY, CONTAINS, COORD_ABS, COORD_LOCAL, COORD_REL, DAMAGE_LATER, DAMAGE_NOW, DEBUG_GRAPHICS_OFFSET, DEBUG_STYLE_FILE, DEBUG_STYLE_GPROPERTY, DEEP, DEFAULT_POINT2D_POOL_SIZE, DEFAULT_POLYGON2D_POOL_SIZE, DEFAULT_RECTANGLE_POOL_SIZE, DEFAULT_REPAINT_THRESHOLD, DEFAULT_SELECT_THRESHOLD, DEFAULT_STRINGBUFFER_POOL_SIZE, DEFAULT_TRANSFORM_POOL_SIZE, DIR_CENTER, DIR_DOWN, DIR_DOWN_LEFT, DIR_DOWN_RIGHT, DIR_LEFT, DIR_RIGHT, DIR_UP, DIR_UP_LEFT, DIR_UP_RIGHT, FILTER_THRESHOLD, FIRST, FLOATING_PT_TOLERANCE, glprops, INTERSECTS, KEY_STYLE_DASHARRAY, KEY_STYLE_DASHPHASE, KEY_STYLE_DRAWCOLOR, KEY_STYLE_DRAWFONT, KEY_STYLE_DRAWTRANSPARENCY, KEY_STYLE_ENDCAP, KEY_STYLE_FILLCOLOR, KEY_STYLE_FILLTRANSPARENCY, KEY_STYLE_LINEJOIN, KEY_STYLE_LINEWIDTH, KEY_STYLE_MITERLIMIT, NEAR, NOTIFY_BOUNDS, NOTIFY_LAYER, NOTIFY_LOCATION, NOTIFY_STYLE, NOTIFY_TRANSFORM, poolPoints, poolPolys, poolRects, poolStrbuf, poolTx, rand, SATIN_DATA_DIRECTORY_DEFAULT, SATIN_DATA_DIRECTORY_GPROPERTY, SATIN_PROPERTIES_FILENAME, SHALLOW
 
Constructor Summary
GraphicalObjectLib()
           
 
Method Summary
static Point2D absoluteToLocal(GraphicalObject gob, Point2D ptIn)
          Convert a coordinate from absolute coordinates to local coordinates.
static Point2D absoluteToLocal(GraphicalObject gob, Point2D ptIn, Point2D ptReturn)
          Convert a coordinate from absolute coordinates to local coordinates.
static Rectangle2D absoluteToLocal(GraphicalObject gob, Rectangle2D rectIn)
          Convert a rectangle from absolute coordinates to local coordinates.
static void animate(GraphicalObject gob, AffineTransform[] txArray)
          Given a set of transforms, animate this graphical object using those transforms.
static boolean atBottom(GraphicalObject gobAA, GraphicalObject gobBB)
          Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
static boolean atBottom(GraphicalObject gobAA, GraphicalObject gobBB, double thresh)
          Check if gobAA is at the bottom of gobBB within threshold dist.
static boolean atLeft(GraphicalObject gobAA, GraphicalObject gobBB)
          Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
static boolean atLeft(GraphicalObject gobAA, GraphicalObject gobBB, double thresh)
          Check if gobAA is at the left of gobBB within threshold dist.
static boolean atRight(GraphicalObject gobAA, GraphicalObject gobBB)
          Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
static boolean atRight(GraphicalObject gobAA, GraphicalObject gobBB, double thresh)
          Check if gobAA is at the right of gobBB within threshold dist.
static boolean atTop(GraphicalObject gobAA, GraphicalObject gobBB)
          Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
static boolean atTop(GraphicalObject gobAA, GraphicalObject gobBB, double thresh)
          Check if gobAA is at the top of gobBB within threshold dist.
static int compareLayers(GraphicalObject gobA, GraphicalObject gobB)
           
static int compareLayers(String gobA, String gobB)
          Compare two GraphicalObject layers to see which one is higher.
static boolean contains(GraphicalObject gob, Shape s)
          Determine if the Graphical Object contains the specified shape.
static boolean contains(Shape s, GraphicalObject gob)
          Determine if the Shape contains the specified Graphical Object.
static boolean contains(Shape sAA, Shape sBB)
          Determine if s1 contains s2.
static GraphicalObjectCollection flatten(GraphicalObjectCollection gobcol)
          Given a hierarchy of GraphicalObjects, flatten it into a single Collection (without modifying the original).
static GraphicalObject getBottommostBranch(GraphicalObjectCollection gobcol)
           
static GraphicalObject getBottommostGraphicalObject(GraphicalObjectCollection gobcol)
          In a GraphicalObjectCollection, get the GraphicalObject nearest to the bottom.
static GraphicalObject getBottommostLeaf(GraphicalObjectCollection gobcol)
           
static Point2D getCenterOfMass(GraphicalObject gob)
           
static Point2D getCenterOfMass(GraphicalObject gob, Point2D pt)
           
static Rectangle getRenderBounds(GraphicalObject gob)
          Given a GraphicalObject, get the bounds for its damage region, that is the region that needs to be repainted.
static double getScaleFactor(int cdsys, GraphicalObject gob)
          Get the scale factor of this Graphical Object.
static GraphicalObject getTopmostBranch(GraphicalObjectCollection gobcol)
           
static GraphicalObject getTopmostGraphicalObject(GraphicalObjectCollection gobcol)
          In a GraphicalObjectCollection, get the GraphicalObject nearest to the top.
static GraphicalObject getTopmostLeaf(GraphicalObjectCollection gobcol)
           
static int getUniqueID()
          Get a (mostly) unique ID, as long as the system is running.
static boolean intersects(GraphicalObject gob, Shape s)
          Determine if the Graphical Object contains the specified shape.
static boolean intersects(Shape s, GraphicalObject gob)
          Determine if the Shape contains the specified Graphical Object.
static boolean intersects(Shape sAA, Shape sBB)
          Determine if s1 intersects s2.
static boolean isAnimating()
          Are we trying to animate or not?
static Point2D localToAbsolute(GraphicalObject gob, Point2D ptIn)
          Convert a coordinate from local coordinates to absolute coordinates.
static Point2D localToAbsolute(GraphicalObject gob, Point2D ptIn, Point2D ptReturn)
          Convert a coordinate from local coordinates to absolute coordinates.
static Rectangle2D localToAbsolute(GraphicalObject gob, Rectangle2D rectIn)
          Convert a rectangle from local coordinates to absolute coordinates.
static void main(String[] argv)
           
static GraphicalObjectCollection removeGraphicalObjectGroups(GraphicalObjectCollection gobcol)
          Given a GraphicalObjectCollection, remove references to all of the GraphicalObjectGroups (and thus Patches too).
static void setAnimating(boolean flag)
          Set whether we are we trying to animate or not.
static void toLocalCoordinates(GraphicalObject gobMove, GraphicalObject gobCoord)
          Shift a Graphical Object from its current coordinate system to that of the other specified Graphical Object.
static Point2D toLocalCoordinates(GraphicalObject gobSrc, Point2D pt, GraphicalObject gobDst)
          Convert a point from one GraphicalObject's local coordinate system to another.
static Point2D toLocalCoordinates(GraphicalObject gobSrc, Point2D ptSrc, GraphicalObject gobDst, Point2D ptDst)
          Convert a point from one GraphicalObject's local coordinate system to another.
static Rectangle2D toLocalCoordinates(GraphicalObject gobSrc, Rectangle2D rectSrc, GraphicalObject gobDst)
           
static Rectangle2D toLocalCoordinates(GraphicalObject gobSrc, Rectangle2D rectSrc, GraphicalObject gobDst, Rectangle2D rectDst)
          Convert a rectangle from one coordinate system to another.
static double weightAtBottom(GraphicalObject gobAA, GraphicalObject gobBB)
           
static double weightAtLeft(GraphicalObject gobAA, GraphicalObject gobBB)
           
static double weightAtRight(GraphicalObject gobAA, GraphicalObject gobBB)
           
static double weightAtTop(GraphicalObject gobAA, GraphicalObject gobBB)
          Compare the center of masses of the two GraphicalObjects.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphicalObjectLib

public GraphicalObjectLib()
Method Detail

getUniqueID

public static final int getUniqueID()
Get a (mostly) unique ID, as long as the system is running.

isAnimating

public static final boolean isAnimating()
Are we trying to animate or not?

setAnimating

public static final void setAnimating(boolean flag)
Set whether we are we trying to animate or not.

animate

public static void animate(GraphicalObject gob,
                           AffineTransform[] txArray)
Given a set of transforms, animate this graphical object using those transforms.
Parameters:
gob - is the GraphicalObject to animate.
txArray - is the array of AffineTransforms to use for transforms. Each transform should undo the previous transform, so we can just iteratively call GraphicalObject.applyTransform(AffineTransform). The array of AffineTransforms can be generated by calling AffineTransformLib.interpolate(AffineTransform, AffineTransform, Interpolation, int).

getRenderBounds

public static Rectangle getRenderBounds(GraphicalObject gob)
Given a GraphicalObject, get the bounds for its damage region, that is the region that needs to be repainted. This is slightly larger than the bounds of the GraphicalObject, since its stroke width may be large.
Parameters:
gob - is the GraphicalObject whose rendering bounds we want.
Returns:
a Rectangle.

toLocalCoordinates

public static void toLocalCoordinates(GraphicalObject gobMove,
                                      GraphicalObject gobCoord)
Shift a Graphical Object from its current coordinate system to that of the other specified Graphical Object.
Parameters:
gobMove - is the Graphical Object whose coordinate system we want to change.
gobCoord - is the Graphical Object to whose coordinate system we want to move to.

toLocalCoordinates

public static Point2D toLocalCoordinates(GraphicalObject gobSrc,
                                         Point2D pt,
                                         GraphicalObject gobDst)
Convert a point from one GraphicalObject's local coordinate system to another.
Parameters:
gobSrc - is the source coordinate system.
ptSrc - is the point in the source coordinate system.
gobDst - is the destination coordinate system.
Returns:
a new point.
See Also:
toLocalCoordinates(GraphicalObject, Point2D, GraphicalObject, Point2D)

toLocalCoordinates

public static Point2D toLocalCoordinates(GraphicalObject gobSrc,
                                         Point2D ptSrc,
                                         GraphicalObject gobDst,
                                         Point2D ptDst)
Convert a point from one GraphicalObject's local coordinate system to another.
Parameters:
gobSrc - is the source coordinate system.
ptSrc - is the point in the source coordinate system.
gobDst - is the destination coordinate system.
ptDst - is storage for the point in the destination coordinate system. Use null and new storage will be created.
Returns:
a reference to ptDst.

toLocalCoordinates

public static Rectangle2D toLocalCoordinates(GraphicalObject gobSrc,
                                             Rectangle2D rectSrc,
                                             GraphicalObject gobDst)
See Also:
toLocalCoordinates(GraphicalObject, Rectangle2D, GraphicalObject, Rectangle2D)

toLocalCoordinates

public static Rectangle2D toLocalCoordinates(GraphicalObject gobSrc,
                                             Rectangle2D rectSrc,
                                             GraphicalObject gobDst,
                                             Rectangle2D rectDst)
Convert a rectangle from one coordinate system to another. Note that this will not always be correct if there are shears or rotation. In these cases, we just take the bounding box.
Parameters:
gobSrc - is the source coordinate system.
rectSrc - is the rectangle in the source coordinate system.
gobDst - is the destination coordinate system.
rectDst - is storage for the rectangle in the destination coordinate system. Use null and new storage will be created.
Returns:
a reference to rectDst.

localToAbsolute

public static Point2D localToAbsolute(GraphicalObject gob,
                                      Point2D ptIn)
Convert a coordinate from local coordinates to absolute coordinates.
Parameters:
gob - is the owner of the local coordinate system.
ptIn - is the point to convert.
Returns:
a new Point containing the converted point.

localToAbsolute

public static Point2D localToAbsolute(GraphicalObject gob,
                                      Point2D ptIn,
                                      Point2D ptReturn)
Convert a coordinate from local coordinates to absolute coordinates.
Parameters:
gob - is the owner of the local coordinate system.
ptIn - is the point to convert.
ptReturn - is the space to return the answer in. This can be the same as ptIn. Use null for new storage.
Returns:
ptReturn.

localToAbsolute

public static Rectangle2D localToAbsolute(GraphicalObject gob,
                                          Rectangle2D rectIn)
Convert a rectangle from local coordinates to absolute coordinates.
Parameters:
gob - is the owner of the local coordinate system.
rectIn - is the point to convert.
Returns:
a new Rectangle containing the converted rectangle.

absoluteToLocal

public static Point2D absoluteToLocal(GraphicalObject gob,
                                      Point2D ptIn)
Convert a coordinate from absolute coordinates to local coordinates.
Parameters:
gob - is the owner of the local coordinate system.
ptIn - is the point to convert.
Returns:
a new Point containing the converted point.

absoluteToLocal

public static Point2D absoluteToLocal(GraphicalObject gob,
                                      Point2D ptIn,
                                      Point2D ptReturn)
Convert a coordinate from absolute coordinates to local coordinates.
Parameters:
gob - is the owner of the local coordinate system.
ptIn - is the point to convert.
ptReturn - is the space to return the answer in. This can be the same as ptIn.
Returns:
ptReturn.

absoluteToLocal

public static Rectangle2D absoluteToLocal(GraphicalObject gob,
                                          Rectangle2D rectIn)
Convert a rectangle from absolute coordinates to local coordinates.
Parameters:
gob - is the owner of the local coordinate system.
rectIn - is the point to convert.
Returns:
a new Rectangle containing the converted rectangle.

getScaleFactor

public static double getScaleFactor(int cdsys,
                                    GraphicalObject gob)
Get the scale factor of this Graphical Object.

compareLayers

public static final int compareLayers(GraphicalObject gobA,
                                      GraphicalObject gobB)
Parameters:
gobA - is one GraphicalObject to compare.
gobB - is one GraphicalObject to compare.
Returns:
-1 if gobA is above gobB, 0 if they are in the same layer, 1 if gobB is above gobA.
See Also:
compareLayers(String, String)

compareLayers

public static final int compareLayers(String gobA,
                                      String gobB)
                               throws NumberFormatException
Compare two GraphicalObject layers to see which one is higher. Each GraphicalObject has a layer like "1.2" and "2.1.4". Here are some examples of what comparing them will return:
    1.2   is above 2.1.14
    1.2   is above 1.3
    1.1   is above 1
    1.2.1 is above 1.2
 
The first two cases are easy to check but the third and fourth are tricky.
Parameters:
strA - is the absolute layer of one GraphicalObject.
strA - is the absolute layer of another GraphicalObject.
Returns:
-1 if strA is above strB, 0 if they are in the same layer, 1 if strB is above strA.
Throws:
NumberFormatException - if the Strings are misformatted.

getTopmostLeaf

public static final GraphicalObject getTopmostLeaf(GraphicalObjectCollection gobcol)

getBottommostLeaf

public static final GraphicalObject getBottommostLeaf(GraphicalObjectCollection gobcol)

getTopmostBranch

public static final GraphicalObject getTopmostBranch(GraphicalObjectCollection gobcol)

getBottommostBranch

public static final GraphicalObject getBottommostBranch(GraphicalObjectCollection gobcol)

getTopmostGraphicalObject

public static final GraphicalObject getTopmostGraphicalObject(GraphicalObjectCollection gobcol)
In a GraphicalObjectCollection, get the GraphicalObject nearest to the top.
Parameters:
gobcol - is the GraphicalObjectCollection to iterate over.
Returns:
the GraphicalObject with the absolute layer closest to the top.

getBottommostGraphicalObject

public static final GraphicalObject getBottommostGraphicalObject(GraphicalObjectCollection gobcol)
In a GraphicalObjectCollection, get the GraphicalObject nearest to the bottom.
Parameters:
gobcol - is the GraphicalObjectCollection to iterate over.
Returns:
the GraphicalObject with the absolute layer closest to the bottom.

flatten

public static final GraphicalObjectCollection flatten(GraphicalObjectCollection gobcol)
Given a hierarchy of GraphicalObjects, flatten it into a single Collection (without modifying the original). In other words, given a tree, flatten it into a list (containing both GraphicalObjects and GraphicalObjectGroups), but keep the tree the same.
Parameters:
gobcol - is the tree to flatten.
Returns:
a flattened GraphicalObjectCollection.

removeGraphicalObjectGroups

public static final GraphicalObjectCollection removeGraphicalObjectGroups(GraphicalObjectCollection gobcol)
Given a GraphicalObjectCollection, remove references to all of the GraphicalObjectGroups (and thus Patches too). The original GraphicalObjectCollection is not modified in any way. Useful in conjunction with flatten(), to give you a collection of GraphicalObjects only.
Parameters:
gobcol - is the Collection to remove GObGroups from. gobcol is not modified in any way.

getCenterOfMass

public static final Point2D getCenterOfMass(GraphicalObject gob)

getCenterOfMass

public static final Point2D getCenterOfMass(GraphicalObject gob,
                                            Point2D pt)

weightAtTop

public static final double weightAtTop(GraphicalObject gobAA,
                                       GraphicalObject gobBB)
Compare the center of masses of the two GraphicalObjects.
Parameters:
gobAA - center of mass is used as the force point.
gobBB - center of mass is used as the fulcrum.
Returns:
the diff along y-axis from gobBB to gobAA.

weightAtBottom

public static final double weightAtBottom(GraphicalObject gobAA,
                                          GraphicalObject gobBB)

weightAtRight

public static final double weightAtRight(GraphicalObject gobAA,
                                         GraphicalObject gobBB)

weightAtLeft

public static final double weightAtLeft(GraphicalObject gobAA,
                                        GraphicalObject gobBB)

atTop

public static final boolean atTop(GraphicalObject gobAA,
                                  GraphicalObject gobBB)
Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
See Also:
atTop(GraphicalObject, GraphicalObject, double)

atTop

public static final boolean atTop(GraphicalObject gobAA,
                                  GraphicalObject gobBB,
                                  double thresh)
Check if gobAA is at the top of gobBB within threshold dist.
     *   gobAA   * 
     *   gobBB   *
     *     *     *
 

atBottom

public static final boolean atBottom(GraphicalObject gobAA,
                                     GraphicalObject gobBB)
Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
See Also:
atBottom(GraphicalObject, GraphicalObject, double)

atBottom

public static final boolean atBottom(GraphicalObject gobAA,
                                     GraphicalObject gobBB,
                                     double thresh)
Check if gobAA is at the bottom of gobBB within threshold dist.
     *     *     * 
     *   gobBB   *
     *   gobAA   *
 

atRight

public static final boolean atRight(GraphicalObject gobAA,
                                    GraphicalObject gobBB)
Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
See Also:
atRight(GraphicalObject, GraphicalObject, double)

atRight

public static final boolean atRight(GraphicalObject gobAA,
                                    GraphicalObject gobBB,
                                    double thresh)
Check if gobAA is at the right of gobBB within threshold dist.
     *     *     * 
     *   gobBB gobAA
     *     *     *
 

atLeft

public static final boolean atLeft(GraphicalObject gobAA,
                                   GraphicalObject gobBB)
Uses the SatinConstants.DEFAULT_SELECT_THRESHOLD.
See Also:
atLeft(GraphicalObject, GraphicalObject, double)

atLeft

public static final boolean atLeft(GraphicalObject gobAA,
                                   GraphicalObject gobBB,
                                   double thresh)
Check if gobAA is at the left of gobBB within threshold dist.
     *     *     * 
   gobAA gobBB   *
     *     *     *
 

contains

public static final boolean contains(Shape sAA,
                                     Shape sBB)
Determine if s1 contains s2.
Parameters:
s1,s2 - are in the same coordinate system.
Returns:
true if s1 contains s2, false otherwise.

contains

public static final boolean contains(GraphicalObject gob,
                                     Shape s)
Determine if the Graphical Object contains the specified shape.
Parameters:
gob - is the Graphical Object.
s - is in absolute coordinates.

contains

public static final boolean contains(Shape s,
                                     GraphicalObject gob)
Determine if the Shape contains the specified Graphical Object.

intersects

public static final boolean intersects(Shape sAA,
                                       Shape sBB)
Determine if s1 intersects s2.

intersects

public static final boolean intersects(GraphicalObject gob,
                                       Shape s)
Determine if the Graphical Object contains the specified shape.

intersects

public static final boolean intersects(Shape s,
                                       GraphicalObject gob)
Determine if the Shape contains the specified Graphical Object.

main

public static void main(String[] argv)
                 throws Exception

Copyright Information