Class WLayout
- All Implemented Interfaces:
WLayoutItem
- Direct Known Subclasses:
WBorderLayout
,WBoxLayout
,WFitLayout
,WGridLayout
public abstract class WLayout extends WObject implements WLayoutItem
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.
A layout never assumes ownership of contained items, instead these are owned by the parent widget to which the layout is applied.
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
Constructors Modifier Constructor Description protected
WLayout()
Create a layout. -
Method Summary
Modifier and Type Method Description abstract void
addItem(WLayoutItem item)
Adds a layout item.void
addWidget(WWidget w)
Adds the given widget to the layout.abstract void
clear()
Removes and deletes all child widgets and nested layouts.protected void
clearLayoutItem(WLayoutItem item)
Clears and deletes an item.WWidgetItem
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.WLayoutItemImpl
getImpl()
Returns the implementation for this layout item.abstract WLayoutItem
getItemAt(int index)
Returns the layout item at a specific index.WLayout
getLayout()
Returns the layout that implements thisWLayoutItem
.WLayout
getParentLayout()
Returns the layout in which this item is contained.WWidget
getWidget()
Returns the widget that is held by thisWLayoutItem
.int
indexOf(WLayoutItem item)
Returns the index of a given item.abstract void
removeItem(WLayoutItem item)
Removes a layout item (widget or nested layout).boolean
removeWidget(WWidget w)
Removes the given widget from the layout.void
setContentsMargins(int left, int top, int right, int bottom)
Set contents margins (in pixels).void
setLayoutHint(java.lang.String name, java.lang.String value)
Provides a hint to the layout implementation.protected void
setLayoutInParent(WWidget parent)
Set the layout in the parent.void
setParentLayout(WLayout layout)
Internal method.void
setParentWidget(WWidget parent)
Internal method.protected void
update()
Update the layout.protected void
update(WLayoutItem item)
Update the layout.protected void
updateAddItem(WLayoutItem item)
Update the layout, adding the given layout item.protected void
updateRemoveItem(WLayoutItem item)
Update the layout, remove the given layout item.Methods inherited from class eu.webtoolkit.jwt.WObject
addChild, getId, getObjectName, remove, setFormData, setObjectName, tr
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
WLayout
protected WLayout()Create a layout.
-
-
Method Details
-
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:
removeItem(WLayoutItem item)
,addWidget(WWidget w)
-
addWidget
Adds the given widget to the layout.This method wraps the widget in a
WWidgetItem
and callsaddItem()
.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:
removeWidget(WWidget w)
,addItem(WLayoutItem item)
-
removeItem
Removes a layout item (widget or nested layout).- See Also:
addItem(WLayoutItem item)
,removeWidget(WWidget w)
-
removeWidget
Removes the given widget from the layout.This method finds the corresponding
WWidgetItem
and callsremoveItem()
. The widget itself is not destroyed.Returns
true
if succesful.- See Also:
addWidget(WWidget w)
,removeItem(WLayoutItem item)
-
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(WLayoutItem item)
,getCount()
-
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:
getItemAt(int index)
-
findWidgetItem
Finds the widget item associated with the given widget.- Specified by:
findWidgetItem
in interfaceWLayoutItem
-
setLayoutHint
public void setLayoutHint(java.lang.String name, java.lang.String value)Provides a hint to the layout implementation.In some cases, a layout implementation may require some hints for rendering its contents. Possible hints are indicated in the reference documentation for each layout manager.
-
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
-
getImpl
Description copied from interface:WLayoutItem
Returns the implementation for this layout item.The implementation of a layout item depends on the kind of container for which the layout does layout management.
- 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. -
clear
public abstract void clear()Removes and deletes all child widgets and nested layouts.This is similar to
WContainerWidget.clear()
, with the exception that the layout itself is not deleted. -
update
Update the layout.Must be called whenever some properties of the layout have changed.
-
update
protected final void update()Update the layout. -
updateAddItem
Update the layout, adding the given layout item.Must be called from the implementation of
addItem()
-
updateRemoveItem
Update the layout, remove the given layout item.Must be called from the implementation of
removeItem()
-
setLayoutInParent
Set the layout in the parent.Must be called from the constructor after the layout has been fully created (since it will call virtual methods
getCount()
andgetItemAt()
). -
clearLayoutItem
Clears and deletes an item.This also deletes nested widgets and layouts.
- See Also:
clear()
-
setParentWidget
Description copied from interface:WLayoutItem
Internal method.- Specified by:
setParentWidget
in interfaceWLayoutItem
-
setParentLayout
Description copied from interface:WLayoutItem
Internal method.- Specified by:
setParentLayout
in interfaceWLayoutItem
-