GWT 2.7.0

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

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.Composite
              extended by com.google.gwt.user.client.ui.ResizeComposite
                  extended by com.google.gwt.user.client.ui.StackLayoutPanel
All Implemented Interfaces:
HasAttachHandlers, HasBeforeSelectionHandlers<java.lang.Integer>, HasSelectionHandlers<java.lang.Integer>, HasHandlers, EventListener, AnimatedLayout, HasVisibility, HasWidgets, IndexedPanel, IndexedPanel.ForIsWidget, IsRenderable, IsWidget, ProvidesResize, RequiresResize, java.lang.Iterable<Widget>

public class StackLayoutPanel
extends ResizeComposite
implements HasWidgets, ProvidesResize, IndexedPanel.ForIsWidget, AnimatedLayout, HasBeforeSelectionHandlers<java.lang.Integer>, HasSelectionHandlers<java.lang.Integer>

A panel that stacks its children vertically, displaying only one at a time, with a header for each child which the user can click to display.

This widget will only work in standards mode, which requires that the HTML page in which it is run have an explicit <!DOCTYPE> declaration.

CSS Style Rules

.gwt-StackLayoutPanel
the panel itself
.gwt-StackLayoutPanel .gwt-StackLayoutPanelHeader
applied to each header widget
.gwt-StackLayoutPanel .gwt-StackLayoutPanelHeader-hovering
applied to each header widget on mouse hover
.gwt-StackLayoutPanel .gwt-StackLayoutPanelContent
applied to each child widget

Example

public class StackLayoutPanelExample implements EntryPoint {

  public void onModuleLoad() {
    // Create a three-item stack, with headers sized in EMs. 
    StackLayoutPanel p = new StackLayoutPanel(Unit.EM);
    p.add(new HTML("this"), new HTML("[this]"), 4);
    p.add(new HTML("that"), new HTML("[that]"), 4);
    p.add(new HTML("the other"), new HTML("[the other]"), 4);

    // 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

A StackLayoutPanel element in a UiBinder template may have a unit attribute with a Style.Unit value (it defaults to PX).

The children of a StackLayoutPanel element are laid out in <g:stack> elements. Each stack can have one widget child and one of two types of header elements. A <g:header> element can hold html, or a <g:customHeader> element can hold a widget. (Note that the tags of the header elements are not capitalized. This is meant to signal that the head is not a runtime object, and so cannot have a ui:field attribute.)

For example:

 <g:StackLayoutPanel unit='PX'>
  <g:stack>
    <g:header size='3'><b>HTML</b> header</g:header>
    <g:Label>able</g:Label>
  </g:stack>
  <g:stack>
    <g:customHeader size='3'>
      <g:Label>Custom header</g:Label>
    </g:customHeader>
    <g:Label>baker</g:Label>
  </g:stack>
 </g:StackLayoutPanel>
 


Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
 
Nested classes/interfaces inherited from interface com.google.gwt.user.client.ui.HasWidgets
HasWidgets.ForIsWidget
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.Widget
eventsToSink
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
 
Constructor Summary
StackLayoutPanel(Style.Unit unit)
          Creates an empty stack panel.
 
Method Summary
 void add(IsWidget widget, IsWidget header, double headerSize)
          Overloaded version for IsWidget.
 void add(IsWidget widget, java.lang.String header, boolean asHtml, double headerSize)
          Overloaded version for IsWidget.
 void add(Widget w)
          Adds a child widget.
 void add(Widget widget, SafeHtml header, double headerSize)
          Adds a child widget to this stack, along with a widget representing the stack header.
 void add(Widget widget, java.lang.String header, boolean asHtml, double headerSize)
          Adds a child widget to this stack, along with a widget representing the stack header.
 void add(Widget widget, java.lang.String header, double headerSize)
          Adds a child widget to this stack, along with a widget representing the stack header.
 void add(Widget widget, Widget header, double headerSize)
          Adds a child widget to this stack, along with a widget representing the stack header.
 HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<java.lang.Integer> handler)
          Adds a BeforeSelectionEvent handler.
 HandlerRegistration addSelectionHandler(SelectionHandler<java.lang.Integer> handler)
          Adds a SelectionEvent handler.
 void animate(int duration)
          Layout children, animating over the specified period of time.
 void animate(int duration, Layout.AnimationCallback callback)
          Layout children, animating over the specified period of time.
 void clear()
          Removes all child widgets.
 void forceLayout()
          Layout children immediately.
 int getAnimationDuration()
          Get the duration of the animated transition between children.
 Widget getHeaderWidget(int index)
          Gets the widget in the stack header at the given index.
 Widget getHeaderWidget(Widget child)
          Gets the widget in the stack header associated with the given child widget.
 int getVisibleIndex()
          Gets the currently-selected index.
 Widget getVisibleWidget()
          Gets the currently-selected widget.
 Widget getWidget(int index)
          Gets the child widget at the specified index.
 int getWidgetCount()
          Gets the number of child widgets in this panel.
 int getWidgetIndex(IsWidget child)
           
 int getWidgetIndex(Widget child)
          Gets the index of the specified child widget.
 void insert(Widget child, SafeHtml html, double headerSize, int beforeIndex)
          Inserts a widget into the panel.
 void insert(Widget child, java.lang.String text, boolean asHtml, double headerSize, int beforeIndex)
          Inserts a widget into the panel.
 void insert(Widget child, java.lang.String text, double headerSize, int beforeIndex)
          Inserts a widget into the panel.
 void insert(Widget child, Widget header, double headerSize, int beforeIndex)
          Inserts a widget into the panel.
 java.util.Iterator<Widget> iterator()
          Gets an iterator for the contained widgets.
protected  void onLoad()
          This method is called immediately after a widget becomes attached to the browser's document.
 void onResize()
          This method must be called whenever the implementor's size has been modified.
 boolean remove(int index)
          Removes the widget at the specified index.
 boolean remove(Widget child)
          Removes a child widget.
 void setAnimationDuration(int duration)
          Set the duration of the animated transition between children.
 void setHeaderHTML(int index, SafeHtml html)
          Sets a stack header's HTML contents.
 void setHeaderHTML(int index, java.lang.String html)
          Sets a stack header's HTML contents.
 void setHeaderText(int index, java.lang.String text)
          Sets a stack header's text contents.
 void showWidget(int index)
          Shows the widget at the specified index and fires events.
 void showWidget(int index, boolean fireEvents)
          Shows the widget at the specified index.
 void showWidget(Widget child)
          Shows the specified widget and fires events.
 void showWidget(Widget child, boolean fireEvents)
          Shows the specified widget.
 
Methods inherited from class com.google.gwt.user.client.ui.ResizeComposite
initWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isOrWasAttached, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
 
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, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, sinkBitlessEvent, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

StackLayoutPanel

public StackLayoutPanel(Style.Unit unit)
Creates an empty stack panel.

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

add

public void add(Widget w)
Description copied from interface: HasWidgets
Adds a child widget.

Specified by:
add in interface HasWidgets
Parameters:
w - the widget to be added

add

public void add(Widget widget,
                SafeHtml header,
                double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.

Parameters:
widget - the child widget to be added
header - the html to be shown on its header
headerSize - the size of the header widget

add

public void add(Widget widget,
                java.lang.String header,
                boolean asHtml,
                double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.

Parameters:
widget - the child widget to be added
header - the text to be shown on its header
asHtml - true to treat the specified text as HTML
headerSize - the size of the header widget

add

public void add(IsWidget widget,
                java.lang.String header,
                boolean asHtml,
                double headerSize)
Overloaded version for IsWidget.

See Also:
add(Widget,String,boolean,double)

add

public void add(Widget widget,
                java.lang.String header,
                double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.

Parameters:
widget - the child widget to be added
header - the text to be shown on its header
headerSize - the size of the header widget

add

public void add(Widget widget,
                Widget header,
                double headerSize)
Adds a child widget to this stack, along with a widget representing the stack header.

Parameters:
widget - the child widget to be added
header - the header widget
headerSize - the size of the header widget

add

public void add(IsWidget widget,
                IsWidget header,
                double headerSize)
Overloaded version for IsWidget.

See Also:
add(Widget,Widget,double)

addBeforeSelectionHandler

public HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<java.lang.Integer> handler)
Description copied from interface: HasBeforeSelectionHandlers
Adds a BeforeSelectionEvent handler.

Specified by:
addBeforeSelectionHandler in interface HasBeforeSelectionHandlers<java.lang.Integer>
Parameters:
handler - the handler
Returns:
the registration for the event

addSelectionHandler

public HandlerRegistration addSelectionHandler(SelectionHandler<java.lang.Integer> handler)
Description copied from interface: HasSelectionHandlers
Adds a SelectionEvent handler.

Specified by:
addSelectionHandler in interface HasSelectionHandlers<java.lang.Integer>
Parameters:
handler - the handler
Returns:
the registration for the event

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,
                    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

clear

public void clear()
Description copied from interface: HasWidgets
Removes all child widgets.

Specified by:
clear in interface HasWidgets

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

getAnimationDuration

public int getAnimationDuration()
Get the duration of the animated transition between children.

Returns:
the duration in milliseconds

getHeaderWidget

public Widget getHeaderWidget(int index)
Gets the widget in the stack header at the given index.

Parameters:
index - the index of the stack header to be retrieved
Returns:
the header widget

getHeaderWidget

public Widget getHeaderWidget(Widget child)
Gets the widget in the stack header associated with the given child widget.

Parameters:
child - the child whose stack header is to be retrieved
Returns:
the header widget

getVisibleIndex

public int getVisibleIndex()
Gets the currently-selected index.

Returns:
the selected index, or -1 if none is selected

getVisibleWidget

public Widget getVisibleWidget()
Gets the currently-selected widget.

Returns:
the selected widget, or null if none exist

getWidget

public Widget getWidget(int index)
Description copied from interface: IndexedPanel
Gets the child widget at the specified index.

Specified by:
getWidget in interface IndexedPanel
Parameters:
index - the child widget's index
Returns:
the child widget

getWidgetCount

public int getWidgetCount()
Description copied from interface: IndexedPanel
Gets the number of child widgets in this panel.

Specified by:
getWidgetCount in interface IndexedPanel
Returns:
the number of children

getWidgetIndex

public int getWidgetIndex(IsWidget child)
Specified by:
getWidgetIndex in interface IndexedPanel.ForIsWidget

getWidgetIndex

public int getWidgetIndex(Widget child)
Description copied from interface: IndexedPanel
Gets the index of the specified child widget.

Specified by:
getWidgetIndex in interface IndexedPanel
Parameters:
child - the widget to be found
Returns:
the widget's index, or -1 if it is not a child of this panel

insert

public void insert(Widget child,
                   SafeHtml html,
                   double headerSize,
                   int beforeIndex)
Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters:
child - the widget to be added
html - the safe html to be shown on its header
headerSize - the size of the header widget
beforeIndex - the index before which it will be inserted

insert

public void insert(Widget child,
                   java.lang.String text,
                   boolean asHtml,
                   double headerSize,
                   int beforeIndex)
Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters:
child - the widget to be added
text - the text to be shown on its header
asHtml - true to treat the specified text as HTML
headerSize - the size of the header widget
beforeIndex - the index before which it will be inserted

insert

public void insert(Widget child,
                   java.lang.String text,
                   double headerSize,
                   int beforeIndex)
Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters:
child - the widget to be added
text - the text to be shown on its header
headerSize - the size of the header widget
beforeIndex - the index before which it will be inserted

insert

public void insert(Widget child,
                   Widget header,
                   double headerSize,
                   int beforeIndex)
Inserts a widget into the panel. If the Widget is already attached, it will be moved to the requested index.

Parameters:
child - the widget to be added
header - the widget to be placed in the associated header
headerSize - the size of the header widget
beforeIndex - the index before which it will be inserted

iterator

public java.util.Iterator<Widget> iterator()
Description copied from interface: HasWidgets
Gets an iterator for the contained widgets. This iterator is required to implement Iterator.remove().

Specified by:
iterator in interface HasWidgets
Specified by:
iterator in interface java.lang.Iterable<Widget>

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
Overrides:
onResize in class ResizeComposite

remove

public boolean remove(int index)
Description copied from interface: IndexedPanel
Removes the widget at the specified index.

Specified by:
remove in interface IndexedPanel
Parameters:
index - the index of the widget to be removed
Returns:
false if the widget is not present

remove

public boolean remove(Widget child)
Description copied from interface: HasWidgets
Removes a child widget.

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

setAnimationDuration

public void setAnimationDuration(int duration)
Set the duration of the animated transition between children.

Parameters:
duration - the duration in milliseconds.

setHeaderHTML

public void setHeaderHTML(int index,
                          java.lang.String html)
Sets a stack header's HTML contents. Use care when setting an object's HTML; it is an easy way to expose script-based security problems. Consider using setHeaderHTML(int, SafeHtml) or setHeaderText(int, String) whenever possible.

Parameters:
index - the index of the header whose HTML is to be set
html - the header's new HTML contents

setHeaderHTML

public void setHeaderHTML(int index,
                          SafeHtml html)
Sets a stack header's HTML contents.

Parameters:
index - the index of the header whose HTML is to be set
html - the header's new HTML contents

setHeaderText

public void setHeaderText(int index,
                          java.lang.String text)
Sets a stack header's text contents.

Parameters:
index - the index of the header whose text is to be set
text - the object's new text

showWidget

public void showWidget(int index)
Shows the widget at the specified index and fires events.

Parameters:
index - the index of the child widget to be shown.

showWidget

public void showWidget(int index,
                       boolean fireEvents)
Shows the widget at the specified index.

Parameters:
index - the index of the child widget to be shown.
fireEvents - true to fire events, false not to

showWidget

public void showWidget(Widget child)
Shows the specified widget and fires events.

Parameters:
child - the child widget to be shown.

showWidget

public void showWidget(Widget child,
                       boolean fireEvents)
Shows the specified widget.

Parameters:
child - the child widget to be shown.
fireEvents - true to fire events, false not to

onLoad

protected void onLoad()
Description copied from class: Widget
This method is called immediately after a widget becomes attached to the browser's document.

Overrides:
onLoad in class Widget

GWT 2.7.0