danger.ui
Class LinkTextBox

java.lang.Object
  extended by danger.app.Listener
      extended by danger.ui.View
          extended by danger.ui.Container
              extended by danger.ui.Control
                  extended by danger.ui.WrappedText
                      extended by danger.ui.DisplayText
                          extended by danger.ui.StaticTextBox
                              extended by danger.ui.ScrollingTextBox
                                  extended by danger.ui.LinkTextBox
All Implemented Interfaces:
Anchored, Spanned, TextControl, ToolTipOwner, GetChars, CharSequence
Direct Known Subclasses:
LogTextBox, SelectTextBox


public class LinkTextBox
extends ScrollingTextBox
implements Anchored

This class is a text box within which the user can select and click inline links.

The CharSequence returned from WrappedText.getContents() is not guaranteed to be Spannable unless a Spanned was passed to setText().


Field Summary
 
Fields inherited from class danger.ui.WrappedText
JUSTIFY_CENTER, JUSTIFY_LEFT, JUSTIFY_RIGHT
 
Fields inherited from class danger.ui.View
DEFAULT_SCROLL_FOCUS_MARGIN, FOCUS_DEFAULT, FOCUS_DOWNWARD, FOCUS_FROM_NOWHERE, FOCUS_LEFTWARD, FOCUS_NONE, FOCUS_RIGHTWARD, FOCUS_UPWARD, HEIGHT_AUTO, HEIGHT_FILL_TO_BOTTOM, HEIGHT_FILL_TO_TOP, HEIGHT_MATCH_CONTROL, HEIGHT_PERCENTAGE, POSITION_ABOVE, POSITION_ALIGN_BASELINE, POSITION_ALIGN_BOTTOM, POSITION_ALIGN_HORIZONTALLY, POSITION_ALIGN_LEFT, POSITION_ALIGN_PARENT_BOTTOM, POSITION_ALIGN_PARENT_RIGHT, POSITION_ALIGN_PARENT_TOP, POSITION_ALIGN_RIGHT, POSITION_ALIGN_TOP, POSITION_ALIGN_VERTICALLY, POSITION_BELOW, POSITION_BELOW_GROUP_BOX_HEADING, POSITION_CENTER_HORIZONTALLY, POSITION_CENTER_VERTICALLY, POSITION_TO_LEFT, POSITION_TO_RIGHT, PREFER_DIRECTION_NONE, PREFER_HORIZONTAL_DIRECTION, PREFER_VERTICAL_DIRECTION, STATE_AT_AND_SPACE_PAGE, STATE_CAN_FOCUS, STATE_DEBUG_BOUNDS, STATE_ENABLED, STATE_FOCUSED, STATE_MAKE_DING, STATE_PARTIAL_FOCUS_OK, STATE_TRANSPARENT, STATE_VISIBLE, WIDTH_AUTO, WIDTH_FILL_TO_LEFT, WIDTH_FILL_TO_RIGHT, WIDTH_MATCH_CONTROL, WIDTH_PERCENTAGE
 
Constructor Summary
LinkTextBox()
          Create a new LinkTextBox with no title.
LinkTextBox(String title)
          Create a new LinkTextBox with the specified title.
 
Method Summary
 boolean addLinkMenuItems(Menu addTo)
          Append the context menu items for the currently selected link, if any, to the specified menu.
 boolean eventKeyUp(char c, Event event)
          Standard UI method: handles the return key, which activates links.
 boolean eventWidgetDown(int widget, Event event)
          Standard UI method: handles rolling and paging down (which advance focus), and arrow up and down (which reverse and advance focus, respectively).
 boolean eventWidgetUp(int widget, Event event)
          Standard UI method: handles the wheel button (which activates links) and rolling and paging up (which reverse link focus).
 boolean getAcceptFocusOnlyWhenLinksVisible()
          Return what you specified in setAcceptFocusOnlyWhenLinksVisible(boolean)
 boolean getCanMakeChanges()
          Return whether the user can make changes to the text.
 ClickSpan getClickSpan()
          Return the currently selected ClickSpan.
 Menu getLinkOptionsMenu()
          Return the "Links" menu, which provides contextual items appropriate to the selected link, or null if none.
 boolean getLinksFocusable()
          Find out whether or not the inline links feature is enabled.
 void loseFocus()
          When a LinkTextBox loses focus, any visible link it may previously have had focused within loses focus.
 boolean moveToAnchor(String anchor)
          Set the scroll position to bring the named anchor into view, if there is such an anchor.
 boolean pageToEnd()
          Standard UI method: after paging to the end, try to select a link that has become visible.
 boolean pageToHome()
          Standard UI method: after paging to the start, try to select a link that has become visible.
 boolean receiveEvent(Event e)
          Standard UI method: receives events to give focus to a visible link (if any) after ScrollView paging.
protected  boolean selectNextLink()
          Select the next visible link, if any.
protected  boolean selectNextLinkBelow(int line)
          Select the next visible link on or below the specified line, if any.
protected  boolean selectNextLinkOn(int line)
          Select the next visible link on the specified line, if any.
protected  boolean selectPreviousLink()
          Select the previous visible link, if any.
protected  boolean selectPreviousLinkAbove(int line)
          Select the previous visible link on or above the specified line, if any.
protected  boolean selectPreviousLinkOn(int line)
          Select the previous visible link on the specified line, if any.
 void setAcceptFocusOnlyWhenLinksVisible(boolean whether)
          Set whether the LinkTextBox will decline focus unless there is a link visible.
 void setLinksFocusable(boolean whether)
          Enable or disable the inline links feature.
 boolean showContextMenu(int enterMenuFlags)
          Show the context menu, if any, for the currently selected link.
 void takeFocus(boolean fromAbove)
          When a LinkTextBox takes focus, it tries to focus the first visible link if from above or the last visible link if from below.
 boolean willFocusWithin(Rect r)
          If you setAcceptFocusOnlyWhenLinksVisible(boolean), the LinkTextBox will decline focus unless there is a link in view.
 boolean willFocusWithin(Rect r, boolean fromAbove)
          If you setAcceptFocusOnlyWhenLinksVisible(boolean), the LinkTextBox will decline focus unless there is a link in view.
 
Methods inherited from class danger.ui.ScrollingTextBox
canSuperFocus, drawContent, getBackgroundColor, getFocusPadding, getInterestingRect, getLabelWhenEmpty, getScrolling, getTextBackgroundColor, getTextColor, getTextOutlineColor, isSuperFocused, setCanSuperFocus, setLabelWhenEmpty, setScrolling, setSuperFocused
 
Methods inherited from class danger.ui.StaticTextBox
bringPointIntoView, chooseWrapWidth, clear, drawFrame, drawTruncationIndicator, getAutoResize, getBaseline, getBorderShowsScrolling, getBottomBorder, getDrawTruncationIndicator, getHeightForLines, getLeftBorder, getPointRect, getRightBorder, getTopBorder, getVisibleSpans, getVisibleSpans, getWantQuoteHack, onSetHasBorder, onSetTitle, paint, setAcceptFocus, setAutoReflowChildren, setAutoResize, setBorderShowsScrolling, setDrawTruncationIndicator, setNumDisplayLines, setSize, setText, setText, setWantQuoteHack, textHeightChanged
 
Methods inherited from class danger.ui.DisplayText
attachScrollbar, canScrollDown, canScrollUp, detachScrollbar, drawText, getDisplayHorizontalScroll, getGrowFromBottom, getHorizontalScroll, getTextAreaHeight, getTextAreaWidth, getVerticalPadding, getVerticalScroll, pageDown, pageDown, pageUp, pageUp, paint, scrollDown, scrollUp, setDrawBottomCroppedText, setGrowFromBottom, setHorizontalScroll, setTextAreaHeight, setTextAreaWidth, setVerticalScroll, setWidth
 
Methods inherited from class danger.ui.WrappedText
afterTextChanged, beforeTextChanged, charAt, getAdvance, getAlignment, getAllSpans, getBlankAfterFinalNewline, getChars, getChars, getChars, getContents, getDisplayText, getFinalLineSpacing, getFont, getLine, getLineBaseline, getLineBottom, getLineCount, getLineEnd, getLineFlags, getLineForOffset, getLineForVertical, getLineParagraphStart, getLineSpacing, getLineStart, getLineTop, getLineVisibleLength, getSpanEnd, getSpanFlags, getSpansOverlapping, getSpanStart, getTabIncrement, getText, getTextHeight, getTextSequence, getVerticalDimensions, getWrapWidth, length, newLineBreaker, nextSpanTransition, numLines, onTextChanged, rewrap, setAlignment, setBlankAfterFinalNewline, setFinalLineSpacing, setFont, setLineSpacing, setMaxFontSize, setTabIncrement, setWrapWidth, subSequence, toString
 
Methods inherited from class danger.ui.Control
drawFocusBox, drawIdleBox, drawIdleBox, getEvent, getEventListener, getEventType, getHasBorder, getMaxToolTipLines, getTitle, getTitleSequence, getToolTip, getValue, hasToolTip, notifyWhenBaselineChanges, onBaselineChanged, onControlBaselineChanged, sendEvent, setEvent, setEvent, setEvent, setEvent, setEvent, setEventArg, setEventListener, setEventMethod, setHasBorder, setMaxToolTipLines, setTitle, setTitle, setToolTip, setValue, showToolTip
 
Methods inherited from class danger.ui.Container
addChild, addChild, addChildAt, addChildAt, addFromContainerResource, addFromContainerResource, addFromContainerResource, addFromDialogResource, addFromDialogResource, advanceFocus, advanceFocusInWindow, childCount, childIsOnScreen, disable, enable, eventKeyDown, eventKeyHeld, eventKeyRepeat, eventPeriodicPulse, eventRawKeyDown, eventRawKeyHeld, eventRawKeyRepeat, eventRawKeyUp, eventShortcut, eventWidgetHeld, focusedDescendantIsValid, getBottomChild, getBottomChild, getChildAt, getChildIndex, getChildWithID, getControlWithID, getDescendantWithID, getFirstChild, getFirstFocusableChild, getFocusableChildInWindow, getFocusedChild, getFocusedLeaf, getLastChild, getLastFocusableChild, getLeftMostChild, getNextFocusableChild, getNextFocusableChild, getPageHeight, getPrevFocusableChild, getPrevFocusableChild, getRightMostChild, getRightMostChild, handleButtonShortcut, hideAllChildren, isDescendant, keepRectInView, moveChildToIndex, onChildPositionChanged, onChildSizeChanged, onChildVisibilityChanged, paintChildren, reflowChildren, removeAllChildren, removeChild, reverseFocus, setFocusedChild, setFocusedChild, setFocusedChild, setFocusedDescendant, setFocusedDescendant, setFocusedDescendant, setFocusToFirstDescendant, setFormatDateForControlWithID, setFormatDateForTextControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setFormatTextForTextControlWithID, setListenerForAllControls, setReflowAdjustHeight, setWindow, showAllChildren, snapHeightToChildren, snapHeightToChildren, snapToChildren, snapWidthToChildren, snapWidthToChildren
 
Methods inherited from class danger.ui.View
boundsIntersect, boundsIntersect, canLoseFocus, clear, clear, copyStyle, getAcceptFocus, getBottom, getBounds, getBounds, getData, getFocusTraversalDirection, getFocusTraversalFrom, getFocusTraversalPolicy, getFrame, getFrame, getGlobalBottom, getGlobalLeft, getGlobalRight, getGlobalTop, getHeight, getID, getInterestingRect, getLabelFont, getLabelFont, getLeft, getOrigin, getOrigin, getOriginX, getOriginY, getParent, getParentContainer, getPartialFocusOK, getRight, getScrollFocusMargin, getSibling, getState, getStyle, getStyleColor, getStyleFont, getTop, getWidth, getWindow, globalToLocal, globalToLocalH, globalToLocalV, hide, invalidate, invalidate, invalidate, invalidateIndependentOfOrigin, invalidateIndependentOfOrigin, isEnabled, isFocusable, isFocused, isObscured, isOnScreen, isTransparent, isVisible, isVisibleInHierarchy, isVisibleOnScreen, justSetVisible, localToGlobal, localToGlobal, localToGlobalH, localToGlobalV, localToWindow, moveBy, notifyWhenFocusChanges, notifyWhenObscurityChanges, notifyWhenParentSizeChanges, notifyWhenPositionChanges, notifyWhenSizeChanges, notifyWhenVisibilityChanges, offsetOrigin, offsetOrigin, onAddedToParent, onDecoded, onEnabledStateChanged, onHide, onPeriodicPulse, onPositionChanged, onRemovedFromParent, onShortcut, onShortcut, onShortcutConsumed, onShow, onSizeChanged, onStyleChanged, onSystemFontChanged, onViewFocusChanged, onViewObscurityChanged, onViewPositionChanged, onViewSizeChanged, onViewVisibilityChanged, onWindowPaint, playLimitSound, receiveEventInternal, resetOrigin, sendEventToWindow, setAtAndSpacePage, setBackground, setBackgroundColor, setBottom, setData, setDebugBounds, setDynamicHeight, setDynamicPosition, setDynamicWidth, setEnabled, setFocusTraversalDirection, setFocusTraversalFrom, setFocusTraversalPolicy, setFrame, setHeight, setKeyedValue, setLabelFont, setLeft, setMakeLimitNoise, setOrigin, setOrigin, setPartialFocusOK, setPosition, setPreferredDirection, setRight, setScrollFocusMargin, setStyle, setStyleColor, setStyleFont, setStyleFrameColor, setTop, setTransparent, setVisible, shouldDropEvent, show, styleIsDefault, swapStyleColors, windowToLocal
 
Methods inherited from class danger.app.Listener
cancelEvents, childEventPump, childEventPumpDone, eventProblem, isDispatchingThread, sendEvent, sendEvent, sendEvent, sendEvent, sendEvent, sendLowPriorityEvent
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.lang.CharSequence
charAt, length, subSequence, toString
 
Methods inherited from interface danger.ui.TextControl
getFont, getTextSequence, setFont
 
Methods inherited from interface java.lang.CharSequence
charAt, length, subSequence, toString
 
Methods inherited from interface danger.util.GetChars
getChars
 
Methods inherited from interface java.lang.CharSequence
charAt, length, subSequence, toString
 

Constructor Detail

LinkTextBox

public LinkTextBox()
Create a new LinkTextBox with no title.


LinkTextBox

public LinkTextBox(String title)
Create a new LinkTextBox with the specified title.

Method Detail

takeFocus

public void takeFocus(boolean fromAbove)
When a LinkTextBox takes focus, it tries to focus the first visible link if from above or the last visible link if from below.

Overrides:
takeFocus in class ScrollingTextBox
Parameters:
fromAbove - whether the focus was entered into this view from above

loseFocus

public void loseFocus()
When a LinkTextBox loses focus, any visible link it may previously have had focused within loses focus.

Overrides:
loseFocus in class Control

eventWidgetUp

public boolean eventWidgetUp(int widget,
                             Event event)
Standard UI method: handles the wheel button (which activates links) and rolling and paging up (which reverse link focus).

Overrides:
eventWidgetUp in class ScrollingTextBox
Parameters:
widget - the widget that went down
Returns:
whether or not the event was consumed

eventWidgetDown

public boolean eventWidgetDown(int widget,
                               Event event)
Standard UI method: handles rolling and paging down (which advance focus), and arrow up and down (which reverse and advance focus, respectively).

Overrides:
eventWidgetDown in class ScrollingTextBox
Parameters:
widget - the widget that went up
Returns:
whether or not the event was consumed

getCanMakeChanges

public boolean getCanMakeChanges()
Return whether the user can make changes to the text. This is of course always false at this level but not necessarily in EditText; the method is here to keep the return key from activating links when making changes is enabled.


eventKeyUp

public boolean eventKeyUp(char c,
                          Event event)
Standard UI method: handles the return key, which activates links.

Overrides:
eventKeyUp in class StaticTextBox
Parameters:
c - the character being released.

willFocusWithin

public boolean willFocusWithin(Rect r,
                               boolean fromAbove)
If you setAcceptFocusOnlyWhenLinksVisible(boolean), the LinkTextBox will decline focus unless there is a link in view.

Overrides:
willFocusWithin in class Container
Parameters:
r - the rectangle to be displayed in
fromAbove - true if the focus is coming from above; false if it is coming from below

willFocusWithin

public boolean willFocusWithin(Rect r)
If you setAcceptFocusOnlyWhenLinksVisible(boolean), the LinkTextBox will decline focus unless there is a link in view.

Overrides:
willFocusWithin in class Container

getAcceptFocusOnlyWhenLinksVisible

public boolean getAcceptFocusOnlyWhenLinksVisible()
Return what you specified in setAcceptFocusOnlyWhenLinksVisible(boolean)


setAcceptFocusOnlyWhenLinksVisible

public void setAcceptFocusOnlyWhenLinksVisible(boolean whether)
Set whether the LinkTextBox will decline focus unless there is a link visible. This is mostly useful when the box is auto-resizing and embedded in a ScrollView, so it will take focus only after a link scrolls into view rather than immediately when the edge of the box is in view. Setting this for an editable text box would probably be a bad idea.


getLinkOptionsMenu

public Menu getLinkOptionsMenu()
Return the "Links" menu, which provides contextual items appropriate to the selected link, or null if none.


addLinkMenuItems

public boolean addLinkMenuItems(Menu addTo)
Append the context menu items for the currently selected link, if any, to the specified menu.

Parameters:
addTo - The Menu to add the items to.
Returns:
true if items were actually added to the menu.

showContextMenu

public boolean showContextMenu(int enterMenuFlags)
Show the context menu, if any, for the currently selected link.

Overrides:
showContextMenu in class View
Parameters:
enterMenuFlags - zero or more of BaseMenu.WITH_WIDGET_HELD and BaseMenu.WITH_KEY_HELD. This should be passed into BaseMenu.enterMenu(boolean).

receiveEvent

public boolean receiveEvent(Event e)
Standard UI method: receives events to give focus to a visible link (if any) after ScrollView paging.

Overrides:
receiveEvent in class Container
Parameters:
e - non-null; the event to process
Returns:
whether (true) or not (false) this method actually handled the event to completion

selectNextLink

protected final boolean selectNextLink()
Select the next visible link, if any.


selectNextLinkBelow

protected final boolean selectNextLinkBelow(int line)
Select the next visible link on or below the specified line, if any. This is used by SelectTextBox to advance the link focus after moving the cursor down.


selectNextLinkOn

protected final boolean selectNextLinkOn(int line)
Select the next visible link on the specified line, if any. This is used by SelectTextBox to advance the link focus before moving the cursor down.


selectPreviousLink

protected final boolean selectPreviousLink()
Select the previous visible link, if any.


selectPreviousLinkAbove

protected final boolean selectPreviousLinkAbove(int line)
Select the previous visible link on or above the specified line, if any. This is used by SelectTextBox to reverse the link focus after moving the cursor up.


selectPreviousLinkOn

protected final boolean selectPreviousLinkOn(int line)
Select the previous visible link on the specified line, if any. This is used by SelectTextBox to reverse the link focus before moving the cursor up.


getClickSpan

public ClickSpan getClickSpan()
Return the currently selected ClickSpan.

Returns:
The currently selected ClickSpan or null.

moveToAnchor

public boolean moveToAnchor(String anchor)
Set the scroll position to bring the named anchor into view, if there is such an anchor.

Specified by:
moveToAnchor in interface Anchored
Returns:
whether the text contains an anchor by that name.

setLinksFocusable

public final void setLinksFocusable(boolean whether)
Enable or disable the inline links feature. If this is not set, the LinkTextBox will basically be an ordinary ScrollingTextBox.


getLinksFocusable

public final boolean getLinksFocusable()
Find out whether or not the inline links feature is enabled.


pageToHome

public boolean pageToHome()
Standard UI method: after paging to the start, try to select a link that has become visible.

Overrides:
pageToHome in class DisplayText

pageToEnd

public boolean pageToEnd()
Standard UI method: after paging to the end, try to select a link that has become visible.

Overrides:
pageToEnd in class DisplayText