Class ControlListBox

java.lang.Object
  extended bywaba.ui.Control
      extended bywaba.ui.Container
          extended byControlListBox
All Implemented Interfaces:
waba.fx.ISurface

public class ControlListBox
extends waba.ui.Container

A ListBox-like container which allows adding of arbitrary non-homogenous controls (instead of text strings).

ControlListBox is 'yet another' implementation of a scrollable container, this time in the spirit of a ListBox which allows the addition of arbitrary controls.

As the name 'listbox' implies, the intention is that items get stacked vertically. It's meant to look and feel a bit like a listbox, except that it allows virtually any Control or subclass to be added.

So far, there is no support for horizontal scrolling, which puts the onus on the programmer to ensure that the added items' width does not exceed this control's width.

Scrollbar is initially invisible, and becomes visible only when needed. Scrolling strategy is pixel-oriented, not item-oriented. But you can invoke setScrollLineAmount to change the step scroll amount.

This is a work in progress - no support exists yet for highlighting, finding or removing items.

You should have received a file called 'Test.java' along with this file. Test.java provides a very clear demonstration.

The anatomy of this control is an outer container holding a viewport container and a scrollbar. The viewport container holds an inner content container, to which the child widgets are added.


Field Summary
protected  waba.util.Vector childControls
           
 waba.ui.Container content
           
protected  int hContent
           
protected  int numChildControls
           
 waba.ui.ScrollBar scrollbar
           
protected  boolean scrollbarShowing
           
protected  int scrollLineAmount
           
 waba.ui.Container viewport
           
protected  int wContent
           
protected  int wScrollbar
           
protected  int xContent
           
protected  int yContent
           
 
Fields inherited from class waba.ui.Container
BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_SIMPLE, children, lastH, lastW, lastX, lastY, parentWindow, started, tabOrder, tail
 
Fields inherited from class waba.ui.Control
AFTER, appId, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, visible, width, x, x2, y, y2
 
Constructor Summary
ControlListBox()
          Creates a ControlListBox widget

After creating this widget, you should setRect() it
 
Method Summary
 void add(waba.ui.Control ctrl)
          Add a single control to this widget, sizing the control to its preferred width/height

If you really want to enforce a size for the control, use the addSized() method instead.
 void add(waba.ui.Control ctrl, int x, int y)
          Dummy override that just passes to add(Control) Both arguments will be ignored.
 void addSized(waba.ui.Control ctrl, int w, int h)
          add a Control to this widget, explicitly setting its width and height
 void debugPopup()
           
 int find(waba.ui.Control c)
          Search for child control c, returning its index if it is in fact a child control, or -1 if it is not present on this widget
 void insert(int idx, waba.ui.Control c)
           
 void insert(int idx, waba.ui.Control c, int height)
          Inserts a control into this widget at given index
 void onEvent(waba.ui.Event e)
          Called by system, to handle scrollbar events
 void remove(waba.ui.Control c)
          Remove a control from this widget
 void remove(int idx)
          Remove the control at the given index
 void resizeChild(int idx, int newHeight)
          changes the height of a child control
 void resizeControl(waba.ui.Control c, int newHeight)
          changes the height of a child control
 void scroll(int dy)
          Scroll the viewable area by a given number of pixels.
 void scrollDownFully()
          Scroll all the way to the bottom
 void scrollDownLine()
          Scroll down one line (using the parameter given in the last call to setScrollLineAmount)
 void scrollDownPage()
          Scroll down one page (less a line's worth)
 void scrollUpFully()
          Scroll all the way to the top
 void scrollUpLine()
          Scroll up one line (using the parameter given in the last call to setScrollLineAmount)
 void scrollUpPage()
          Scroll up one page (less a line's worth)
 void setRect(int x, int y, int w, int h)
          Adjusts size and placement of this widget, and updates the inner structure as needed
 void setRect(waba.fx.Rect r)
          Adjusts size and placement of this widget, and updates the inner structure as needed
 void setScrollLineAmount(int numPixels)
          Set the number of pixels by which the control should line-scroll.
protected  void shiftContents(int idx, int dy)
           
protected  void updatePanes()
          shows or hides the scrollbar, ensuring that if the scrollbar is displayed, it is updated
protected  void updateScrollbar()
          Update scrollbar state if required
 
Methods inherited from class waba.ui.Container
add, broadcastEvent, findChild, getChildren, getClientRect, getClientRect, onAdd, onColorsChanged, onPaint, onRemove, onStart, paintChildren, setBorderStyle, setEnabled, setHighlighting
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getPreferredHeight, getPreferredWidth, getRect, getSize, isDisplayed, isEnabled, isVisible, onBoundsChanged, onFontChanged, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

viewport

public waba.ui.Container viewport

content

public waba.ui.Container content

xContent

protected int xContent

yContent

protected int yContent

wContent

protected int wContent

hContent

protected int hContent

scrollbar

public waba.ui.ScrollBar scrollbar

wScrollbar

protected int wScrollbar

scrollbarShowing

protected boolean scrollbarShowing

scrollLineAmount

protected int scrollLineAmount

childControls

protected waba.util.Vector childControls

numChildControls

protected int numChildControls
Constructor Detail

ControlListBox

public ControlListBox()
Creates a ControlListBox widget

After creating this widget, you should setRect() it

Method Detail

setRect

public void setRect(int x,
                    int y,
                    int w,
                    int h)
Adjusts size and placement of this widget, and updates the inner structure as needed


setRect

public void setRect(waba.fx.Rect r)
Adjusts size and placement of this widget, and updates the inner structure as needed


add

public void add(waba.ui.Control ctrl,
                int x,
                int y)
Dummy override that just passes to add(Control) Both arguments will be ignored.


add

public void add(waba.ui.Control ctrl)
Add a single control to this widget, sizing the control to its preferred width/height

If you really want to enforce a size for the control, use the addSized() method instead.

Parameters:
ctrl - almost any widget object with Control in its pedigree

addSized

public void addSized(waba.ui.Control ctrl,
                     int w,
                     int h)
add a Control to this widget, explicitly setting its width and height

Parameters:
ctrl - the control to add
w - width to set for the control
h - height to set for the control

find

public int find(waba.ui.Control c)
Search for child control c, returning its index if it is in fact a child control, or -1 if it is not present on this widget


remove

public void remove(int idx)
Remove the control at the given index

Parameters:
idx - the integer index at which this control was added

remove

public void remove(waba.ui.Control c)
Remove a control from this widget


insert

public void insert(int idx,
                   waba.ui.Control c,
                   int height)
Inserts a control into this widget at given index


insert

public void insert(int idx,
                   waba.ui.Control c)

resizeControl

public void resizeControl(waba.ui.Control c,
                          int newHeight)
changes the height of a child control


resizeChild

public void resizeChild(int idx,
                        int newHeight)
changes the height of a child control


shiftContents

protected void shiftContents(int idx,
                             int dy)

scroll

public void scroll(int dy)
Scroll the viewable area by a given number of pixels. Negative scroll arg means view items higher on the list

Parameters:
dy - Number of pixels to scroll

scrollUpFully

public void scrollUpFully()
Scroll all the way to the top


scrollUpPage

public void scrollUpPage()
Scroll up one page (less a line's worth)


scrollUpLine

public void scrollUpLine()
Scroll up one line (using the parameter given in the last call to setScrollLineAmount)


scrollDownLine

public void scrollDownLine()
Scroll down one line (using the parameter given in the last call to setScrollLineAmount)


scrollDownPage

public void scrollDownPage()
Scroll down one page (less a line's worth)


scrollDownFully

public void scrollDownFully()
Scroll all the way to the bottom


setScrollLineAmount

public void setScrollLineAmount(int numPixels)
Set the number of pixels by which the control should line-scroll. Setting this to 11 gets accurate scrolling if the widget is populated only by Label controls/ Initially the widget is set to 10 pixels per line scroll

Parameters:
numPixels - the number of pixels per line, will be set to 1 if <= 0

updatePanes

protected void updatePanes()
shows or hides the scrollbar, ensuring that if the scrollbar is displayed, it is updated


updateScrollbar

protected void updateScrollbar()
Update scrollbar state if required


onEvent

public void onEvent(waba.ui.Event e)
Called by system, to handle scrollbar events


debugPopup

public void debugPopup()