GWT Tk 0.2.3

asquare.gwt.tk.client.ui.behavior
Class FocusModel

java.lang.Object
  extended by asquare.gwt.tk.client.ui.behavior.FocusModel

public class FocusModel
extends Object

A primitive focus model. Tracks the widgets in a focus cycle and which widget should be focused.


Constructor Summary
FocusModel()
           
 
Method Summary
 void add(HasFocus widget)
          Add a widget to the model.
 void add(HasFocus[] widgets)
          Add widgets to the model in bulk.
 void addListener(FocusModelListener listener)
           
 void clear()
          Remove all widgets from the model.
 int getCurrentIndex()
          Get the index corresponding to the currently focused widget.
 HasFocus getFocusWidget()
          Get the widget which is focused.
 int getIndexOf(HasFocus widget)
          Get the index of the specified widget in the model.
 HasFocus getNextWidget()
          Get the widget after the currently focused widget.
 HasFocus getNextWidget(boolean forward)
          Get the next widget in the cycle.
 HasFocus getPreviousWidget()
          Get the widget previous to the currently focused widget.
 int getSize()
          Get the number of widgets in the model.
 HasFocus getWidgetAt(int index)
          Get the widget at the specified index.
 void insert(HasFocus widget, int index)
          Inserts a widget into to the model at the specified index.
 void remove(HasFocus widget)
          Removes a widget from the model.
 void removeListener(FocusModelListener listener)
           
 void setFocusWidget(HasFocus widget)
          Set the widget which is focused.
protected  boolean shouldAdd(HasFocus widget)
          Determines whether the specified Widget can be added to the model.
protected  boolean shouldFocus(HasFocus w)
          Determines whether the specified Widget can receive focus.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FocusModel

public FocusModel()
Method Detail

addListener

public void addListener(FocusModelListener listener)

removeListener

public void removeListener(FocusModelListener listener)

getSize

public int getSize()
Get the number of widgets in the model.


clear

public void clear()
Remove all widgets from the model.


add

public void add(HasFocus[] widgets)
Add widgets to the model in bulk.

Parameters:
widgets - an array of 0 or more widgets
Throws:
IllegalArgumentException - if widgets is null
IllegalArgumentException - if an element is null
IllegalArgumentException - if an element is already present in the model
See Also:
shouldAdd(HasFocus)

add

public void add(HasFocus widget)
Add a widget to the model.

Parameters:
widget - a widget
Throws:
IllegalArgumentException - if widget is null
IllegalArgumentException - if widget is already present in the model
See Also:
shouldAdd(HasFocus)

insert

public void insert(HasFocus widget,
                   int index)
Inserts a widget into to the model at the specified index.

Parameters:
widget - a widget
index - an integer greater than 0 and less than or equal to number of widgets in the model
Throws:
IllegalArgumentException - if widget is null
IllegalArgumentException - if widget is already present in the model
IndexOutOfBoundsException - if index < 0 || index > getSize()
See Also:
shouldAdd(HasFocus)

shouldAdd

protected boolean shouldAdd(HasFocus widget)
Determines whether the specified Widget can be added to the model.

Parameters:
widget - a widget which is candidate to be added to the model
Returns:
true if widget.getTabIndex() >= 0

getCurrentIndex

public int getCurrentIndex()
Get the index corresponding to the currently focused widget.

Returns:
a value between 0 and getSize(), or -1 if no widget is focused

getIndexOf

public int getIndexOf(HasFocus widget)
Get the index of the specified widget in the model.

Parameters:
widget - a widget
Returns:
a valid index, or -1 if widget is not present in the model
Throws:
IllegalArgumentException - if widget is null

getWidgetAt

public HasFocus getWidgetAt(int index)
Get the widget at the specified index.

Parameters:
index - an integer greater than 0 and less than or equal to number of widgets in the model
Returns:
the widget
Throws:
IndexOutOfBoundsException - if index is out of range

remove

public void remove(HasFocus widget)
Removes a widget from the model.

Parameters:
widget -

getFocusWidget

public HasFocus getFocusWidget()
Get the widget which is focused.

Returns:
a widget, or null if no widget is focused

setFocusWidget

public void setFocusWidget(HasFocus widget)
Set the widget which is focused.

Parameters:
widget - a widget in the model, or null
Throws:
IllegalArgumentException - if widget is not present in the model and not null

getNextWidget

public HasFocus getNextWidget(boolean forward)
Get the next widget in the cycle. The widget is skipped if (widget.getTabIndex() < 0 || ! widget.isEnabled()).

Parameters:
forward - true to cycle forward, false to cycle backward
Returns:
the next focusable widget, or
the currently focused widget if no other focusable widget is available, or
null no if focusable widget is available
Throws:
IllegalStateException - if the model is empty

getNextWidget

public HasFocus getNextWidget()
Get the widget after the currently focused widget.

Returns:
the next widget
Throws:
IllegalStateException - if the model is empty

getPreviousWidget

public HasFocus getPreviousWidget()
Get the widget previous to the currently focused widget.

Returns:
the previous widget
Throws:
IllegalStateException - if the model is empty

shouldFocus

protected boolean shouldFocus(HasFocus w)
Determines whether the specified Widget can receive focus.

Parameters:
w - a widget in this model which is candidate for focus
Returns:
true unless w is a disabled FocusWidget

GWT Tk 0.2.3

© 2007 Mat Gessel