|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.miginfocom.util.gfx.GfxUtil
public class GfxUtil
A number of utility methods for graphics operations.
| Field Summary | |
|---|---|
static int |
AA_HINT_DEFAULT
The AA will be set to be default. |
static int |
AA_HINT_INHERIT
The AA will not be changed and will thus inhert the setting from the painted object before. |
static int |
AA_HINT_LCD_GASP
Uses the font's GASP table to decide if AA should be used. |
static int |
AA_HINT_LCD_HBGR
Uses HBGR sub pixel AA or normal AA if sub pixel AA is not supported. |
static int |
AA_HINT_LCD_HRGB
Uses HRGB sub pixel AA or normal AA if sub pixel AA is not supported. |
static int |
AA_HINT_LCD_VBGR
Uses VBGR sub pixel AA or normal AA if sub pixel AA is not supported. |
static int |
AA_HINT_LCD_VRGB
Uses VRGB sub pixel AA or normal AA if sub pixel AA is not supported. |
static int |
AA_HINT_OFF
The AA will be set to off. |
static int |
AA_HINT_ON
Turns AA on. |
static int |
AA_HINT_PLATFORM
Uses the same AA as the current platform. |
static java.awt.Font |
DEFAULT_FONT
|
static int |
defaultImageTransparency
The default transparency of an image that is created and no other transparency information is available. |
| Constructor Summary | |
|---|---|
GfxUtil()
|
|
| Method Summary | |
|---|---|
static void |
addInsets(java.awt.Insets source,
java.awt.Insets add)
Adds add to source |
static java.awt.Color |
alphaColor(java.awt.Color color,
int alpha)
Returns a copy of the color with the alpha set to 'alpha' |
static java.lang.Object |
confAntiAliasingHint(java.awt.Graphics2D g2,
boolean isText,
int migHint)
Sets the anti aliasing hint in a very decoupled way. |
static java.util.ArrayList |
createLayouts(java.awt.Graphics2D g2,
java.lang.String text,
int width,
int ulWidth)
Breaks the text into lines and wrap those at width putting the lines (TextLayouts)
in an array. |
static java.util.ArrayList |
createLayouts(java.awt.Graphics2D g2,
java.lang.String text,
int width,
int ulWidth,
int lineHeight,
int maxHeight)
Breaks the text into lines and wrap those at width putting the lines (TextLayouts)
in an array. |
static void |
cropRect(java.awt.Rectangle r,
java.awt.Insets c)
Crops a rectangle. |
static java.awt.Shape |
cropShape(java.awt.Shape clip,
java.awt.Shape shape)
Cuts shape with clip in a lenient and effective way. |
static int |
cutRect(java.awt.Rectangle r,
java.util.List cutRects,
int side)
Reduces r with all overlapping rectangles in cutRects. |
static int |
cutRectEdge(java.awt.Rectangle r,
java.awt.Rectangle cr,
int side)
Cuts (reduces) r so that it no longer overlaps cr. |
static void |
drawArrow(java.awt.Graphics2D g,
int x,
int y,
int width,
int height,
int direction,
java.awt.Color arrowColor,
java.awt.Color shadowColor)
Draws an arrow within the bounds. |
static java.awt.Rectangle |
drawFittingStringInRect(java.awt.Graphics2D g2,
StringProvider provider,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
Draws a text line. |
static java.awt.Rectangle |
drawFittingStringInRect(java.awt.Graphics2D g2,
StringProvider provider,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
Draws a text line. |
static java.awt.Rectangle |
drawFittingStringRot90(java.awt.Graphics2D g2,
StringProvider provider,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
Draws a text line rotated 90 degrees clock- or counter wise. |
static java.awt.Rectangle |
drawFittingStringRot90(java.awt.Graphics2D g2,
StringProvider provider,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
Draws a text line rotated 90 degrees clock- or counter wise. |
static void |
drawRoundRect(java.awt.Graphics2D g2,
java.awt.Rectangle r,
float arcW,
float arcH,
java.awt.Paint background,
java.awt.BasicStroke stroke,
java.awt.Paint strokePaint)
Draws a round rectangle with a fill and/or outline. |
static java.awt.Rectangle |
drawStringInRect(java.awt.Graphics2D g2,
java.lang.String str,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
Draws a text line. |
static java.awt.Rectangle |
drawStringInRect(java.awt.Graphics2D g2,
java.lang.String str,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
Draws a text line. |
static java.awt.Rectangle |
drawStringRot90(java.awt.Graphics2D g2,
java.lang.String str,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
Draws a text line rotated 90 degrees clock- or counter wise. |
static java.awt.Rectangle |
drawStringRot90(java.awt.Graphics2D g2,
java.lang.String str,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
Draws a text line rotated 90 degrees clock- or counter wise. |
static java.awt.Rectangle |
drawTextLinesInRect(java.awt.Graphics2D g2,
java.lang.String text,
java.awt.Rectangle r,
int ulWidth,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int leadCorr,
boolean clip,
boolean doDraw,
int aaHint)
Draw a text inside a rectangle with row breaks on word boundaries and '\n'. |
static java.awt.Rectangle |
drawTextLinesInRect(java.awt.Graphics2D g2,
java.lang.String text,
java.awt.Rectangle r,
int ulWidth,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int leadCorr,
java.awt.Point shadowOff,
boolean clip,
boolean doDraw,
int aaHint)
Draw a text inside a rectangle with row breaks on word boundaries and '\n'. |
static double |
getAngleBetweenCords(double x1,
double y1,
double x2,
double y2)
Returns the angle between two vectors originating from (0, 0) to (x1, y1) and (x2, y2). |
static java.awt.image.BufferedImage |
getBufferedImage(javax.swing.Icon icon,
int transparency)
Converts the Icon to an BufferedImage. |
static java.awt.image.BufferedImage |
getBufferedImage(java.awt.Image img,
int transparency)
Converts the Image to an BufferedImage. |
static java.awt.image.BufferedImage |
getBufferedImage(java.lang.Object imgOrIcon,
int transparency)
Converts wrapper that calls the correct getBufferedImage depending on whether imgOrIcon is an
Image or an Icon. |
static float |
getConstrainedSize(AtRefNumber size,
AtRefNumber loBounds,
AtRefNumber hiBounds,
float refSize)
Returns the size that is indicated by num but corrected for a lower and upper bounds. |
static java.awt.Color |
getCrossColor(java.awt.Color c1,
java.awt.Color c2,
float f)
Creates a Color that lies in between c1 and c2. |
static double |
getCrossDouble(double v1,
double v2,
double perc)
Returns a double relative to v1 and v2. |
static java.awt.geom.Rectangle2D |
getCrossedRect2D(java.awt.geom.Rectangle2D r1,
java.awt.geom.Rectangle2D r2,
double d)
Returns a Rectangle2D.Double that is a cross between r1 and r2. |
static float |
getCrossFloat(float v1,
float v2,
float perc)
Returns a float relative to v1 and v2. |
static java.awt.image.BufferedImage |
getCrossImage(java.awt.Image im1,
java.awt.Image im2,
java.awt.image.BufferedImage dest,
int trans,
float f,
boolean fadeIm1)
Returns an image (normally managed) that is crossed (faded) between two images. |
static java.awt.TexturePaint |
getCrossTexturePaint(java.awt.TexturePaint tp1,
java.awt.TexturePaint tp2,
float f,
int transparency,
boolean fadeTp1)
Returns a TexturePaint that is crossed (faded) between two TexturePaint. |
static java.awt.Cursor |
getCursor(java.lang.Object cursorHint)
Returns a cursor for a hint. |
static java.awt.GraphicsConfiguration |
getDefaultConfiguration()
Returns the default configuration on the default graphics environment |
static java.awt.Graphics2D |
getDummyGraphics()
Creates a dummy Grapics2D. |
static java.awt.image.BufferedImage |
getImageFromString(java.lang.String csStr,
java.lang.Integer forceTrans)
Returns an image. |
static java.awt.image.BufferedImage |
getImageFromString(java.lang.String csStr,
java.lang.StringBuffer report,
java.lang.Integer forceTrans)
Returns an image. |
static int |
getMaxStringWidth(java.lang.String[] strings,
java.awt.Font font,
boolean isAntiAlias,
boolean fractionalMetrics)
Return the with of the widest string. |
static java.awt.Rectangle |
getOutlineRect(java.awt.geom.RectangularShape r)
Returns the smallest Rectangle that contains the whole of r. |
static java.awt.Rectangle |
getRect(java.awt.Point p1,
java.awt.Point p2)
Returns a rectangle from a diagonal between the points |
static double |
getRelativeSizeXXX(java.lang.Number num,
double refSize)
Returns the size that is either absolute or relative to refSize. |
static java.awt.Rectangle |
getResizedRect(java.awt.Rectangle r,
float scaleX,
float scaleY,
float alignX,
float alignY)
Creates an expanded/reduced Rectangle. |
static java.awt.Rectangle |
getResizedRect(java.awt.Rectangle r,
java.awt.Insets insets,
boolean positiveReduces)
Creates an expanded/reduced Rectangle. |
static java.awt.Rectangle |
getRoundedRect(java.awt.geom.RectangularShape rect2d,
boolean roundToCords)
Converts a Rectangle2D to a Rectangle by rounding its values to the nearest int. |
static java.awt.Frame |
getShowingFrame()
Returns the fist visible Frame we can find or null if none. |
static int |
getStringWidth(java.awt.Font font,
java.lang.String text,
java.lang.Object aaHint)
Return the string width for the text with the indicated attributes. |
static int |
getTextLinesHeight(java.awt.Font font,
java.lang.String text,
java.lang.Integer width,
int leadCorr,
java.lang.Object aaHint)
Returns the height needed to draw the text with drawTextLinesInRect(java.awt.Graphics2D, String, java.awt.Rectangle, int, AtRefRangeNumber, AtRefRangeNumber, int, Point, boolean, boolean, int). |
static java.awt.Shape |
getTransformedShape(java.awt.geom.AffineTransform at,
java.awt.Shape shape)
Calls returns a shape that is transformed by at. |
static java.awt.Shape[] |
getTransformedShapes(java.awt.geom.AffineTransform at,
java.awt.Shape[] shapes)
Calls getTransformedShape(java.awt.geom.AffineTransform, java.awt.Shape) for every shape in the array and return a new arrays with
the transformed shapes. |
static int |
getTransparency(java.lang.Object img)
Calls getTransparency(Object, int) with defaultImageTransparency as the default transparency. |
static int |
getTransparency(java.lang.Object img,
int defTrans)
Tries to find the transparency for the image. |
static java.lang.String |
getUIName()
Returns the name of the UI. |
static double |
getVectorAngle(double x1,
double y1,
double angle)
Returns the angle between 'angle' and a vector from (0, 0) to (x1, y1). |
static java.awt.image.VolatileImage |
getVolatileImage(java.awt.Image img)
Converts the Image to an VolatileImage. |
static int |
HSLtoRGB(float h,
float s,
float l)
|
static java.lang.String |
imageToBase64(java.awt.Image img,
java.lang.String formatName)
Convers an image to a base64 string by saving it with ImageIO to a byte stream and convert that
stream to base64. |
static void |
reduceRectXXX(java.awt.geom.Rectangle2D r,
java.lang.Number widthRed,
java.lang.Number heightRed)
Reduces a rectangle. |
static void |
repaintAllFrames()
Repaints all frames in the application. |
static void |
resizeRect(java.awt.Rectangle r,
java.awt.Insets i,
boolean positiveReduces)
Expands/reduces Rectangle. |
static float[] |
RGBtoHSL(int r,
int g,
int b)
hslVals may be null |
static void |
setTextAntiAliasPlatformDefault(java.lang.Object renderingHint)
Sets the default text anti alias rendering hint. |
void |
setUIName(java.lang.String s)
Forces the UI name to be a specific value. |
static java.awt.Color |
tintColor(java.awt.Color c,
float f)
Brightens or darkens a color (towards white or black) |
static java.awt.Color |
tintColor(java.awt.Color c,
int diff)
Brightens or darkens a color (towards white or black) |
static void |
unionInsets(java.awt.Insets source,
java.awt.Insets unionWith)
Unions two insets so that source will contain the smalles insets that will fit both insets. |
static boolean |
waitForImage(java.awt.Image image,
long timeOut)
Waits for an image to load and then returns. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final java.awt.Font DEFAULT_FONT
public static final int AA_HINT_INHERIT
public static final int AA_HINT_OFF
public static final int AA_HINT_DEFAULT
AA_HINT_INHERIT.
public static final int AA_HINT_ON
public static final int AA_HINT_LCD_GASP
public static final int AA_HINT_LCD_HRGB
public static final int AA_HINT_LCD_HBGR
public static final int AA_HINT_LCD_VRGB
public static final int AA_HINT_LCD_VBGR
public static final int AA_HINT_PLATFORM
public static final int defaultImageTransparency
Transparency.OPAQUE is default.
| Constructor Detail |
|---|
public GfxUtil()
| Method Detail |
|---|
public static void setTextAntiAliasPlatformDefault(java.lang.Object renderingHint)
renderingHint - The rendering hint. E.g. RenderingHints.VALUE_ANTIALIAS_ON. Not null.
public static java.lang.Object confAntiAliasingHint(java.awt.Graphics2D g2,
boolean isText,
int migHint)
g2 - The graphics object to set the anti aliasing hint on. May be null.isText - If it's the text AA to set. (RenderingHints.KEY_TEXT_ANTIALIASING vs RenderingHints.KEY_ANTIALIASING)migHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
g2 != null and the hint to set (which can also be null) if g2 == null !!!public static java.awt.GraphicsConfiguration getDefaultConfiguration()
public static java.awt.Graphics2D getDummyGraphics()
public static java.lang.String getUIName()
null.setUIName(String)public void setUIName(java.lang.String s)
null will re-read it from the Java System.
public static java.awt.Frame getShowingFrame()
Frame we can find or null if none.
Frame we can find or null if none.public static java.awt.Cursor getCursor(java.lang.Object cursorHint)
cursorHint - Can be an Integer, String or Cursor that hints what cursor to use.
Cursor.getSystemCustomCursor(java.lang.String),
Cursor.getPredefinedCursor(int),
Cursor
public static int getMaxStringWidth(java.lang.String[] strings,
java.awt.Font font,
boolean isAntiAlias,
boolean fractionalMetrics)
strings - The strings to test. Not null.font - The font, nor null.isAntiAlias - If the text is to be anti aliased.fractionalMetrics - If fractional metrics is to be used.
public static java.awt.Shape[] getTransformedShapes(java.awt.geom.AffineTransform at,
java.awt.Shape[] shapes)
getTransformedShape(java.awt.geom.AffineTransform, java.awt.Shape) for every shape in the array and return a new arrays with
the transformed shapes.
for the arguments.
public static java.awt.Shape getTransformedShape(java.awt.geom.AffineTransform at,
java.awt.Shape shape)
at. Checks if shape is a Rectangle
and if so returns a correct Reactangle2D rather that going through AffineTransform.createTransformedShape(java.awt.Shape),
which is slower.
at - The transform. Not null. No shear for Rectange2D optimizations to occur and only integer translates and no scale for
Rectange optimization.shape - The shape to transform. Has optimizations for Ractangle2D and even mor so for Rectangle objects.
at. Rectangle2D.Double if shape is a Reactangle2D.
public static final java.awt.Color tintColor(java.awt.Color c,
float f)
c - The color to brighten or darkens. Never null.f - The percent to move the color towards white or black. -1.0f .. 1.0f. Minus darkens, eg. -0.1 darkens 10%
public static final java.awt.Color tintColor(java.awt.Color c,
int diff)
c - The color to brighten or darkens. Never null.diff - The value to add to each of the red/green/blue. Will be kept inside 0..255
public static java.awt.Color getCrossColor(java.awt.Color c1,
java.awt.Color c2,
float f)
Color that lies in between c1 and c2. Counts on Color beeing immutal.
c1 - The first, source, color. Not null.c2 - The second, target, color. Not null.f - How far between c1 and c2 the returned color should lie. 0.0 is at c1,
1.0 is at c2. Values outside 0..1 will return c1 or c2 respectively.
Color that lies in between c1 and c2.
public static final java.awt.Color alphaColor(java.awt.Color color,
int alpha)
color - The color. not nullalpha - The new alpha
public static java.awt.Rectangle drawFittingStringInRect(java.awt.Graphics2D g2,
StringProvider provider,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
g2's current font and paint. Draws the first line from the provider that fits the the length of the bounds. Always draws the
last provided string, without even checking the length of it. This gives that a provider with only one string imposes no overhead. If the last string should not
be drawn if it doesn't fit have the provider return "" as last string.
g2 - The graphics object to draw in. Won't be changed.provider - The source of the strings. Will be aksed from index 0 to size -1. If "" is returned nothing is drawn. The last string is always drawn even if it doesn't fit.bounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlinedoDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.drawStringInRect(java.awt.Graphics2D, String, java.awt.Rectangle, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, int, boolean, int)
public static java.awt.Rectangle drawFittingStringInRect(java.awt.Graphics2D g2,
StringProvider provider,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
g2's current font and paint. Draws the first line from the provider that fits the the length of the bounds. Always draws the
last provided string, without even checking the length of it. This gives that a provider with only one string imposes no overhead. If the last string should not
be drawn, if it doesn't fit, have the provider return "" as last string.
g2 - The graphics object to draw in. Won't be changed.provider - The source of the strings. Will be aksed from index 0 to size -1. If "" is returned nothing is drawn. The last string is always drawn even if it doesn't fit.bounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlineshadowOff - The offset in pixels for an optional shadow. If null no shapdow is drawn. g2.getBackground() will be the color of the shadow.doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.drawStringInRect(java.awt.Graphics2D, String, java.awt.Rectangle, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, int, boolean, int)
public static java.awt.Rectangle drawStringInRect(java.awt.Graphics2D g2,
java.lang.String str,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
g2's current font and paint.
g2 - The graphics object to draw in. Won't be changed.str - The String to draw. Not null.bounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlinedoDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.
public static java.awt.Rectangle drawStringInRect(java.awt.Graphics2D g2,
java.lang.String str,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
g2's current font and paint.
g2 - The graphics object to draw in. Won't be changed.str - The String to draw. Not null.bounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlineshadowOff - The offset in pixels for an optional shadow. If null no shapdow is drawn. g2.getBackground() will be the color of the shadow.doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.
public static java.awt.Rectangle drawFittingStringRot90(java.awt.Graphics2D g2,
StringProvider provider,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
g2's current font and paint.
Draws the first line from the provider that fits the the length of the bounds. Always draws the
last provided string, without even checking the length of it. This gives that a provider with only one string imposes no overhead. If the last string should not
be drawn if it doesn't fit have the provider return "" as last string.
g2 - The graphics object to draw in. Won't be changed.provider - The source of the strings. Will be aksed from index 0 to size -1. If "" is returned nothing is drawn. The last string is always drawn even if it doesn't fit.cw - true is clockwise and false is counter clockwisebounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlinedoDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.drawStringInRect(java.awt.Graphics2D, String, java.awt.Rectangle, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, int, boolean, int)
public static java.awt.Rectangle drawFittingStringRot90(java.awt.Graphics2D g2,
StringProvider provider,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
g2's current font and paint.
Draws the first line from the provider that fits the the length of the bounds. Always draws the
last provided string, without even checking the length of it. This gives that a provider with only one string imposes no overhead. If the last string should not
be drawn if it doesn't fit have the provider return "" as last string.
g2 - The graphics object to draw in. Won't be changed.provider - The source of the strings. Will be aksed from index 0 to size -1. If "" is returned nothing is drawn. The last string is always drawn even if it doesn't fit.cw - true is clockwise and false is counter clockwisebounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlineshadowOff - The offset in pixels for an optional shadow. If null no shapdow is drawn. g2.getBackground() will be the color of the shadow.doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.drawStringInRect(java.awt.Graphics2D, String, java.awt.Rectangle, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, com.miginfocom.util.gfx.geometry.numbers.AtRefRangeNumber, int, boolean, int)
public static java.awt.Rectangle drawStringRot90(java.awt.Graphics2D g2,
java.lang.String str,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
boolean doDraw,
int aaHint)
g2's current font and paint.
g2 - The graphics object to draw in. Won't be changed.str - The String to draw. Not null.cw - true is clockwise and false is counter clockwisebounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlinedoDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.
public static java.awt.Rectangle drawStringRot90(java.awt.Graphics2D g2,
java.lang.String str,
boolean cw,
java.awt.Rectangle bounds,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int ulWidth,
java.awt.Point shadowOff,
boolean doDraw,
int aaHint)
g2's current font and paint.
g2 - The graphics object to draw in. Won't be changed.str - The String to draw. Not null.cw - true is clockwise and false is counter clockwisebounds - The bounds to draw within. not null.alignX - The x alignment. null is left justified (same as new AtStart(0))alignY - The y alignment. null is top justified (same as new AtStart(0))ulWidth - The underline with or 0 if no underlineshadowOff - The offset in pixels for an optional shadow. If null no shapdow is drawn. g2.getBackground() will be the color of the shadow.doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returnedaaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null.
public static java.awt.Rectangle drawTextLinesInRect(java.awt.Graphics2D g2,
java.lang.String text,
java.awt.Rectangle r,
int ulWidth,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int leadCorr,
boolean clip,
boolean doDraw,
int aaHint)
g2 - The object to draw in. font, clip or colors will not be changed when done. not null.text - The text to drawr - The rectangel to draw the text relativ toulWidth - The underline width. 0, 1 and 2 are valid.alignX - The x alignment for the rows. r is used as the reference value.alignY - The y alignment for the rows. r is used as the reference value.leadCorr - Adjusts the empty space between two adjacent lines. Normally this spacing is a bit to large for small fonts drawn
in areas when information needs to be more dense. A value of -2 or -3 it normally good. See FontMetrics.getLeading().clip - Clips the text with 'rect' and g's current clip combineddoDraw - If false the text isn't actually drawn into the graphics object, just the height is calculated.aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null. Will have width and height set to 0 if no text was drawn.
public static java.awt.Rectangle drawTextLinesInRect(java.awt.Graphics2D g2,
java.lang.String text,
java.awt.Rectangle r,
int ulWidth,
AtRefRangeNumber alignX,
AtRefRangeNumber alignY,
int leadCorr,
java.awt.Point shadowOff,
boolean clip,
boolean doDraw,
int aaHint)
g2 - The object to draw in. font, clip or colors will not be changed when done. not null.text - The text to drawr - The rectangel to draw the text relativ toulWidth - The underline width. 0, 1 and 2 are valid.alignX - The x alignment for the rows. r is used as the reference value.alignY - The y alignment for the rows. r is used as the reference value.leadCorr - Adjusts the empty space between two adjacent lines. Normally this spacing is a bit to large for small fonts drawn
in areas when information needs to be more dense. A value of -2 or -3 it normally good. See FontMetrics.getLeading().shadowOff - The offset in pixels for an optional shadow. If null no shapdow is drawn. g2.getBackground() will be the color of the shadow.clip - Clips the text with 'rect' and g's current clip combineddoDraw - If false the text isn't actually drawn into the graphics object, just the height is calculated.aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
null. Will have width and height set to 0 and upper left corner same as r if no text was
drawn for some reason.
public static int getTextLinesHeight(java.awt.Font font,
java.lang.String text,
java.lang.Integer width,
int leadCorr,
java.lang.Object aaHint)
drawTextLinesInRect(java.awt.Graphics2D, String, java.awt.Rectangle, int, AtRefRangeNumber, AtRefRangeNumber, int, Point, boolean, boolean, int).
font - The font used to drawtext - The text to drawwidth - The available width to wrap at. If null a singel line's height is returned.leadCorr - Adjusts the empty space between two adjacent lines. Normally this spacing is a bit to large for small fonts drawn
in areas when information needs to be more dense. A value of -2 or -3 it normally good. See FontMetrics.getLeading().aaHint - The anti aliasing rendering hint or null to use default.
public static int getStringWidth(java.awt.Font font,
java.lang.String text,
java.lang.Object aaHint)
font - The font used to drawtext - The text to draw. If null or length 0 then 0 is returned quickly.aaHint - The anti aliasing rendering hint or null to use default.
public static java.util.ArrayList createLayouts(java.awt.Graphics2D g2,
java.lang.String text,
int width,
int ulWidth)
width putting the lines (TextLayouts)
in an array.
Note! null elemements in the array represents empty rows, such as an empty "\n".
g2 - The object used for getting font and font render context from. Antialias should be correctly set on it.text - The text to draw. Not null.width - The with at which to wrapulWidth - The underline width. If >0 an underline attribute will be added. See TextAttribute.UNDERLINE.
TextLayouts, possibly with null elements. Never null.
public static java.util.ArrayList createLayouts(java.awt.Graphics2D g2,
java.lang.String text,
int width,
int ulWidth,
int lineHeight,
int maxHeight)
width putting the lines (TextLayouts)
in an array.
Note! null elemements in the array represents empty rows, such as an empty "\n".
g2 - The object used for getting font and font render context from. Antialias should be correctly set on it.text - The text to draw. Not null.width - The with at which to wrapulWidth - The underline width. If >0 an underline attribute will be added. See TextAttribute.UNDERLINE.lineHeight - The height use to calculate the total height. Used to check maxHeight only.maxHeight - When the added height of the TextLayouts if greated than this value the method will
return the TextLayouts. Note that this will not include inter-row spacing, only the height of the text layouts.
TextLayouts, possibly with null elements. Never null.
public static void unionInsets(java.awt.Insets source,
java.awt.Insets unionWith)
source will contain the smalles insets that will fit both insets.
source - The insets to change. Not nullunionWith - The union to also check. May be null in which case source is unchanged.
public static void addInsets(java.awt.Insets source,
java.awt.Insets add)
add to source
source - The insets to be changedadd - The insets to add. Not changed. If null nothing will happen.
public static void drawRoundRect(java.awt.Graphics2D g2,
java.awt.Rectangle r,
float arcW,
float arcH,
java.awt.Paint background,
java.awt.BasicStroke stroke,
java.awt.Paint strokePaint)
g2 - The graphics object to draw in. Color, paint, stroke and such won't be changed.r - The bounds to draw the rect inarcW - The rounded corner's arc widtharcH - The rounded corner's arc heightbackground - The background or null for no backgroundstroke - The outline stroke or null for no outlinestrokePaint - The outline stroke paint or null for no outline
public static void drawArrow(java.awt.Graphics2D g,
int x,
int y,
int width,
int height,
int direction,
java.awt.Color arrowColor,
java.awt.Color shadowColor)
g - The graphics object to draw in. Color, paint, stroke and such won't be changed.x - Xy - Ywidth - The width of the boundsheight - The height of the boundsdirection - Where the arrow should point. E.g. SwingConstants.NORTH.arrowColor - The normalt color to paint the arrow.shadowColor - Optional shadow for the arrow. May be null.
public static java.awt.Shape cropShape(java.awt.Shape clip,
java.awt.Shape shape)
shape with clip in a lenient and effective way.
The method is optimized to recognize Rectangle2Ds for both clip and shape.
Any shape is ok but slower since it means Area intersection calculations, which is slow.
clip - A clip to exclude (cut) from shape. Can be null.shape - The shape to add. If null this is a no-op and returns null.
shape if clip == null. Can be null.public static final java.awt.Rectangle getOutlineRect(java.awt.geom.RectangularShape r)
Rectangle that contains the whole of r.
r - The rect to convert. Not null.
Rectangle that contains the whole of r.
public static final java.awt.Rectangle getRoundedRect(java.awt.geom.RectangularShape rect2d,
boolean roundToCords)
rect2d - The rect to convert. if null, returns null.roundToCords - If true the returned rectangle is rounded so that the start and end
coordinates is as close to the original positions as possible. If it is false the
the start coordinates and the width and height is rounded so it is as close to the original values
as possible (just rounds x, y, width, height respectively).true is best for rectangles that are painted on a pixel based screen.
null only if rect2d is null.
public static java.awt.geom.Rectangle2D getCrossedRect2D(java.awt.geom.Rectangle2D r1,
java.awt.geom.Rectangle2D r2,
double d)
Rectangle2D.Double that is a cross between r1 and r2. So when
f goes from 0.0f to 1.0f inclusive the returned rectangle transforma from
r1 to r2.
r1 - The first rectangle. Not null.r2 - The seconds rectangle. Not null.d - An unchecked value that should be 0..1 inclusive.
Rectangle2D.Double that is a cross between r1 and r2.
public static void resizeRect(java.awt.Rectangle r,
java.awt.Insets i,
boolean positiveReduces)
Rectangle.
r - The rect to be expanded/reduced. Will be changed!.i - The number of pixels to add around the rect. If null nothing will happen.positiveReduces - If true possitive values in 'insets' reduces the size.
public static void cropRect(java.awt.Rectangle r,
java.awt.Insets c)
resizeRect(java.awt.Rectangle, java.awt.Insets, boolean) but negative/positive
means different things.
Negative values is relative to the opposed edge. E.g. setting r.bottom to -20 would cut the bottom
of the rectangle, leaving the top 20 pixels. Instead setting it to +20 would crop of 20 pixels from the bottom, leaving the top to
whatever size it left when the bottom 20 pixels is cut of.
The rectangle can have negative values when returned and will never be bigger than the size sent in.
r - The rectangle to change.c - The crop. If null this is a no-op.
public static final java.awt.Rectangle getResizedRect(java.awt.Rectangle r,
java.awt.Insets insets,
boolean positiveReduces)
Rectangle.
r - The rect to be expanded/reduced. Does not change. The returned rectangle has the new size. Not null.insets - The number of pixels to add around the rect. Possitive values expands, negative reduces the size. If null, r
will be returned cloned.positiveReduces - If true possitive values in 'insets' reduces the size.
public static final java.awt.Rectangle getResizedRect(java.awt.Rectangle r,
float scaleX,
float scaleY,
float alignX,
float alignY)
Rectangle.
r - The rectange to be resized.scaleX - The horizontal scale. 1.0f returns a rectangle with the same horizontal size.scaleY - The vertical scale. 1.0f returns a rectangle with the same vertical size.alignX - The horizontal alignment. 0f..1falignY - The vertical alignment. 0f..1f
public static java.awt.Rectangle getRect(java.awt.Point p1,
java.awt.Point p2)
p1 - The first point. Not null.p2 - The second point. Not null.
.isEmpty == false if p1 != p2. Never null.
public static final void reduceRectXXX(java.awt.geom.Rectangle2D r,
java.lang.Number widthRed,
java.lang.Number heightRed)
Number arguments.
The type can be of two kinds:Float or Double:Integer: The width/height in absolute pixels to reduce on each side. Same as Rectangle.grow(-widthRed)
widthRed - How much to reduce the width. If null width remain the sameheightRed - How much to reduce the height. If null height remain the same
public static final int cutRectEdge(java.awt.Rectangle r,
java.awt.Rectangle cr,
int side)
r so that it no longer overlaps cr. r will only be cut from one side, side.
r - The rectangle to cut. Will be altered and may be empty after the method.cr - The rectangle used for cutting. Must overlap r1. Not changedside - The side to cut away. (SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.TOP or SwingConstants.BOTTOM) or use
SwingConstants.CENTER and the method will cut the side that leaves the biggest rectangle.
r has area <= 0 after the cut. (I.e. r.isEmpty() is true).Rectangle.intersects(java.awt.Rectangle).
public static int cutRect(java.awt.Rectangle r,
java.util.List cutRects,
int side)
r with all overlapping rectangles in cutRects. Basically calls cutRectEdge(java.awt.Rectangle, java.awt.Rectangle, int)
for all rectangles in cutRects the overlap r. If r gets empty the method bails out and returns false immediately.
r - The rectangle to cut. Will be altered and may be empty after the method.cutRects - A number of rectangles used for cutting. Don't have to overlap r. Not null.side - The side to cut away. (SwingConstants.LEFT, SwingConstants.RIGHT, SwingConstants.TOP or SwingConstants.BOTTOM) or use
SwingConstants.CENTER and the method will cut the side that leaves the biggest rectangle for every rectangle in curRects.
side or -1 if r has area <= 0 after the cut. (I.e. r.isEmpty() is true). Note that this
is a bit different from cutRectEdge(java.awt.Rectangle, java.awt.Rectangle, int) since many sides can have been cut.cutRectEdge(java.awt.Rectangle, java.awt.Rectangle, int),
Rectangle.intersects(java.awt.Rectangle).
public static final double getRelativeSizeXXX(java.lang.Number num,
double refSize)
refSize. Some sproberties in a Theme
can be of both Float or Integer type and this method represents the normal interpretation.
num - Can be of three types:null returns 0.0Float or Double: It's a percentage (1.0 is 100%) of refSize that will be returnedInteger: It's an absolute size and returned directly.
Long: It's an absolute size relative to the "end". I.e. returned with refSize added.refSize - The reference size that will be used if num is a Float
public static final float getConstrainedSize(AtRefNumber size,
AtRefNumber loBounds,
AtRefNumber hiBounds,
float refSize)
num but corrected for a lower and upper bounds.
size - The size to check. If null refSize will be used.loBounds - The lower boundary (or null for no boundary).hiBounds - The upper boundary (or null for no boundary).refSize - The reference size if any of the boundaries are relative.
public static final double getVectorAngle(double x1,
double y1,
double angle)
x1 - First points x-coordinatey1 - First points y-coordinateangle - The angle to compare to. >= 0 and < 360. (0 is pointing to the right)
public static final double getAngleBetweenCords(double x1,
double y1,
double x2,
double y2)
x1 - First points x-coordinatey1 - First points y-coordinatex2 - Second points x-coordinatey2 - Second points y-coordinate
public static double getCrossDouble(double v1,
double v2,
double perc)
v1 and v2.
v1 - Start valuev2 - End valueperc - Percentage between v1 and v2. 0.0f is at v1 and 1.0f is at v2.
v1 and v2.
public static float getCrossFloat(float v1,
float v2,
float perc)
v1 and v2.
v1 - Start valuev2 - End valueperc - Percentage between v1 and v2. 0.0f is at v1 and 1.0f is at v2.
v1 and v2.
public static java.awt.TexturePaint getCrossTexturePaint(java.awt.TexturePaint tp1,
java.awt.TexturePaint tp2,
float f,
int transparency,
boolean fadeTp1)
TexturePaint that is crossed (faded) between two TexturePaint. Image and/or
anchor rectangle are crossed. If image are same (reference wise) no new image are created which would reduce creation
time considerably. tp1 OR tp2 can be null to create a fade in or fade out effect.
tp1 - The first paint. Can be null to create a fade in of tp2.tp2 - The second paint. Can be null to create a fade out of tp1.transparency - The transparency of the resulting texture paint. Unly used if images are different in tp1
and tp2. (E.g. Transparency.TRANSLUCENT. Can be recieved with im1.getTransparency().fadeTp1 - If true tp1's image are faded away when im2's image are faded in. This will make
the background shine through in the middle of the f range but creates better results if tp2's image is
partially transparent/translucent. Unly used if images are different in tp1 and tp2.
TexturePaint that is crossed (faded) between two TexturePaint.
public static java.awt.image.BufferedImage getCrossImage(java.awt.Image im1,
java.awt.Image im2,
java.awt.image.BufferedImage dest,
int trans,
float f,
boolean fadeIm1)
im1.
im1 - The first image. May be null, this creates a fade in of im2.im2 - The second image. May be null, this creates a fade out of im1.dest - If non-null this image will be used to draw the resulting image in. If null a
new compatible image will be created to hold the result.trans - The transparency of the returned image (if dest == null).
E.g. Transparency.TRANSLUCENT.f - 0..1 0.0f returnes im1, 1.0f returns im2. Values in between returns a faded