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

edu.berkeley.guir.lib.satin.graphics
Class GraphicsLib

java.lang.Object
  |
  +--edu.berkeley.guir.lib.satin.graphics.GraphicsLib
All Implemented Interfaces:
GraphicsConstants

public final class GraphicsLib
extends Object
implements GraphicsConstants

This software is distributed under the Berkeley Software License.

 Revisions:  - SATIN-v1.0-1.0.0, Jul 22 1999, 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 )

Fields inherited from interface edu.berkeley.guir.lib.satin.graphics.GraphicsConstants
BOTTOM, BOTTOM_LEFT, BOTTOM_RIGHT, CENTER, HIGH_QUALITY, HIGHEST_QUALITY, LEFT, LOW_QUALITY, LOWEST_QUALITY, MEDIUM_QUALITY, RIGHT, TOP, TOP_LEFT, TOP_RIGHT
 
Method Summary
static Rectangle calculateBoundingBox(String str, Font f, int x, int y, int pos)
          Calculate the bounding box for this String.
static Rectangle calculateBoundingBox(String str, FontMetrics fmetric, int x, int y, int pos)
          Calculate the bounding box for this String.
static Point calculateNewPosition(Shape shape, int pos)
          Shift an object to have new coordinates.
static int calculateTotalHeight(String str, Font font)
          Using the specified font, calculate the height (in pixels) of the specified String.
static int calculateTotalHeight(String str, FontMetrics fmetric)
          First, calculate how many rows there are.
static int calculateTotalWidth(String str, Font font)
          Using the specified font, calculate the width (in pixels) of the specified String.
static int calculateTotalWidth(String str, FontMetrics fmetric)
          Using the specified font metric, calculate the max width of this String in pixels, that is the longest width among each of the rows of this String.
static Point calculateTranslation(Shape shape, int x, int y, int pos)
          Calculate how much a Shape should be translated along x- and y- such that the specified position of the Shape will be at the specified (x,y) coordinate.
static Color makeTransparent(Color c, float aa)
          Set the transparency for drawing.
static Color makeTransparent(Color c, int aa)
          Set the transparency for draw.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

calculateNewPosition

public static Point calculateNewPosition(Shape shape,
                                         int pos)
Shift an object to have new coordinates. For example, most objects are drawn using the specified (x,y) coordinates as the top-left corner. Let's say you want to use the specified (x,y) coordinates as the center. This method does this transformation, returning an (x,y) coordinate that says where you should draw.

Suppose you have a Rectangle, and you want to draw it such that it is centered at (0,0). Just call calculateNewPosition(rect, GraphicsLib.CENTER) to figure out where the top-left corner of the Rectangle should be drawn. Pretty neat, eh?

Parameters:
shape - is some shape to draw.
pos - specifies where to shift the drawing to (CENTER, TOP_LEFT, etc).
Returns:
a Point containing where to draw the object's top-left corner.

calculateTranslation

public static Point calculateTranslation(Shape shape,
                                         int x,
                                         int y,
                                         int pos)
Calculate how much a Shape should be translated along x- and y- such that the specified position of the Shape will be at the specified (x,y) coordinate.

For example, say you already have a circle, and want to draw this circle with (0,0) as its center. Just call calculateTranslation(circle, 0, 0, CENTER) to figure out how much the shape should be translated.

Parameters:
shape - is the Shape to determine how much to move. Make sure that the coordinates of shape are in the same coordinate system as x and y below.
x - is the x-coordinate to move it to.
y - is the y-coordinate to move it to.
pos - is the position that x and y represent (e.g. CENTER, TOP_LEFT, etc).
Returns:
a Point containing the amount to translate along x and y.

calculateTotalWidth

public static int calculateTotalWidth(String str,
                                      Font font)
Using the specified font, calculate the width (in pixels) of the specified String.
Parameters:
str - is the String whose max width in pixels we want.
font - is the font to use for this String.
Returns:
the height (in pixels) of this String.
See Also:
calculateTotalWidth(java.lang.String, java.awt.FontMetrics)

calculateTotalWidth

public static int calculateTotalWidth(String str,
                                      FontMetrics fmetric)
Using the specified font metric, calculate the max width of this String in pixels, that is the longest width among each of the rows of this String.
Parameters:
str - is the String whose max width in pixels we want.
fmetric - is the FontMetrics to use for calculation.
Returns:
the width (in pixels) of the longest row of this String.

calculateTotalHeight

public static int calculateTotalHeight(String str,
                                       Font font)
Using the specified font, calculate the height (in pixels) of the specified String.
Parameters:
str - is the String whose max width in pixels we want.
font - is the font to use for this String.
Returns:
the height (in pixels) of this String.
See Also:
calculateTotalHeight(java.lang.String, java.awt.FontMetrics)

calculateTotalHeight

public static int calculateTotalHeight(String str,
                                       FontMetrics fmetric)
First, calculate how many rows there are. Then, using the current font metric, calculate the total height of this String in pixels.
Parameters:
str - is the String whose max width in pixels we want.
fmetric - is the FontMetrics to use for calculation.
Returns:
the height (in pixels) of this String.

calculateBoundingBox

public static Rectangle calculateBoundingBox(String str,
                                             Font f,
                                             int x,
                                             int y,
                                             int pos)
Calculate the bounding box for this String. Uses the current font metrics for this graphics object.
Parameters:
str - is the String whose bounding box we want.
f - is the Font to use.
x - is the left side of the bounding box.
y - is the top side of the bounding box (NOT bottom).
pos - specifies what (x,y) are relative to the bounding box (e.g. the CENTER, TOP_LEFT, etc).
Returns:
the bounding box.
See Also:
calculateBoundingBox(String, FontMetrics, int, int, int)

calculateBoundingBox

public static Rectangle calculateBoundingBox(String str,
                                             FontMetrics fmetric,
                                             int x,
                                             int y,
                                             int pos)
Calculate the bounding box for this String. Uses the current font metrics for this graphics object. Since Strings do not inherently have coordinates, use the specified (x,y) position as the top-left.
Parameters:
str - is the String whose bounding box we want.
fmetric - is the FontMetric to use.
x - is the left side of the bounding box.
y - is the top side of the bounding box (NOT bottom).
pos - specifies what (x,y) are relative to the bounding box (e.g. the CENTER, TOP_LEFT, etc).
Returns:
the bounding box.

makeTransparent

public static final Color makeTransparent(Color c,
                                          float aa)
Set the transparency for drawing.
Parameters:
aa - is the transparency value, from 0 to 1, 0 being transparent and 1 being solid.

makeTransparent

public static final Color makeTransparent(Color c,
                                          int aa)
Set the transparency for draw.
Parameters:
aa - is the transparency value (0-255). Sets to 0 if less than 0, or to 255 if greater than 255.

Copyright Information