org.aeonscope.media
Class GraphicKit

java.lang.Object
  extended by org.aeonscope.media.GraphicKit

public class GraphicKit
extends Object

General graphical user interface utilities.

Author:
Brooke Kuhlmann

Field Summary
static int DEFAULT_HEIGHT
          The default height.
static int DEFAULT_WIDTH
          The default width.
 
Constructor Summary
GraphicKit()
           
 
Method Summary
static Point2D.Double center(Dimension secondary, Dimension primary)
          Centers the secondary dimension relative to the primary dimension using double precision.
static Point2D.Double center(double width1, double height1, double width2, double height2)
          Centers the first dimensions (width 1 x height 1) relative to the second dimensions (width 2 x height 2) using double precision.
static Point2D.Double center(Rectangle secondary, Rectangle primary)
          Centers the secondary rectangle relative to the primary rectangle using double precision.
static Point2D.Double centerToScreen(Dimension dimension)
          Centers a dimension to the current screen dimension.
static Point2D.Double centerToScreen(double width, double height)
          Centers the a width and height to the current screen dimension.
static Point2D.Double centerToScreen(String text, FontMetrics metrics)
          Centers the text with a specific font to the screen.
static BufferedImage createTransparentImage(int width, int height)
          Creates a transparent buffered image.
static double heightRatio(Dimension dimension)
          Calculates the width ratio (width / height) of a dimension using double precision.
static void resizeToScreen(Rectangle rectangle)
          Resizes a rectangle to current screen dimensions using double precision.

NOTE: Distortion can occur as proportions are not maintained.

NOTE: Null input will result in skipped operations.

static void scaleHeight(Dimension inner, Dimension outer)
          Changes the inner dimension so that it fits in the outer dimension based on height (i.e.
static void scaleHeight(Dimension dimension, double newWidth)
          Scales the dimension height proportionally based on the new width using double precision.
static void scaleHeight(Rectangle inner, Rectangle outer)
          A convenience method to handle the fitting of rectangles.
static void scaleHeightToScreen(Rectangle rectangle)
          Fits the given rectangle to the current screen by centering and maintaining proportions.
static void scaleWidth(Dimension inner, Dimension outer)
          Changes the inner dimension so that it fits in the outer dimension based on width (i.e.
static void scaleWidth(Dimension dimension, double newHeight)
          Scales the dimension width proportionally based on the new height using double precision.
static void scaleWidth(Rectangle inner, Rectangle outer)
          A convenience method to handle the fitting of rectangles.
static void scaleWidthToScreen(Rectangle rectangle)
          Fits the given rectangle to the current screen by centering and maintaining proportions.
static double widthRatio(Dimension dimension)
          Calculates the width ratio (width / height) of a dimension using double precision.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_WIDTH

public static final int DEFAULT_WIDTH
The default width.

See Also:
Constant Field Values

DEFAULT_HEIGHT

public static final int DEFAULT_HEIGHT
The default height.

See Also:
Constant Field Values
Constructor Detail

GraphicKit

public GraphicKit()
Method Detail

createTransparentImage

public static BufferedImage createTransparentImage(int width,
                                                   int height)
Creates a transparent buffered image. Default width and height are set when the supplied width and height are less than the defaults.

Parameters:
width - The image width.
height - The image height.
Returns:
The new transparent image.

center

public static Point2D.Double center(double width1,
                                    double height1,
                                    double width2,
                                    double height2)
Centers the first dimensions (width 1 x height 1) relative to the second dimensions (width 2 x height 2) using double precision. Negative values are allowed.

Parameters:
width1 - The width to be centered.
height1 - The height to be centered.
width2 - The width to center on.
height2 - The height to center on.
Returns:
The x,y (top,left) coordinates for which to position the secondary dimension.

center

public static Point2D.Double center(Dimension secondary,
                                    Dimension primary)
Centers the secondary dimension relative to the primary dimension using double precision.

Parameters:
secondary - The dimension to be centered.
primary - The reference dimension.
Returns:
The x,y (top,left) coordinates for which to position the secondary dimension, otherwise 0,0 when null input or secondary and primary dimensions are equal.
See Also:
center(double, double, double, double)

center

public static Point2D.Double center(Rectangle secondary,
                                    Rectangle primary)
Centers the secondary rectangle relative to the primary rectangle using double precision.

Parameters:
secondary - The rectangle to be centered.
primary - The reference rectangle.
Returns:
The x,y (top,left) coordinates for which to position the secondary rectangle, otherwise 0,0 when null input or primary and secondary rectangles are equal.
See Also:
center(Dimension, Dimension)

widthRatio

public static double widthRatio(Dimension dimension)
Calculates the width ratio (width / height) of a dimension using double precision.

Parameters:
dimension - The dimension to calculate.
Returns:
The width ratio, otherwise zero if null input.

heightRatio

public static double heightRatio(Dimension dimension)
Calculates the width ratio (width / height) of a dimension using double precision.

Parameters:
dimension - The dimension to calculate.
Returns:
The width ratio, otherwise zero if null input.

centerToScreen

public static Point2D.Double centerToScreen(String text,
                                            FontMetrics metrics)
Centers the text with a specific font to the screen.

Parameters:
text - The text to be centered.
metrics - The font metrics used to calculate font width and height.
Returns:
The x,y (top-left) coordinates for center, otherwise 0,0 when null input.

centerToScreen

public static Point2D.Double centerToScreen(Dimension dimension)
Centers a dimension to the current screen dimension.

Parameters:
dimension - The dimension to be centered.
Returns:
The x,y (top-left) coordinates for center, otherwise 0,0 when null input.

centerToScreen

public static Point2D.Double centerToScreen(double width,
                                            double height)
Centers the a width and height to the current screen dimension.

Parameters:
width - The width.
height - The height.
Returns:
The x,y (top-left) coordinates for center, otherwise 0,0.

scaleWidth

public static void scaleWidth(Dimension dimension,
                              double newHeight)
Scales the dimension width proportionally based on the new height using double precision. Null input will result in skipped operations.

Parameters:
dimension - The dimension to scale.
newHeight - The new height.

scaleWidth

public static void scaleWidth(Dimension inner,
                              Dimension outer)
Changes the inner dimension so that it fits in the outer dimension based on width (i.e. inner width = outer width). The inner height is scaled proportionally based on changes to the inner width so as to not distort the inner dimension. Of course, there is a chance that the inner height might be larger than the outer height due to scaling.

NOTE: Null input will result in no changes being made to the inner dimension.

Parameters:
inner - The dimension to fit.
outer - The dimension to fit in.

scaleWidth

public static void scaleWidth(Rectangle inner,
                              Rectangle outer)
A convenience method to handle the fitting of rectangles.

Parameters:
inner - The rectangle to fit.
outer - The rectangle to fit in.
See Also:
scaleWidth(Dimension, Dimension)

scaleWidthToScreen

public static void scaleWidthToScreen(Rectangle rectangle)
Fits the given rectangle to the current screen by centering and maintaining proportions.

Parameters:
rectangle - The rectangle to fit.
See Also:
scaleWidth(Rectangle, Rectangle)

scaleHeight

public static void scaleHeight(Dimension dimension,
                               double newWidth)
Scales the dimension height proportionally based on the new width using double precision. Null input will result in skipped operations.

Parameters:
dimension - The dimension to scale.
newWidth - The new width.

scaleHeight

public static void scaleHeight(Dimension inner,
                               Dimension outer)
Changes the inner dimension so that it fits in the outer dimension based on height (i.e. inner height = outer height). The inner width is scaled proportionally based on changes to the inner height so as to not distort the inner dimension. Of course, there is a chance that the inner width might be larger than the outer height due to scaling.

NOTE: Null input will result in no changes being made to the inner dimension.

Parameters:
inner - The dimension to fit.
outer - The dimension to fit in.

scaleHeight

public static void scaleHeight(Rectangle inner,
                               Rectangle outer)
A convenience method to handle the fitting of rectangles.

Parameters:
inner - The rectangle to fit.
outer - The rectangle to fit in.
See Also:
scaleHeight(Dimension, Dimension)

scaleHeightToScreen

public static void scaleHeightToScreen(Rectangle rectangle)
Fits the given rectangle to the current screen by centering and maintaining proportions.

Parameters:
rectangle - The rectangle to fit.
See Also:
scaleWidth(Rectangle, Rectangle)

resizeToScreen

public static void resizeToScreen(Rectangle rectangle)
Resizes a rectangle to current screen dimensions using double precision.

NOTE: Distortion can occur as proportions are not maintained.

NOTE: Null input will result in skipped operations.

Parameters:
rectangle - The rectangle to resize.