|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectde.winterdrache.layout.MSBLayout.Gap
public static class MSBLayout.Gap
The Gap class contains constants that can be used as
margin constraints
instead of fixed pixel
values to get automatic context-dependent gaps.
When using MSBLayout
there are several ways to specify gaps between Component
s.
MSBLayout.glue(int, int, int, int, int, int)
offers complete control over the size and
resizing behaviour of a gap. However it is tedious to manually add glues everywhere.
Constraints
offer a simpler alternative via the use of margins. Because
they can be set once in a ConstraintsFactory
and will apply to a
complete class of Component
s, they allow you to add gaps to a dialog automatically.
While you can create nice-looking dialogs with statically defined margins, there is still room
for improvement. For instance it usually makes sense to have larger gaps between components
that have no logical relationship and smaller gaps between components that are logically
related. You may also want gaps between a container's borders and the contained components to
be different from gaps between components. Sometimes it may even make sense to have the size of
a gap depend on the kind of components surrounding it.
Layouting details like this are encapsulated in the LayoutStyle
class.
MSBLayout
will use either the global LayoutStyle
returned by
LayoutStyle.getInstance()
or the one set by
MSBLayout.setLayoutStyle(LayoutStyle)
to translate the constants specified in this Gap
class into actual pixel values.
NOTE: Although LayoutStyle
's methods require JComponent
s, MSBLayout
uses it for plain AWT Component
s, too. Whenever a plain Component is involved in a gap
computation it will be replaced (for purposes of calling LayoutStyle
's methods) by a
dummy JComponent
. While this does not allow controlling the gaps based on the types of
the components (e.g. Button
or Checkbox
), it still retains the ability to
distinguish between related, unrelated and container gaps. It also means that you don't need to
provide your own LayoutStyle. You will get a reasonable default spacing from the Swing LAF even
when working with plain AWT.
Because all components and even hboxes and vboxes have their own Constraints
, it is possible that two adjacent (or, if h/vboxes are involved, even overlapping)
margins specify conflicting gaps. The following rules are used to resolve these conflicts:
UNRELATED
overrides adjacent or overlapping RELATED
WEAK_UNRELATED
overrides adjacent or overlapping WEAK_RELATED
UNRELATED
and RELATED
override both WEAK_UNRELATED
and
WEAK_RELATED
DEFER
is overridden by every other value.LayoutStyle
returns gap values either between 2 actual
(J)Components or between a (J)Component and its Container
and that the distinction
between unrelated and related gaps is not supported for container gaps.
MSBLayout.hbox(Container)
) and a component, the gap's type is
irrelevant. Even DEFER
will cause the gap to be computed according to
LayoutStyle.getContainerGap(JComponent, int, Container)
.glues
are not actual components and do not support
context-dependent gaps, except for container gaps. If a context-dependent gap is set on
a margin of a glue, it is treated as if it were a context-independent gap of 0, unless the
margin touches the Container
's edge. Usually it does not make much sense to assign
non-0 margins to a glue, anyway, because MSBLayout.glue(int, int, int, int, int, int)
allows the creation of glues with any size.DEFER
. Empty hboxes/vboxes are similar to glues in this respect.
MSBLayout.setLayoutStyle(LayoutStyle)
,
MSBLayout.recomputeMargins()
Field Summary | |
---|---|
static int |
DEFER
Usually used only on hboxes/vboxes and means that the margin should not participate in gap computation. |
static int |
RELATED
Specifies a gap between Component s that are logically related in a dialog, such as a
textfield and its label. |
static int |
UNRELATED
Specifies a gap between Component s that are not logically related in a dialog. |
static int |
WEAK_RELATED
Like RELATED , but when a WEAK_ gap and a non-WEAK_ gap conflict, the non-WEAK_ gap
overrides. |
static int |
WEAK_UNRELATED
Like UNRELATED , but when a WEAK_ gap and a non-WEAK_ gap conflict, the non-WEAK_ gap
overrides. |
Method Summary |
---|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFER
DEFER
will be overridden by everything else. Numeric
value -1. As a general rule smaller (i.e. "more negative") constants override larger ones.
public static final int WEAK_RELATED
RELATED
, but when a WEAK_ gap and a non-WEAK_ gap conflict, the non-WEAK_ gap
overrides. Numeric value -2. As a general rule smaller (i.e. "more negative") constants
override larger ones.
public static final int WEAK_UNRELATED
UNRELATED
, but when a WEAK_ gap and a non-WEAK_ gap conflict, the non-WEAK_ gap
overrides. Numeric value -3. As a general rule smaller (i.e. "more negative") constants
override larger ones.
public static final int RELATED
Component
s that are logically related in a dialog, such as a
textfield and its label. Numeric value -4. As a general rule smaller (i.e. "more negative")
constants override larger ones.
public static final int UNRELATED
Component
s that are not logically related in a dialog.
Numeric value -5. As a general rule smaller (i.e. "more negative") constants override larger
ones.
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010 Matthias S. Benkmann. See LICENSE file for licensing details.
Hosted on