com.miginfocom.util.gfx
Class GfxUtil

java.lang.Object
  extended by com.miginfocom.util.gfx.GfxUtil

public class GfxUtil
extends java.lang.Object

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.awt.Color brightColor(java.awt.Color c, int delta)
          Brightens or darkens a color (towards white or black)
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

DEFAULT_FONT

public static final java.awt.Font DEFAULT_FONT

AA_HINT_INHERIT

public static final int AA_HINT_INHERIT
The AA will not be changed and will thus inhert the setting from the painted object before.

See Also:
Constant Field Values

AA_HINT_OFF

public static final int AA_HINT_OFF
The AA will be set to off.

See Also:
Constant Field Values

AA_HINT_DEFAULT

public static final int AA_HINT_DEFAULT
The AA will be set to be default. Might not be same as not setting it with AA_HINT_INHERIT.

See Also:
Constant Field Values

AA_HINT_ON

public static final int AA_HINT_ON
Turns AA on.

See Also:
Constant Field Values

AA_HINT_LCD_GASP

public static final int AA_HINT_LCD_GASP
Uses the font's GASP table to decide if AA should be used. May or may not result in normal AA/LCD sub pixel AA or no AA at all. For Java < version 1.6 normal AA will be used.

See Also:
Constant Field Values

AA_HINT_LCD_HRGB

public static final int AA_HINT_LCD_HRGB
Uses HRGB sub pixel AA or normal AA if sub pixel AA is not supported.

See Also:
Constant Field Values

AA_HINT_LCD_HBGR

public static final int AA_HINT_LCD_HBGR
Uses HBGR sub pixel AA or normal AA if sub pixel AA is not supported.

See Also:
Constant Field Values

AA_HINT_LCD_VRGB

public static final int AA_HINT_LCD_VRGB
Uses VRGB sub pixel AA or normal AA if sub pixel AA is not supported.

See Also:
Constant Field Values

AA_HINT_LCD_VBGR

public static final int AA_HINT_LCD_VBGR
Uses VBGR sub pixel AA or normal AA if sub pixel AA is not supported.

See Also:
Constant Field Values

AA_HINT_PLATFORM

public static final int AA_HINT_PLATFORM
Uses the same AA as the current platform.

See Also:
Constant Field Values

defaultImageTransparency

public static final int defaultImageTransparency
The default transparency of an image that is created and no other transparency information is available. Transparency.OPAQUE is default.

See Also:
Constant Field Values
Constructor Detail

GfxUtil

public GfxUtil()
Method Detail

setTextAntiAliasPlatformDefault

public static void setTextAntiAliasPlatformDefault(java.lang.Object renderingHint)
Sets the default text anti alias rendering hint. This is taken from the desktop properties normally but you can override it with this value.

Parameters:
renderingHint - The rendering hint. E.g. RenderingHints.VALUE_ANTIALIAS_ON. Not null.

confAntiAliasingHint

public static java.lang.Object confAntiAliasingHint(java.awt.Graphics2D g2,
                                                    boolean isText,
                                                    int migHint)
Sets the anti aliasing hint in a very decoupled way. New modes can be introduced later and we can set sub pixel AA for 1.4, even though this will just default it to normal aa..

Parameters:
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.
Returns:
The old hint if g2 != null and the hint to set (which can also be null) if g2 == null !!!

getDefaultConfiguration

public static java.awt.GraphicsConfiguration getDefaultConfiguration()
Returns the default configuration on the default graphics environment

Returns:
he default configuration on the default graphics environment

getDummyGraphics

public static java.awt.Graphics2D getDummyGraphics()
Creates a dummy Grapics2D.

Returns:
A dummy Grapics2D.

getUIName

public static java.lang.String getUIName()
Returns the name of the UI. Enhances the name by returning "Ocean" for 1.5 "Ocean" and "WindowsXP" for "Windows" on Windows XP (not classic). If the UI name cannot be read because of access denial it is reset to "Metal".

Returns:
Rthe name of the UI. Never null.
See Also:
setUIName(String)

setUIName

public void setUIName(java.lang.String s)
Forces the UI name to be a specific value. null will re-read it from the Java System.


getShowingFrame

public static java.awt.Frame getShowingFrame()
Returns the fist visible Frame we can find or null if none.

Returns:
The fist visible Frame we can find or null if none.

getCursor

public static java.awt.Cursor getCursor(java.lang.Object cursorHint)
Returns a cursor for a hint.

Parameters:
cursorHint - Can be an Integer, String or Cursor that hints what cursor to use.
Returns:
The cursor
See Also:
Cursor.getSystemCustomCursor(java.lang.String), Cursor.getPredefinedCursor(int), Cursor

getMaxStringWidth

public static int getMaxStringWidth(java.lang.String[] strings,
                                    java.awt.Font font,
                                    boolean isAntiAlias,
                                    boolean fractionalMetrics)
Return the with of the widest string.

Parameters:
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.
Returns:
The with of the widest string.

getTransformedShapes

public 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.

See Also:
for the arguments.

getTransformedShape

public static java.awt.Shape getTransformedShape(java.awt.geom.AffineTransform at,
                                                 java.awt.Shape shape)
Calls returns a shape that is transformed by 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.

Parameters:
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.
Returns:
A shape that is transformed by at. Rectangle2D.Double if shape is a Reactangle2D.

brightColor

public static final java.awt.Color brightColor(java.awt.Color c,
                                               int delta)
Brightens or darkens a color (towards white or black)

Parameters:
c - The color to brighten or darkens. Never null.
delta - The absolute number to add to RGB.
Returns:
A brighter or darker color.

tintColor

public static final java.awt.Color tintColor(java.awt.Color c,
                                             float f)
Brightens or darkens a color (towards white or black)

Parameters:
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%
Returns:
A brighter or darker color.

tintColor

public static final java.awt.Color tintColor(java.awt.Color c,
                                             int diff)
Brightens or darkens a color (towards white or black)

Parameters:
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
Returns:
A brighter or darker color.

getCrossColor

public 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. Counts on Color beeing immutal.

Parameters:
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.
Returns:
A Color that lies in between c1 and c2.

alphaColor

public static final java.awt.Color alphaColor(java.awt.Color color,
                                              int alpha)
Returns a copy of the color with the alpha set to 'alpha'

Parameters:
color - The color. not null
alpha - The new alpha
Returns:
A copy of the color with the alpha set to 'alpha'

drawFittingStringInRect

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)
Draws a text line. Uses 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.

Parameters:
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 underline
doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.
See Also:
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)

drawFittingStringInRect

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)
Draws a text line. Uses 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.

Parameters:
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 underline
shadowOff - 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 returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.
See Also:
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)

drawStringInRect

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)
Draws a text line. Uses g2's current font and paint.

Parameters:
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 underline
doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.

drawStringInRect

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)
Draws a text line. Uses g2's current font and paint.

Parameters:
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 underline
shadowOff - 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 returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.

drawFittingStringRot90

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)
Draws a text line rotated 90 degrees clock- or counter wise. Uses 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.

Parameters:
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 clockwise
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 underline
doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.
See Also:
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)

drawFittingStringRot90

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)
Draws a text line rotated 90 degrees clock- or counter wise. Uses 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.

Parameters:
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 clockwise
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 underline
shadowOff - 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 returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.
See Also:
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)

drawStringRot90

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)
Draws a text line rotated 90 degrees clock- or counter wise. Uses g2's current font and paint.

Parameters:
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 clockwise
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 underline
doDraw - If false the text isn't actually drawn into the graphics object, just the place is calculated and returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.

drawStringRot90

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)
Draws a text line rotated 90 degrees clock- or counter wise. Uses g2's current font and paint.

Parameters:
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 clockwise
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 underline
shadowOff - 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 returned
aaHint - The hint for the anti alias. GfxUtil.AA_HINT_*. E.g. GfxUtil.AA_HINT_ON. If -1 nothing is done.
Returns:
The exact bounds of the drawn text. Never null.

drawTextLinesInRect

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)
Draw a text inside a rectangle with row breaks on word boundaries and '\n'.

Parameters:
g2 - The object to draw in. font, clip or colors will not be changed when done. not null.
text - The text to draw
r - The rectangel to draw the text relativ to
ulWidth - 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 combined
doDraw - 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.
Returns:
The bounds of the actual painted text. Never null. Will have width and height set to 0 if no text was drawn.

drawTextLinesInRect

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)
Draw a text inside a rectangle with row breaks on word boundaries and '\n'.

Parameters:
g2 - The object to draw in. font, clip or colors will not be changed when done. not null.
text - The text to draw
r - The rectangel to draw the text relativ to
ulWidth - 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 combined
doDraw - 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.
Returns:
The bounds of the actual painted text. Never null. Will have width and height set to 0 and upper left corner same as r if no text was drawn for some reason.

getTextLinesHeight

public 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).

Parameters:
font - The font used to draw
text - The text to draw
width - 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.
Returns:
The height needed to draw the text

getStringWidth

public 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.

Parameters:
font - The font used to draw
text - 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.
Returns:
The string width for the text

createLayouts

public 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.

Note! null elemements in the array represents empty rows, such as an empty "\n".

Parameters:
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 wrap
ulWidth - The underline width. If >0 an underline attribute will be added. See TextAttribute.UNDERLINE.
Returns:
The TextLayouts, possibly with null elements. Never null.

createLayouts

public 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.

Note! null elemements in the array represents empty rows, such as an empty "\n".

Parameters:
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 wrap
ulWidth - 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.
Returns:
The TextLayouts, possibly with null elements. Never null.

unionInsets

public 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.

Parameters:
source - The insets to change. Not null
unionWith - The union to also check. May be null in which case source is unchanged.

addInsets

public static void addInsets(java.awt.Insets source,
                             java.awt.Insets add)
Adds add to source

Parameters:
source - The insets to be changed
add - The insets to add. Not changed. If null nothing will happen.

drawRoundRect

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)
Draws a round rectangle with a fill and/or outline.

Parameters:
g2 - The graphics object to draw in. Color, paint, stroke and such won't be changed.
r - The bounds to draw the rect in
arcW - The rounded corner's arc width
arcH - The rounded corner's arc height
background - The background or null for no background
stroke - The outline stroke or null for no outline
strokePaint - The outline stroke paint or null for no outline

drawArrow

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)
Draws an arrow within the bounds.

Parameters:
g - The graphics object to draw in. Color, paint, stroke and such won't be changed.
x - X
y - Y
width - The width of the bounds
height - The height of the bounds
direction - 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.

cropShape

public static java.awt.Shape cropShape(java.awt.Shape clip,
                                       java.awt.Shape shape)
Cuts 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.

Parameters:
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.
Returns:
The clipped shape. May be shape if clip == null. Can be null.

getOutlineRect

public static final java.awt.Rectangle getOutlineRect(java.awt.geom.RectangularShape r)
Returns the smallest Rectangle that contains the whole of r.

Parameters:
r - The rect to convert. Not null.
Returns:
The smallest Rectangle that contains the whole of r.

getRoundedRect

public static final 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.

Parameters:
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.
Returns:
A rectangle as like as rect2D as possible. null only if rect2d is null.

getCrossedRect2D

public 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. So when f goes from 0.0f to 1.0f inclusive the returned rectangle transforma from r1 to r2.

Parameters:
r1 - The first rectangle. Not null.
r2 - The seconds rectangle. Not null.
d - An unchecked value that should be 0..1 inclusive.
Returns:
A Rectangle2D.Double that is a cross between r1 and r2.

resizeRect

public static void resizeRect(java.awt.Rectangle r,
                              java.awt.Insets i,
                              boolean positiveReduces)
Expands/reduces Rectangle.

Parameters:
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.

cropRect

public static void cropRect(java.awt.Rectangle r,
                            java.awt.Insets c)
Crops a rectangle. Similar to 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.

Parameters:
r - The rectangle to change.
c - The crop. If null this is a no-op.

getResizedRect

public static final java.awt.Rectangle getResizedRect(java.awt.Rectangle r,
                                                      java.awt.Insets insets,
                                                      boolean positiveReduces)
Creates an expanded/reduced Rectangle.

Parameters:
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.
Returns:
A new resized (and moved) rectangle.

getResizedRect

public static final java.awt.Rectangle getResizedRect(java.awt.Rectangle r,
                                                      float scaleX,
                                                      float scaleY,
                                                      float alignX,
                                                      float alignY)
Creates an expanded/reduced Rectangle.

Parameters:
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..1f
alignY - The vertical alignment. 0f..1f
Returns:
A resized and possibly moved rectangle. Cloned.

getRect

public static java.awt.Rectangle getRect(java.awt.Point p1,
                                         java.awt.Point p2)
Returns a rectangle from a diagonal between the points

Parameters:
p1 - The first point. Not null.
p2 - The second point. Not null.
Returns:
A new rectangle (.isEmpty == false if p1 != p2. Never null.

reduceRectXXX

public static final void reduceRectXXX(java.awt.geom.Rectangle2D r,
                                       java.lang.Number widthRed,
                                       java.lang.Number heightRed)
Reduces a rectangle. The reduction algorithm is depending on the type of the Number arguments. The type can be of two kinds:
Float or Double:
0 to 1 The width/height is reduced with this percentage. e.g. 0.2f reduces 20%. Integer: The width/height in absolute pixels to reduce on each side. Same as Rectangle.grow(-widthRed)

Parameters:
widthRed - How much to reduce the width. If null width remain the same
heightRed - How much to reduce the height. If null height remain the same

cutRectEdge

public static final int cutRectEdge(java.awt.Rectangle r,
                                    java.awt.Rectangle cr,
                                    int side)
Cuts (reduces) r so that it no longer overlaps cr. r will only be cut from one side, side.

Parameters:
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 changed
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.
Returns:
The edge that was cut or -1 if r has area <= 0 after the cut. (I.e. r.isEmpty() is true).
See Also:
Rectangle.intersects(java.awt.Rectangle).

cutRect

public static int cutRect(java.awt.Rectangle r,
                          java.util.List cutRects,
                          int side)
Reduces 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.

Parameters:
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.
Returns:
Input argument 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.
See Also:
cutRectEdge(java.awt.Rectangle, java.awt.Rectangle, int), Rectangle.intersects(java.awt.Rectangle).

getRelativeSizeXXX

public static final double getRelativeSizeXXX(java.lang.Number num,
                                              double refSize)
Returns the size that is either absolute or relative to refSize. Some sproberties in a Theme can be of both Float or Integer type and this method represents the normal interpretation.

Parameters:
num - Can be of three types:
null returns 0.0
Float or Double: It's a percentage (1.0 is 100%) of refSize that will be returned
Integer: 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
Returns:
The correct size.

getConstrainedSize

public static final 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.

Parameters:
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.
Returns:
The size adjustend for the bounds.

getVectorAngle

public static final double getVectorAngle(double x1,
                                          double y1,
                                          double angle)
Returns the angle between 'angle' and a vector from (0, 0) to (x1, y1). The angle returns the smallest ( <= 180) of the two possible angles and is >= 0.

Parameters:
x1 - First points x-coordinate
y1 - First points y-coordinate
angle - The angle to compare to. >= 0 and < 360. (0 is pointing to the right)
Returns:
The angle between two vectors

getAngleBetweenCords

public static final 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). The angle returns the smallest ( <= 180) of the two possible angles and is >= 0.

Parameters:
x1 - First points x-coordinate
y1 - First points y-coordinate
x2 - Second points x-coordinate
y2 - Second points y-coordinate
Returns:
The angle between two vectors

getCrossDouble

public static double getCrossDouble(double v1,
                                    double v2,
                                    double perc)
Returns a double relative to v1 and v2.

Parameters:
v1 - Start value
v2 - End value
perc - Percentage between v1 and v2. 0.0f is at v1 and 1.0f is at v2.
Returns:
A double relative to v1 and v2.

getCrossFloat

public static float getCrossFloat(float v1,
                                  float v2,
                                  float perc)
Returns a float relative to v1 and v2.

Parameters:
v1 - Start value
v2 - End value
perc - Percentage between v1 and v2. 0.0f is at v1 and 1.0f is at v2.
Returns:
A float relative to v1 and v2.

getCrossTexturePaint

public 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. 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.

Parameters:
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.
Returns:
A TexturePaint that is crossed (faded) between two TexturePaint.

getCrossImage

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)
Returns an image (normally managed) that is crossed (faded) between two images. Size is so that both will fit and the images are centered and not stretched. Transparency is taken from im1.

Parameters:
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 image with the weight
fadeIm1 - If true im1 are faded away when im2 are faded in. This will make the background shine through in the middle of the f range but creates better results if im2 is partially transparent/translucent.
Returns:
An image (managed if creted by this method) that is crossed (faded) between two images. Always a new object.

getImageFromString

public static java.awt.image.BufferedImage getImageFromString(java.lang.String csStr,
                                                              java.lang.Integer forceTrans)
Returns an image. This method can be used to set up a loading queue where a number of images are tried in sequence and the first one that succeeds is returned.

For instance one can set the first image to be a resource reference for production and a second one as an absolute file name to use when developing. As a fallback there can for instance be a BASE64 encoded image that will never fail to load since it's in the string.

One can't provide a filename to a BASE64 encoded image file though.

Parameters:
csStr - Interpreted as a filename/resource name if it doesn't start with "file", "http", "https" or "ftp" (case insensetive), in which case an URL is used to fetch the image. If null, null will be returned directly.
If the string is a BASE64 encoded image of some supported (by ImageIO that is) type, it will be decoded and created as an image.
Alternate images (queue) can be separated by a comma ",". The first image is tried first and if it can't be found (IOError) or not loadid within the timeOut the next image is tried. The last image will not time out though, it will be loaded asynchronously.
Returns:
The loaded image or null if anything has gone wrong (s was null or "")
See Also:
Toolkit.getImage(java.lang.String), ImageIO.read(java.io.File), IOUtil.isProbableBase64(String), IOUtil.isProbableURL(String), waitForImage(java.awt.Image, long), Class.getResource(String)

getImageFromString

public static java.awt.image.BufferedImage getImageFromString(java.lang.String csStr,
                                                              java.lang.StringBuffer report,
                                                              java.lang.Integer forceTrans)
Returns an image. This method can be used to set up a loading queue where a number of images are tried in sequence and the first one that succeeds is returned.
For instance one can set the first image to be a resource reference for production and a second one as an absolute file name to use when developing. As a fallback there can for instance be a BASE64 encoded image that will never fail to load since it's in the string.
One can't provide a filename to a BASE64 encoded image file though.

Parameters:
csStr - Interpreted as a filename/resource name if it doesn't start with "file", "http", "https" or "ftp" (case insensetive), in which case an URL is used to fetch the image. If null, null will be returned directly.
If the string is a BASE64 encoded image of some supported (by ImageIO that is) type, it will be decoded and created as an image.
Alternate images (queue) can be separated by a comma ",". The first image is tried first and if it can't be found (IOError) or not loadid within the timeOut the next image is tried. The last image will not time out though, it will be loaded asynchronously.
report - If not null a concise report will be appended specified the load success for all images.
Returns:
The loaded image or null if anything has gone wrong (s was null or "")
See Also:
Toolkit.getImage(java.lang.String), ImageIO.read(java.io.File), IOUtil.isProbableBase64(String), IOUtil.isProbableURL(String), waitForImage(java.awt.Image, long), Class.getResource(String)

waitForImage

public static boolean waitForImage(java.awt.Image image,
                                   long timeOut)
                            throws java.io.IOException
Waits for an image to load and then returns. Throws an IOException if there was an error when loading the image.

Parameters:
image - The image to wait for
timeOut - Max millis to wait
Returns:
true if the image is finished loading. false indicate that the image is still beeing loaded.
Throws:
java.io.IOException

imageToBase64

public 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. This can be used to serialize a generic image to xml or a text file in general.

Parameters:
img - The image to convert. If not a RenderedImage (BufferedImage is) the image will be converted to a buffered image with getBufferedImage(java.awt.Image, int) first.
formatName - The mime type to send to the encoder. See ImageIO.write(java.awt.image.RenderedImage, String, javax.imageio.stream.ImageOutputStream)
Returns:
The string or null if somethig went wrong.

getBufferedImage

public 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.

Parameters:
imgOrIcon - The image or icon to be converted. Not null.
transparency - E.g. Transparency.TRANSLUCENT
Returns:
An BufferedImage that is created with GraphicsConfiguration.createCompatibleImage(int, int) so that it will be accelerated when blitted. Can be null if imgOrIcon is a XtdImage or of unknown type.

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(java.awt.Image img,
                                                            int transparency)
Converts the Image to an BufferedImage. If image is an BufferedImage already and its transparency equals transparency, it is returned directly.

Parameters:
img - The image to be converted. Not null.
transparency - E.g. Transparency.TRANSLUCENT
Returns:
An BufferedImage that is created with GraphicsConfiguration.createCompatibleImage(int, int) so that it will be accelerated when blitted. Not nul.

getBufferedImage

public static java.awt.image.BufferedImage getBufferedImage(javax.swing.Icon icon,
                                                            int transparency)
Converts the Icon to an BufferedImage. If icon is an XtdImage the wrapped BufferedImage is returned.

Parameters:
icon - The icon to be converted. Not null.
transparency - E.g. Transparency.TRANSLUCENT
Returns:
An BufferedImage that is created with GraphicsConfiguration.createCompatibleImage(int, int) so that it will be accelerated when blitted. NOTE! Can be null if icon is a XtdImage that aren't loaded yet or loaded with an error. This differs from getBufferedImage(java.awt.Image, int).

getVolatileImage

public static java.awt.image.VolatileImage getVolatileImage(java.awt.Image img)
Converts the Image to an VolatileImage. If image is an VolatileImage already, it is returned directly.

Parameters:
img - The image to be converted. Not null.
Returns:
An VolatileImage that is created with GraphicsConfiguration.createCompatibleImage(int, int) so that it will be accelerated when blitted.

getTransparency

public static int getTransparency(java.lang.Object img)
Calls getTransparency(Object, int) with defaultImageTransparency as the default transparency.


getTransparency

public static int getTransparency(java.lang.Object img,
                                  int defTrans)
Tries to find the transparency for the image. Since Image iself doesn't provide this info it is checked if it's a subclass that does provide the info. Returns defTrans otherwise.
Also recignized Transparency and RenderedImage (which include BufferedImage.

Parameters:
img - The image or icon to check. Not null.
defTrans - Will be returned if no other transparency info is found.
Returns:
The transparency of the image or defTrans.
See Also:
defaultImageTransparency

repaintAllFrames

public static void repaintAllFrames()
Repaints all frames in the application.


RGBtoHSL

public static float[] RGBtoHSL(int r,
                               int g,
                               int b)
hslVals may be null


HSLtoRGB

public static int HSLtoRGB(float h,
                           float s,
                           float l)


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.