|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectdanger.app.Listener
danger.ui.View
danger.ui.ActiveListView
public class ActiveListView
This class is a UI object that manages and draws the contents of
an ActiveList (typically a StdActiveList).
This handles much of the expected human interaction. The arrow keys and the wheel can be used to navigate up and down through the list in the usual fashion.
If you want customized drawing to take place you will need to
subclass and override paintItemLine(danger.ui.Pen, int, int, int, int, boolean, java.lang.Object) and/or paintEmptyList(danger.ui.Pen, int, int).
If you want to actually do something when focus changes, then you
will need to override itemFocused(java.lang.Object). If you want to do something
when an item is activated (by pressing the button or return key), then
you will need to override itemActivated(java.lang.Object).
Alternatively, you can override the usual event methods to catch these things before this class gets a crack at them.
| Field Summary | |
|---|---|
protected CharSequence |
mToolTip
|
protected int |
mToolTipY
|
| Constructor Summary | |
|---|---|
ActiveListView()
Construct a new instance at (0, 0) with 0
width and height. |
|
ActiveListView(int left,
int top,
int right,
int bottom)
Construct a new instance with the given bounds. |
|
ActiveListView(Rect bounds)
Construct a new instance with the given bounds. |
|
| Method Summary | |
|---|---|
boolean |
eventKeyUp(char inChar,
Event event)
This method is called when the user releases a key. |
boolean |
eventShortcut(char c,
Event e)
Handle a shortcut key. |
boolean |
eventWidgetDown(int inWhichWidget,
Event event)
|
boolean |
eventWidgetUp(int inWhichWidget,
Event event)
|
boolean |
getAutoResize()
Get whether or not this instance automatically resizes its height when items are added to or removed from the list being viewed. |
protected int |
getContentWidth()
Get the usable width for content in this instance. |
protected int |
getFirstVisibleItemIndex()
|
int |
getFocus()
Get the index of the currently focused item, if any. |
Object |
getFocusedItem()
Get the currently focused item, if any. |
boolean |
getHasBorder()
Get whether or not this instance has a visible border. |
boolean |
getHasScrollbar()
Get whether or not this instance has a scrollbar. |
Rect |
getInterestingRect(Rect rect)
Store into the given Rect the area of this instance that is
most "interesting" (typically, an area of focus if the instance has
one), in the local coordinates of the instance itself. |
ActiveList |
getList()
Get the list of this instance. |
protected int |
getListSize()
Get the size of the list. |
int |
getMaxToolTipLines(int maxLines)
Get the maximum number of lines to show in a tool tip. |
protected int |
getMaxVisibleItems()
Get the maximum number of visible items, rounded down if the height isn't an even multiple of the item height (and assuming it's not the case that two partial items are shown). |
protected CharSequence |
getToolTipForItem(Object item)
Get the tooltip text to show for the currently focused item. |
boolean |
hasToolTip()
Returns whether a custom tooltip has been set for this view. |
protected void |
itemActivated(Object item)
Indicate that the given item was just activated (via button press or return key). |
protected void |
itemFocused(Object item)
Indicate that the given item just gained focus or, if passed null, that no item has focus. |
protected boolean |
itemIsFocused(int index)
|
protected void |
itemUpdated(Object item,
boolean isFocused)
Indicate that the given item just got updated. |
void |
loseFocus()
This method is called when this view loses its previous status as the focused child of a container. |
protected boolean |
moveFocus(int amount)
Move the focus. |
void |
onHide()
This method is called when this view is hidden, via the method View.hide(). |
void |
onItemAdded(ActiveList list,
Object item,
int index)
This method is called whenever an item is added to an ActiveList instance. |
void |
onItemRemoved(ActiveList list,
Object item,
int index)
This method is called whenever an individual item is removed from an ActiveList instance. |
void |
onItemsReordered(ActiveList list)
This method is called whenever items get reordered in an ActiveList instance. |
void |
onItemUpdated(ActiveList list,
Object item,
int index)
This method is called whenever an item is updated. |
void |
onRangeAdded(ActiveList list,
Object[] items,
int start)
This method is called whenever a contiguous range of items is added to an ActiveList instance. |
void |
onRangeRemoved(ActiveList list,
Object[] items,
int start)
This method is called whenever a range of items is removed from an ActiveList instance. |
boolean |
pageToEnd()
Page to the bottom of this view. |
boolean |
pageToHome()
Page to the top of this view. |
void |
paint(Pen p)
Draw the contents of this View. |
protected void |
paintEmptyList(Pen p,
int width,
int height)
This is called to paint this instance when there are no items in its list. |
protected void |
paintItemLine(Pen p,
int left,
int top,
int right,
int bottom,
boolean focused,
Object item)
Paint the given item at the given coordinates. |
protected void |
paintSelection(Pen p,
int left,
int top,
int right,
int bottom)
Fill a round-rect around the given area, as if it is focused. |
void |
setAutoResize(boolean autoResize)
Set whether or not this instance automatically resizes its height when items are added to or removed from the list being viewed. |
void |
setFocus(int index)
Set the focus to be at the given index. |
boolean |
setFocusedItem(Object item)
Set the focus to be the given item, if found in the list being viewed as compared with ==. |
void |
setHasBorder(boolean hasBorder)
Set whether or not this instance has a visible border. |
void |
setHasScrollbar(boolean hasScrollbar)
Set whether or not to display a scrollbar. |
void |
setItemHeight(int height)
Set the height of the items. |
void |
setList(ActiveList list)
Set the list of this instance, or set this instance to no longer have a list (if passed null). |
void |
setMaxToolTipLines(int maxLines)
Set the maximum number of lines to show in a tool tip. |
void |
setToolTip(CharSequence inToolTip)
Sets the tooltip text for this menu item. |
void |
showToolTip()
Show the tool tip for this view. |
void |
snapHeight()
Resize the height of this instance to fit all elements currently in the list it views. |
void |
takeFocus(boolean inFromAbove)
This method is called when this view is set as the focused child of a container through Container.setFocusedChild(danger.ui.View, boolean). |
| Methods inherited from class danger.app.Listener |
|---|
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, receiveEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected CharSequence mToolTip
protected int mToolTipY
| Constructor Detail |
|---|
public ActiveListView()
(0, 0) with 0
width and height. It is initially unattached to an ActiveList, set to accept focus, set not to auto-resize, has
an item height of 12, and has a scrollbar and a border.
public ActiveListView(Rect bounds)
ActiveList, set to accept focus, set
not to auto-resize, has an item height of 12,
and has a scrollbar and a border.
bounds - non-null; the bounds for the instance
public ActiveListView(int left,
int top,
int right,
int bottom)
ActiveList. It is initially unattached to
an ActiveList, set to accept focus, set not to
auto-resize, has an item height of 12, and has a
scrollbar and a border.
left - the left coordinate of the boundstop - the top coordinate of the boundsright - the right coordinate of the boundsbottom - the bottom coordinate of the bounds| Method Detail |
|---|
public final ActiveList getList()
public final void setList(ActiveList list)
null). If non-null,
this will call ActiveList.removeDelegate(danger.util.ActiveList.Delegate) on the old list and
ActiveList.addDelegate(danger.util.ActiveList.Delegate) on the new one, to remove this
instance as the old list's delegate and set this instance as the new
list's delegate.
list - null-ok; the list to renderpublic final void setItemHeight(int height)
height - > 0; the height of each itempublic final void setHasScrollbar(boolean hasScrollbar)
Note: It doesn't make sense to have an instance that both has a scrollbar and auto-resizes, so if a call to this method turns on the scrollbar, it will automatically force off auto-resize.
hasScrollbar - whether or not to display a scrollbarpublic final boolean getHasScrollbar()
public final void setHasBorder(boolean hasBorder)
hasBorder - whether or not this instance has a visible borderpublic final boolean getHasBorder()
public final void setAutoResize(boolean autoResize)
ScrollView, then it may make sense to have auto-resize
on; if, however, you are relying on this class to manage its own
scrolling, then you should not have auto-resize on.
Note: It doesn't make sense to have an instance that both has a scrollbar and auto-resizes, so if a call to this method turns on auto-resize, it will automatically force the scrollbar to be off.
autoResize - whether or not to auto-resizepublic final boolean getAutoResize()
public final void snapHeight()
public final Object getFocusedItem()
null
if there is no currently focused itempublic final boolean setFocusedItem(Object item)
==. If the item isn't found,
then the focus isn't changed.
item - null-ok; the item to focus
true iff the item was found and focusedpublic final int getFocus()
-1 if no item has focus.public final void setFocus(int index)
index - >= 0 && < size, where size is
the size of the list being viewed; the index for the focused item
IndexOutOfBoundsException - thrown if index is
out of range
public boolean eventWidgetDown(int inWhichWidget,
Event event)
eventWidgetDown in class View
public boolean eventWidgetUp(int inWhichWidget,
Event event)
eventWidgetUp in class View
public boolean eventKeyUp(char inChar,
Event event)
View
eventKeyUp in class View
public boolean eventShortcut(char c,
Event e)
ViewScreenWindow, DialogWindow,
BaseMenuWindow.
eventShortcut in class Viewc - the key that was pressede - the event associated with the key press
true if the shortcut was handledpublic boolean pageToHome()
ViewScrollView if the user
pages up in a scroll view that's already at the top.
This default implementation does nothing.
pageToHome in class Viewpublic boolean pageToEnd()
ViewScrollView if the user
pages down in a scroll view that's already at the bottom.
This default implementation does nothing.
pageToEnd in class Viewpublic void paint(Pen p)
ViewThe implementation of this method in this class will merely call
clear() pen, if this View is opaque (not transparent),
and will do nothing otherwise. If you don't need this behavior, then
there is no point in calling super.paint() in an
overriding method.
paint in class Viewp - non-null; the pen to use for drawing operationsprotected boolean itemIsFocused(int index)
public Rect getInterestingRect(Rect rect)
ViewRect the area of this instance that is
most "interesting" (typically, an area of focus if the instance has
one), in the local coordinates of the instance itself. (E.g.,
(0,0) represents the top-left of this instance.) This
method returns whatever object was passed in. By default, this
instance sets the rect's values to be the full bounds of this
instance, but you may override this behavior in a subclass that has
a more interesting area.
getInterestingRect in class Viewrect - non-null; the Rect to store the interesting values
into
rect, always
public void onItemUpdated(ActiveList list,
Object item,
int index)
ActiveList.DelegateActiveList instance notifies this
instance that is was updated via its update mechanism.
onItemUpdated in interface ActiveList.Delegatelist - non-null; the list which was notifieditem - null-ok; the item that was updatedindex - >= 0; the index that the item is at
public void onItemAdded(ActiveList list,
Object item,
int index)
ActiveList.DelegateActiveList instance.
onItemAdded in interface ActiveList.Delegatelist - non-null; the list which was modifieditem - null-ok; the item that was addedindex - >= 0; the index that the item was added
(inserted) at
public void onRangeAdded(ActiveList list,
Object[] items,
int start)
ActiveList.DelegateActiveList instance.
onRangeAdded in interface ActiveList.Delegatelist - non-null; the list which was modifieditems - non-null; array containing the items that were addedstart - >= 0; the start index that the range was added
(inserted) at
public void onItemRemoved(ActiveList list,
Object item,
int index)
ActiveList.DelegateActiveList instance. For example, StdActiveList.removeItem(java.lang.Object) or and StdActiveList.removeItemAt(int) are two concrete methods that remove
individual items from an instance.
onItemRemoved in interface ActiveList.Delegatelist - non-null; the list which was modifieditem - null-ok; the item that was removedindex - >= 0; the index that the item was removed from
public void onRangeRemoved(ActiveList list,
Object[] items,
int start)
ActiveList.DelegateActiveList instance. For example, StdActiveList.removeRange(int, int) and StdActiveList.removeAllItems()
are two concrete methods that remove ranges of items from an
instance.
onRangeRemoved in interface ActiveList.Delegatelist - non-null; the list which was modifieditems - non-null; array containing the removed itemsstart - >= 0; the start index that the items were
removed frompublic void onItemsReordered(ActiveList list)
ActiveList.DelegateActiveList instance. For example, StdActiveList.sort(java.util.Comparator) is
a concrete method that reorders the items of an instance.
onItemsReordered in interface ActiveList.Delegatelist - non-null; the list which was modifiedprotected final int getContentWidth()
protected void paintEmptyList(Pen p,
int width,
int height)
p - non-null; the pen to use for drawingwidth - the width of the area to draw inheight - the width of the area to draw in
protected void paintItemLine(Pen p,
int left,
int top,
int right,
int bottom,
boolean focused,
Object item)
paintSelection(danger.ui.Pen, int, int, int, int). Then, this simply draws the string form of the
item vertically centered in its area and left justified with a
margin of 2 pixels, in the BACKGROUND_COLOR if focused
or the FOREGROUND_COLOR if not.
p - non-null; the pen to use for drawingleft - the left of the area to draw intop - the top of the area to draw inright - the right of the area to draw inbottom - the bottom of the area to draw infocused - whether or not the item is currenctly focuseditem - non-null; the item to draw
protected void paintSelection(Pen p,
int left,
int top,
int right,
int bottom)
p - non-null; the pen to use for drawingleft - the left of the area to draw intop - the top of the area to draw inright - the right of the area to draw inbottom - the bottom of the area to draw inprotected void itemActivated(Object item)
null if an
activation action happened without any item in focus.
item - null-ok; the item that was just activatedprotected void itemFocused(Object item)
null, that no item has focus. This method does nothing
by default; it exists so subclasses can override it to do something
useful whenever the focus changes.
item - null-ok; the item that just got focused
protected void itemUpdated(Object item,
boolean isFocused)
item - non-null; the item that just got updatedisFocused - whether or not the item currently has focusprotected int getMaxVisibleItems()
protected int getListSize()
protected boolean moveFocus(int amount)
amount - the amount to move (negative for up, positive for down)
protected int getFirstVisibleItemIndex()
public final void setToolTip(CharSequence inToolTip)
inToolTip - the text to display to the userpublic final boolean hasToolTip()
public void showToolTip()
ToolTipOwner interface.
Generally, you will not need to call or override this method,
as it is called automatically. You can specify the content of
the tool tip by using setToolTip(java.lang.CharSequence).
showToolTip in interface ToolTipOwnerpublic void setMaxToolTipLines(int maxLines)
getMaxToolTipLines(int).
public final int getMaxToolTipLines(int maxLines)
setMaxToolTipLines(int).
public void takeFocus(boolean inFromAbove)
ViewContainer.setFocusedChild(danger.ui.View, boolean).
If you need to do anything special when taking focus, you should
override this method.
If you need to know the direction the focus is changing
(left/right/up/down), you can call View.getFocusTraversalDirection(boolean)
from within takeFocus.
In the rare occasion that you need to call this method yourself,
you should call View.setFocusTraversalDirection(int) and
View.setFocusTraversalFrom(danger.ui.View) immediately before calling this method.
takeFocus in class ViewinFromAbove - whether the focus was entered into this view from abovepublic void loseFocus()
ViewThis method is called when this view loses its previous status as the focused child of a container.
You generally wouldn't call this method yourself, but instead would override it if you wanted to know when the view is losing focus.
If you don't want this view to have focus anymore, you should
use Container.setFocusedChild(View) or
Container.setFocusedDescendant(View).
loseFocus in class Viewpublic void onHide()
ViewView.hide(). It is called as the very last thing done by that
method, and it is only ever called if the view was not already
hidden. Overriding this method is the recommended way to get special
behavior when a view gets hidden .
The implementation in this class does nothin.
onHide in class Viewprotected CharSequence getToolTipForItem(Object item)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||