Package com.privatejgoodies.forms.util

## Class AbstractUnitConverter

- java.lang.Object
- - com.privatejgoodies.common.bean.Bean
  - - com.privatejgoodies.forms.util.AbstractUnitConverter

All Implemented Interfaces:
  `ObservableBean`, `ObservableBean2`, `UnitConverter`, `java.io.Serializable`

Direct Known Subclasses:
  `DefaultUnitConverter`

    public abstract class AbstractUnitConverter
    extends Bean
    implements UnitConverter

An abstract implementation of the `UnitConverter` interface that minimizes the effort required to convert font-dependent sizes to pixels.

Version:
  $Revision: 1.8 $
Author:
  Karsten Lentzsch
See Also:
  `DefaultUnitConverter`, `Size`, `Sizes`, Serialized Form

### Field Summary

### Fields inherited from class com.privatejgoodies.common.bean.Bean

`changeSupport`

### Constructor Summary

Constructors
`AbstractUnitConverter()`

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`protected static int` `centimeterAsPixel​(double cm, int dpi)` Converts Centimeters and returns pixels using the specified resolution.
`int` `centimeterAsPixel​(double cm, java.awt.Component component)` Converts Centimeters and returns pixels using the resolution of the given component's graphics object.
`protected double` `computeAverageCharWidth​(java.awt.FontMetrics metrics, java.lang.String testString)` Computes and returns the average character width of the specified test string using the given FontMetrics.
`protected int` `dialogUnitXAsPixel​(int dluX, double dialogBaseUnitsX)` Converts horizontal dialog units and returns pixels.
`int` `dialogUnitXAsPixel​(int dluX, java.awt.Component c)` Converts horizontal dialog units and returns pixels.
`protected int` `dialogUnitYAsPixel​(int dluY, double dialogBaseUnitsY)` Converts vertical dialog units and returns pixels.
`int` `dialogUnitYAsPixel​(int dluY, java.awt.Component c)` Converts vertical dialog units and returns pixels.
`protected int` `getDefaultScreenResolution()` Computes and returns the default resolution.
`protected abstract double` `getDialogBaseUnitsX​(java.awt.Component component)` Gets and returns the horizontal dialog base units.
`protected abstract double` `getDialogBaseUnitsY​(java.awt.Component component)` Gets and returns the vertical dialog base units.
`protected int` `getScreenResolution​(java.awt.Component c)` Returns the components screen resolution or the default screen resolution if the component is null or has no toolkit assigned yet.
`protected static int` `inchAsPixel​(double in, int dpi)` Converts Inches and returns pixels using the specified resolution.
`int` `inchAsPixel​(double in, java.awt.Component component)` Converts Inches and returns pixels using the specified resolution.
`protected static int` `millimeterAsPixel​(double mm, int dpi)` Converts Millimeters and returns pixels using the specified resolution.
`int` `millimeterAsPixel​(double mm, java.awt.Component component)` Converts Millimeters and returns pixels using the resolution of the given component's graphics object.
`protected static int` `pointAsPixel​(int pt, int dpi)` Converts DTP Points and returns pixels using the specified resolution.
`int` `pointAsPixel​(int pt, java.awt.Component component)` Converts DTP Points and returns pixels using the resolution of the given component's graphics object.

### Methods inherited from class com.privatejgoodies.common.bean.Bean

`addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, createPropertyChangeSupport, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

### Constructor Detail

#### AbstractUnitConverter

    public AbstractUnitConverter()

### Method Detail

#### inchAsPixel

    public int inchAsPixel​(double in,
                           java.awt.Component component)

Converts Inches and returns pixels using the specified resolution.

Specified by:
  `inchAsPixel` in interface `UnitConverter`
Parameters:
  `in` - the Inches
  `component` - the component that provides the graphics object
Returns:
  the given Inches as pixels

#### millimeterAsPixel

    public int millimeterAsPixel​(double mm,
                                 java.awt.Component component)

Converts Millimeters and returns pixels using the resolution of the given component's graphics object.

Specified by:
  `millimeterAsPixel` in interface `UnitConverter`
Parameters:
  `mm` - Millimeters
  `component` - the component that provides the graphics object
Returns:
  the given Millimeters as pixels

#### centimeterAsPixel

    public int centimeterAsPixel​(double cm,
                                 java.awt.Component component)

Converts Centimeters and returns pixels using the resolution of the given component's graphics object.

Specified by:
  `centimeterAsPixel` in interface `UnitConverter`
Parameters:
  `cm` - Centimeters
  `component` - the component that provides the graphics object
Returns:
  the given Centimeters as pixels

#### pointAsPixel

    public int pointAsPixel​(int pt,
                            java.awt.Component component)

Converts DTP Points and returns pixels using the resolution of the given component's graphics object.

Specified by:
  `pointAsPixel` in interface `UnitConverter`
Parameters:
  `pt` - DTP Points
  `component` - the component that provides the graphics object
Returns:
  the given Points as pixels

#### dialogUnitXAsPixel

    public int dialogUnitXAsPixel​(int dluX,
                                  java.awt.Component c)

Converts horizontal dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.

Specified by:
  `dialogUnitXAsPixel` in interface `UnitConverter`
Parameters:
  `dluX` - the horizontal dialog units
  `c` - a Component that provides the font and graphics
Returns:
  the given horizontal dialog units as pixels

#### dialogUnitYAsPixel

    public int dialogUnitYAsPixel​(int dluY,
                                  java.awt.Component c)

Converts vertical dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.

Specified by:
  `dialogUnitYAsPixel` in interface `UnitConverter`
Parameters:
  `dluY` - the vertical dialog units
  `c` - a Component that provides the font and graphics
Returns:
  the given vertical dialog units as pixels

#### getDialogBaseUnitsX

    protected abstract double getDialogBaseUnitsX​(java.awt.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​(java.awt.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

#### inchAsPixel

    protected static 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

    protected static 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

#### centimeterAsPixel

    protected static 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

#### pointAsPixel

    protected static 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

#### 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

    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

#### computeAverageCharWidth

    protected double computeAverageCharWidth​(java.awt.FontMetrics metrics,
                                             java.lang.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.

#### getScreenResolution

    protected int getScreenResolution​(java.awt.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

#### getDefaultScreenResolution

    protected int getDefaultScreenResolution()

Computes and returns the default resolution.

Returns:
  the default screen resolution