Package totalcross.ui
Class ScrollContainer
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ScrollContainer
-
- All Implemented Interfaces:
Scrollable
- Direct Known Subclasses:
ButtonMenu,Document,DynamicScrollContainer,ListContainer
public class ScrollContainer extends Container implements Scrollable
ScrollContainer is a container with a horizontal only, vertical only, both or no ScrollBars, depending on the control positions. The default unit scroll is an Edit's height (for the vertical scrollbar), and the width of '@' (for the horizontal scrollbar).Caution: you must not use RIGHT, BOTTOM, CENTER and FILL when setting the control bounds, unless you disable the corresponding ScrollBar! The only exception to this is to use FILL on the control's height, which is allowed.
Here is an example showing how it can be used:
public class MyProgram extends MainWindow { ScrollContainer sc; public void initUI() { ScrollContainer sc; add(sc = new ScrollContainer()); sc.setBorderStyle(BORDER_SIMPLE); sc.setRect(LEFT+10,TOP+10,FILL-20,FILL-20); int xx = new Label("Name99").getPreferredWidth()+2; // edit's alignment for (int i =0; i < 100; i++) { sc.add(new Label("Name"+i),LEFT,AFTER); sc.add(new Edit("@@@@@@@@@@@@@@@@@@@@"),xx,SAME); if (i % 3 == 0) sc.add(new Button("Go"), AFTER+2,SAME,PREFERRED,SAME); } } }
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanautoScrollAutomatically scrolls the container when an item is clicked.protected ClippedContainerbagprotected Containerbag0protected FlickflickThe Flick object listens and performs flick animations on PenUp events when appropriate.static java.util.HashSet<java.lang.Class<?>>hsIgnoreAutoScrollDefines a list of classes that will make autoScroll be ignored.protected intlastHprotected intlastVScrollBarsbHReturns the scrollbar for this ScrollContainer.ScrollBarsbVReturns the scrollbar for this ScrollContainer.booleanshrink2sizeSet to true, to make the surrounding container shrink to its size.-
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, 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
-
-
Constructor Summary
Constructors Constructor Description ScrollContainer()Standard constructor for a new ScrollContainer, with both scrollbars enabled.ScrollContainer(boolean allowScrollBars)Constructor used to specify when both scrollbars are enabled or not.ScrollContainer(boolean allowHScrollBar, boolean allowVScrollBar)Constructor used to specify when each scrollbar is enabled or not.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Control control)Adds a child control to the bag container.protected voidbagSetRect(int x, int y, int w, int h, boolean screenChanged)booleancanScrollContent(int direction, java.lang.Object target)Checks if there is room to flick this container in the given direction.protected booleancanShowScrollBars(boolean vertical)voidflickEnded(boolean atPenDown)Called when the flick animation is ended.booleanflickStarted()Called when the flick animation is started.Control[]getBagChildren()Returns the children of the bag.protected intgetBagInitialHeight()Overwrite this method to define a custom height for the scrolling areaprotected intgetBagInitialWidth()Overwrite this method to define a custom width for the scrolling areaRectgetClientRect()Returns the client rect from the area that scrollsFlickgetFlick()Returns the current flick object.intgetPreferredHeight()Returns the preferred height AFTER the resize method was called.intgetPreferredWidth()Returns the preferred width AFTER the resize method was called.RectgetRealClientRect()Returns the client rect from the ScrollContainer controlintgetScrollDistance()Override this method to return the correct scroll distance.intgetScrollPosition(int direction)Returns the current position given the direction.ControlmoveFocusToNextControl(Control control, boolean forward)Moves the focus to the next control, which can be an Edit, a MultiEdit, or another control type.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).voidremove(Control control)Removes a child control from the bag container.voidremoveAll()Removes all controls from the ScrollContainer.voidreposition()Reposition this control, calling again setRect with the original parameters.voidresize()This method resizes the control to the needed bounds, based on added childs.voidresize(int maxX, int maxY)This method resizes the control to the needed bounds, based on the given maximum width and heights.booleanscrollContent(int dx, int dy, boolean fromFlick)Performs a relative move.voidscrollPage(boolean left)Scrolls a page to left or right.voidscrollToControl(Control c)Scrolls to the given control.voidscrollToOrigin()Scroll the container to origin position 0,0voidscrollToPage(int p)Scrolls to the given page, which is the flick's scrollDistance (if set), or the control's height.voidsetBorderStyle(byte border)Sets the border for this container.protected voidsetHValue(int val)Sets the horizontal's ScrollBar value to the given one.protected voidsetScrollBars(boolean allowHScrollBar, boolean allowVScrollBar)protected voidsetVValue(int val)Sets the vertical's ScrollBar value to the given one.booleanwasScrolled()Returns true if the control was scrolled since last pen down-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resizeHeight, resizeWidth, 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, 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
-
sbH
public ScrollBar sbH
Returns the scrollbar for this ScrollContainer. With it, you can directly set its parameters, like blockIncrement, unitIncrement and liveScrolling. But be careful, don't mess with the minimum, maximum and visibleItems. If using Android or Material user interface style, these are replaced by the ScrollPosition. If you setsbV.transparentBackground=true(or for sbH), you will expand the client area to over the ScrollPosition's area.
-
sbV
public ScrollBar sbV
Returns the scrollbar for this ScrollContainer. With it, you can directly set its parameters, like blockIncrement, unitIncrement and liveScrolling. But be careful, don't mess with the minimum, maximum and visibleItems. If using Android or Material user interface style, these are replaced by the ScrollPosition. If you setsbV.transparentBackground=true(or for sbH), you will expand the client area to over the ScrollPosition's area.
-
flick
protected Flick flick
The Flick object listens and performs flick animations on PenUp events when appropriate.
-
bag
protected ClippedContainer bag
-
bag0
protected Container bag0
-
lastV
protected int lastV
-
lastH
protected int lastH
-
shrink2size
public boolean shrink2size
Set to true, to make the surrounding container shrink to its size.
-
autoScroll
public boolean autoScroll
Automatically scrolls the container when an item is clicked.- See Also:
hsIgnoreAutoScroll
-
hsIgnoreAutoScroll
public static java.util.HashSet<java.lang.Class<?>> hsIgnoreAutoScroll
Defines a list of classes that will make autoScroll be ignored. Use it like:ScrollContainer.hsIgnoreAutoScroll.add(totalcross.ui.SpinList.class); ...
This is useful if such class usually requires more than one press to have a value defined.- See Also:
autoScroll
-
-
Constructor Detail
-
ScrollContainer
public ScrollContainer()
Standard constructor for a new ScrollContainer, with both scrollbars enabled.
-
ScrollContainer
public ScrollContainer(boolean allowScrollBars)
Constructor used to specify when both scrollbars are enabled or not.
-
ScrollContainer
public ScrollContainer(boolean allowHScrollBar, boolean allowVScrollBar)Constructor used to specify when each scrollbar is enabled or not. By disabling the horizontal scrollbar, you can use RIGHT and CENTER on the x parameter of a control that is added. By disabling the vertical scrollbar, you can use BOTTOM and CENTER on the y parameter of a control that is added.- Since:
- TotalCross 1.27
-
-
Method Detail
-
getClientRect
public Rect getClientRect()
Returns the client rect from the area that scrolls- Overrides:
getClientRectin classContainer- See Also:
Container.getClientRect(Rect)
-
getRealClientRect
public Rect getRealClientRect()
Returns the client rect from the ScrollContainer control
-
setScrollBars
protected void setScrollBars(boolean allowHScrollBar, boolean allowVScrollBar)
-
getBagInitialHeight
protected int getBagInitialHeight()
Overwrite this method to define a custom height for the scrolling area
-
getBagInitialWidth
protected int getBagInitialWidth()
Overwrite this method to define a custom width for the scrolling area
-
flickStarted
public boolean flickStarted()
Description copied from interface:ScrollableCalled when the flick animation is started.- Specified by:
flickStartedin interfaceScrollable
-
flickEnded
public void flickEnded(boolean atPenDown)
Description copied from interface:ScrollableCalled when the flick animation is ended.- Specified by:
flickEndedin interfaceScrollable- Parameters:
atPenDown- Flag indicating if the animation ended due to a pendown event.
-
canScrollContent
public boolean canScrollContent(int direction, java.lang.Object target)Description copied from interface:ScrollableChecks if there is room to flick this container in the given direction.- Specified by:
canScrollContentin interfaceScrollable- Parameters:
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.- Returns:
- true if the container can flick in the indicated direction.
-
scrollContent
public boolean scrollContent(int dx, int dy, boolean fromFlick)Description copied from interface:ScrollablePerforms a relative move.- Specified by:
scrollContentin interfaceScrollable- Parameters:
dx- The relative amount of pixels to move in the X axis.dy- The relative amount of pixels to move in the Y axis.
-
getScrollPosition
public int getScrollPosition(int direction)
Description copied from interface:ScrollableReturns the current position given the direction. Used on page scrolls.- Specified by:
getScrollPositionin interfaceScrollable
-
add
public void add(Control control)
Adds a child control to the bag container.
-
remove
public void remove(Control control)
Removes a child control from the bag container.
-
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)
-
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
-
bagSetRect
protected void bagSetRect(int x, int y, int w, int h, boolean screenChanged)
-
resize
public void resize()
This method resizes the control to the needed bounds, based on added childs. Must be called if you're controlling reposition by your own, after you repositioned the controls inside of it.- Overrides:
resizein classContainer- See Also:
Container.resizeWidth(),Container.resizeHeight()
-
resize
public void resize(int maxX, int maxY)This method resizes the control to the needed bounds, based on the given maximum width and heights.
-
canShowScrollBars
protected boolean canShowScrollBars(boolean vertical)
-
getScrollDistance
public int getScrollDistance()
Override this method to return the correct scroll distance. Defaults to the container's width.
-
reposition
public void reposition()
Description copied from class:ControlReposition this control, calling again setRect with the original parameters.- Overrides:
repositionin classControl
-
getPreferredWidth
public int getPreferredWidth()
Returns the preferred width AFTER the resize method was called. If the ScrollBars are disabled, returns the maximum size of the container to hold all controls.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Returns the preferred height AFTER the resize method was called. If the ScrollBars are disabled, returns the maximum size of the container to hold all controls.- Overrides:
getPreferredHeightin classControl
-
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.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
scrollToPage
public void scrollToPage(int p)
Scrolls to the given page, which is the flick's scrollDistance (if set), or the control's height.- Since:
- TotalCross 1.53
-
scrollPage
public void scrollPage(boolean left)
Scrolls a page to left or right. Works only if it has a flick and a page position.
-
scrollToControl
public void scrollToControl(Control c)
Scrolls to the given control.
-
scrollToOrigin
public void scrollToOrigin()
Scroll the container to origin position 0,0
-
setVValue
protected void setVValue(int val)
Sets the vertical's ScrollBar value to the given one.
-
setHValue
protected void setHValue(int val)
Sets the horizontal's ScrollBar value to the given one.
-
setBorderStyle
public void setBorderStyle(byte border)
Description copied from class:ContainerSets the border for this container. The insets are changed after this method is called. The BORDER_ROUNDED sets the background to transparent.- Overrides:
setBorderStylein classContainer- See Also:
Container.BORDER_NONE,Container.BORDER_LOWERED,Container.BORDER_RAISED,Container.BORDER_SIMPLE,Container.BORDER_TOP,Container.BORDER_ROUNDED
-
getFlick
public Flick getFlick()
Description copied from interface:ScrollableReturns the current flick object.- Specified by:
getFlickin interfaceScrollable
-
wasScrolled
public boolean wasScrolled()
Description copied from interface:ScrollableReturns true if the control was scrolled since last pen down- Specified by:
wasScrolledin interfaceScrollable
-
removeAll
public void removeAll()
Removes all controls from the ScrollContainer.
-
getBagChildren
public Control[] getBagChildren()
Returns the children of the bag. If you call ScrollContainer.getChildren, it will not return the controls added to the ScrollContainer, since they are actually added to the bag.- Since:
- TotalCross 1.5
-
onFontChanged
public void onFontChanged()
Description copied from class:ControlCalled after a setFont- Overrides:
onFontChangedin classControl
-
moveFocusToNextControl
public Control moveFocusToNextControl(Control control, boolean forward)
Description copied from class:ContainerMoves the focus to the next control, which can be an Edit, a MultiEdit, or another control type. It does not show the keyboard.- Overrides:
moveFocusToNextControlin classContainer- Returns:
- The selected control or null if none was found.
-
-