Class DockLayoutPanel
- All Implemented Interfaces:
HasAttachHandlers,HasHandlers,EventListener,AnimatedLayout,HasVisibility,HasWidgets,HasWidgets.ForIsWidget,IndexedPanel,IndexedPanel.ForIsWidget,IsWidget,ProvidesResize,RequiresResize,Iterable<Widget>
- Direct Known Subclasses:
SplitLayoutPanel
This widget will only work in standards mode, which requires that the HTML page in which it is run have an explicit <!DOCTYPE> declaration.
Example
public class DockLayoutPanelExample implements EntryPoint {
public void onModuleLoad() {
// Attach five widgets to a DockLayoutPanel, one in each direction. Lay
// them out in 'em' units.
DockLayoutPanel p = new DockLayoutPanel(Unit.EM);
p.addNorth(new HTML("north"), 2);
p.addSouth(new HTML("south"), 2);
p.addEast(new HTML("east"), 2);
p.addWest(new HTML("west"), 2);
p.add(new HTML("center"));
// Attach the LayoutPanel to the RootLayoutPanel. The latter will listen for
// resize events on the window to ensure that its children are informed of
// possible size changes.
RootLayoutPanel rp = RootLayoutPanel.get();
rp.add(p);
}
}
Use in UiBinder Templates
DockLayoutPanel elements in
UiBinder templates
lay out their children in elements tagged with the cardinal directions,
and center:
- <g:center>
- <g:north>
- <g:south>
- <g:west>
- <g:east>
- <g:north>
Each child can hold only widget, and there can be only one <g:center>. However, there can be any number of the directional children.
(Note that the tags of the child elements are not
capitalized. This is meant to signal that they are not runtime objects,
and so cannot have a ui:field attribute.)
For example:
<g:DockLayoutPanel unit='EM'>
<g:north size='5'>
<g:Label>Top</g:Label>
</g:north>
<g:center>
<g:Label>Body</g:Label>
</g:center>
<g:west size='192'>
<g:HTML>
<ul>
<li>Sidebar</li>
<li>Sidebar</li>
<li>Sidebar</li>
</ul>
</g:HTML>
</g:west>
</g:DockLayoutPanel>
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic enumUsed inaddEast(Widget, double)et al to specify the direction in which a child widget will be added.protected static classLayout data associated with each widget.Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabledNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidgetNested classes/interfaces inherited from interface com.google.gwt.user.client.ui.IndexedPanel
IndexedPanel.ForIsWidget -
Field Summary
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSinkFields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a widget at the center of the dock.voidOverloaded version for IsWidget.voidAdds a widget to the east edge of the dock.voidaddLineEnd(Widget widget, double size) Adds a widget to the end of the line.voidaddLineStart(Widget widget, double size) Adds a widget to the start of the line.voidOverloaded version for IsWidget.voidAdds a widget to the north edge of the dock.voidOverloaded version for IsWidget.voidAdds a widget to the south edge of the dock.voidOverloaded version for IsWidget.voidAdds a widget to the west edge of the dock.voidanimate(int duration) Layout children, animating over the specified period of time.voidanimate(int duration, Layout.AnimationCallback callback) Layout children, animating over the specified period of time.(package private) voidassertIsChild(Widget widget) voidLayout children immediately.protected Widgetprotected doubleprotected doubleprotected DockLayoutPanel.DirectiongetResolvedDirection(DockLayoutPanel.Direction direction) Resolve the specified direction based on the current locale.protected Style.UnitgetUnit()getWidgetContainerElement(Widget child) Gets the container element wrapping the given child widget.getWidgetDirection(Widget child) Gets the layout direction of the given child widget.getWidgetSize(Widget child) Gets the layout size of the given child widget.protected voidinsert(Widget widget, DockLayoutPanel.Direction direction, double size, Widget before) Adds a widget to the specified edge of the dock.voidinsertEast(Widget widget, double size, Widget before) Adds a widget to the east edge of the dock, inserting it before an existing widget.voidinsertLineEnd(Widget widget, double size, Widget before) Adds a widget to the start of the line, inserting it before an existing widget.voidinsertLineStart(Widget widget, double size, Widget before) Adds a widget to the end of the line, inserting it before an existing widget.voidinsertNorth(Widget widget, double size, Widget before) Adds a widget to the north edge of the dock, inserting it before an existing widget.voidinsertSouth(Widget widget, double size, Widget before) Adds a widget to the south edge of the dock, inserting it before an existing widget.voidinsertWest(Widget widget, double size, Widget before) Adds a widget to the west edge of the dock, inserting it before an existing widget.protected voidonAttach()This method is called when a widget is attached to the browser's document.protected voidonDetach()This method is called when a widget is detached from the browser's document.voidonResize()This method must be called whenever the implementor's size has been modified.booleanRemoves a child widget.voidsetWidgetHidden(Widget widget, boolean hidden) Sets whether or not the given widget should be hidden.voidsetWidgetSize(Widget widget, double size) Updates the size of the widget passed in as long as it is not the center widget and updates the layout of the dock.Methods inherited from class com.google.gwt.user.client.ui.ComplexPanel
add, add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, doLogicalClear, getChildren, getWidget, getWidgetCount, getWidgetIndex, getWidgetIndex, insert, insert, iterator, removeMethods inherited from class com.google.gwt.user.client.ui.Panel
add, adopt, clear, doAttachChildren, doDetachChildren, orphan, removeMethods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isAttached, isOrWasAttached, onBrowserEvent, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEventsMethods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, resolvePotentialElement, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toStringMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
DockLayoutPanel
Creates an empty dock panel.- Parameters:
unit- the unit to be used for layout
-
-
Method Details
-
add
Adds a widget at the center of the dock. No further widgets may be added after this one.- Specified by:
addin interfaceHasWidgets- Overrides:
addin classPanel- Parameters:
widget- the widget to be added- See Also:
-
addEast
Adds a widget to the east edge of the dock.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addEast
Overloaded version for IsWidget.- See Also:
-
addLineEnd
Adds a widget to the end of the line. In LTR mode, the widget is added to the east. In RTL mode, the widget is added to the west.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addLineStart
Adds a widget to the start of the line. In LTR mode, the widget is added to the west. In RTL mode, the widget is added to the east.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addNorth
Adds a widget to the north edge of the dock.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addNorth
Overloaded version for IsWidget.- See Also:
-
addSouth
Adds a widget to the south edge of the dock.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addSouth
Overloaded version for IsWidget.- See Also:
-
addWest
Adds a widget to the west edge of the dock.- Parameters:
widget- the widget to be addedsize- the child widget's size
-
addWest
Overloaded version for IsWidget.- See Also:
-
animate
public void animate(int duration) Description copied from interface:AnimatedLayoutLayout children, animating over the specified period of time.- Specified by:
animatein interfaceAnimatedLayout- Parameters:
duration- the animation duration, in milliseconds
-
animate
Description copied from interface:AnimatedLayoutLayout children, animating over the specified period of time.This method provides a callback that will be informed of animation updates. This can be used to create more complex animation effects.
- Specified by:
animatein interfaceAnimatedLayout- Parameters:
duration- the animation duration, in millisecondscallback- the animation callback
-
forceLayout
public void forceLayout()Description copied from interface:AnimatedLayoutLayout children immediately.This is not normally necessary, unless you want to update child widgets' positions explicitly to create a starting point for a subsequent call to
AnimatedLayout.animate(int).- Specified by:
forceLayoutin interfaceAnimatedLayout- See Also:
-
getWidgetContainerElement
Gets the container element wrapping the given child widget.- Parameters:
child-- Returns:
- the widget's container element
-
getWidgetDirection
Gets the layout direction of the given child widget.- Parameters:
child- the widget to be queried- Returns:
- the widget's layout direction, or
nullif it is not a child of this panel - Throws:
AssertionError- if the widget is not a child and assertions are enabled
-
getWidgetSize
Gets the layout size of the given child widget.- Parameters:
child- the widget to be queried- Returns:
- the widget's layout size, or
nullif it is not a child of this panel - Throws:
AssertionError- if the widget is not a child and assertions are enabled
-
insertEast
Adds a widget to the east edge of the dock, inserting it before an existing widget.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
insertLineEnd
Adds a widget to the start of the line, inserting it before an existing widget. In LTR mode, the widget is added to the east. In RTL mode, the widget is added to the west.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
insertLineStart
Adds a widget to the end of the line, inserting it before an existing widget. In LTR mode, the widget is added to the west. In RTL mode, the widget is added to the east.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
insertNorth
Adds a widget to the north edge of the dock, inserting it before an existing widget.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
insertSouth
Adds a widget to the south edge of the dock, inserting it before an existing widget.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
insertWest
Adds a widget to the west edge of the dock, inserting it before an existing widget.- Parameters:
widget- the widget to be addedsize- the child widget's sizebefore- the widget before which to insert the new child, ornullto append
-
onResize
public void onResize()Description copied from interface:RequiresResizeThis method must be called whenever the implementor's size has been modified.- Specified by:
onResizein interfaceRequiresResize
-
remove
Description copied from class:PanelRemoves a child widget.How to Override this Method
There are several important things that must take place in the correct order to properly remove a Widget from a Panel. Not all of these steps will be relevant to every Panel, but all of the steps must be considered.
- Validate: Make sure this Panel is actually the parent of the
child Widget; return
falseif it is not. - Orphan: Call
Panel.orphan(Widget)first while the child Widget is still attached. - Physical Detach: Adjust the DOM to account for the removal of the child Widget. The Widget's Element must be physically removed from the DOM.
- Logical Detach: Update the Panel's state variables to reflect
the removal of the child Widget. Example: the Widget is removed from the
Panel's
WidgetCollection.
- Specified by:
removein interfaceHasWidgets- Overrides:
removein classComplexPanel- Parameters:
w- the widget to be removed- Returns:
trueif the child was present
- Validate: Make sure this Panel is actually the parent of the
child Widget; return
-
setWidgetHidden
Sets whether or not the given widget should be hidden.- Parameters:
widget- the widget to hide or displayhidden- true to hide the widget, false to display it
-
setWidgetSize
Updates the size of the widget passed in as long as it is not the center widget and updates the layout of the dock.- Parameters:
widget- the widget that needs to update its sizesize- the size to update the widget to
-
getCenter
-
getCenterHeight
protected double getCenterHeight() -
getCenterWidth
protected double getCenterWidth() -
getResolvedDirection
Resolve the specified direction based on the current locale. If the direction isDockLayoutPanel.Direction.LINE_STARTorDockLayoutPanel.Direction.LINE_END, the return value will be one ofDockLayoutPanel.Direction.EASTorDockLayoutPanel.Direction.WESTdepending on the RTL mode of the locale. For all other directions, the specified value is returned.- Parameters:
direction- the specified direction- Returns:
- the locale
-
getUnit
-
insert
protected void insert(Widget widget, DockLayoutPanel.Direction direction, double size, Widget before) Adds a widget to the specified edge of the dock. If the widget is already a child of this panel, this method behaves as thoughremove(Widget)had already been called.- Parameters:
widget- the widget to be addeddirection- the widget's direction in the dockbefore- the widget before which to insert the new child, ornullto append
-
onAttach
protected void onAttach()Description copied from class:WidgetThis method is called when a widget is attached to the browser's document. To receive notification after a Widget has been added to the document, override the
Widget.onLoad()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onLoad()orWidget.doAttachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onAttach()to ensure that the Widget has been attached to its underlying Element. -
onDetach
protected void onDetach()Description copied from class:WidgetThis method is called when a widget is detached from the browser's document. To receive notification before a Widget is removed from the document, override the
Widget.onUnload()method or useWidget.addAttachHandler(com.google.gwt.event.logical.shared.AttachEvent.Handler).It is strongly recommended that you override
Widget.onUnload()orWidget.doDetachChildren()instead of this method to avoid inconsistencies between logical and physical attachment states.Subclasses that override this method must call
super.onDetach()to ensure that the Widget has been detached from the underlying Element. Failure to do so will result in application memory leaks due to circular references between DOM Elements and JavaScript objects. -
assertIsChild
-