Package totalcross.ui
Class Bar
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.Bar
-
public class Bar extends Container
This class provides a title area and a button area (at right). The title and the button are optional, although it doesn't make sense to have aBarwithout title and buttons. You can add or remove buttons, and change the title text; the title text can have an icon at left. Here's an example of how to use it, taken from the old UIGadgets sample:final Bar h1,h2; Font f = Font.getFont(true,Font.NORMAL_SIZE+2); h1 = new Bar("fakeboot"); h1.canSelectTitle = true; h1.setFont(f); h1.setBackForeColors(0x0A246A,Color.WHITE); h1.addButton(new Image("ic_dialog_alert.png")); h1.addButton(new Image("ic_dialog_info.png")); add(h1, LEFT,0,FILL,PREFERRED); // use 0 instead of TOP to overwrite the default menu areaAControlEvent.PRESSEDis sent to the caller, and the button index can be retrieved using thegetSelectedIndex()method. By default, the background is shaded. You can change it to plain usingh1.backgroundStyle = BACKGROUND_SOLID;.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classBar.BarButtonA Bar's button.-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleancanSelectTitleSet totrueto allow the title to be selected and send events.booleandrawBordersSet tofalseto remove the bordersintlandscapePrefHThe preferred height on portrait or landscape, in pixels.intportraitPrefHThe preferred height on portrait or landscape, in pixels.inttitleAlignThe title horizontal alignment (LEFT,CENTER, orRIGHT).-
Fields inherited from class totalcross.ui.Container
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, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intaddButton(Image icon)Adds an image button at right.intaddButton(Image icon, boolean atRight)Adds an image button at the given position.intaddControl(Control c)Adds a control to the bar at right.intaddControl(Control c, boolean atRight)Adds a control to the bar.voidassignBackKeyToButton(int idx)Assigns the BACK key on Android (mapped toSpecialKeys.ESCAPE) to the given button.voidcreateSpinner(int color)Creates a spinner with the following color.protected intgetButtonWidth(int idx)Override this method to return a customized button's widthImagegetIcon()Returns the icon set (and possibly resized) with setIcon, or null if none was setintgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.intgetSelectedIndex()Returns the selected button, or -1 if none was selected.java.lang.StringgetTitle()Retrieves the current title.intgetTitleWidth()voidinitUI()Called to initialize the user interface of this container.voidonColorsChanged(boolean colorsChanged)Called after asetEnabled(),setForeColor(), orsetBackColor(); or when a control has been added to a container.voidonFontChanged()Called after a setFontvoidremoveButton(int index)Removes a button at the given index, starting at 1.voidreposition()Repositions this control, calling againsetRect()with the original parameters.voidsetButtonRepeatRate(int idx, int ms)Sets the given button with an auto-repeat interval in the given milliseconds.voidsetButtonsVisible(boolean visible, int... indexes)Shows or hide a set of buttons.voidsetIcon(Image icon)An image icon that can be placed at the left of the title.voidsetSpinner(Spinner s)Sets the spinner to the given one.voidsetTitle(java.lang.String newTitle)Changes the title to the given one.voidstartSpinner()Shows and starts the spinner (if one has been assigned to thespinnerfield).voidstopSpinner()Stops and hides the spinner (if createSpinner or setSpinner was called before)voidupdateSinner()Updates the spinner; sets it visible if not yet.-
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onPaint, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderStyle, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onEvent, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
drawBorders
public boolean drawBorders
Set tofalseto remove the borders
-
canSelectTitle
public boolean canSelectTitle
Set totrueto allow the title to be selected and send events.
-
titleAlign
public int titleAlign
The title horizontal alignment (LEFT,CENTER, orRIGHT). Defaults toLEFT.
-
portraitPrefH
public int portraitPrefH
The preferred height on portrait or landscape, in pixels.
-
landscapePrefH
public int landscapePrefH
The preferred height on portrait or landscape, in pixels.
-
-
Constructor Detail
-
Bar
public Bar()
Constructs aBarobject without a title. Note that if you call thesetTitle()method, aRuntimeExceptionwill be thrown. If you want to change the title later, use the other constructor and pass an empty string ("").
-
Bar
public Bar(java.lang.String title)
Constructs aBarobject with the given title.- Parameters:
title- The bar title.
-
-
Method Detail
-
setIcon
public void setIcon(Image icon)
An image icon that can be placed at the left of the title. It only shows if there's a title set. Passnullto remove the icon if it was previously set.- Parameters:
icon- The image icon.
-
getIcon
public Image getIcon()
Returns the icon set (and possibly resized) with setIcon, or null if none was set
-
setTitle
public void setTitle(java.lang.String newTitle)
Changes the title to the given one.- Parameters:
newTitle- The bar new title.
-
getTitle
public java.lang.String getTitle()
Retrieves the current title.- Returns:
- The bar title.
-
addButton
public int addButton(Image icon)
Adds an image button at right.- Parameters:
icon- The image to the add to a button in the bar.- Returns:
- The button index
-
addButton
public int addButton(Image icon, boolean atRight)
Adds an image button at the given position.- Parameters:
icon- The image to the add to a button in the bar.atRight- if true, button is added at right; if false, button is added at left.- Returns:
- The button index
-
setButtonRepeatRate
public void setButtonRepeatRate(int idx, int ms)Sets the given button with an auto-repeat interval in the given milliseconds.- Parameters:
idx- The index of the button in the bar.ms- The auto-repeat interval in milliseconds.
-
addControl
public int addControl(Control c)
Adds a control to the bar at right. Not all types of controls are supported.- Parameters:
c- The control to be added.- Returns:
- The button index
-
addControl
public int addControl(Control c, boolean atRight)
Adds a control to the bar. Not all types of controls are supported.- Parameters:
atRight- if true, button is added at right; if false, button is added at left.c- The control to be added.- Returns:
- The button index
-
removeButton
public void removeButton(int index)
Removes a button at the given index, starting at 1.- Parameters:
index- The index of the button to be removed.
-
setButtonsVisible
public void setButtonsVisible(boolean visible, int... indexes)Shows or hide a set of buttons.
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected button, or -1 if none was selected. The title always has index 0 (even if there's no title), and the button' index start at index 1.- Returns:
- The index of the selected button.
-
initUI
public void initUI()
Called to initialize the user interface of this container.
-
getButtonWidth
protected int getButtonWidth(int idx)
Override this method to return a customized button's width
-
onColorsChanged
public void onColorsChanged(boolean colorsChanged)
Called after asetEnabled(),setForeColor(), orsetBackColor(); or when a control has been added to a container. IfcolorsChangedistrue, it was called fromsetForeColor()/setBackColor()/Container.add(); otherwise, it was called fromsetEnabled().- Overrides:
onColorsChangedin classContainer- Parameters:
colorsChanged- Indicates if the control colors have changed, which happens after asetForeColor(),setBackColor(), orContainer.add().
-
getPreferredWidth
public int getPreferredWidth()
Returns the preferred width of this control.- Overrides:
getPreferredWidthin classControl- Returns:
- The preferred width of this control.
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height of this control.- Overrides:
getPreferredHeightin classControl- Returns:
- The preferred height of this control.
-
startSpinner
public void startSpinner()
Shows and starts the spinner (if one has been assigned to thespinnerfield).- See Also:
spinner
-
updateSinner
public void updateSinner()
Updates the spinner; sets it visible if not yet.
-
stopSpinner
public void stopSpinner()
Stops and hides the spinner (if createSpinner or setSpinner was called before)- See Also:
spinner
-
reposition
public void reposition()
Repositions this control, calling againsetRect()with the original parameters.- Overrides:
repositionin classControl
-
onFontChanged
public void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
assignBackKeyToButton
public void assignBackKeyToButton(int idx)
Assigns the BACK key on Android (mapped toSpecialKeys.ESCAPE) to the given button. This can only be called after the bar has been added to a container. For example, if button 1 is assigned withtotalcross.res.Resources.back, callassignBackKeyToButton(1);.- Parameters:
idx- The index of the bar button, starting at 1.
-
createSpinner
public void createSpinner(int color)
Creates a spinner with the following color. The spinner will be placed at the right of the title (it only works if there's a title).- Parameters:
color- The spinner color.
-
setSpinner
public void setSpinner(Spinner s)
Sets the spinner to the given one.
-
getTitleWidth
public int getTitleWidth()
-
-