waba.ui
Class TabPanel

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--waba.ui.TabPanel

public class TabPanel
extends Container

TabPanel is a bar of text or image tabs. It is assumed that all images will have the same height, but they may have different widths.
A scroll is automatically added when the total width of the titles is bigger than the control's width.
The panels are created automaticaly and switched when the user press the corresponding tab, and a beep is heard.

Here is an example showing a tab bar being used:

 public class MyProgram extends MainWindow
 {
    TabPanel tab;

    public void onStart()
    {
       String nomes[] = {"Edition","Report"};
       tab = new TabPanel(nomes);
       add(tab);
       tab.setGaps(2,2,2,2); // set it before setting the rect
       tab.setRect(getClientRect());
       tab.setPanel(0,new Edition()); // replace container 1 by a class that extends Container.
       tab.getPanel(1).add(new Label("Not implemented"),CENTER,CENTER);
       add(tab);
    }

    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 TabPanels, one with images and another one with scrolling tabs. Note that you must create img1.bmp and img2.bmp.
 TabPanel tp1 = new TabPanel(new Image[]{new Image("img1.bmp"), new Image("img2.bmp")}, null);
 add(tp1);
 tp1.setRect(LEFT,TOP,Settings.screenWidth/2,Settings.screenHeight/2);
 tp1.activeTabBackColor = new Color(222,222,222);

 TabPanel tp2 = new TabPanel(new String[]{"verinha","marcelo","denise","guilherme","renato","michelle","rafael","barbara","lucas","ronaldo","nenem",});
 add(tp2);
 tp2.setRect(LEFT,AFTER+2,FILL,FILL);
 
Important: you CANNOT do a swap of a TabPanel to a Window. You must use the sample code above (add and setRect) instead.


Field Summary
 Color activeTabBackColor
          This color is the one used to paint the background of the active tab.
 boolean beepOn
          Set to off to disable the beep when a tab is clicked
 int lastActiveTab
          Stores the last active tab index, or -1 if none was previously selected.
static byte TABS_BOTTOM
           
static byte TABS_TOP
           
 boolean useOnTabThePanelsColor
          Sets the tabs with the same colors of the container.
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, started, tabOrder, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
TabPanel(Image[] imgCaptions, Color transparentColor)
          Constructs a tab bar control with images as captions, using the given color as transparent color.
TabPanel(java.lang.String[] strCaptions)
          Constructs a tab bar control with Strings as captions.
 
Method Summary
 void changeHighlighted(Container p, boolean forward)
          Tranfer the focus between the containers on this TabPanel
 int getActiveTab()
          Returns the index of the selected tab
 Color getCaptionColor()
          Gets the text color of the captions. return a grayed value if this control is not enabled.
 Rect getClientRect()
          Returns the area excluding the tabs and borders for this TabPanel.
 void getClientRect(Rect r)
          Returns the area excluding the tabs and borders for this TabPanel.
 Container getPanel(int i)
          Returns the Container for tab i
 int getPreferredHeight()
          Returns the caption height for this TabPanel.
 int getPreferredWidth()
          Returns the minimum width for this TabPanel
protected  void onBoundsChanged()
          used internally. resizes all the containers and add the arrows if scroll is needed.
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.
protected  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 setActiveTab(int tab)
          Sets the currently active tab.
 void setBorderStyle(byte style)
          Sets the type of border. see the waba.ui.Window xxx_BORDER constants.
 void setCaptionColor(Color capColor)
          Sets the text color of the captions
 void setGaps(int gapL, int gapR, int gapT, int gapB)
          sets gaps between the containers and the TabPanel.
 void setHighlighting()
          Only return to highlighting when we want
 void setPanel(int i, Container container)
          Replaces the default created Container with the given one.
 void setPanelsBackColor(Color[] backColors)
          Deprecated. You may set the back color directly in the class that extends Container, or use getPanel(i).setBackColor(...).
 void setType(byte type)
          Sets the position of the tabs. use constants TABS_TOP or TABS_BOTTOM.
 
Methods inherited from class waba.ui.Container
add, add, add, broadcastEvent, clear, findChild, getChildren, onAdd, onRemove, onStart, paintChildren, remove, setEnabled, swapToTopmostWindow
 
Methods inherited from class waba.ui.Control
addTimer, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

beepOn

public boolean beepOn
Set to off to disable the beep when a tab is clicked

activeTabBackColor

public Color activeTabBackColor
This color is the one used to paint the background of the active tab. This is specially useful for image tabs.
Since:
SuperWaba 5.64

useOnTabThePanelsColor

public boolean useOnTabThePanelsColor
Sets the tabs with the same colors of the container.
Since:
SuperWaba 5.72

lastActiveTab

public int lastActiveTab
Stores the last active tab index, or -1 if none was previously selected.
Since:
SuperWaba 4.21

TABS_TOP

public static final byte TABS_TOP

TABS_BOTTOM

public static final byte TABS_BOTTOM
Constructor Detail

TabPanel

public TabPanel(java.lang.String[] strCaptions)
Constructs a tab bar control with Strings as captions.

TabPanel

public TabPanel(Image[] imgCaptions,
                Color transparentColor)
Constructs a tab bar control with images as captions, using the given color as transparent color. If you don't want to use transparent colors, just pass null to the color.
Method Detail

setPanelsBackColor

public void setPanelsBackColor(Color[] backColors)
Deprecated. You may set the back color directly in the class that extends Container, or use getPanel(i).setBackColor(...).

Sets the colors of the panels. The number of colors must match the number of panels.

setType

public void setType(byte type)
Sets the position of the tabs. use constants TABS_TOP or TABS_BOTTOM. Since the tabs are not changed dinamicaly, this method must be called after the constructor.

getPanel

public Container getPanel(int i)
Returns the Container for tab i

setGaps

public void setGaps(int gapL,
                    int gapR,
                    int gapT,
                    int gapB)
sets gaps between the containers and the TabPanel. Must be called before setRect

setBorderStyle

public void setBorderStyle(byte style)
Sets the type of border. see the waba.ui.Window xxx_BORDER constants. PS: currently, only the NO_BORDER and RECT_BORDER are supported. NO_BORDER only draws the line under the tabs.
Overrides:
setBorderStyle in class Container

setPanel

public void setPanel(int i,
                     Container container)
Replaces the default created Container with the given one. This way you can avoid adding a container to a container and, as such, waste memory. Note that you must do this before the first setRect for this tabPanel; otherwise, you must explicitly call setRect again to update the added container bounds

setActiveTab

public void setActiveTab(int tab)
Sets the currently active tab. A PRESSED event will be posted to the given tab if it is not the currently active tab. the panels will be switched.

getActiveTab

public int getActiveTab()
Returns the index of the selected tab

getPreferredHeight

public int getPreferredHeight()
Returns the caption height for this TabPanel. Note that it is not possible to compute the correct height of each container.
Overrides:
getPreferredHeight in class Control

getPreferredWidth

public int getPreferredWidth()
Returns the minimum width for this TabPanel
Overrides:
getPreferredWidth in class Control

onBoundsChanged

protected void onBoundsChanged()
used internally. resizes all the containers and add the arrows if scroll is needed.
Overrides:
onBoundsChanged in class Control

onFontChanged

protected void onFontChanged()
Compute the rectangles of the tabs based on the selected (bolded) and unselected (plain) titles.
Overrides:
onFontChanged in class Control

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Container

onPaint

public void onPaint(Graphics g)
Called by the system to draw the tab bar.
Overrides:
onPaint in class Container
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

setCaptionColor

public void setCaptionColor(Color capColor)
Sets the text color of the captions

getCaptionColor

public Color getCaptionColor()
Gets the text color of the captions. return a grayed value if this control is not enabled.

getClientRect

public Rect getClientRect()
Returns the area excluding the tabs and borders for this TabPanel. Note: do not change the returning rect object !
Overrides:
getClientRect in class Container

getClientRect

public void getClientRect(Rect r)
Returns the area excluding the tabs and borders for this TabPanel. In this version, you provide the created Rect to be filled with the coords.
Overrides:
getClientRect in class Container

onEvent

public void onEvent(Event event)
Called by the system to pass events to the tab bar control.
Overrides:
onEvent in class Control
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

changeHighlighted

public void changeHighlighted(Container p,
                              boolean forward)
Tranfer the focus between the containers on this TabPanel
Overrides:
changeHighlighted in class Control

setHighlighting

public void setHighlighting()
Only return to highlighting when we want
Overrides:
setHighlighting in class Container