de.matthiasmann.twl
Class TextArea

java.lang.Object
  extended by de.matthiasmann.twl.Widget
      extended by de.matthiasmann.twl.TextArea

public class TextArea
extends Widget

Formatted text rendering (HTML/CSS subset). Supports embedded images, bullet point lists, hyper links, multiple fonts, block text, embedded widgets and floating elements. It uses a simplified HTML/CSS model.


Nested Class Summary
static interface TextArea.Callback
           
static interface TextArea.Callback2
           
static interface TextArea.ImageResolver
           
static interface TextArea.WidgetResolver
           
 
Nested classes/interfaces inherited from class de.matthiasmann.twl.Widget
Widget.OffscreenMouseAdjustments, Widget.RenderOffscreen
 
Field Summary
static AnimationState.StateKey STATE_HOVER
           
 
Fields inherited from class de.matthiasmann.twl.Widget
STATE_DISABLED, STATE_HAS_FOCUSED_CHILD, STATE_HAS_OPEN_POPUPS, STATE_KEYBOARD_FOCUS
 
Constructor Summary
TextArea()
           
TextArea(TextAreaModel model)
           
 
Method Summary
 void addCallback(TextArea.Callback cb)
           
protected  void afterAddToGUI(GUI gui)
          Called after this widget has been added to a GUI tree.
protected  void allChildrenRemoved()
          All children have been removed.
protected  void applyTheme(ThemeInfo themeInfo)
          Apply the given theme.
protected  void applyThemeTextArea(ThemeInfo themeInfo)
           
protected  void childAdded(Widget child)
          A new child has been added.
protected  void childRemoved(Widget exChild)
          A child has been removed.
 void destroy()
          Clean up GL resources.
 DraggableButton.DragListener getDragListener()
           
 Rect getElementRect(TextAreaModel.Element element)
           
 TextAreaModel getModel()
           
 int getPreferredInnerHeight()
          Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children.
 int getPreferredInnerWidth()
          Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children.
 int getPreferredWidth()
          Returns the preferred width based on it's children and preferred inner width.
 StyleSheetResolver getStyleClassResolver()
           
protected  java.lang.Object getTooltipContentAt(int mouseX, int mouseY)
          Automatic tooltip support.
protected  boolean handleEvent(Event evt)
          Called when an event occurred that this widget could be interested in.
 void insertChild(Widget child, int index)
          Inserts a new child into this widget.
protected  void layout()
          Called when the layoutInvalid flag is set.
protected  void paintWidget(GUI gui)
          Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.
 void registerImage(java.lang.String name, Image image)
           
 void registerImageResolver(TextArea.ImageResolver resolver)
           
 void registerWidget(java.lang.String name, Widget widget)
           
 void registerWidgetResolver(java.lang.String name, TextArea.WidgetResolver resolver)
           
 void removeAllChildren()
          Removes all children of this widget.
 void removeCallback(TextArea.Callback cb)
           
 Widget removeChild(int index)
          Removes the specified child from this widget.
 void setDefaultStyleSheet()
          Sets a default style sheet with the following content:
 void setDragListener(DraggableButton.DragListener dragListener)
           
 void setMaxSize(int width, int height)
          Sets the maximum size of the widget.
 void setMinSize(int width, int height)
          Sets the minimum size of the widget.
 void setModel(TextAreaModel model)
           
 void setStyleClassResolver(StyleSheetResolver styleClassResolver)
           
protected  void sizeChanged()
          Called when the size of this widget has changed.
 void unregisterAllWidgets()
           
 void unregisterImage(java.lang.String name)
           
 void unregisterImageResolver(TextArea.ImageResolver imageResolver)
           
 void unregisterWidget(java.lang.String name)
           
 void unregisterWidgetResolver(java.lang.String name)
           
 
Methods inherited from class de.matthiasmann.twl.Widget
add, addActionMapping, addPropertyChangeListener, addPropertyChangeListener, adjustSize, applyThemeBackground, applyThemeBorder, applyThemeInputMap, applyThemeMaxSize, applyThemeMinSize, applyThemeMouseCursor, applyThemeOffscreenExtra, applyThemeOverlay, applyThemeTooltip, beforeRemoveFromGUI, borderChanged, canAcceptKeyboardFocus, childInvalidateLayout, childVisibilityChanged, computeSize, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, focusFirstChild, focusLastChild, focusNextChild, focusPrevChild, getActionMap, getAnimationState, getBackground, getBorderBottom, getBorderHorizontal, getBorderLeft, getBorderRight, getBorderTop, getBorderVertical, getBottom, getChild, getChildAt, getChildIndex, getGUI, getHeight, getInnerBottom, getInnerHeight, getInnerRight, getInnerWidth, getInnerX, getInnerY, getInputMap, getKeyboardFocusOrder, getMaxHeight, getMaxWidth, getMinHeight, getMinWidth, getMouseCursor, getMouseCursor, getNumChildren, getOffscreenExtraBottom, getOffscreenExtraLeft, getOffscreenExtraRight, getOffscreenExtraTop, getOrCreateActionMap, getOverlay, getParent, getPreferredHeight, getRenderOffscreen, getRight, getRootWidget, getTheme, getThemePath, getThemeTooltipContent, getTintAnimator, getTooltipContent, getWidgetAt, getWidth, getX, getY, giveupKeyboardFocus, handleKeyStrokeAction, hasKeyboardFocus, hasOpenPopups, hasSharedAnimationState, invalidateLayout, invalidateLayoutLocally, isAbsoluteTheme, isClip, isDepthFocusTraversal, isEnabled, isFocusKeyEnabled, isInside, isLocallyEnabled, isMouseInside, isVisible, keyboardFocusChildChanged, keyboardFocusGained, keyboardFocusGained, keyboardFocusLost, layoutChildFullInnerArea, layoutChildrenFullInnerArea, moveChild, paint, paintBackground, paintChild, paintChildren, paintDragOverlay, paintOverlay, positionChanged, reapplyTheme, removeChild, removePropertyChangeListener, removePropertyChangeListener, requestKeyboardFocus, requestKeyboardFocus, resetTooltip, setActionMap, setBackground, setBorderSize, setBorderSize, setBorderSize, setBorderSize, setCanAcceptKeyboardFocus, setClip, setDepthFocusTraversal, setEnabled, setFocusKeyEnabled, setInnerSize, setInputMap, setMouseCursor, setOffscreenExtra, setOffscreenExtra, setOverlay, setPosition, setRenderOffscreen, setSize, setTheme, setTintAnimator, setTooltipContent, setVisible, updateTintAnimation, updateTooltip, validateLayout, widgetDisabled
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

STATE_HOVER

public static final AnimationState.StateKey STATE_HOVER
Constructor Detail

TextArea

public TextArea()

TextArea

public TextArea(TextAreaModel model)
Method Detail

getModel

public TextAreaModel getModel()

setModel

public void setModel(TextAreaModel model)

registerWidget

public void registerWidget(java.lang.String name,
                           Widget widget)

registerWidgetResolver

public void registerWidgetResolver(java.lang.String name,
                                   TextArea.WidgetResolver resolver)

unregisterWidgetResolver

public void unregisterWidgetResolver(java.lang.String name)

unregisterWidget

public void unregisterWidget(java.lang.String name)

unregisterAllWidgets

public void unregisterAllWidgets()

registerImage

public void registerImage(java.lang.String name,
                          Image image)

registerImageResolver

public void registerImageResolver(TextArea.ImageResolver resolver)

unregisterImage

public void unregisterImage(java.lang.String name)

unregisterImageResolver

public void unregisterImageResolver(TextArea.ImageResolver imageResolver)

addCallback

public void addCallback(TextArea.Callback cb)

removeCallback

public void removeCallback(TextArea.Callback cb)

getDragListener

public DraggableButton.DragListener getDragListener()

setDragListener

public void setDragListener(DraggableButton.DragListener dragListener)

getStyleClassResolver

public StyleSheetResolver getStyleClassResolver()

setStyleClassResolver

public void setStyleClassResolver(StyleSheetResolver styleClassResolver)

setDefaultStyleSheet

public void setDefaultStyleSheet()
Sets a default style sheet with the following content:
p, ul {
    margin-bottom: 1em
}
pre {
    white-space: pre
}


getElementRect

public Rect getElementRect(TextAreaModel.Element element)

applyTheme

protected void applyTheme(ThemeInfo themeInfo)
Description copied from class: Widget
Apply the given theme. This method also calls invalidateLayout()

Overrides:
applyTheme in class Widget
Parameters:
themeInfo - The theme info for this widget

applyThemeTextArea

protected void applyThemeTextArea(ThemeInfo themeInfo)

afterAddToGUI

protected void afterAddToGUI(GUI gui)
Description copied from class: Widget
Called after this widget has been added to a GUI tree.

Overrides:
afterAddToGUI in class Widget
Parameters:
gui - the GUI object - same as getGUI()
See Also:
Widget.getGUI()

insertChild

public void insertChild(Widget child,
                        int index)
Description copied from class: Widget
Inserts a new child into this widget. The position of the child is treated as relative to this widget and adjusted. If a theme was applied to this widget then this theme is also applied to the new child.

Overrides:
insertChild in class Widget
Parameters:
child - the child that should be inserted
index - the index where it should be inserted

removeAllChildren

public void removeAllChildren()
Description copied from class: Widget
Removes all children of this widget. The position of the all removed children is changed to the relative position to this widget. Calls allChildrenRemoved after removing all children.

Overrides:
removeAllChildren in class Widget
See Also:
Widget.allChildrenRemoved()

removeChild

public Widget removeChild(int index)
Description copied from class: Widget
Removes the specified child from this widget. The position of the removed child is changed to the relative position to this widget. Calls invalidateLayout after removing the child.

Overrides:
removeChild in class Widget
Parameters:
index - the index of the child
Returns:
the removed widget
See Also:
Widget.invalidateLayout()

getPreferredInnerWidth

public int getPreferredInnerWidth()
Description copied from class: Widget
Computes the preferred inner width (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerWidth in class Widget
Returns:
the preferred inner width

getPreferredInnerHeight

public int getPreferredInnerHeight()
Description copied from class: Widget
Computes the preferred inner height (the size of the widget without the border) The default implementation uses the current position of the children. It is highly recommended to override this method as the default implementation lead to unstable layouts. The default behavior might change in the future to provide a better default behavior.

Overrides:
getPreferredInnerHeight in class Widget
Returns:
the preferred inner height

getPreferredWidth

public int getPreferredWidth()
Description copied from class: Widget
Returns the preferred width based on it's children and preferred inner width. Subclasses can overwrite this method to compute the preferred size differently.

Overrides:
getPreferredWidth in class Widget
Returns:
the preferred width.
See Also:
Widget.getPreferredInnerWidth()

setMaxSize

public void setMaxSize(int width,
                       int height)
Description copied from class: Widget
Sets the maximum size of the widget. A value of 0 means no expansion, use Short.MAX_VALUE for unbounded expansion.

The maximum size is set via the theme in Widget.applyThemeMaxSize(de.matthiasmann.twl.ThemeInfo)

Overrides:
setMaxSize in class Widget
Parameters:
width - the maximum width
height - the maximum height
See Also:
Widget.getMaxWidth(), Widget.getMaxHeight()

setMinSize

public void setMinSize(int width,
                       int height)
Description copied from class: Widget
Sets the minimum size of the widget. This size includes the border.

The minimum size is set via the theme in Widget.applyThemeMinSize(de.matthiasmann.twl.ThemeInfo)

Overrides:
setMinSize in class Widget
Parameters:
width - the minimum width
height - the minimum height
See Also:
Widget.getMinWidth(), Widget.getMinHeight()

layout

protected void layout()
Description copied from class: Widget
Called when the layoutInvalid flag is set. The default implementation does nothing.

Overrides:
layout in class Widget

paintWidget

protected void paintWidget(GUI gui)
Description copied from class: Widget
Called by Widget.paint(de.matthiasmann.twl.GUI) after painting the background and before painting all children.

This should be overwritten instead of paint if normal themeable painting is desired by the subclass.

The default implementation does nothing.

Overrides:
paintWidget in class Widget
Parameters:
gui - the GUI object - it's the same as getGUI()

sizeChanged

protected void sizeChanged()
Description copied from class: Widget
Called when the size of this widget has changed. The default implementation calls invalidateLayoutLocally. As size changes are normally the result of the parent's layout() function.

Overrides:
sizeChanged in class Widget
See Also:
Widget.invalidateLayoutLocally()

childAdded

protected void childAdded(Widget child)
Description copied from class: Widget
A new child has been added. The default implementation calls invalidateLayout.

Overrides:
childAdded in class Widget
Parameters:
child - the new child
See Also:
Widget.invalidateLayout()

childRemoved

protected void childRemoved(Widget exChild)
Description copied from class: Widget
A child has been removed. The default implementation calls invalidateLayout.

Overrides:
childRemoved in class Widget
Parameters:
exChild - the removed widget - no longer a child
See Also:
Widget.invalidateLayout()

allChildrenRemoved

protected void allChildrenRemoved()
Description copied from class: Widget
All children have been removed. This is called by removeAllChildren instead of childRemoved. The default implementation calls invalidateLayout.

Overrides:
allChildrenRemoved in class Widget
See Also:
Widget.invalidateLayout()

destroy

public void destroy()
Description copied from class: Widget
Clean up GL resources. When overwritten then super method must be called.

Overrides:
destroy in class Widget

handleEvent

protected boolean handleEvent(Event evt)
Description copied from class: Widget
Called when an event occurred that this widget could be interested in.

The default implementation handles only keyboard events and delegates them to the child widget which has keyboard focus. If focusKey handling is enabled then this widget cycles the keyboard focus through it's children. If the key was not consumed by a child or focusKey and an inputMap is specified then the event is translated by the InputMap and handleKeyStrokeAction is called when a mapping was found.

If the widget wants to receive mouse events then it must return true for all mouse events except for MOUSE_WHEEL (which is optional) event. Otherwise the following mouse event are not send. Before mouse movement or button events are send a MOUSE_ENTERED event is send first.

Overrides:
handleEvent in class Widget
Parameters:
evt - The event - do not store this object - it may be reused
Returns:
true if the widget handled this event
See Also:
Widget.setFocusKeyEnabled(boolean), Widget.handleKeyStrokeAction(java.lang.String, de.matthiasmann.twl.Event), Widget.setInputMap(de.matthiasmann.twl.InputMap)

getTooltipContentAt

protected java.lang.Object getTooltipContentAt(int mouseX,
                                               int mouseY)
Description copied from class: Widget
Automatic tooltip support. This function is called when the mouse is idle over the widget for a certain time. The default implementation returns the result from getTooltipContent if it is non null, otherwise the result from getThemeTooltipContent is returned. This method is not called if the tooltip is already open and the mouse is moved but does not leave this widget. If the tooltip depends on the mouse position then updateTooltip must be called from handleEvent.

Overrides:
getTooltipContentAt in class Widget
Parameters:
mouseX - the mouse X coordinate
mouseY - the mouse Y coordinate
Returns:
the tooltip message or null if no tooltip is specified.
See Also:
Widget.updateTooltip()