Package com.jgoodies.forms.layout
Class Sizes
- java.lang.Object
-
- com.jgoodies.forms.layout.Sizes
-
public final class Sizes extends java.lang.Object
Consists only of static methods that create and convert sizes as required by the FormLayout. The conversion of sizes that are not based on pixel is delegated to an implementation ofUnitConverter
. The conversion methods require the layout container as parameter to read its current font and resolution.- Version:
- $Revision: 1.19 $
- See Also:
Size
,UnitConverter
,DefaultUnitConverter
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static class
Sizes.ComponentSize
An ordinal-based serializable typesafe enumeration that implements theSize
interface for the component sizes: min, pref, default.
-
Field Summary
Fields Modifier and Type Field Description static Sizes.ComponentSize
DEFAULT
Use the maximum of all component sizes as column or row size; measures preferred sizes when asked for the preferred size and minimum sizes when asked for the minimum size.private static ConstantSize.Unit
defaultUnit
Holds the Unit that is used if no Unit is provided in encoded ConstantSizes.static ConstantSize
DLUX1
static ConstantSize
DLUX11
static ConstantSize
DLUX14
static ConstantSize
DLUX2
static ConstantSize
DLUX21
21 horizontal dialog units.static ConstantSize
DLUX3
static ConstantSize
DLUX4
static ConstantSize
DLUX5
static ConstantSize
DLUX6
static ConstantSize
DLUX7
static ConstantSize
DLUX8
static ConstantSize
DLUX9
static ConstantSize
DLUY1
static ConstantSize
DLUY11
static ConstantSize
DLUY14
static ConstantSize
DLUY2
static ConstantSize
DLUY21
21 vertical dialog units.static ConstantSize
DLUY3
static ConstantSize
DLUY4
static ConstantSize
DLUY5
static ConstantSize
DLUY6
static ConstantSize
DLUY7
static ConstantSize
DLUY8
static ConstantSize
DLUY9
static Sizes.ComponentSize
MINIMUM
Use the maximum of all component minimum sizes as column or row size.static Sizes.ComponentSize
PREFERRED
Use the maximum of all component preferred sizes as column or row size.private static UnitConverter
unitConverter
Holds the current converter that maps non-pixel sizes to pixels.private static Sizes.ComponentSize[]
VALUES
An array of all enumeration values used to canonicalize deserialized component sizes.static ConstantSize
ZERO
-
Constructor Summary
Constructors Modifier Constructor Description private
Sizes()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static Size
bounded(Size basis, Size lowerBound, Size upperBound)
Creates and returns a BoundedSize for the given basis using the specified lower and upper bounds.static int
centimeterAsPixel(double cm, java.awt.Component component)
Converts Centimeters and returns pixels using the resolution of the given component's graphics object.static ConstantSize
constant(java.lang.String encodedValueAndUnit, boolean horizontal)
Creates and returns an instance ofConstantSize
from the given encoded size and unit description.static int
dialogUnitXAsPixel(int dluX, java.awt.Component component)
Converts horizontal dialog units and returns pixels.static int
dialogUnitYAsPixel(int dluY, java.awt.Component component)
Converts vertical dialog units and returns pixels.static ConstantSize
dluX(int value)
Creates and returns a ConstantSize for the specified value in horizontal dialog units.static ConstantSize
dluY(int value)
Creates and returns a ConstantSize for the specified value in vertical dialog units.static ConstantSize.Unit
getDefaultUnit()
Returns the Unit that is used if an encoded ConstantSize contains no unit string.static UnitConverter
getUnitConverter()
Returns the currentUnitConverter
.static int
inchAsPixel(double in, java.awt.Component component)
Converts Inches and returns pixels using the specified resolution.static int
millimeterAsPixel(double mm, java.awt.Component component)
Converts Millimeters and returns pixels using the resolution of the given component's graphics object.static ConstantSize
pixel(int value)
Creates and returns a ConstantSize for the specified pixel value.static int
pointAsPixel(int pt, java.awt.Component component)
Converts DTP Points and returns pixels using the resolution of the given component's graphics object.static void
setDefaultUnit(ConstantSize.Unit unit)
Sets the Unit that shall be used if an encoded ConstantSize provides no unit string.static void
setUnitConverter(UnitConverter newUnitConverter)
Sets a new UnitConverter that will be used to convert font-dependent sizes to pixel sizes.
-
-
-
Field Detail
-
ZERO
public static final ConstantSize ZERO
-
DLUX1
public static final ConstantSize DLUX1
-
DLUX2
public static final ConstantSize DLUX2
-
DLUX3
public static final ConstantSize DLUX3
-
DLUX4
public static final ConstantSize DLUX4
-
DLUX5
public static final ConstantSize DLUX5
-
DLUX6
public static final ConstantSize DLUX6
-
DLUX7
public static final ConstantSize DLUX7
-
DLUX8
public static final ConstantSize DLUX8
-
DLUX9
public static final ConstantSize DLUX9
-
DLUX11
public static final ConstantSize DLUX11
-
DLUX14
public static final ConstantSize DLUX14
-
DLUX21
public static final ConstantSize DLUX21
21 horizontal dialog units.- Since:
- 1.2
-
DLUY1
public static final ConstantSize DLUY1
-
DLUY2
public static final ConstantSize DLUY2
-
DLUY3
public static final ConstantSize DLUY3
-
DLUY4
public static final ConstantSize DLUY4
-
DLUY5
public static final ConstantSize DLUY5
-
DLUY6
public static final ConstantSize DLUY6
-
DLUY7
public static final ConstantSize DLUY7
-
DLUY8
public static final ConstantSize DLUY8
-
DLUY9
public static final ConstantSize DLUY9
-
DLUY11
public static final ConstantSize DLUY11
-
DLUY14
public static final ConstantSize DLUY14
-
DLUY21
public static final ConstantSize DLUY21
21 vertical dialog units.- Since:
- 1.2
-
MINIMUM
public static final Sizes.ComponentSize MINIMUM
Use the maximum of all component minimum sizes as column or row size.
-
PREFERRED
public static final Sizes.ComponentSize PREFERRED
Use the maximum of all component preferred sizes as column or row size.
-
DEFAULT
public static final Sizes.ComponentSize DEFAULT
Use the maximum of all component sizes as column or row size; measures preferred sizes when asked for the preferred size and minimum sizes when asked for the minimum size.
-
VALUES
private static final Sizes.ComponentSize[] VALUES
An array of all enumeration values used to canonicalize deserialized component sizes.
-
unitConverter
private static UnitConverter unitConverter
Holds the current converter that maps non-pixel sizes to pixels.- See Also:
setUnitConverter(UnitConverter)
-
defaultUnit
private static ConstantSize.Unit defaultUnit
Holds the Unit that is used if no Unit is provided in encoded ConstantSizes.- See Also:
setDefaultUnit(ConstantSize.Unit)
-
-
Method Detail
-
constant
public static ConstantSize constant(java.lang.String encodedValueAndUnit, boolean horizontal)
Creates and returns an instance ofConstantSize
from the given encoded size and unit description.- Parameters:
encodedValueAndUnit
- value and unit in string representationhorizontal
- true for horizontal, false for vertical- Returns:
- a
ConstantSize
for the given value and unit
-
dluX
public static ConstantSize dluX(int value)
Creates and returns a ConstantSize for the specified value in horizontal dialog units.- Parameters:
value
- size value in horizontal dialog units- Returns:
- the associated
ConstantSize
-
dluY
public static ConstantSize dluY(int value)
Creates and returns a ConstantSize for the specified value in vertical dialog units.- Parameters:
value
- size value in vertical dialog units- Returns:
- the associated
ConstantSize
-
pixel
public static ConstantSize pixel(int value)
Creates and returns a ConstantSize for the specified pixel value.- Parameters:
value
- value in pixel- Returns:
- the associated
ConstantSize
-
bounded
public static Size bounded(Size basis, Size lowerBound, Size upperBound)
Creates and returns a BoundedSize for the given basis using the specified lower and upper bounds.- Parameters:
basis
- the base sizelowerBound
- the lower bound sizeupperBound
- the upper bound size- Returns:
- a
BoundedSize
for the given basis and bounds - Throws:
java.lang.NullPointerException
- ifbasis
isnull
, or if bothlowerBound
andupperBound
arenull
.
-
inchAsPixel
public static int inchAsPixel(double in, java.awt.Component component)
Converts Inches and returns pixels using the specified resolution.- Parameters:
in
- the Inchescomponent
- the component that provides the graphics object- Returns:
- the given Inches as pixels
-
millimeterAsPixel
public static int millimeterAsPixel(double mm, java.awt.Component component)
Converts Millimeters and returns pixels using the resolution of the given component's graphics object.- Parameters:
mm
- Millimeterscomponent
- the component that provides the graphics object- Returns:
- the given Millimeters as pixels
-
centimeterAsPixel
public static int centimeterAsPixel(double cm, java.awt.Component component)
Converts Centimeters and returns pixels using the resolution of the given component's graphics object.- Parameters:
cm
- Centimeterscomponent
- the component that provides the graphics object- Returns:
- the given Centimeters as pixels
-
pointAsPixel
public static int pointAsPixel(int pt, java.awt.Component component)
Converts DTP Points and returns pixels using the resolution of the given component's graphics object.- Parameters:
pt
- DTP Pointscomponent
- the component that provides the graphics object- Returns:
- the given Points as pixels
-
dialogUnitXAsPixel
public static int dialogUnitXAsPixel(int dluX, java.awt.Component component)
Converts horizontal dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.- Parameters:
dluX
- the horizontal dialog unitscomponent
- the component that provides the graphics object- Returns:
- the given horizontal dialog units as pixels
-
dialogUnitYAsPixel
public static int dialogUnitYAsPixel(int dluY, java.awt.Component component)
Converts vertical dialog units and returns pixels. Honors the resolution, dialog font size, platform, and l&f.- Parameters:
dluY
- the vertical dialog unitscomponent
- the component that provides the graphics object- Returns:
- the given vertical dialog units as pixels
-
getUnitConverter
public static UnitConverter getUnitConverter()
Returns the currentUnitConverter
. If it has not been initialized before it will get an instance ofDefaultUnitConverter
.- Returns:
- the current
UnitConverter
-
setUnitConverter
public static void setUnitConverter(UnitConverter newUnitConverter)
Sets a new UnitConverter that will be used to convert font-dependent sizes to pixel sizes.- Parameters:
newUnitConverter
- the unit converter to be set
-
getDefaultUnit
public static ConstantSize.Unit getDefaultUnit()
Returns the Unit that is used if an encoded ConstantSize contains no unit string.- Returns:
- the Unit if no unit string is provided
- Since:
- 1.2
-
setDefaultUnit
public static void setDefaultUnit(ConstantSize.Unit unit)
Sets the Unit that shall be used if an encoded ConstantSize provides no unit string.- Parameters:
unit
- the new default Unit,null
for dialog units- Throws:
java.lang.IllegalArgumentException
- ifunit
isConstantSize.DLUX
orConstantSize.DLUY
.- Since:
- 1.2
-
-