:: Reference :: Constant Sizes ::
Constant sizes are used to set the size of gaps
and other fixed layout elements. They can also be used
in bounded sizes as lower or upper bound.
Units
Constant sizes are specified by a value plus unit that is one of:
Pixel, Points, Inches, Millimeter, Centimeter and Dialog Units.
In string representations the units are abbreviated as:
px, pt, in, mm, cm and dlu.
Constant Non-Pixel Sizes
Constant sizes are constant for a given dialog font, font size and screen resolution.
Pixel sizes map to a fixed dimension in pixels - even if these
parameters change. This is undesired in screen design, especially
in multi-platform environments.
Therefore you should favor non-pixel sizes over pixel sizes.
If you move an application from Windows to Mac or Linux, you want
to retain the overall appearance and layout propertions.
And if you just change your Windows desktop font settings,
you want all layout elements grow appropriately: labels, fields,
buttons, but also: gaps, borders, minimum sizes and dialog dimensions.
Layout managers have been designed to address this issues.
Nevertheless, most of them fail to retain proportions
if you specify dimensions in pixel, which is often the case
for gaps, borders, dialog sizes, and custom minimum and preferred sizes.
For example, a well designed OK button shall have a minimum width;
75px is appropriate for an 8pt Tahoma font on Windows with 96dpi.
But on 120dpi and 10pt Arial, 75 pixels are perceived
as quite narrow.
Dialog Units allow to specify such a size
in a way that it grows and shrinks with the environment. For example,
the MS layout style guide suggests a command button minimum width
of 50dlu, which maps to 75px in the first context and to 100px in the second.
Points, Inches, Millimeters and Centimeters
are intended for sizes that shall grow with the screen resolution
but that are independent of the font and font size.
Unit Conversion
Class Sizes provides methods to convert non-pixel sizes
to pixels. The actual mapping is performed by a customizable
Unit converter.
Logical Constant Sizes
Logical sizes can be used to specify a size that changes
with the current platform or style guide.
For example, if you want to specify a button's minimum width,
you may want to use 50dlu on Windows and 68px on a Mac.
Or you define the gap between two related text field rows
as 3dlu on Windows and 4px on a Mac.
The FormLayout itself provides no means for such an abstraction.
However, you can use logical sizes via the builders, factories and
layout style. You can obtain the current Layout Style from
that class via getCurrent(). The result implementation
returns style guide-specific logical sizes for frequently used
gaps and minimum widths and heights; you can quickly access
these constants via the FormFactory.
The ButtonBarBuilder uses logical sizes to honor style
guide settings for button minimum width, and gaps between related
and unrelated components.
String Representations
I recommend to specify column and row sizes in
the FormLayout constructor using string representations.
These strings will be accepted by the FormLayout,
ColumnSpec, RowSpec and Borders classes.
constantSize ::= integerUnit | doubleUnit
integerUnit ::= PX | PT | DLU
doubleUnit ::= IN | MM | CM
Examples
new ColumnSpec("50dlu");
new ColumnSpec("75px");
new RowSpec("2in");
new RowSpec("100px");
new FormLayout("100dlu, 4dlu, 200dlu",
" 14dlu, 3dlu, 14dlu");
|