Package totalcross.ui

Class 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);
         }
      }
     
    • 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
      • 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
      • 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.
      • recomputeParams

        protected void recomputeParams​(boolean justValue)
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • 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: Container
        Sets if this container and all childrens can or not accept events
        Overrides:
        setEnabled in class Container
      • 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)
        Description copied from class: Container
        Draws the border (if any). If you override this method, be sure to call super.onPaint(g);, or the border will not be drawn.
        Overrides:
        onPaint in class Container
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • 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:
        getPreferredWidth in class Control
      • 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:
        getPreferredHeight in class Control
      • onFontChanged

        public void onFontChanged()
        Description copied from class: Control
        Called after a setFont
        Overrides:
        onFontChanged in class Control
      • onBoundsChanged

        protected void onBoundsChanged​(boolean screenChanged)
        Description copied from class: Control
        Called after a setRect.
        Overrides:
        onBoundsChanged in class Control
        Parameters:
        screenChanged - If the bounds were changed due to a screen change (rotation, collapse)
      • setHighlighting

        public void setHighlighting()
        Description copied from class: Container
        Called 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:
        setHighlighting in class Container
      • clear

        public void clear()
        Clears this control, setting the value to clearValueInt.
        Overrides:
        clear in class Container
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Control
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        Overrides:
        handleGeographicalFocusChangeKeys in class Control
        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