Package totalcross.ui
Class ScrollBar
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ScrollBar
-
- All Implemented Interfaces:
ControlAnimation.AnimationFinished,PathAnimation.SetPosition
- Direct Known Subclasses:
ScrollPosition,Slider
public class ScrollBar extends Container implements PathAnimation.SetPosition, ControlAnimation.AnimationFinished
ScrollBar is an implementation of a Scrollbar. The scrollbar orientation can be horizontal or vertical. It implements auto scroll when pressing and holding a button or the gap area of the scrollBar. Here is an example of how to use it.// declarations ScrollBar sb1; ScrollBar sb2; ScrollBar sb3; ScrollBar sb4; // init public void testScrollBars() { add(sb1 = new ScrollBar(ScrollBar.VERTICAL), RIGHT, CENTER, PREFERRED, totalcross.sys.Settings.screenHeight/2); add(sb2 = new ScrollBar(ScrollBar.VERTICAL), BEFORE, SAME, PREFERRED, SAME); sb2.setLiveScrolling(true); add(sb3 = new ScrollBar(ScrollBar.HORIZONTAL), LEFT,CENTER,totalcross.sys.Settings.screenWidth/2, PREFERRED); add(sb4 = new ScrollBar(ScrollBar.HORIZONTAL), SAME, AFTER, SAME, PREFERRED); } public void onEvent(Event event) { if (event.type == ControlEvent.PRESSED && event.target == sb2) { int value = sb2.getValue(); sb1.setValue(value); sb3.setValue(value); sb4.setValue(value); } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description static intAUTO_DELAYThe frequency in which the scroll will be done.protected intbColorprotected intblockIncrementprotected ArrowButtonbtnDecprotected ArrowButtonbtnIncprotected intbtnWHprotected booleandirectMovebooleandisableBlockIncrementSet to true to disable block increments, which occurs when the user clicks outside the bar and buttons.protected intdragBarMaxprotected intdragBarMinprotected intdragBarPosprotected intdragBarSizeprotected booleanenableAutoScrollstatic intextraSizeThe extra size (width for vertical ScrollBars or height for horizontal ones) used in all ScrollBars.protected int[]fourColorsstatic byteHORIZONTALTo be passed in the constructorstatic intINITIAL_DELAYThe initial delay to start the automatic scroll.protected booleanliveScrollingprotected intmaximumprotected intmidBarSizeintminDragBarSizeThe minimum dragbar size in pixels.protected intminimumprotected NinePatch.PartsnpPartsHandleprotected intsbColorprotected intsbColorDisprotected intsfColorprotected intsizeprotected intstartDragPosprotected intunitIncrementprotected intvalueprotected doublevaluesPerPixelstatic byteVERTICALTo be passed in the constructorprotected booleanverticalBarprotected intvisibleItems-
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, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_TIME
-
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, 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 Summary
Constructors Constructor Description ScrollBar()Creates Scrollbar with default values:
maximum = 100
minimum = 0
orientation = VERTICAL
blockIncrement = 50
unitIncrement = 1
value = 0
visibleItems = blockIncrementScrollBar(byte orientation)Creates Scrollbar with the given orientation and these default values:
maximum = 100
minimum = 0
blockIncrement = 50
unitIncrement = 1
value = 0
visibleItems = blockIncrement
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidblockScroll(boolean inc)Scrolls a block, and post the PRESSED event if the value changes.voidclear()Clears this control, setting the value to clearValueInt.intgetBlockIncrement()Get the amount to increment the value when clicking above the bar.intgetMaximum()Get the maximum valueintgetMinimum()Get the minimum valueintgetPreferredHeight()If this is a horizontal scroll bar, i strongly suggest you use PREFERRED in your control's height (with small adjustments)intgetPreferredWidth()If this is a vertical scroll bar, i strongly suggest you use PREFERRED in your control's width (with small adjustments).intgetUnitIncrement()Get the amount to increment the value when clicking the up or down buttonsintgetValue()Get the value.intgetVisibleItems()Get the count of visible items for the scrollbarControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.voidonAnimationFinished(ControlAnimation anim)protected voidonBoundsChanged(boolean screenChanged)Called after a setRect.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event event)Called to process key, pen, control and other posted events.voidonFontChanged()Called after a setFontvoidonPaint(Graphics g)Draws the border (if any).protected voidrecomputeParams(boolean justValue)voidsetBlockIncrement(int i)Set the amount to increment the value when clicking above the bar.voidsetEnabled(boolean enabled)Sets if this container and all childrens can or not accept eventsvoidsetHighlighting()Called by the event dispatcher to set highlighting back to true.voidsetLiveScrolling(boolean liveScrolling)Set the live scrolling.voidsetMaximum(int i)Set the maximum value.voidsetMinimum(int i)Set the minimum valuevoidsetNinePatchHandle(Image img, int corner, int side)Set the Handle NinePatch imagevoidsetPos(int x, int y)voidsetUnitIncrement(int i)Set the amount to increment the value when clicking the up or down buttonsvoidsetValue(int i)Sets the value.voidsetValues(int newValue, int newVisibleItems, int newMinimum, int newMaximum)Sets the value, visibleItems, minimum and maximum valuesvoidsetVisibleItems(int i)Set the count of visible items for the scrollbar.voidtempShow()Used by ScrollPositionprotected voidupdateValue(int pos)-
Methods inherited from class totalcross.ui.Container
add, add, add, add, add, broadcastEvent, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, remove, removeAll, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setFocusTraversable, setInsets, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, 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, 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, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
VERTICAL
public static final byte VERTICAL
To be passed in the constructor- See Also:
- Constant Field Values
-
HORIZONTAL
public static final byte HORIZONTAL
To be passed in the constructor- See Also:
- Constant Field Values
-
disableBlockIncrement
public boolean disableBlockIncrement
Set to true to disable block increments, which occurs when the user clicks outside the bar and buttons.- Since:
- TotalCross 1.3.4
-
maximum
protected int maximum
-
minimum
protected int minimum
-
blockIncrement
protected int blockIncrement
-
unitIncrement
protected int unitIncrement
-
value
protected int value
-
visibleItems
protected int visibleItems
-
valuesPerPixel
protected double valuesPerPixel
-
dragBarSize
protected int dragBarSize
-
btnWH
protected int btnWH
-
btnInc
protected ArrowButton btnInc
-
btnDec
protected ArrowButton btnDec
-
startDragPos
protected int startDragPos
-
verticalBar
protected boolean verticalBar
-
dragBarPos
protected int dragBarPos
-
liveScrolling
protected boolean liveScrolling
-
size
protected int size
-
dragBarMax
protected int dragBarMax
-
dragBarMin
protected int dragBarMin
-
bColor
protected int bColor
-
sbColor
protected int sbColor
-
sfColor
protected int sfColor
-
sbColorDis
protected int sbColorDis
-
fourColors
protected int[] fourColors
-
npPartsHandle
protected NinePatch.Parts npPartsHandle
-
directMove
protected boolean directMove
-
midBarSize
protected int midBarSize
-
minDragBarSize
public int minDragBarSize
The minimum dragbar size in pixels. By default, 5. This has no effect if the ui style is Palm OS.
-
enableAutoScroll
protected boolean enableAutoScroll
-
INITIAL_DELAY
public static int INITIAL_DELAY
The initial delay to start the automatic scroll.
-
AUTO_DELAY
public static int AUTO_DELAY
The frequency in which the scroll will be done.
-
extraSize
public static int extraSize
The extra size (width for vertical ScrollBars or height for horizontal ones) used in all ScrollBars. Note that this member is static so it will affect all ScrollBars created afterwards, unless you reset it to 0.- Since:
- TotalCross 1.14
-
-
Constructor Detail
-
ScrollBar
public ScrollBar()
Creates Scrollbar with default values:
maximum = 100
minimum = 0
orientation = VERTICAL
blockIncrement = 50
unitIncrement = 1
value = 0
visibleItems = blockIncrement
-
ScrollBar
public ScrollBar(byte orientation)
Creates Scrollbar with the given orientation and these default values:
maximum = 100
minimum = 0
blockIncrement = 50
unitIncrement = 1
value = 0
visibleItems = blockIncrement
-
-
Method Detail
-
setValues
public void setValues(int newValue, int newVisibleItems, int newMinimum, int newMaximum)Sets the value, visibleItems, minimum and maximum values
-
setMaximum
public void setMaximum(int i)
Set the maximum value. Note that you must explicitly call repaint.
-
getMaximum
public int getMaximum()
Get the maximum value
-
setMinimum
public void setMinimum(int i)
Set the minimum value
-
getMinimum
public int getMinimum()
Get the minimum value
-
setBlockIncrement
public void setBlockIncrement(int i)
Set the amount to increment the value when clicking above the bar. This value is set as default to be equal to visibleItems.
-
getBlockIncrement
public int getBlockIncrement()
Get the amount to increment the value when clicking above the bar.
-
setUnitIncrement
public void setUnitIncrement(int i)
Set the amount to increment the value when clicking the up or down buttons
-
getUnitIncrement
public int getUnitIncrement()
Get the amount to increment the value when clicking the up or down buttons
-
setValue
public void setValue(int i)
Sets the value.
-
getValue
public int getValue()
Get the value. This is the value minus the visible items.
-
setVisibleItems
public void setVisibleItems(int i)
Set the count of visible items for the scrollbar. This value cannot be zero. It also sets the blockIncrement to be equal to the given value.
-
getVisibleItems
public int getVisibleItems()
Get the count of visible items for the scrollbar
-
setLiveScrolling
public void setLiveScrolling(boolean liveScrolling)
Set the live scrolling. If "true" an event is thrown during dragging or when the button is held.
-
setNinePatchHandle
public void setNinePatchHandle(Image img, int corner, int side)
Set the Handle NinePatch image
-
recomputeParams
protected void recomputeParams(boolean justValue)
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
updateValue
protected void updateValue(int pos)
-
blockScroll
public void blockScroll(boolean inc)
Scrolls a block, and post the PRESSED event if the value changes.
-
setEnabled
public void setEnabled(boolean enabled)
Description copied from class:ContainerSets if this container and all childrens can or not accept events- Overrides:
setEnabledin classContainer
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
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 classContainer
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ContainerDraws the border (if any). If you override this method, be sure to callsuper.onPaint(g);, or the border will not be drawn.
-
getPreferredWidth
public int getPreferredWidth()
If this is a vertical scroll bar, i strongly suggest you use PREFERRED in your control's width (with small adjustments).- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
If this is a horizontal scroll bar, i strongly suggest you use PREFERRED in your control's height (with small adjustments)- Overrides:
getPreferredHeightin classControl
-
onFontChanged
public void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
onBoundsChanged
protected void onBoundsChanged(boolean screenChanged)
Description copied from class:ControlCalled after a setRect.- Overrides:
onBoundsChangedin classControl- Parameters:
screenChanged- If the bounds were changed due to a screen change (rotation, collapse)
-
setHighlighting
public void setHighlighting()
Description copied from class:ContainerCalled by the event dispatcher to set highlighting back to true. A class may extend this to decide when its time to turn it on again or not.- Overrides:
setHighlightingin classContainer
-
clear
public void clear()
Clears this control, setting the value to clearValueInt.
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classControl- Parameters:
ke- The KeyEvent to be processed- Returns:
- The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
- See Also:
Settings.geographicalFocus
-
tempShow
public void tempShow()
Used by ScrollPosition
-
setPos
public void setPos(int x, int y)- Specified by:
setPosin interfacePathAnimation.SetPosition
-
onAnimationFinished
public void onAnimationFinished(ControlAnimation anim)
- Specified by:
onAnimationFinishedin interfaceControlAnimation.AnimationFinished
-
-