waba.ui
Class ScrollBar

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.Container
              |
              +--waba.ui.ScrollBar

public class ScrollBar
extends Container

ScrollBar is a simple implementation of a Scrollbar. The scroll bar orientation can be horizontal or vertical. 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));
     sb1.setRect(RIGHT, CENTER, PREFERRED, waba.sys.Settings.screenHeight/2);

     add(sb2 = new ScrollBar(ScrollBar.VERTICAL));
     sb2.setRect(BEFORE, SAME, PREFERRED, SAME);
     sb2.setLiveScrolling(true);

     add(sb3 = new ScrollBar(ScrollBar.HORIZONTAL));
     sb3.setRect(LEFT,CENTER,waba.sys.Settings.screenWidth/2, PREFERRED);

     add(sb4 = new ScrollBar(ScrollBar.HORIZONTAL));
     sb4.setRect(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 Summary
static byte HORIZONTAL
          To be passed in the constructor
static byte VERTICAL
          To be passed in the constructor
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, font, foreColor, foreDis, height, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2
 
Constructor Summary
ScrollBar()
          Creates Scrollbar with default values:
maximum = 100
minimum = 0
orientation = VERTICAL
blockIncrement = 10
unitIncrement = 1
value = 0
visibleItems = 10
ScrollBar(byte orientation)
           
 
Method Summary
 int getBlockIncrement()
          Get the items to increment by clicking the above the scrollbar
 int getMaximum()
          Get the maximum of elements
 int getMinimum()
          Get the minimum of elements
 int getPreferredHeight()
          If this is a horizontal scroll bar, i strongly suggest you use PREFERRED in your control's height
 int getPreferredWidth()
          If this is a vertical scroll bar, i strongly suggest you use PREFERRED in your control's width.
 int getUnitIncrement()
          Get the items to increment by clicking the above the scrollbar
 int getValue()
          Get the value.
 int getVisibleItems()
          Get the count of visible items for the scrollbar
protected  void onBoundsChanged()
          Called after an setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called to process key, pen, control and other posted events.
 void onPaint(Graphics g)
          Draws the border (if any).
 void setBlockIncrement(int i)
          Set the items to increment by clicking the above the scrollbar.
 void setEnabled(boolean enabled)
          sets if this container and all childrens can or not accept events
 void setLiveScrolling(boolean liveScrolling)
          Set the live scrolling.
 void setMaximum(int i)
          Set the maximum of elements
 void setMinimum(int i)
          Set the minimum of elements
 void setUnitIncrement(int i)
          Set the items to increment by clicking the up button
 void setValue(int i)
          Set the value if visibleItems+i+minimum <= maximum.
 void setValues(int newValue, int newVisibleItems, int newMinimum, int newMaximum)
          Sets the value, visibleItems, minimum and maximum values
 void setVisibleItems(int i)
          Set the count of visible items for the scrollbar.
 
Methods inherited from class waba.ui.Container
add, add, add, broadcastEvent, findChild, getChildren, getClientRect, onStart, paintChildren, remove, setBorderStyle
 
Methods inherited from class waba.ui.Control
addTimer, contains, createGraphics, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onFontChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, toString, wait, wait
 

Field Detail

VERTICAL

public static final byte VERTICAL
To be passed in the constructor

HORIZONTAL

public static final byte HORIZONTAL
To be passed in the constructor
Constructor Detail

ScrollBar

public ScrollBar()
Creates Scrollbar with default values:
maximum = 100
minimum = 0
orientation = VERTICAL
blockIncrement = 10
unitIncrement = 1
value = 0
visibleItems = 10

ScrollBar

public ScrollBar(byte orientation)
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 of elements

getMaximum

public int getMaximum()
Get the maximum of elements

setMinimum

public void setMinimum(int i)
Set the minimum of elements

getMinimum

public int getMinimum()
Get the minimum of elements

setBlockIncrement

public void setBlockIncrement(int i)
Set the items to increment by clicking the above the scrollbar. This value is set as default to be equal to visibleItems.

getBlockIncrement

public int getBlockIncrement()
Get the items to increment by clicking the above the scrollbar

setUnitIncrement

public void setUnitIncrement(int i)
Set the items to increment by clicking the up button

getUnitIncrement

public int getUnitIncrement()
Get the items to increment by clicking the above the scrollbar

setValue

public void setValue(int i)
Set the value if visibleItems+i+minimum <= maximum.

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, neither can change (unless the control height changes). 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.

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
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

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
Tags copied from class: Control
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.
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
Overrides:
getPreferredHeight in class Control

onBoundsChanged

protected void onBoundsChanged()
Description copied from class: Control
Called after an setRect.
Overrides:
onBoundsChanged in class Control