Class AbstractUnitConverter
java.lang.Object
com.jgoodies.forms.util.AbstractUnitConverter
- All Implemented Interfaces:
UnitConverter
- Direct Known Subclasses:
DefaultUnitConverter
An abstract implementation of the
UnitConverter interface that
minimizes the effort required to convert font-dependent sizes to pixels.- Version:
- $Revision: 1.6 $
- Author:
- Karsten Lentzsch
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected final intcentimeterAsPixel(double cm, int dpi) Converts Centimeters and returns pixels using the specified resolution.intcentimeterAsPixel(double cm, Component component) Converts Centimeters and returns pixels using the resolution of the given component's graphics object.protected doublecomputeAverageCharWidth(FontMetrics metrics, String testString) Computes and returns the average character width of the specified test string using the given FontMetrics.protected intdialogUnitXAsPixel(int dluX, double dialogBaseUnitsX) Converts horizontal dialog units and returns pixels.intdialogUnitXAsPixel(int dluX, Component c) Converts horizontal dialog units and returns pixels.protected intdialogUnitYAsPixel(int dluY, double dialogBaseUnitsY) Converts vertical dialog units and returns pixels.intdialogUnitYAsPixel(int dluY, Component c) Converts vertical dialog units and returns pixels.protected intComputes 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 intReturns the components screen resolution or the default screen resolution if the component is null or has no toolkit assigned yet.protected final intinchAsPixel(double in, int dpi) Converts Inches and returns pixels using the specified resolution.intinchAsPixel(double in, Component component) Converts Inches and returns pixels using the specified resolution.protected final intmillimeterAsPixel(double mm, int dpi) Converts Millimeters 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 final intpointAsPixel(int pt, int dpi) Converts DTP Points 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.
-
Constructor Details
-
AbstractUnitConverter
public AbstractUnitConverter()
-
-
Method Details
-
inchAsPixel
Converts Inches and returns pixels using the specified resolution.- Specified by:
inchAsPixelin interfaceUnitConverter- Parameters:
in- the Inchescomponent- the component that provides the graphics object- Returns:
- the given Inches as pixels
-
millimeterAsPixel
Converts Millimeters and returns pixels using the resolution of the given component's graphics object.- Specified by:
millimeterAsPixelin interfaceUnitConverter- Parameters:
mm- Millimeterscomponent- the component that provides the graphics object- Returns:
- the given Millimeters as pixels
-
centimeterAsPixel
Converts Centimeters and returns pixels using the resolution of the given component's graphics object.- Specified by:
centimeterAsPixelin interfaceUnitConverter- Parameters:
cm- Centimeterscomponent- the component that provides the graphics object- Returns:
- the given Centimeters as pixels
-
pointAsPixel
Converts DTP Points and returns pixels using the resolution of the given component's graphics object.- Specified by:
pointAsPixelin interfaceUnitConverter- Parameters:
pt- DTP Pointscomponent- the component that provides the graphics object- Returns:
- the given Points as pixels
-
dialogUnitXAsPixel
Converts horizontal dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.- Specified by:
dialogUnitXAsPixelin interfaceUnitConverter- Parameters:
dluX- the horizontal dialog unitsc- a Component that provides the font and graphics- Returns:
- the given horizontal dialog units as pixels
-
dialogUnitYAsPixel
Converts vertical dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.- Specified by:
dialogUnitYAsPixelin interfaceUnitConverter- Parameters:
dluY- the vertical dialog unitsc- a Component that provides the font and graphics- Returns:
- the given vertical dialog units as pixels
-
getDialogBaseUnitsX
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
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
-
inchAsPixel
protected final int inchAsPixel(double in, int dpi) Converts Inches and returns pixels using the specified resolution.- Parameters:
in- the Inchesdpi- the resolution- Returns:
- the given Inches as pixels
-
millimeterAsPixel
protected final int millimeterAsPixel(double mm, int dpi) Converts Millimeters and returns pixels using the specified resolution.- Parameters:
mm- Millimetersdpi- the resolution- Returns:
- the given Millimeters as pixels
-
centimeterAsPixel
protected final int centimeterAsPixel(double cm, int dpi) Converts Centimeters and returns pixels using the specified resolution.- Parameters:
cm- Centimetersdpi- the resolution- Returns:
- the given Centimeters as pixels
-
pointAsPixel
protected final int pointAsPixel(int pt, int dpi) Converts DTP Points and returns pixels using the specified resolution.- Parameters:
pt- DTP Pointsdpi- the resolution in dpi- Returns:
- the given Points as pixels
-
dialogUnitXAsPixel
protected int dialogUnitXAsPixel(int dluX, double dialogBaseUnitsX) Converts horizontal dialog units and returns pixels.- Parameters:
dluX- the horizontal dialog unitsdialogBaseUnitsX- the horizontal dialog base units- Returns:
- the given dialog base units as pixels
-
dialogUnitYAsPixel
protected int dialogUnitYAsPixel(int dluY, double dialogBaseUnitsY) Converts vertical dialog units and returns pixels.- Parameters:
dluY- the vertical dialog unitsdialogBaseUnitsY- the vertical dialog base units- Returns:
- the given dialog base units as pixels
-
computeAverageCharWidth
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 widthtestString- the string that shall represent an "average" text- Returns:
- the test string's average character width.
-
getScreenResolution
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
-
getDefaultScreenResolution
protected int getDefaultScreenResolution()Computes and returns the default resolution.- Returns:
- the default screen resolution
-