Class WLayout
- java.lang.Object
-
- eu.webtoolkit.jwt.WObject
-
- eu.webtoolkit.jwt.WLayout
-
- All Implemented Interfaces:
WLayoutItem
- Direct Known Subclasses:
WBorderLayout,WBoxLayout,WFitLayout,WGridLayout
public abstract class WLayout extends WObject implements WLayoutItem
An abstract base class for layout managers.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, usesetContentsMargins().
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class eu.webtoolkit.jwt.WObject
WObject.FormData
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedWLayout()Create a layout.
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description abstract voidaddItem(WLayoutItem item)Adds a layout item.voidaddWidget(WWidget w)Adds the given widget to the layout.WWidgetItemfindWidgetItem(WWidget widget)Finds the widget item associated with the given widget.intgetContentsMargin(Side side)Returns a contents margin.abstract intgetCount()Returns the number of items in this layout.WLayoutImplgetImpl()protected LayoutImplementationgetImplementation()abstract WLayoutItemgetItemAt(int index)Returns the layout item at a specific index.WLayoutgetLayout()Returns the layout that implements thisWLayoutItem.WLayoutgetParentLayout()Returns the layout in which this item is contained.WWidgetgetParentWidget()protected LayoutImplementationgetPreferredImplementation()WWidgetgetWidget()Returns the widget that is held by thisWLayoutItem.intindexOf(WLayoutItem item)Returns the index of a given item.booleanisImplementationIsFlexLayout()protected voiditemAdded(WLayoutItem item)protected voiditemRemoved(WLayoutItem item)abstract WLayoutItemremoveItem(WLayoutItem item)Removes a layout item (widget or nested layout).WWidgetremoveWidget(WWidget w)Removes the given widget from the layout.voidsetContentsMargins(int left, int top, int right, int bottom)Set contents margins (in pixels).static voidsetDefaultImplementation(LayoutImplementation implementation)Sets the preferred layout implementation globally.protected voidsetImpl(WLayoutImpl impl)voidsetObjectName(java.lang.String name)Sets an object name.voidsetParentLayout(WLayout layout)Internal method.voidsetParentWidget(WWidget parent)Internal method.voidsetPreferredImplementation(LayoutImplementation implementation)Set the preferred layout implementation.protected voidupdate()Update the layout.protected voidupdate(WLayoutItem item)Update the layout.protected voidupdateImplementation()-
Methods inherited from class eu.webtoolkit.jwt.WObject
getId, getObjectName, remove, setFormData, 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
-
-
-
-
Method Detail
-
setPreferredImplementation
public void setPreferredImplementation(LayoutImplementation implementation)
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.JavaScriptis used.
-
setDefaultImplementation
public static void setDefaultImplementation(LayoutImplementation implementation)
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.JavaScriptis used.Because there are cases where
LayoutImplementation.Flexdoes 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
public abstract void addItem(WLayoutItem item)
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
public void addWidget(WWidget w)
Adds the given widget to the layout.This method wraps the widget in a
WWidgetItemand 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:
removeWidget(WWidget w)
-
removeItem
public abstract WLayoutItem removeItem(WLayoutItem item)
Removes a layout item (widget or nested layout).- See Also:
removeWidget(WWidget w)
-
removeWidget
public WWidget removeWidget(WWidget w)
Removes the given widget from the layout.This method finds the corresponding
WWidgetItemand callsremoveItem(), and returns the widget.- See Also:
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
public abstract WLayoutItem getItemAt(int index)
Returns the layout item at a specific index.If there is no item at the
index,nullis returned.- See Also:
indexOf(WLayoutItem item),getCount()
-
indexOf
public int indexOf(WLayoutItem item)
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
public WWidgetItem findWidgetItem(WWidget widget)
Finds the widget item associated with the given widget.- Specified by:
findWidgetItemin interfaceWLayoutItem
-
getWidget
public WWidget getWidget()
Description copied from interface:WLayoutItemReturns the widget that is held by thisWLayoutItem.This implements a type-safe upcasting mechanism to a
WWidgetItem.- Specified by:
getWidgetin interfaceWLayoutItem
-
getLayout
public WLayout getLayout()
Description copied from interface:WLayoutItemReturns the layout that implements thisWLayoutItem.This implements a type-safe upcasting mechanism to a
WLayout.- Specified by:
getLayoutin interfaceWLayoutItem
-
getParentLayout
public WLayout getParentLayout()
Description copied from interface:WLayoutItemReturns the layout in which this item is contained.- Specified by:
getParentLayoutin interfaceWLayoutItem
-
getParentWidget
public WWidget getParentWidget()
- Specified by:
getParentWidgetin interfaceWLayoutItem
-
getImpl
public WLayoutImpl getImpl()
- Specified by:
getImplin 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
public int getContentsMargin(Side side)
Returns a contents margin.
-
isImplementationIsFlexLayout
public boolean isImplementationIsFlexLayout()
-
setObjectName
public void setObjectName(java.lang.String name)
Description copied from class:WObjectSets an object name.The object name can be used to easily identify a type of object in the DOM, and does not need to be unique. It will usually reflect the widget type or role. The object name is prepended to the auto-generated object
WObject.getId().The default object name is empty.
- Overrides:
setObjectNamein classWObject- Parameters:
name- the object name.
-
update
protected void update(WLayoutItem item)
Update the layout.Must be called whenever some properties of the layout have changed.
-
update
protected final void update()
Update the layout.
-
itemAdded
protected void itemAdded(WLayoutItem item)
-
itemRemoved
protected void itemRemoved(WLayoutItem item)
-
setParentWidget
public void setParentWidget(WWidget parent)
Description copied from interface:WLayoutItemInternal method.- Specified by:
setParentWidgetin interfaceWLayoutItem
-
setImpl
protected void setImpl(WLayoutImpl impl)
-
getImplementation
protected LayoutImplementation getImplementation()
-
getPreferredImplementation
protected LayoutImplementation getPreferredImplementation()
-
updateImplementation
protected void updateImplementation()
-
setParentLayout
public void setParentLayout(WLayout layout)
Description copied from interface:WLayoutItemInternal method.- Specified by:
setParentLayoutin interfaceWLayoutItem
-
-