:: 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.
Prototype Sizes
You can describe a column width or row height by providing a
string prototype, for example
new FormLayout("right:pref, 3dlu, '+49-89-32168'").
Prototype sizes scale better than Dialog Units if
the content consists only of special characters, for example digits.
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 Forms layout system supports logical sizes in builder
classes, via the Layout Style and the FormFactory
constants.
Since version 1.2 you can use logical sizes in encoded
column and row specifications too, by means of layout variables.
For example new FormLayout("right:pref, $lcgap, pref")
uses the short name of the variable $label-component-gap
that describes the platform-specific gap between a label and
its associated component.
The ButtonBarFactory, ButtonBarBuilder and
ButtonStackBuilder
use logical sizes and in turn style guide-specific logical sizes
for frequently used gaps and minimum widths and heights.
For example the ButtonBarBuilder uses logical sizes
to honor style guide settings for button minimum width, and gaps
between related and unrelated components.
If you develop a custom builder class, you can refer to the
logical sizes using the current Layout Style or
the FormFactory constants.
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 ColumnSpec("'xxx-MMM-000-xxx'");
new RowSpec("2in");
new RowSpec("100px");
new FormLayout("100dlu, 4dlu, 200dlu",
" 14dlu, 3dlu, 14dlu");
|