com.jgoodies.forms.util
Class DefaultUnitConverter
- UnitConverter
public final class DefaultUnitConverter
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
custom computation.
More information how to use dialog units in screen design can be found
in Microsoft's
Design
Specifications and Guidelines.
Since the Forms 1.1 this converter logs font information at
the
CONFIG
level.
centimeterAsPixel , centimeterAsPixel , computeAverageCharWidth , dialogUnitXAsPixel , dialogUnitXAsPixel , dialogUnitYAsPixel , dialogUnitYAsPixel , getDefaultScreenResolution , getDialogBaseUnitsX , getDialogBaseUnitsY , getScreenResolution , inchAsPixel , inchAsPixel , millimeterAsPixel , millimeterAsPixel , pointAsPixel , pointAsPixel |
addPropertyChangeListener
public void addPropertyChangeListener(PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list. The listener is
registered for all bound properties of this class.
If listener is null, no exception is thrown and no action is performed.
listener
- the PropertyChangeListener to be added
addPropertyChangeListener
public void addPropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Adds a PropertyChangeListener to the listener list for a specific
property. The specified property may be user-defined.
Note that if this Model is inheriting a bound property, then no event
will be fired in response to a change in the inherited property.
If listener is null, no exception is thrown and no action is performed.
propertyName
- one of the property names listed abovelistener
- the PropertyChangeListener to be added
removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
, addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
getAverageCharacterWidthTestString
public String getAverageCharacterWidthTestString()
Returns the string used to compute the average character width.
By default it is initialized to "X".
- the test string used to compute the average character width
getDefaultDialogFont
public Font getDefaultDialogFont()
Returns the dialog font that is used to compute the dialog base units.
If a default dialog font has been set using
setDefaultDialogFont(Font)
, this font will be returned.
Otherwise a cached fallback will be lazily created.
- the font used to compute the dialog base units
getDialogBaseUnitsX
protected double getDialogBaseUnitsX(Component component)
Returns the cached or computed horizontal dialog base units.
- getDialogBaseUnitsX in interface AbstractUnitConverter
component
- a Component that provides the font and graphics
- the horizontal dialog base units
getDialogBaseUnitsY
protected double getDialogBaseUnitsY(Component component)
Returns the cached or computed vertical dialog base units
for the given component.
- getDialogBaseUnitsY in interface AbstractUnitConverter
component
- a Component that provides the font and graphics
- the vertical dialog base units
getInstance
public static DefaultUnitConverter getInstance()
Lazily instantiates and returns the sole instance.
- the lazily instantiated sole instance
removePropertyChangeListener
public void removePropertyChangeListener(PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list. This method
should be used to remove PropertyChangeListeners that were registered
for all bound properties of this class.
If listener is null, no exception is thrown and no action is performed.
listener
- the PropertyChangeListener to be removed
removePropertyChangeListener
public void removePropertyChangeListener(String propertyName,
PropertyChangeListener listener)
Removes a PropertyChangeListener from the listener list for a specific
property. This method should be used to remove PropertyChangeListeners
that were registered for a specific bound property.
If listener is null, no exception is thrown and no action is performed.
propertyName
- a valid property namelistener
- the PropertyChangeListener to be removed
addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
, removePropertyChangeListener(java.beans.PropertyChangeListener)
setAverageCharacterWidthTestString
public void setAverageCharacterWidthTestString(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"
newTestString
- the test string to be used
setDefaultDialogFont
public void setDefaultDialogFont(Font newFont)
Sets a dialog font that will be used to compute the dialog base units.
newFont
- the default dialog font to be set
Copyright © 2002-2008 JGoodies Karsten Lentzsch. All Rights Reserved.