Class StackLayoutPanel
- All Implemented Interfaces:
HasAttachHandlers,HasBeforeSelectionHandlers<Integer>,HasSelectionHandlers<Integer>,HasHandlers,EventListener,AnimatedLayout,HasVisibility,HasWidgets,IndexedPanel,IndexedPanel.ForIsWidget,IsRenderable,IsWidget,ProvidesResize,RequiresResize,Iterable<Widget>
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.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 TypeMethodDescriptionvoidOverloaded version for IsWidget.voidOverloaded version for IsWidget.voidAdds a child widget.voidAdds a child widget to this stack, along with a widget representing the stack header.voidAdds a child widget to this stack, along with a widget representing the stack header.voidAdds a child widget to this stack, along with a widget representing the stack header.voidAdds a child widget to this stack, along with a widget representing the stack header.Adds aBeforeSelectionEventhandler.addSelectionHandler(SelectionHandler<Integer> handler) Adds aSelectionEventhandler.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.voidclear()Removes all child widgets.voidLayout children immediately.intGet the duration of the animated transition between children.getHeaderWidget(int index) Gets the widget in the stack header at the given index.getHeaderWidget(Widget child) Gets the widget in the stack header associated with the given child widget.intGets the currently-selected index.Gets the currently-selected widget.getWidget(int index) Gets the child widget at the specified index.intGets the number of child widgets in this panel.intgetWidgetIndex(IsWidget child) intgetWidgetIndex(Widget child) Gets the index of the specified child widget.voidInserts a widget into the panel.voidInserts a widget into the panel.voidInserts a widget into the panel.voidInserts a widget into the panel.iterator()Gets an iterator for the contained widgets.protected voidonLoad()This method is called immediately after a widget becomes attached to the browser's document.voidonResize()This method must be called whenever the implementor's size has been modified.booleanremove(int index) Removes the widget at the specified index.booleanRemoves a child widget.voidsetAnimationDuration(int duration) Set the duration of the animated transition between children.voidsetHeaderHTML(int index, SafeHtml html) Sets a stack header's HTML contents.voidsetHeaderHTML(int index, String html) Sets a stack header's HTML contents.voidsetHeaderText(int index, String text) Sets a stack header's text contents.voidshowWidget(int index) Shows the widget at the specified index and fires events.voidshowWidget(int index, boolean fireEvents) Shows the widget at the specified index.voidshowWidget(Widget child) Shows the specified widget and fires events.voidshowWidget(Widget child, boolean fireEvents) Shows the specified widget.Methods inherited from class com.google.gwt.user.client.ui.ResizeComposite
initWidgetMethods inherited from class com.google.gwt.user.client.ui.Composite
claimElement, getWidget, initializeClaimedElement, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidgetMethods 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, 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, 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 com.google.gwt.event.shared.HasHandlers
fireEventMethods inherited from interface java.lang.Iterable
forEach, spliterator
-
Constructor Details
-
StackLayoutPanel
Creates an empty stack panel.- Parameters:
unit- the unit to be used for layout
-
-
Method Details
-
add
Description copied from interface:HasWidgetsAdds a child widget.- Specified by:
addin interfaceHasWidgets- Parameters:
w- the widget to be added
-
add
Adds a child widget to this stack, along with a widget representing the stack header.- Parameters:
widget- the child widget to be addedheader- the text to be shown on its headerasHtml-trueto treat the specified text as HTMLheaderSize- the size of the header widget
-
add
Overloaded version for IsWidget.- See Also:
-
add
Adds a child widget to this stack, along with a widget representing the stack header.- Parameters:
widget- the child widget to be addedheader- the text to be shown on its headerheaderSize- the size of the header widget
-
add
Adds a child widget to this stack, along with a widget representing the stack header.- Parameters:
widget- the child widget to be addedheader- the header widgetheaderSize- the size of the header widget
-
add
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
-
clear
public void clear()Description copied from interface:HasWidgetsRemoves all child widgets.- Specified by:
clearin interfaceHasWidgets
-
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:
-
getAnimationDuration
public int getAnimationDuration()Get the duration of the animated transition between children.- Returns:
- the duration in milliseconds
-
getHeaderWidget
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
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
-1if none is selected
-
getVisibleWidget
Gets the currently-selected widget.- Returns:
- the selected widget, or
nullif none exist
-
getWidget
Description copied from interface:IndexedPanelGets the child widget at the specified index.- Specified by:
getWidgetin interfaceIndexedPanel- Parameters:
index- the child widget's index- Returns:
- the child widget
-
getWidgetCount
public int getWidgetCount()Description copied from interface:IndexedPanelGets the number of child widgets in this panel.- Specified by:
getWidgetCountin interfaceIndexedPanel- Returns:
- the number of children
-
getWidgetIndex
- Specified by:
getWidgetIndexin interfaceIndexedPanel.ForIsWidget
-
getWidgetIndex
Description copied from interface:IndexedPanelGets the index of the specified child widget.- Specified by:
getWidgetIndexin interfaceIndexedPanel- Parameters:
child- the widget to be found- Returns:
- the widget's index, or
-1if it is not a child of this panel
-
insert
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 addedtext- the text to be shown on its headerasHtml-trueto treat the specified text as HTMLheaderSize- the size of the header widgetbeforeIndex- the index before which it will be inserted
-
insert
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 addedtext- the text to be shown on its headerheaderSize- the size of the header widgetbeforeIndex- the index before which it will be inserted
-
insert
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 addedheader- the widget to be placed in the associated headerheaderSize- the size of the header widgetbeforeIndex- the index before which it will be inserted
-
iterator
Description copied from interface:HasWidgetsGets an iterator for the contained widgets. This iterator is required to implementIterator.remove().- Specified by:
iteratorin interfaceHasWidgets- Specified by:
iteratorin interfaceIterable<Widget>
-
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- Overrides:
onResizein classResizeComposite
-
remove
public boolean remove(int index) Description copied from interface:IndexedPanelRemoves the widget at the specified index.- Specified by:
removein interfaceIndexedPanel- Parameters:
index- the index of the widget to be removed- Returns:
falseif the widget is not present
-
remove
Description copied from interface:HasWidgetsRemoves a child widget.- Specified by:
removein interfaceHasWidgets- Parameters:
child- the widget to be removed- Returns:
trueif 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
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 usingsetHeaderHTML(int, SafeHtml)orsetHeaderText(int, String)whenever possible.- Parameters:
index- the index of the header whose HTML is to be sethtml- the header's new HTML contents
-
setHeaderText
Sets a stack header's text contents.- Parameters:
index- the index of the header whose text is to be settext- 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
Shows the specified widget and fires events.- Parameters:
child- the child widget to be shown.
-
showWidget
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:WidgetThis method is called immediately after a widget becomes attached to the browser's document.
-