GWT 2.0.3

com.google.gwt.user.client.ui
Class DockLayoutPanel

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Panel
              extended by com.google.gwt.user.client.ui.ComplexPanel
                  extended by com.google.gwt.user.client.ui.DockLayoutPanel
All Implemented Interfaces:
HasHandlers, EventListener, AnimatedLayout, HasWidgets, IndexedPanel, ProvidesResize, RequiresResize, java.lang.Iterable<Widget>
Direct Known Subclasses:
SplitLayoutPanel

public class DockLayoutPanel
extends ComplexPanel
implements AnimatedLayout, RequiresResize, ProvidesResize

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

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>

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
static class DockLayoutPanel.Direction
          Used in addEast(Widget, double) et al to specify the direction in which a child widget will be added.
protected static class DockLayoutPanel.LayoutData
          Layout data associated with each widget.
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
DockLayoutPanel(Style.Unit unit)
          Creates an empty dock panel.
 
Method Summary
 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 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 children, animating over the specified period of time.
 void animate(int duration, com.google.gwt.layout.client.Layout.AnimationCallback callback)
          Layout children, animating over the specified period of time.
 void forceLayout()
          Layout children immediately.
protected  Widget getCenter()
           
protected  Style.Unit getUnit()
           
 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.
protected  void insert(Widget widget, DockLayoutPanel.Direction direction, double size, Widget before)
          Adds a widget to the specified edge of the dock.
 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 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.
protected  void onLoad()
          A Panel's onLoad method will be called after all of its children are attached.
 void onResize()
          This method must be called whenever the implementor's size has been modified.
protected  void onUnload()
          A Panel's onUnload method will be called before its children become detached themselves.
 boolean remove(Widget w)
          Removes a child widget.
 
Methods inherited from class com.google.gwt.user.client.ui.ComplexPanel
add, adjustIndex, checkIndexBoundsForAccess, checkIndexBoundsForInsertion, getChildren, getWidget, getWidgetCount, getWidgetIndex, insert, insert, iterator, remove
 
Methods inherited from class com.google.gwt.user.client.ui.Panel
adopt, adopt, clear, disown, doAttachChildren, doDetachChildren, orphan
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addDomHandler, addHandler, delegateEvent, fireEvent, getHandlerCount, getLayoutData, getParent, isAttached, isOrWasAttached, onAttach, onBrowserEvent, onDetach, removeFromParent, setLayoutData, sinkEvents
 
Methods 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, setElement, setElement, setHeight, setPixelSize, setSize, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

DockLayoutPanel

public DockLayoutPanel(Style.Unit unit)
Creates an empty dock panel.

Parameters:
unit - the unit to be used for layout
Method Detail

add

public void add(Widget widget)
Adds a widget at the center of the dock. No further widgets may be added after this one.

Specified by:
add in interface HasWidgets
Overrides:
add in class Panel
Parameters:
widget - the widget to be added
See Also:
HasWidgets.add(Widget)

addEast

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

addNorth

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

addSouth

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

addWest

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

animate

public void animate(int duration)
Description copied from interface: AnimatedLayout
Layout children, animating over the specified period of time.

Specified by:
animate in interface AnimatedLayout
Parameters:
duration - the animation duration, in milliseconds

animate

public void animate(int duration,
                    com.google.gwt.layout.client.Layout.AnimationCallback callback)
Description copied from interface: AnimatedLayout
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.

Specified by:
animate in interface AnimatedLayout
Parameters:
duration - the animation duration, in milliseconds
callback - the animation callback

forceLayout

public void forceLayout()
Description copied from interface: AnimatedLayout
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 AnimatedLayout.animate(int).

Specified by:
forceLayout in interface AnimatedLayout
See Also:
AnimatedLayout.animate(int), #animate(int, AnimationCallback)

getWidgetContainerElement

public Element getWidgetContainerElement(Widget child)
Gets the container element wrapping the given child widget.

Parameters:
child -
Returns:
the widget's container element

getWidgetDirection

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

insertEast

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

insertNorth

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

insertSouth

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

insertWest

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

onResize

public void onResize()
Description copied from interface: RequiresResize
This method must be called whenever the implementor's size has been modified.

Specified by:
onResize in interface RequiresResize

remove

public boolean remove(Widget w)
Description copied from class: Panel
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 Panel.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.

Specified by:
remove in interface HasWidgets
Overrides:
remove in class ComplexPanel
Parameters:
w - the widget to be removed
Returns:
true if the child was present

getCenter

protected Widget getCenter()

getUnit

protected Style.Unit 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 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

onLoad

protected void onLoad()
Description copied from class: Panel
A Panel's onLoad method will be called after all of its children are attached.

Overrides:
onLoad in class Panel
See Also:
Widget.onLoad()

onUnload

protected void onUnload()
Description copied from class: Panel
A Panel's onUnload method will be called before its children become detached themselves.

Overrides:
onUnload in class Panel
See Also:
Widget.onLoad()

GWT 2.0.3