com.jgoodies.forms.util

Class AbstractUnitConverter

public abstract class AbstractUnitConverter extends Object implements UnitConverter

An abstract implementation of the {@link UnitConverter} interface that minimizes the effort required to convert font-dependent sizes to pixels.

Version: $Revision: 1.5 $

Author: Karsten Lentzsch

See Also: DefaultUnitConverter Size Sizes

Method Summary
intcentimeterAsPixel(double cm, Component component)
Converts Centimeters and returns pixels using the resolution of the given component's graphics object.
protected intcentimeterAsPixel(double cm, int dpi)
Converts Centimeters and returns pixels using the specified resolution.
protected doublecomputeAverageCharWidth(FontMetrics metrics, String testString)
Computes and returns the average character width of the specified test string using the given FontMetrics.
intdialogUnitXAsPixel(int dluX, Component c)
Converts horizontal dialog units and returns pixels.
protected intdialogUnitXAsPixel(int dluX, double dialogBaseUnitsX)
Converts horizontal dialog units and returns pixels.
intdialogUnitYAsPixel(int dluY, Component c)
Converts vertical dialog units and returns pixels.
protected intdialogUnitYAsPixel(int dluY, double dialogBaseUnitsY)
Converts vertical dialog units and returns pixels.
protected intgetDefaultScreenResolution()
Computes and returns the default resolution.
protected abstract doublegetDialogBaseUnitsX(Component component)
Gets and returns the horizontal dialog base units.
protected abstract doublegetDialogBaseUnitsY(Component component)
Gets and returns the vertical dialog base units.
protected intgetScreenResolution(Component c)
Returns the components screen resolution or the default screen resolution if the component is null or has no toolkit assigned yet.
intinchAsPixel(double in, Component component)
Converts Inches and returns pixels using the specified resolution.
protected intinchAsPixel(double in, int dpi)
Converts Inches and returns pixels using the specified resolution.
intmillimeterAsPixel(double mm, Component component)
Converts Millimeters and returns pixels using the resolution of the given component's graphics object.
protected intmillimeterAsPixel(double mm, int dpi)
Converts Millimeters and returns pixels using the specified resolution.
intpointAsPixel(int pt, Component component)
Converts DTP Points and returns pixels using the resolution of the given component's graphics object.
protected intpointAsPixel(int pt, int dpi)
Converts DTP Points and returns pixels using the specified resolution.

Method Detail

centimeterAsPixel

public int centimeterAsPixel(double cm, Component component)
Converts Centimeters and returns pixels using the resolution of the given component's graphics object.

Parameters: cm Centimeters component the component that provides the graphics object

Returns: the given Centimeters as pixels

centimeterAsPixel

protected final int centimeterAsPixel(double cm, int dpi)
Converts Centimeters and returns pixels using the specified resolution.

Parameters: cm Centimeters dpi the resolution

Returns: the given Centimeters as pixels

computeAverageCharWidth

protected double computeAverageCharWidth(FontMetrics metrics, String testString)
Computes and returns the average character width of the specified test string using the given FontMetrics. The test string shall represent an "average" text.

Parameters: metrics used to compute the test string's width testString the string that shall represent an "average" text

Returns: the test string's average character width.

dialogUnitXAsPixel

public int dialogUnitXAsPixel(int dluX, Component c)
Converts horizontal dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.

Parameters: dluX the horizontal dialog units c a Component that provides the font and graphics

Returns: the given horizontal dialog units as pixels

dialogUnitXAsPixel

protected int dialogUnitXAsPixel(int dluX, double dialogBaseUnitsX)
Converts horizontal dialog units and returns pixels.

Parameters: dluX the horizontal dialog units dialogBaseUnitsX the horizontal dialog base units

Returns: the given dialog base units as pixels

dialogUnitYAsPixel

public int dialogUnitYAsPixel(int dluY, Component c)
Converts vertical dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.

Parameters: dluY the vertical dialog units c a Component that provides the font and graphics

Returns: the given vertical dialog units as pixels

dialogUnitYAsPixel

protected int dialogUnitYAsPixel(int dluY, double dialogBaseUnitsY)
Converts vertical dialog units and returns pixels.

Parameters: dluY the vertical dialog units dialogBaseUnitsY the vertical dialog base units

Returns: the given dialog base units as pixels

getDefaultScreenResolution

protected int getDefaultScreenResolution()
Computes and returns the default resolution.

Returns: the default screen resolution

getDialogBaseUnitsX

protected abstract double getDialogBaseUnitsX(Component component)
Gets and returns the horizontal dialog base units. Implementations are encouraged to cache previously computed dialog base units.

Parameters: component a Component that provides the font and graphics

Returns: the horizontal dialog base units

getDialogBaseUnitsY

protected abstract double getDialogBaseUnitsY(Component component)
Gets and returns the vertical dialog base units. Implementations are encouraged to cache previously computed dialog base units.

Parameters: component a Component that provides the font and graphics

Returns: the vertical dialog base units

getScreenResolution

protected int getScreenResolution(Component c)
Returns the components screen resolution or the default screen resolution if the component is null or has no toolkit assigned yet.

Parameters: c the component to ask for a toolkit

Returns: the component's screen resolution

inchAsPixel

public int inchAsPixel(double in, Component component)
Converts Inches and returns pixels using the specified resolution.

Parameters: in the Inches component the component that provides the graphics object

Returns: the given Inches as pixels

inchAsPixel

protected final int inchAsPixel(double in, int dpi)
Converts Inches and returns pixels using the specified resolution.

Parameters: in the Inches dpi the resolution

Returns: the given Inches as pixels

millimeterAsPixel

public int millimeterAsPixel(double mm, Component component)
Converts Millimeters and returns pixels using the resolution of the given component's graphics object.

Parameters: mm Millimeters component the component that provides the graphics object

Returns: the given Millimeters as pixels

millimeterAsPixel

protected final int millimeterAsPixel(double mm, int dpi)
Converts Millimeters and returns pixels using the specified resolution.

Parameters: mm Millimeters dpi the resolution

Returns: the given Millimeters as pixels

pointAsPixel

public int pointAsPixel(int pt, Component component)
Converts DTP Points and returns pixels using the resolution of the given component's graphics object.

Parameters: pt DTP Points component the component that provides the graphics object

Returns: the given Points as pixels

pointAsPixel

protected final int pointAsPixel(int pt, int dpi)
Converts DTP Points and returns pixels using the specified resolution.

Parameters: pt DTP Points dpi the resolution in dpi

Returns: the given Points as pixels

Copyright © 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.