Package totalcross.ui
Class ProgressBar
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.ProgressBar
-
public class ProgressBar extends Control
A basic progress bar, with the bar and a text. The text is comprised of a prefix and a suffix.You can create a horizontal endless ProgressBar, always going from left to right, by setting the given parameters:
- call setEndless()
- max-min: used to compute the width of the bar
- prefix and suffix: displayed, but the current value is not displayed
- setValue(n): n used to increment the current value, not to set the value to n.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleandrawBorderIf false, no border is drawn.booleandrawTextSet to false to don't let the text be drawn.booleandrawValueSet to false to don't let the value be drawn.booleanhighlightIf true, the text is highlighted.inthighlightColorThe highlight color, or -1 to use one based on textColor.intmaxThe maximum value of a progress bar.intminThe minimum value of a progress bar.java.lang.StringprefixThe string prefix.java.lang.StringsuffixThe string prefix.inttextColorThe text colorbooleanverticalIf false, use horizontal mode (default)-
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
-
-
Constructor Summary
Constructors Constructor Description ProgressBar()Creates a progress bar, with minimum and maximum set as 0 and 100, respectively.ProgressBar(int min, int max)Creates a progress bar, String is set tonull, which is the default.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this control, setting the value to clearValueInt.intgetPreferredHeight()Returns the preferred height, which is fmH+2intgetPreferredWidth()Gets the preferred width, which is the parent's width-6, or the screen's width.intgetValue()Returns the current valuevoidonBoundsChanged(boolean b)Called after a setRect.voidonColorsChanged(boolean b)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonPaint(Graphics g)Paint the Progress Bar.voidsetEndless()Call this method to make this ProgressBar a horizontal endless progressbar; just keep callingsetValue(step)to increase the value of the progressbar.voidsetValue(int n)Sets the current value.voidsetValue(int value, java.lang.String prefix, java.lang.String suffix)Sets the current value and the prefix and suffix.-
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, onEvent, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
min
public int min
The minimum value of a progress bar.
-
max
public int max
The maximum value of a progress bar.
-
prefix
public java.lang.String prefix
The string prefix. The displayed label will be prefix+value+sufix. The default is an empty string.
-
suffix
public java.lang.String suffix
The string prefix. The displayed label will be prefix+value+sufix. The default is the percentage symbol.
-
drawText
public boolean drawText
Set to false to don't let the text be drawn.- Since:
- TotalCross 1.0
-
drawValue
public boolean drawValue
Set to false to don't let the value be drawn. Note that the prefix and suffix will still be drawn.- Since:
- TotalCross 1.0
-
textColor
public int textColor
The text color
-
drawBorder
public boolean drawBorder
If false, no border is drawn.
-
highlight
public boolean highlight
If true, the text is highlighted.
-
highlightColor
public int highlightColor
The highlight color, or -1 to use one based on textColor.
-
vertical
public boolean vertical
If false, use horizontal mode (default)- Since:
- TotalCross 1.15
-
-
Constructor Detail
-
ProgressBar
public ProgressBar()
Creates a progress bar, with minimum and maximum set as 0 and 100, respectively.
-
ProgressBar
public ProgressBar(int min, int max)Creates a progress bar, String is set tonull, which is the default. Uses the specified minimum for the initial value of the progress bar.- Parameters:
min- The minimum valuemax- The maximum value
-
-
Method Detail
-
setEndless
public void setEndless()
Call this method to make this ProgressBar a horizontal endless progressbar; just keep callingsetValue(step)to increase the value of the progressbar.
-
getPreferredWidth
public int getPreferredWidth()
Gets the preferred width, which is the parent's width-6, or the screen's width.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height, which is fmH+2- Overrides:
getPreferredHeightin classControl
-
setValue
public void setValue(int n)
Sets the current value. Due to performance reasons, min and max are not verified. If the value was not changed, nothing happens. The progress bar is repainted immediately.If this is an endless ProgressBar, the given number is used as an increment to the current value. Note that n must be greater than 0. If you call this method and the bar isnt updated, you can try to call
MainWindow.pumpEvents().- Parameters:
n- The new value- See Also:
getValue()
-
setValue
public void setValue(int value, java.lang.String prefix, java.lang.String suffix)Sets the current value and the prefix and suffix. Note that, due to performance reasons, min and max are not verified. This does not check if the value had changed; it always repaint the progress bar immediately.- Parameters:
value- The new value- See Also:
getValue()
-
getValue
public int getValue()
Returns the current value
-
onColorsChanged
public void onColorsChanged(boolean b)
Description copied from class:ControlCalled 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:
onColorsChangedin classControl
-
onBoundsChanged
public void onBoundsChanged(boolean b)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
b- If the bounds were changed due to a screen change (rotation, collapse)
-
onPaint
public void onPaint(Graphics g)
Paint the Progress Bar. The filled part of the bar is painted with the foreground color; the empty part of the bar is painted with the background color; the text is painted with the defined textColor color; no border is drawn.
-
-