public class TabLayoutPanel extends ResizeComposite implements HasWidgets, ProvidesResize, IndexedPanel.ForIsWidget, AnimatedLayout, HasBeforeSelectionHandlers<java.lang.Integer>, HasSelectionHandlers<java.lang.Integer>
This widget will only work in standards mode, which requires that the HTML page in which it is run have an explicit <!DOCTYPE> declaration.
public class TabLayoutPanelExample implements EntryPoint { public void onModuleLoad() { // Create a three-item tab panel, with the tab area 1.5em tall. TabLayoutPanel p = new TabLayoutPanel(1.5, Unit.EM); p.add(new HTML("this"), "[this]"); p.add(new HTML("that"), "[that]"); p.add(new HTML("the other"), "[the other]"); // 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); } }
A TabLayoutPanel element in a UiBinder
template must have a barHeight
attribute with a double
value, and may have a barUnit
attribute with a
Style.Unit
value.
barUnit
defaults to PX.
The children of a TabLayoutPanel element are laid out in <g:tab>
elements. Each tab 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:TabLayoutPanel barUnit='EM' barHeight='3'> <g:tab> <g:header size='7'><b>HTML</b> header</g:header> <g:Label>able</g:Label> </g:tab> <g:tab> <g:customHeader size='7'> <g:Label>Custom header</g:Label> </g:customHeader> <g:Label>baker</g:Label> </g:tab> </g:TabLayoutPanel>
UIObject.DebugIdImpl, UIObject.DebugIdImplEnabled
HasWidgets.ForIsWidget
eventsToSink
DEBUG_ID_PREFIX, MISSING_ELEMENT_ERROR, SETELEMENT_TWICE_ERROR
Constructor and Description |
---|
TabLayoutPanel(double barHeight,
Style.Unit barUnit)
Creates an empty tab panel.
|
Modifier and Type | Method and Description |
---|---|
void |
add(IsWidget w)
Convenience overload to allow
IsWidget to be used directly. |
void |
add(IsWidget w,
IsWidget tab)
Convenience overload to allow
IsWidget to be used directly. |
void |
add(IsWidget w,
java.lang.String text)
Convenience overload to allow
IsWidget to be used directly. |
void |
add(IsWidget w,
java.lang.String text,
boolean asHtml)
Convenience overload to allow
IsWidget to be used directly. |
void |
add(Widget w)
Adds a child widget.
|
void |
add(Widget child,
SafeHtml html)
Adds a widget to the panel.
|
void |
add(Widget child,
java.lang.String text)
Adds a widget to the panel.
|
void |
add(Widget child,
java.lang.String text,
boolean asHtml)
Adds a widget to the panel.
|
void |
add(Widget child,
Widget tab)
Adds a widget to the panel.
|
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 tabs.
|
int |
getSelectedIndex()
Gets the index of the currently-selected tab.
|
Widget |
getTabWidget(int index)
Gets the widget in the tab at the given index.
|
Widget |
getTabWidget(IsWidget child)
Convenience overload to allow
IsWidget to be used directly. |
Widget |
getTabWidget(Widget child)
Gets the widget in the tab associated with the given child widget.
|
Widget |
getWidget(int index)
Returns the widget at the given index.
|
int |
getWidgetCount()
Returns the number of tabs and widgets.
|
int |
getWidgetIndex(IsWidget child)
Convenience overload to allow
IsWidget to be used directly. |
int |
getWidgetIndex(Widget child)
Returns the index of the given child, or -1 if it is not a child.
|
void |
insert(IsWidget child,
int beforeIndex)
Convenience overload to allow
IsWidget to be used directly. |
void |
insert(IsWidget child,
IsWidget tab,
int beforeIndex)
Convenience overload to allow
IsWidget to be used directly. |
void |
insert(IsWidget child,
java.lang.String text,
boolean asHtml,
int beforeIndex)
Convenience overload to allow
IsWidget to be used directly. |
void |
insert(IsWidget child,
java.lang.String text,
int beforeIndex)
Convenience overload to allow
IsWidget to be used directly. |
void |
insert(Widget child,
int beforeIndex)
Inserts a widget into the panel.
|
void |
insert(Widget child,
SafeHtml html,
int beforeIndex)
Inserts a widget into the panel.
|
void |
insert(Widget child,
java.lang.String text,
boolean asHtml,
int beforeIndex)
Inserts a widget into the panel.
|
void |
insert(Widget child,
java.lang.String text,
int beforeIndex)
Inserts a widget into the panel.
|
void |
insert(Widget child,
Widget tab,
int beforeIndex)
Inserts a widget into the panel.
|
boolean |
isAnimationVertical()
Check whether or not transitions slide in vertically or horizontally.
|
java.util.Iterator<Widget> |
iterator()
Gets an iterator for the contained widgets.
|
boolean |
remove(int index)
Removes the widget at the specified index.
|
boolean |
remove(Widget w)
Removes a child widget.
|
void |
selectTab(int index)
Programmatically selects the specified tab and fires events.
|
void |
selectTab(int index,
boolean fireEvents)
Programmatically selects the specified tab.
|
void |
selectTab(IsWidget child)
Convenience overload to allow
IsWidget to be used directly. |
void |
selectTab(IsWidget child,
boolean fireEvents)
Convenience overload to allow
IsWidget to be used directly. |
void |
selectTab(Widget child)
Programmatically selects the specified tab and fires events.
|
void |
selectTab(Widget child,
boolean fireEvents)
Programmatically selects the specified tab.
|
void |
setAnimationDuration(int duration)
Set the duration of the animated transition between tabs.
|
void |
setAnimationVertical(boolean isVertical)
Set whether or not transitions slide in vertically or horizontally.
|
void |
setTabHTML(int index,
SafeHtml html)
Sets a tab's HTML contents.
|
void |
setTabHTML(int index,
java.lang.String html)
Sets a tab's HTML contents.
|
void |
setTabText(int index,
java.lang.String text)
Sets a tab's text contents.
|
initWidget, onResize
claimElement, getWidget, initializeClaimedElement, isAttached, onAttach, onBrowserEvent, onDetach, render, render, resolvePotentialElement, setWidget
addAttachHandler, addBitlessDomHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, ensureHandlers, fireEvent, getHandlerCount, getHandlerManager, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, replaceElement, setLayoutData, setParent, sinkEvents, unsinkEvents
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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
fireEvent
public TabLayoutPanel(double barHeight, Style.Unit barUnit)
barHeight
- the size of the tab barbarUnit
- the unit in which the tab bar size is specifiedpublic void add(IsWidget w, IsWidget tab)
IsWidget
to be used directly.public void add(IsWidget w, java.lang.String text)
IsWidget
to be used directly.public void add(IsWidget w, java.lang.String text, boolean asHtml)
IsWidget
to be used directly.public void add(Widget w)
HasWidgets
add
in interface HasWidgets
w
- the widget to be addedpublic void add(Widget child, java.lang.String text)
child
- the widget to be addedtext
- the text to be shown on its tabpublic void add(Widget child, SafeHtml html)
child
- the widget to be addedhtml
- the html to be shown on its tabpublic void add(Widget child, java.lang.String text, boolean asHtml)
child
- the widget to be addedtext
- the text to be shown on its tabasHtml
- true
to treat the specified text as HTMLpublic void add(Widget child, Widget tab)
child
- the widget to be addedtab
- the widget to be placed in the associated tabpublic HandlerRegistration addBeforeSelectionHandler(BeforeSelectionHandler<java.lang.Integer> handler)
HasBeforeSelectionHandlers
BeforeSelectionEvent
handler.addBeforeSelectionHandler
in interface HasBeforeSelectionHandlers<java.lang.Integer>
handler
- the handlerpublic HandlerRegistration addSelectionHandler(SelectionHandler<java.lang.Integer> handler)
HasSelectionHandlers
SelectionEvent
handler.addSelectionHandler
in interface HasSelectionHandlers<java.lang.Integer>
handler
- the handlerpublic void animate(int duration)
AnimatedLayout
animate
in interface AnimatedLayout
duration
- the animation duration, in millisecondspublic void animate(int duration, Layout.AnimationCallback callback)
AnimatedLayout
This method provides a callback that will be informed of animation updates. This can be used to create more complex animation effects.
animate
in interface AnimatedLayout
duration
- the animation duration, in millisecondscallback
- the animation callbackpublic void clear()
HasWidgets
clear
in interface HasWidgets
public void forceLayout()
AnimatedLayout
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)
.
forceLayout
in interface AnimatedLayout
AnimatedLayout.animate(int)
,
AnimatedLayout.animate(int, Layout.AnimationCallback)
public int getAnimationDuration()
public int getSelectedIndex()
-1
if none is selected.public Widget getTabWidget(int index)
index
- the index of the tab to be retrievedpublic Widget getTabWidget(IsWidget child)
IsWidget
to be used directly.public Widget getTabWidget(Widget child)
child
- the child whose tab is to be retrievedpublic Widget getWidget(int index)
getWidget
in interface IndexedPanel
index
- the child widget's indexpublic int getWidgetCount()
getWidgetCount
in interface IndexedPanel
public int getWidgetIndex(IsWidget child)
IsWidget
to be used directly.getWidgetIndex
in interface IndexedPanel.ForIsWidget
public int getWidgetIndex(Widget child)
getWidgetIndex
in interface IndexedPanel
child
- the widget to be found-1
if it is not a child of this
panelpublic void insert(IsWidget child, int beforeIndex)
IsWidget
to be used directly.public void insert(IsWidget child, IsWidget tab, int beforeIndex)
IsWidget
to be used directly.public void insert(IsWidget child, java.lang.String text, boolean asHtml, int beforeIndex)
IsWidget
to be used directly.public void insert(IsWidget child, java.lang.String text, int beforeIndex)
IsWidget
to be used directly.public void insert(Widget child, int beforeIndex)
child
- the widget to be addedbeforeIndex
- the index before which it will be insertedpublic void insert(Widget child, SafeHtml html, int beforeIndex)
child
- the widget to be addedhtml
- the html to be shown on its tabbeforeIndex
- the index before which it will be insertedpublic void insert(Widget child, java.lang.String text, boolean asHtml, int beforeIndex)
child
- the widget to be addedtext
- the text to be shown on its tabasHtml
- true
to treat the specified text as HTMLbeforeIndex
- the index before which it will be insertedpublic void insert(Widget child, java.lang.String text, int beforeIndex)
child
- the widget to be addedtext
- the text to be shown on its tabbeforeIndex
- the index before which it will be insertedpublic void insert(Widget child, Widget tab, int beforeIndex)
child
- the widget to be addedtab
- the widget to be placed in the associated tabbeforeIndex
- the index before which it will be insertedpublic boolean isAnimationVertical()
public java.util.Iterator<Widget> iterator()
HasWidgets
Iterator.remove()
.iterator
in interface HasWidgets
iterator
in interface java.lang.Iterable<Widget>
public boolean remove(int index)
IndexedPanel
remove
in interface IndexedPanel
index
- the index of the widget to be removedfalse
if the widget is not presentpublic boolean remove(Widget w)
HasWidgets
remove
in interface HasWidgets
w
- the widget to be removedtrue
if the widget was presentpublic void selectTab(int index)
index
- the index of the tab to be selectedpublic void selectTab(int index, boolean fireEvents)
index
- the index of the tab to be selectedfireEvents
- true to fire events, false not topublic void selectTab(IsWidget child)
IsWidget
to be used directly.public void selectTab(IsWidget child, boolean fireEvents)
IsWidget
to be used directly.public void selectTab(Widget child)
child
- the child whose tab is to be selectedpublic void selectTab(Widget child, boolean fireEvents)
child
- the child whose tab is to be selectedfireEvents
- true to fire events, false not topublic void setAnimationDuration(int duration)
duration
- the duration in milliseconds.public void setAnimationVertical(boolean isVertical)
isVertical
- true for vertical transitions, false for horizontalpublic void setTabHTML(int index, java.lang.String html)
setTabHTML(int, SafeHtml)
or
setTabText(int, String)
whenever possible.index
- the index of the tab whose HTML is to be sethtml
- the tab's new HTML contentspublic void setTabHTML(int index, SafeHtml html)
index
- the index of the tab whose HTML is to be sethtml
- the tab's new HTML contentspublic void setTabText(int index, java.lang.String text)
index
- the index of the tab whose text is to be settext
- the object's new text