public class TabbedContainer extends ClippedContainer implements Scrollable, ControlAnimation.AnimationFinished
Here is an example showing a tab bar being used:
public class MyProgram extends MainWindow { TabbedContainer tab; public void initUI() { String names[] = {"Edition","Report"}; tab = new TabbedContainer(names); add(tab); tab.setGaps(2,2,2,2); // set it before setting the rect tab.setRect(LEFT,TOP,FILL,FILL); tab.setContainer(0,new Edition()); // replace container 1 by a class that extends Container. tab.getContainer(1).add(new Label("Not implemented"),CENTER,CENTER); } public void onEvent(Event event) { if (event.type == ControlEvent.PRESSED && event.target == tp) { int activeIndex = tp.getActiveTab(); ... handle tab being pressed } } }Here's another sample that will show two TabbedContainers, one with images and another one with scrolling tabs. Note that you must create img1.png and img2.png.
TabbedContainer tp1 = new TabbedContainer(new Image[]{new Image("img1.png"), new Image("img2.png")}, null); add(tp1); tp1.setRect(LEFT,TOP,Settings.screenWidth/2,Settings.screenHeight/2); tp1.activeTabBackColor = Color.getRGB(222,222,222); TabbedContainer tp2 = new TabbedContainer(new String[]{"verinha","marcelo","denise","guilherme","renato","michelle","rafael","barbara","lucas","ronaldo","nenem",}); add(tp2); tp2.setRect(LEFT,AFTER+2,FILL,FILL);When the user interface is Android, the tabs do not look good if the background is the same of the parent's. In this case, we force the background to be slighly darker. There are a few fields that you can use to change the color, like activeTabBackColor, useOnTabTheContainerColor and pressedColor. Important: starting in TotalCross 1.3, with Settings.fingerTouch=true, you CANNOT call setRect in your container. Otherwise, the flick and drag will not work and your container will be positioned incorrectly.
Control.TranslucentShape
Modifier and Type | Field and Description |
---|---|
int |
activeTabBackColor
This color is the one used to paint the background of the active tab.
|
static boolean |
allowFlick
Set to false to disable flicking between tabs.
|
boolean |
allSameWidth
Set to true to make all tabs have the same width.
|
int |
animationTime
Animation time when you click in the tab.
|
int |
arrowsColor
Set the arrows color right after the constructor and after calling setCaptionsColor, which also change this property.
|
boolean |
autoShrinkCaptions
Set to true to automatically shrink the captions to prevent using arrows.
|
int |
extraTabHeight
Define an extra height for the tabs.
|
protected Flick |
flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
|
boolean |
flickIntoDisabledTabs
In finger touch devices, the user still can flick into a disabled tab.
|
int |
lastActiveTab
Stores the last active tab index, or -1 if none was previously selected.
|
int |
pressedColor
Set the color when the user clicks on the tab.
|
boolean |
showArrows
Enables or not the arrows if scroll is needed.
|
static byte |
TABS_BOTTOM
To be used on the setType method: specifies that the tabs will be placed on the bottom.
|
static byte |
TABS_NONE
To be used on the setType method: specifies that the tabs will be hidden and you will be responsible to change them.
|
static byte |
TABS_TOP
To be used on the setType method: specifies that the tabs will be placed on the top.
|
int[] |
tabsBackColor
Sets the colors used on each tab.
|
int |
unselectedTextColor
The color used for the text of unselected tabs.
|
boolean |
useBorder2
Set to true to enable the alternative tab border
|
boolean |
useOnTabTheContainerColor
Sets the tabs with the same colors of the container.
|
bagClipX0, bagClipXf, bagClipY0, bagClipYf, lastMid, verticalOnly
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
Constructor and Description |
---|
TabbedContainer(Image[] imgCaptions)
Constructs a tab bar control with images as captions, using the given color as transparent color.
|
TabbedContainer(Image[] imgCaptions,
int transparentColor)
Constructor to keep compilation compatibility with TC 1; transparentColor is ignored.
|
TabbedContainer(java.lang.String[] strCaptions)
Constructs a tab bar control with Strings as captions.
|
Modifier and Type | Method and Description |
---|---|
boolean |
canScrollContent(int direction,
java.lang.Object target)
Checks if there is room to flick this container in the given direction.
|
void |
changeHighlighted(Container p,
boolean forward)
Tranfer the focus between the containers on this TabbedContainer
|
protected void |
computeClipRect() |
void |
computeTabsRect()
compute the rects that represents each tab on the screen.
|
void |
flickEnded(boolean atPenDown)
Called when the flick animation is ended.
|
boolean |
flickStarted()
Called when the flick animation is started.
|
Container |
getActiveContainer()
Returns the container of the active tab.
|
int |
getActiveTab()
Returns the index of the selected tab
|
int |
getCaptionColor()
Gets the text color of the captions.
|
Rect |
getClientRect()
Returns the area excluding the tabs and borders for this TabbedContainer.
|
protected void |
getClientRect(Rect r)
Returns the area excluding the tabs and borders for this TabbedContainer.
|
Container |
getContainer(int i)
Returns the Container for tab i
|
int |
getEffectH() |
int |
getEffectW() |
int |
getEffectX() |
int |
getEffectY() |
Flick |
getFlick()
Returns the current flick object.
|
void |
getFocusableControls(Vector v)
Get a list of child controls of this container which are focus candidates
|
int |
getPreferredHeight()
Returns the caption height for this TabbedContainer.
|
int |
getPreferredWidth()
Returns the minimum width (based on the sizes of the captions) for this TabbedContainer
|
int |
getScrollPosition(int direction)
Returns the current position given the direction.
|
int |
getTabColor(int tab)
Returns the color of the given tab.
|
int |
getTabCount()
Returns the number of tabs.
|
int |
getType()
Returns the tabs type.
|
Control |
handleGeographicalFocusChangeKeys(KeyEvent ke)
Used by the main event loop to give the currently focused control an opportunity to act directly on
the KeyEvent.
|
void |
initUI()
Called to initialize the User Interface of this container.
|
boolean |
isAtTop()
Deprecated.
Use getType
|
boolean |
isEnabled(int tabIndex)
Returns if the given tab index is enabled.
|
void |
onAnimationFinished(ControlAnimation anim) |
protected void |
onBoundsChanged(boolean screenChanged)
Used internally.
|
protected void |
onColorsChanged(boolean colorsChanged)
Called after a setEnabled, setForeColor and setBackColor and when a control has
been added to a Container.
|
void |
onEvent(Event event)
Called by the system to pass events to the tab bar control.
|
void |
onFontChanged()
Compute the rectangles of the tabs based on the selected
(bolded) and unselected (plain) titles.
|
void |
onPaint(Graphics g)
Called by the system to draw the tab bar.
|
void |
reposition()
Reposition this control, calling again setRect with the original parameters.
|
void |
resizeHeight()
Resizes the height of each added container and sets the height of this TabbedContainer to the maximum height of the containers.
|
boolean |
scrollContent(int xDelta,
int yDelta,
boolean fromFlick)
Performs a relative move.
|
void |
setActiveIcon(Image newActiveIcon)
Sets the active icon.
|
void |
setActiveTab(int tab)
Sets the currently active tab, animating it.
|
void |
setActiveTab(int tab,
boolean animate)
Sets the currently active tab.
|
void |
setBorderStyle(byte style)
Sets the type of border.
|
void |
setCaptionColor(int capColor)
Sets the text color of the captions in the tabs.
|
void |
setCaptions(java.lang.String[] caps)
Changes the tab captions.
|
void |
setContainer(int i,
Container container)
Replaces the default created Container with the given one.
|
void |
setEnabled(boolean b)
Sets if this container and all childrens can or not accept events
|
void |
setEnabled(int tabIndex,
boolean on)
Sets the given tab index as enabled or not.
|
void |
setHighlighting()
Only return to highlighting when we want
|
void |
setIcons(Image[] icons)
Set the given icons to appear at the top (or bottom, if TABS_BOTTOM) of a text TabbedContainer.
|
void |
setIcons(Image[] icons,
Image activeIcon)
Set the given icons to appear at the top (or bottom, if TABS_BOTTOM) of a text TabbedContainer.
|
void |
setNinePatch(Image img,
int side,
int corner)
Set the NinePatch of the control.
|
void |
setType(byte type)
Sets the position of the tabs.
|
boolean |
wasScrolled()
Returns true if the control was scrolled since last pen down
|
paintChildren
add, add, add, add, add, broadcastEvent, clear, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getFirstChild, getInsets, incLastX, incLastY, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, remove, removeAll, resize, resizeWidth, setBorderRadius, setFocusTraversable, setInsets, setPressColor, setPressed, swapToTopmostWindow
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
public int arrowsColor
public boolean useBorder2
public boolean autoShrinkCaptions
public boolean showArrows
public int activeTabBackColor
Control.setBackColor(int)
,
useOnTabTheContainerColor
,
tabsBackColor
public int[] tabsBackColor
Control.setBackColor(int)
,
useOnTabTheContainerColor
,
activeTabBackColor
public boolean useOnTabTheContainerColor
Control.setBackColor(int)
,
tabsBackColor
,
activeTabBackColor
public int lastActiveTab
public boolean flickIntoDisabledTabs
public static final byte TABS_TOP
public static final byte TABS_BOTTOM
public static final byte TABS_NONE
public int pressedColor
public boolean allSameWidth
public int extraTabHeight
setIcons(Image[])
public int unselectedTextColor
protected Flick flick
public static boolean allowFlick
TabbedContainer.allowFlick = false; TabbedContainer tc = new TabbedContainer(caps); TabbedContainer.allowFlick = true;
public int animationTime
public TabbedContainer(java.lang.String[] strCaptions)
public TabbedContainer(Image[] imgCaptions, int transparentColor)
public TabbedContainer(Image[] imgCaptions)
protected void computeClipRect()
computeClipRect
in class ClippedContainer
public void initUI()
Container
public int getTabCount()
public void setEnabled(int tabIndex, boolean on)
on
- If true, the tab is enabled, if false it is disabled.tabIndex
- The tab's index (0 to count-1)setActiveTab(int)
public boolean isEnabled(int tabIndex)
public void setActiveIcon(Image newActiveIcon)
public void setIcons(Image[] icons)
public void setIcons(Image[] icons, Image activeIcon)
public void setType(byte type)
public int getType()
public Container getContainer(int i)
public void setBorderStyle(byte style)
setBorderStyle
in class Container
Container.BORDER_NONE
,
Container.BORDER_LOWERED
,
Container.BORDER_RAISED
,
Container.BORDER_SIMPLE
,
Container.BORDER_TOP
,
Container.BORDER_ROUNDED
public void setContainer(int i, Container container)
public void setActiveTab(int tab)
public void setActiveTab(int tab, boolean animate)
public void onAnimationFinished(ControlAnimation anim)
onAnimationFinished
in interface ControlAnimation.AnimationFinished
public int getActiveTab()
public Container getActiveContainer()
public int getPreferredHeight()
getPreferredHeight
in class Control
public int getPreferredWidth()
getPreferredWidth
in class Control
public void setNinePatch(Image img, int side, int corner)
Control
setNinePatch
in class Control
img
- The image to make the NinePatch.
The image must be on a NinePatch format.side
- The size, in pixels, of the NinePatch's cornercorner
- The size, in pixels, of the NinePatch's side.protected void onBoundsChanged(boolean screenChanged)
onBoundsChanged
in class Control
screenChanged
- If the bounds were changed due to a screen change (rotation, collapse)public void setEnabled(boolean b)
Container
setEnabled
in class Container
public void computeTabsRect()
public void onFontChanged()
onFontChanged
in class Control
protected void onColorsChanged(boolean colorsChanged)
Control
onColorsChanged
in class Container
public void onPaint(Graphics g)
public int getEffectW()
getEffectW
in class Control
public int getEffectH()
getEffectH
in class Control
public int getEffectX()
getEffectX
in class Control
public int getEffectY()
getEffectY
in class Control
public int getTabColor(int tab)
public void setCaptionColor(int capColor)
public int getCaptionColor()
public Rect getClientRect()
getClientRect
in class Container
Container.getClientRect(Rect)
protected void getClientRect(Rect r)
getClientRect
in class Container
public void onEvent(Event event)
public void changeHighlighted(Container p, boolean forward)
changeHighlighted
in class Control
public void setHighlighting()
setHighlighting
in class Container
public void reposition()
Control
reposition
in class Control
public void getFocusableControls(Vector v)
Container
getFocusableControls
in class Container
v
- A vector into which to add the focus candidates.public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Control
handleGeographicalFocusChangeKeys
in class Control
ke
- The KeyEvent to be processedSettings.geographicalFocus
@Deprecated public boolean isAtTop()
public void resizeHeight()
resizeHeight
in class Container
Container.resizeWidth()
,
Container.resize()
public boolean flickStarted()
Scrollable
flickStarted
in interface Scrollable
public void flickEnded(boolean atPenDown)
Scrollable
flickEnded
in interface Scrollable
atPenDown
- Flag indicating if the animation ended due to a pendown event.public boolean canScrollContent(int direction, java.lang.Object target)
Scrollable
canScrollContent
in interface Scrollable
direction
- The direction we want to flick given by one of the following constants:target
- The target of the series of PEN events that triggered this flick attempt.public boolean scrollContent(int xDelta, int yDelta, boolean fromFlick)
Scrollable
scrollContent
in interface Scrollable
xDelta
- The relative amount of pixels to move in the X axis.yDelta
- The relative amount of pixels to move in the Y axis.public int getScrollPosition(int direction)
Scrollable
getScrollPosition
in interface Scrollable
public Flick getFlick()
Scrollable
getFlick
in interface Scrollable
public boolean wasScrolled()
Scrollable
wasScrolled
in interface Scrollable
public void setCaptions(java.lang.String[] caps)