public class FigureUtilities
extends java.lang.Object
Constructor and Description |
---|
FigureUtilities() |
Modifier and Type | Method and Description |
---|---|
static Color |
darker(Color color)
Returns a new Color the same as the passed color in a darker hue.
|
static IFigure |
findCommonAncestor(IFigure l,
IFigure r)
Returns the figure which is the nearest common ancestor of both figures,
or
null if there is no common ancestor. |
static FontMetrics |
getFontMetrics(Font f)
Returns the FontMetrics associated with the passed Font.
|
protected static GC |
getGC()
Deprecated.
do not mess with this GC
|
static IFigure |
getRoot(IFigure figure)
Returns the highest ancestor for the given figure
|
protected static Point |
getStringDimension(java.lang.String s,
Font f)
Returns the dimensions of the String s using the font f.
|
static Dimension |
getStringExtents(java.lang.String s,
Font f)
Returns the Dimensions of s in Font f.
|
protected static Point |
getTextDimension(java.lang.String s,
Font f)
Returns the dimensions of the String s using the font f.
|
static Dimension |
getTextExtents(java.lang.String text,
Font f)
Returns the Dimensions of the given text, converting newlines and tabs
appropriately.
|
static void |
getTextExtents(java.lang.String s,
Font f,
Dimension result)
Returns the Dimensions of the given text, converting newlines and tabs
appropriately.
|
static int |
getTextWidth(java.lang.String s,
Font f)
Returns the width of s in Font f.
|
static boolean |
isAncestor(IFigure ancestor,
IFigure descendant)
Returns
true if the ancestor contains the descendant, or is
the ancestor of the descendant's parent. |
static boolean |
isNotFullyClipped(IFigure figure)
Determines whether the given figure is showing and not (completely)
clipped.
|
static Color |
lighter(Color rgb)
Returns a Color the same as the passed color in a lighter hue.
|
static Shape |
makeGhostShape(Shape s)
Produces a ghosting effect on the shape s.
|
static Color |
mixColors(Color c1,
Color c2)
Mixes the passed Colors and returns the resulting Color.
|
static Color |
mixColors(Color c1,
Color c2,
double weight)
Mixes the passed Colors and returns the resulting Color.
|
static void |
paintEtchedBorder(Graphics g,
Rectangle r)
Paints a border with an etching effect, having a shadow of a darker
version of g's background color, and a highlight a lighter version of g's
background color.
|
static void |
paintEtchedBorder(Graphics g,
Rectangle r,
Color shadow,
Color highlight)
Paints a border with an etching effect, having a shadow of Color
shadow and highlight of Color highlight.
|
static void |
paintGrid(Graphics g,
IFigure f,
Point origin,
int distanceX,
int distanceY)
Helper method to paint a grid.
|
protected static void |
setFont(Font f)
Sets Font to passed value.
|
public static Color darker(Color color)
color
- the color to darkenpublic static FontMetrics getFontMetrics(Font f)
f
- the fontGC.getFontMetrics()
protected static GC getGC()
protected static Point getTextDimension(java.lang.String s, Font f)
s
- the stringf
- the fontGC.textExtent(String)
public static IFigure getRoot(IFigure figure)
figure
- a figureprotected static Point getStringDimension(java.lang.String s, Font f)
s
- the stringf
- the fontGC.stringExtent(java.lang.String)
public static Dimension getTextExtents(java.lang.String text, Font f)
text
- the textf
- the fontpublic static Dimension getStringExtents(java.lang.String s, Font f)
s
- the stringf
- the fontpublic static void getTextExtents(java.lang.String s, Font f, Dimension result)
s
- the stringf
- the fontresult
- the Dimension that will contain the result of this calculationpublic static int getTextWidth(java.lang.String s, Font f)
s
- the stringf
- the fontpublic static Color lighter(Color rgb)
rgb
- the colorpublic static Shape makeGhostShape(Shape s)
s
- the shapepublic static Color mixColors(Color c1, Color c2, double weight)
c1
- the first colorc2
- the second colorweight
- the first color's weight from 0-1public static Color mixColors(Color c1, Color c2)
c1
- the first colorc2
- the second colorpublic static void paintEtchedBorder(Graphics g, Rectangle r, Color shadow, Color highlight)
g
- the graphics objectr
- the bounds of the bordershadow
- the shadow colorhighlight
- the highlight colorpublic static void paintGrid(Graphics g, IFigure f, Point origin, int distanceX, int distanceY)
g
- The Graphics object to be used for paintingf
- The figure in which the grid is to be paintedorigin
- Any point where the grid lines are expected to intersectdistanceX
- Distance between vertical grid lines; if 0 or less, vertical
grid lines will not be drawndistanceY
- Distance between horizontal grid lines; if 0 or less,
horizontal grid lines will not be drawnpublic static void paintEtchedBorder(Graphics g, Rectangle r)
g
- the graphics objectr
- the bounds of the borderprotected static void setFont(Font f)
f
- the new fontpublic static IFigure findCommonAncestor(IFigure l, IFigure r)
null
if there is no common ancestor. A figure is an
ancestor if it is the parent of another figure, or if it is the ancestor
of that figure's parent. If one figure is the ancestor of the other, it
is returned as the common ancestor.l
- leftr
- rightnull
.public static boolean isAncestor(IFigure ancestor, IFigure descendant)
true
if the ancestor contains the descendant, or is
the ancestor of the descendant's parent.ancestor
- the ancestordescendant
- the descendanttrue
if ancestorpublic static boolean isNotFullyClipped(IFigure figure)
figure
- The figure to testtrue
if the given figure is showing and not
completely clipped, false
otherwise.Copyright (c) IBM Corp. and others 2000, 2011. All Rights Reserved.