Class DefaultUnitConverter
- java.lang.Object
-
- com.jgoodies.forms.util.AbstractUnitConverter
-
- com.jgoodies.forms.util.DefaultUnitConverter
-
- All Implemented Interfaces:
UnitConverter
public final class DefaultUnitConverter extends AbstractUnitConverter
This is the default implementation of theUnitConverterinterface. 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
CONFIGlevel.- Version:
- $Revision: 1.17 $
- Author:
- Karsten Lentzsch
- See Also:
UnitConverter,Size,Sizes
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROPERTY_AVERAGE_CHARACTER_WIDTH_TEST_STRINGstatic java.lang.StringPROPERTY_DEFAULT_DIALOG_FONT
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list.voidaddPropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Adds a PropertyChangeListener to the listener list for a specific property.java.lang.StringgetAverageCharacterWidthTestString()Returns the string used to compute the average character width.java.awt.FontgetDefaultDialogFont()Returns the dialog font that is used to compute the dialog base units.protected doublegetDialogBaseUnitsX(java.awt.Component component)Returns the cached or computed horizontal dialog base units.protected doublegetDialogBaseUnitsY(java.awt.Component component)Returns the cached or computed vertical dialog base units for the given component.static DefaultUnitConvertergetInstance()Lazily instantiates and returns the sole instance.voidremovePropertyChangeListener(java.beans.PropertyChangeListener listener)Removes a PropertyChangeListener from the listener list.voidremovePropertyChangeListener(java.lang.String propertyName, java.beans.PropertyChangeListener listener)Removes a PropertyChangeListener from the listener list for a specific property.voidsetAverageCharacterWidthTestString(java.lang.String newTestString)Sets a string that will be used to compute the average character width.voidsetDefaultDialogFont(java.awt.Font newFont)Sets a dialog font that will be used to compute the dialog base units.-
Methods inherited from class com.jgoodies.forms.util.AbstractUnitConverter
centimeterAsPixel, centimeterAsPixel, computeAverageCharWidth, dialogUnitXAsPixel, dialogUnitXAsPixel, dialogUnitYAsPixel, dialogUnitYAsPixel, getDefaultScreenResolution, getScreenResolution, inchAsPixel, inchAsPixel, millimeterAsPixel, millimeterAsPixel, pointAsPixel, pointAsPixel
-
-
-
-
Field Detail
-
PROPERTY_AVERAGE_CHARACTER_WIDTH_TEST_STRING
public static final java.lang.String PROPERTY_AVERAGE_CHARACTER_WIDTH_TEST_STRING
- See Also:
- Constant Field Values
-
PROPERTY_DEFAULT_DIALOG_FONT
public static final java.lang.String PROPERTY_DEFAULT_DIALOG_FONT
- See Also:
- Constant Field Values
-
-
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 emptyjava.lang.NullPointerException- if the test string isnull
-
getDefaultDialogFont
public java.awt.Font getDefaultDialogFont()
Returns the dialog font that is used to compute the dialog base units. If a default dialog font has been set usingsetDefaultDialogFont(Font), this font will be returned. Otherwise a cached fallback will be lazily created.- 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:
getDialogBaseUnitsXin classAbstractUnitConverter- 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:
getDialogBaseUnitsYin classAbstractUnitConverter- Parameters:
component- a Component that provides the font and graphics- Returns:
- the vertical dialog base units
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.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.
- Parameters:
listener- the PropertyChangeListener to be added- See Also:
removePropertyChangeListener(PropertyChangeListener),removePropertyChangeListener(String, PropertyChangeListener),addPropertyChangeListener(String, PropertyChangeListener)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.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.
- Parameters:
listener- the PropertyChangeListener to be removed- See Also:
addPropertyChangeListener(PropertyChangeListener),addPropertyChangeListener(String, PropertyChangeListener),removePropertyChangeListener(String, PropertyChangeListener)
-
addPropertyChangeListener
public void addPropertyChangeListener(java.lang.String propertyName, java.beans.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.
- Parameters:
propertyName- one of the property names listed abovelistener- the PropertyChangeListener to be added- See Also:
removePropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.lang.String propertyName, java.beans.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.
- Parameters:
propertyName- a valid property namelistener- the PropertyChangeListener to be removed- See Also:
addPropertyChangeListener(java.lang.String, java.beans.PropertyChangeListener),removePropertyChangeListener(java.beans.PropertyChangeListener)
-
-