Class DefaultUnitConverter

  • All Implemented Interfaces:
    UnitConverter

    public final class DefaultUnitConverter
    extends AbstractUnitConverter
    This is the default implementation of the UnitConverter interface. It converts horizontal and vertical dialog base units to pixels.

    The horizontal base unit is equal to the average width, in pixels, of the characters in the system font; the vertical base unit is equal to the height, in pixels, of the font. Each horizontal base unit is equal to 4 horizontal dialog units; each vertical base unit is equal to 8 vertical dialog units.

    The DefaultUnitConverter computes dialog base units using a default font and a test string for the average character width. You can configure the font and the test string via the bound Bean properties defaultDialogFont and averageCharacterWidthTestString. See also Microsoft's suggestion for a custom computation here.

    Since the Forms 1.1 this converter logs font information at the CONFIG level.

    Version:
    $Revision$
    Author:
    Karsten Lentzsch
    See Also:
    UnitConverter, Size, Sizes
    • Method Detail

      • getInstance

        public static DefaultUnitConverter getInstance()
        Lazily instantiates and returns the sole instance.
        Returns:
        the lazily instantiated sole instance
      • getAverageCharacterWidthTestString

        public java.lang.String getAverageCharacterWidthTestString()
        Returns the string used to compute the average character width. By default it is initialized to "X".
        Returns:
        the test string used to compute the average character width
      • setAverageCharacterWidthTestString

        public void setAverageCharacterWidthTestString​(java.lang.String newTestString)
        Sets a string that will be used to compute the average character width. By default it is initialized to "X". You can provide other test strings, for example:
        • "Xximeee"
        • "ABCEDEFHIJKLMNOPQRSTUVWXYZ"
        • "abcdefghijklmnopqrstuvwxyz"
        Parameters:
        newTestString - the test string to be used
        Throws:
        java.lang.IllegalArgumentException - if the test string is empty
        java.lang.NullPointerException - if the test string is null
      • getDefaultDialogFont

        public java.awt.Font getDefaultDialogFont()
        Lazily creates and returns the dialog font used to compute the dialog base units.
        Returns:
        the font used to compute the dialog base units
      • setDefaultDialogFont

        public void setDefaultDialogFont​(java.awt.Font newFont)
        Sets a dialog font that will be used to compute the dialog base units.
        Parameters:
        newFont - the default dialog font to be set
      • getDialogBaseUnitsX

        protected double getDialogBaseUnitsX​(java.awt.Component component)
        Returns the cached or computed horizontal dialog base units.
        Specified by:
        getDialogBaseUnitsX in class AbstractUnitConverter
        Parameters:
        component - a Component that provides the font and graphics
        Returns:
        the horizontal dialog base units
      • getDialogBaseUnitsY

        protected double getDialogBaseUnitsY​(java.awt.Component component)
        Returns the cached or computed vertical dialog base units for the given component.
        Specified by:
        getDialogBaseUnitsY in class AbstractUnitConverter
        Parameters:
        component - a Component that provides the font and graphics
        Returns:
        the vertical dialog base units