public class

DockLayoutPanel

extends ComplexPanel
implements AnimatedLayout ProvidesResize RequiresResize
java.lang.Object
   ↳ com.google.gwt.user.client.ui.UIObject
     ↳ com.google.gwt.user.client.ui.Widget
       ↳ com.google.gwt.user.client.ui.Panel
         ↳ com.google.gwt.user.client.ui.ComplexPanel
           ↳ com.google.gwt.user.client.ui.DockLayoutPanel
Known Direct Subclasses

Class Overview

A panel that lays its child widgets out "docked" at its outer edges, and allows its last widget to take up the remaining space in its center.

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

{@example com.google.gwt.examples.DockLayoutPanelExample}

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>

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>
 

Summary

Nested Classes
enum DockLayoutPanel.Direction Used in addEast(Widget, double) et al to specify the direction in which a child widget will be added. 
class DockLayoutPanel.LayoutData Layout data associated with each widget. 
[Expand]
Inherited Constants
From class com.google.gwt.user.client.ui.UIObject
Public Constructors
DockLayoutPanel(Style.Unit unit)
Creates an empty dock panel.
Public Methods
void add(Widget widget)
Adds a widget at the center of the dock.
void addEast(Widget widget, double size)
Adds a widget to the east edge of the dock.
void addLineEnd(Widget widget, double size)
Adds a widget to the end of the line.
void addLineStart(Widget widget, double size)
Adds a widget to the start of the line.
void addNorth(Widget widget, double size)
Adds a widget to the north edge of the dock.
void addSouth(Widget widget, double size)
Adds a widget to the south edge of the dock.
void addWest(Widget widget, double size)
Adds a widget to the west edge of the dock.
void animate(int duration, Layout.AnimationCallback callback)
Layout children, animating over the specified period of time.
void animate(int duration)
Layout children, animating over the specified period of time.
void forceLayout()
Layout children immediately.
Element getWidgetContainerElement(Widget child)
Gets the container element wrapping the given child widget.
DockLayoutPanel.Direction getWidgetDirection(Widget child)
Gets the layout direction of the given child widget.
void insertEast(Widget widget, double size, Widget before)
Adds a widget to the east edge of the dock, inserting it before an existing widget.
void insertLineEnd(Widget widget, double size, Widget before)
Adds a widget to the start of the line, inserting it before an existing widget.
void insertLineStart(Widget widget, double size, Widget before)
Adds a widget to the end of the line, inserting it before an existing widget.
void insertNorth(Widget widget, double size, Widget before)
Adds a widget to the north edge of the dock, inserting it before an existing widget.
void insertSouth(Widget widget, double size, Widget before)
Adds a widget to the south edge of the dock, inserting it before an existing widget.
void insertWest(Widget widget, double size, Widget before)
Adds a widget to the west edge of the dock, inserting it before an existing widget.
void onResize()
This method must be called whenever the implementor's size has been modified.
boolean remove(Widget w)
Removes a child widget.
void setWidgetSize(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.
Protected Methods
Widget getCenter()
double getCenterHeight()
double getCenterWidth()
DockLayoutPanel.Direction getResolvedDirection(DockLayoutPanel.Direction direction)
Resolve the specified direction based on the current locale.
Style.Unit getUnit()
void insert(Widget widget, DockLayoutPanel.Direction direction, double size, Widget before)
Adds a widget to the specified edge of the dock.
void onLoad()
This method is called immediately after a widget becomes attached to the browser's document.
void onUnload()
This method is called immediately before a widget will be detached from the browser's document.
[Expand]
Inherited Methods
From class com.google.gwt.user.client.ui.ComplexPanel
From class com.google.gwt.user.client.ui.Panel
From class com.google.gwt.user.client.ui.Widget
From class com.google.gwt.user.client.ui.UIObject
From class java.lang.Object
From interface com.google.gwt.event.logical.shared.HasAttachHandlers
From interface com.google.gwt.event.shared.HasHandlers
From interface com.google.gwt.user.client.EventListener
From interface com.google.gwt.user.client.ui.AnimatedLayout
From interface com.google.gwt.user.client.ui.HasWidgets
From interface com.google.gwt.user.client.ui.HasWidgets.ForIsWidget
From interface com.google.gwt.user.client.ui.IndexedPanel
From interface com.google.gwt.user.client.ui.IndexedPanel.ForIsWidget
From interface com.google.gwt.user.client.ui.IsWidget
From interface com.google.gwt.user.client.ui.RequiresResize
From interface java.lang.Iterable

Public Constructors

public DockLayoutPanel (Style.Unit unit)

Creates an empty dock panel.

Parameters
unit the unit to be used for layout

Public Methods

public void add (Widget widget)

Adds a widget at the center of the dock. No further widgets may be added after this one.

Parameters
widget the widget to be added

public void addEast (Widget widget, double size)

Adds a widget to the east edge of the dock.

Parameters
widget the widget to be added
size the child widget's size

public void addLineEnd (Widget widget, double size)

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 added
size the child widget's size

public void addLineStart (Widget widget, double size)

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 added
size the child widget's size

public void addNorth (Widget widget, double size)

Adds a widget to the north edge of the dock.

Parameters
widget the widget to be added
size the child widget's size

public void addSouth (Widget widget, double size)

Adds a widget to the south edge of the dock.

Parameters
widget the widget to be added
size the child widget's size

public void addWest (Widget widget, double size)

Adds a widget to the west edge of the dock.

Parameters
widget the widget to be added
size the child widget's size

public void animate (int duration, Layout.AnimationCallback callback)

Layout 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.

Parameters
duration the animation duration, in milliseconds
callback the animation callback

public void animate (int duration)

Layout children, animating over the specified period of time.

Parameters
duration the animation duration, in milliseconds

public void forceLayout ()

Layout 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 animate(int).

public Element getWidgetContainerElement (Widget child)

Gets the container element wrapping the given child widget.

Returns
  • the widget's container element

public DockLayoutPanel.Direction getWidgetDirection (Widget child)

Gets the layout direction of the given child widget.

Parameters
child the widget to be queried
Returns
  • the widget's layout direction, or null if it is not a child of this panel

public void insertEast (Widget widget, double size, Widget before)

Adds a widget to the east edge of the dock, inserting it before an existing widget.

Parameters
widget the widget to be added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void insertLineEnd (Widget widget, double size, Widget before)

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 added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void insertLineStart (Widget widget, double size, Widget before)

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 added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void insertNorth (Widget widget, double size, Widget before)

Adds a widget to the north edge of the dock, inserting it before an existing widget.

Parameters
widget the widget to be added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void insertSouth (Widget widget, double size, Widget before)

Adds a widget to the south edge of the dock, inserting it before an existing widget.

Parameters
widget the widget to be added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void insertWest (Widget widget, double size, Widget before)

Adds a widget to the west edge of the dock, inserting it before an existing widget.

Parameters
widget the widget to be added
size the child widget's size
before the widget before which to insert the new child, or null to append

public void onResize ()

This method must be called whenever the implementor's size has been modified.

public boolean remove (Widget w)

Removes 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.

  1. Validate: Make sure this Panel is actually the parent of the child Widget; return false if it is not.
  2. Orphan: Call orphan(Widget) first while the child Widget is still attached.
  3. 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.
  4. 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.

Parameters
w the widget to be removed
Returns
  • true if the child was present

public void setWidgetSize (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.

Parameters
widget the widget that needs to update its size
size the size to update the widget to

Protected Methods

protected Widget getCenter ()

protected double getCenterHeight ()

protected double getCenterWidth ()

protected DockLayoutPanel.Direction getResolvedDirection (DockLayoutPanel.Direction direction)

Resolve the specified direction based on the current locale. If the direction is LINE_START or LINE_END, the return value will be one of EAST or WEST depending on the RTL mode of the locale. For all other directions, the specified value is returned.

Parameters
direction the specified direction
Returns
  • the locale

protected Style.Unit getUnit ()

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 though remove(Widget) had already been called.

Parameters
widget the widget to be added
direction the widget's direction in the dock
before the widget before which to insert the new child, or null to append

protected void onLoad ()

This method is called immediately after a widget becomes attached to the browser's document.

protected void onUnload ()

This method is called immediately before a widget will be detached from the browser's document.