Class WLayout
- All Implemented Interfaces:
WLayoutItem
- Direct Known Subclasses:
WBorderLayout
,WBoxLayout
,WFitLayout
,WGridLayout
This class is the abstract base class for any layout manager. A layout manager is associated with a container widget, and manages the layout of children inside the whole space available to the container widget.
The implementation of the layout manager depends on the container widget to which it is set,
and is therefore deferred to WLayoutImpl
.
Note: When applying a layout manager to a WContainerWidget
, you may not
define any padding for the container widget. Instead, use setContentsMargins()
.
-
Nested Class Summary
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionabstract void
addItem
(WLayoutItem item) Adds a layout item.void
Adds the given widget to the layout.findWidgetItem
(WWidget widget) Finds the widget item associated with the given widget.int
getContentsMargin
(Side side) Returns a contents margin.abstract int
getCount()
Returns the number of items in this layout.getImpl()
protected LayoutImplementation
abstract WLayoutItem
getItemAt
(int index) Returns the layout item at a specific index.Returns the layout that implements thisWLayoutItem
.Returns the layout in which this item is contained.protected LayoutImplementation
Returns the widget that is held by thisWLayoutItem
.int
indexOf
(WLayoutItem item) Returns the index of a given item.boolean
protected void
itemAdded
(WLayoutItem item) protected void
itemRemoved
(WLayoutItem item) abstract WLayoutItem
removeItem
(WLayoutItem item) Removes a layout item (widget or nested layout).Removes the given widget from the layout.void
setContentsMargins
(int left, int top, int right, int bottom) Set contents margins (in pixels).static void
setDefaultImplementation
(LayoutImplementation implementation) Sets the preferred layout implementation globally.protected void
setImpl
(WLayoutImpl impl) void
setParentLayout
(WLayout layout) Internal method.void
setParentWidget
(WWidget parent) Internal method.void
setPreferredImplementation
(LayoutImplementation implementation) Set the preferred layout implementation.protected final void
update()
Update the layout.protected void
update
(WLayoutItem item) Update the layout.protected void
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface eu.webtoolkit.jwt.WLayoutItem
iterateWidgets
-
Constructor Details
-
WLayout
protected WLayout()Create a layout.
-
-
Method Details
-
setPreferredImplementation
Set the preferred layout implementation.The default implementation for box layouts and fit layouts is
LayoutImplementation.Flex
(if supported by the browser). Otherwise a fallback toLayoutImplementation.JavaScript
is used. -
setDefaultImplementation
Sets the preferred layout implementation globally.The default implementation for box layouts and fit layouts is
LayoutImplementation.Flex
(if supported by the browser). Otherwise a fallback toLayoutImplementation.JavaScript
is used.Because there are cases where
LayoutImplementation.Flex
does not work properly, this method can be used to set the global preferred implementation to instead. Since this is a system-wide setting, and not a per-session setting, you should call this function before any session is created, e.g. in main() before calling WRun(). setPreferredImplementation() -
addItem
Adds a layout item.The item may be a widget or nested layout.
How the item is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.
- See Also:
-
addWidget
Adds the given widget to the layout.This method wraps the widget in a
WWidgetItem
and calls addItem(WLayoutItem *).How the widget is layed out with respect to siblings is implementation specific to the layout manager. In some cases, a layout manager will overload this method with extra arguments that specify layout options.
- See Also:
-
removeItem
Removes a layout item (widget or nested layout).- See Also:
-
removeWidget
Removes the given widget from the layout.This method finds the corresponding
WWidgetItem
and callsremoveItem()
, and returns the widget.- See Also:
-
getCount
public abstract int getCount()Returns the number of items in this layout.This may be a theoretical number, which is greater than the actual number of items. It can be used to iterate over the items in the layout, in conjunction with
getItemAt()
. -
getItemAt
Returns the layout item at a specific index.If there is no item at the
index
,null
is returned.- See Also:
-
indexOf
Returns the index of a given item.The default implementation loops over all items, and returns the index for which itemAt(index) equals
item
.- See Also:
-
findWidgetItem
Finds the widget item associated with the given widget.- Specified by:
findWidgetItem
in interfaceWLayoutItem
-
getWidget
Description copied from interface:WLayoutItem
Returns the widget that is held by thisWLayoutItem
.This implements a type-safe upcasting mechanism to a
WWidgetItem
.- Specified by:
getWidget
in interfaceWLayoutItem
-
getLayout
Description copied from interface:WLayoutItem
Returns the layout that implements thisWLayoutItem
.This implements a type-safe upcasting mechanism to a
WLayout
.- Specified by:
getLayout
in interfaceWLayoutItem
-
getParentLayout
Description copied from interface:WLayoutItem
Returns the layout in which this item is contained.- Specified by:
getParentLayout
in interfaceWLayoutItem
-
getParentWidget
- Specified by:
getParentWidget
in interfaceWLayoutItem
-
getImpl
- Specified by:
getImpl
in interfaceWLayoutItem
-
setContentsMargins
public void setContentsMargins(int left, int top, int right, int bottom) Set contents margins (in pixels).The default contents margins are 9 pixels in all directions.
Note: Only used when the layout manager is applied to a
WContainerWidget
. -
getContentsMargin
Returns a contents margin. -
isImplementationIsFlexLayout
public boolean isImplementationIsFlexLayout() -
update
Update the layout.Must be called whenever some properties of the layout have changed.
-
update
protected final void update()Update the layout. -
itemAdded
-
itemRemoved
-
setParentWidget
Description copied from interface:WLayoutItem
Internal method.- Specified by:
setParentWidget
in interfaceWLayoutItem
-
setImpl
-
getImplementation
-
getPreferredImplementation
-
updateImplementation
protected void updateImplementation() -
setParentLayout
Description copied from interface:WLayoutItem
Internal method.- Specified by:
setParentLayout
in interfaceWLayoutItem
-