Eclipse Draw2d
3.0

org.eclipse.draw2d.text
Class TextFlow

java.lang.Object
  extended byorg.eclipse.draw2d.Figure
      extended byorg.eclipse.draw2d.text.FlowFigure
          extended byorg.eclipse.draw2d.text.InlineFlow
              extended byorg.eclipse.draw2d.text.TextFlow
All Implemented Interfaces:
IFigure

public class TextFlow
extends InlineFlow

An inline flow that renders a string of text across one or more lines. A TextFlow must not have any children. It does not provide a FlowContext.

The TextFlow's fragments are sized using the text plus any required joiners. Clients should add the joiners to the text before breaking it up according to fragments.

WARNING: This class is not intended to be subclassed by clients.

Since:
2.1

Nested Class Summary
 
Nested classes inherited from class org.eclipse.draw2d.Figure
Figure.FigureIterator, Figure.IdentitySearch
 
Nested classes inherited from class org.eclipse.draw2d.IFigure
IFigure.NoInsets
 
Field Summary
 
Fields inherited from class org.eclipse.draw2d.Figure
bgColor, border, bounds, fgColor, flags, font, MAX_FLAG, maxSize, minSize, NO_MANAGER, prefSize, toolTip
 
Fields inherited from interface org.eclipse.draw2d.IFigure
MAX_DIMENSION, MIN_DIMENSION, NO_INSETS
 
Constructor Summary
TextFlow()
          Constructs a new TextFlow with the empty String.
TextFlow(String s)
          Constructs a new TextFlow with the specified String.
 
Method Summary
 String addJoiners(String text)
          Same as invoking prependJoiner(String) and appendJoiner(String) with the given text.
 boolean addLeadingWordRequirements(int[] width)
          Returns the width of the text until the first line-break.
 String appendJoiner(String text)
          Appends the Zero-Width Joiner character at the end of the given String if required.
protected  void contributeBidi(BidiProcessor proc)
          A TextFlow contributes its text.
protected  FlowFigureLayout createDefaultFlowLayout()
          Creates the default layout manager
 Rectangle getCaretPlacement(int offset, boolean trailing)
          Returns the rectangular bounds for placing a Caret at the given offset.
 int getFirstOffsetForLine(int y)
          Returns the first caret position which occupies the line at the given y location.
 int getLastOffsetForLine(int y)
          Returns the last caret position which occupies the line at the given y location.
 int getNextOffset(Point p, boolean down)
          Returns the offset nearest the given point either up or down one line.
 int getOffset(Point p, int[] trailing)
          Returns the textual offset nearest the specified point.
 String getText()
           
protected  void invalidateBidi()
          Throws away the cached Bidi state for this figure and all its children.
 boolean isTextTruncated()
          Returns true if a portion if the text is truncated using ellipses ("...").
protected  void paintFigure(Graphics g)
          Paints this Figure's primary representation, or background.
 String prependJoiner(String text)
          Prepends the Zero-Width Joiner character to the beginning of the given text if required.
 void setAppendJoiner(boolean append)
          This method is invoked by the BidiProcessor if it determines that a shaping character needs to be appended to the text contributed by this Figure for it to appear properly on the screen.
 void setPrependJoiner(boolean prepend)
          This method is invoked by the BidiProcessor if it determines that a shaping character needs to be prepended to the text contributed by this Figure for it to appear properly on the screen.
 void setSelection(int begin, int end)
          Sets the extent of selection.
 void setText(String s)
          Sets the string being displayed.
 
Methods inherited from class org.eclipse.draw2d.text.InlineFlow
containsPoint, getFragments, postValidate
 
Methods inherited from class org.eclipse.draw2d.text.FlowFigure
add, getBidiValues, remove, revalidateBidi, setBidiValues, setBounds, setFlowContext
 
Methods inherited from class org.eclipse.draw2d.Figure
add, add, add, addAncestorListener, addCoordinateListener, addFigureListener, addFocusListener, addKeyListener, addLayoutListener, addListener, addMouseListener, addMouseMotionListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, containsPoint, erase, findDescendantAtExcluding, findFigureAt, findFigureAt, findFigureAt, findFigureAtExcluding, findMouseEventTargetAt, findMouseEventTargetInDescendantsAt, fireCoordinateSystemChanged, fireFigureMoved, fireMoved, firePropertyChange, firePropertyChange, firePropertyChange, getBackgroundColor, getBorder, getBounds, getChildren, getClientArea, getClientArea, getCursor, getFlag, getFont, getForegroundColor, getInsets, getLayoutManager, getListeners, getLocalBackgroundColor, getLocalForegroundColor, getLocation, getMaximumSize, getMinimumSize, getMinimumSize, getParent, getPreferredSize, getPreferredSize, getSize, getToolTip, getUpdateManager, handleFocusGained, handleFocusLost, handleKeyPressed, handleKeyReleased, handleMouseDoubleClicked, handleMouseDragged, handleMouseEntered, handleMouseExited, handleMouseHover, handleMouseMoved, handleMousePressed, handleMouseReleased, hasFocus, internalGetEventDispatcher, intersects, invalidate, invalidateTree, isCoordinateSystem, isEnabled, isFocusTraversable, isMouseEventTarget, isOpaque, isRequestFocusEnabled, isShowing, isValid, isValidationRoot, isVisible, layout, paint, paintBorder, paintChildren, paintClientArea, primTranslate, removeAll, removeAncestorListener, removeCoordinateListener, removeFigureListener, removeFocusListener, removeKeyListener, removeLayoutListener, removeListener, removeMouseListener, removeMouseMotionListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, revalidate, setBackgroundColor, setBorder, setChildrenDirection, setChildrenEnabled, setChildrenOrientation, setConstraint, setCursor, setEnabled, setFlag, setFocusTraversable, setFont, setForegroundColor, setLayoutManager, setLocation, setMaximumSize, setMinimumSize, setOpaque, setParent, setPreferredSize, setPreferredSize, setRequestFocusEnabled, setSize, setSize, setToolTip, setValid, setVisible, translate, translateFromParent, translateToAbsolute, translateToParent, translateToRelative, useLocalCoordinates, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextFlow

public TextFlow()
Constructs a new TextFlow with the empty String.

See Also:
Object.Object()

TextFlow

public TextFlow(String s)
Constructs a new TextFlow with the specified String.

Parameters:
s - the string
Method Detail

addJoiners

public String addJoiners(String text)
Same as invoking prependJoiner(String) and appendJoiner(String) with the given text.

Parameters:
text - the text to be formatted for shaping
Returns:
the given text with shaping characters appended as needed
Since:
3.1

addLeadingWordRequirements

public boolean addLeadingWordRequirements(int[] width)
Returns the width of the text until the first line-break.

Overrides:
addLeadingWordRequirements in class InlineFlow
See Also:
FlowFigure.addLeadingWordRequirements(int[])

appendJoiner

public String appendJoiner(String text)
Appends the Zero-Width Joiner character at the end of the given String if required.

Parameters:
text - the String to be formatted for shaping
Returns:
the given text with the shaping character appended if needed
Since:
3.1
See Also:
setAppendJoiner(boolean)

contributeBidi

protected void contributeBidi(BidiProcessor proc)
A TextFlow contributes its text.

Overrides:
contributeBidi in class FlowFigure
Parameters:
proc - the BidiProcessor to which contributions should be made
See Also:
FlowFigure.contributeBidi(org.eclipse.draw2d.text.BidiProcessor)

createDefaultFlowLayout

protected FlowFigureLayout createDefaultFlowLayout()
Description copied from class: FlowFigure
Creates the default layout manager

Overrides:
createDefaultFlowLayout in class InlineFlow
See Also:
InlineFlow.createDefaultFlowLayout()

getCaretPlacement

public Rectangle getCaretPlacement(int offset,
                                   boolean trailing)
Returns the rectangular bounds for placing a Caret at the given offset. The offset must be between 0 and the length of the String being displayed.

Parameters:
offset - the location in this figures text
trailing - true if the caret is being placed after the offset
Returns:
the caret bounds relative to this figure
Throws:
IllegalArgumentException - If the offset is not between 0 and the length of the string inclusively
Since:
3.1

getFirstOffsetForLine

public int getFirstOffsetForLine(int y)
Returns the first caret position which occupies the line at the given y location. The y location is relative to this figure. If no fragment occupies that y coordinate, -1 is returned.

Parameters:
y - the baseline's y coordinate
Returns:
-1 of the first offset at the given baseline
Since:
3.1

getLastOffsetForLine

public int getLastOffsetForLine(int y)
Returns the last caret position which occupies the line at the given y location. The y location is relative to this figure. If no fragment occupies that y coordinate, -1 is returned.

Parameters:
y - the baseline's y coordinate
Returns:
-1 of the last offset at the given baseline
Since:
3.1

getNextOffset

public int getNextOffset(Point p,
                         boolean down)
Returns the offset nearest the given point either up or down one line. If no offset is found, -1 is returned.

Parameters:
p - a reference point
down - true if the search is down
Returns:
the next offset or -1
Since:
3.1

getOffset

public int getOffset(Point p,
                     int[] trailing)
Returns the textual offset nearest the specified point. The must be relative to this figure. If the point is not inside any fragment, -1 is returned. Otherwise the offset will be between 0 and getText().length() inclusively.

Parameters:
p - a point relative to this figure
Returns:
the offset in the string or -1
Since:
3.1

getText

public String getText()
Returns:
the String being displayed

invalidateBidi

protected void invalidateBidi()
Description copied from class: FlowFigure
Throws away the cached Bidi state for this figure and all its children. This method is invoked by BlockFlow.revalidateBidi(IFigure).

Overrides:
invalidateBidi in class FlowFigure
See Also:
FlowFigure.invalidateBidi()

isTextTruncated

public boolean isTextTruncated()
Returns true if a portion if the text is truncated using ellipses ("...").

Returns:
true if the text is truncated with ellipses

paintFigure

protected void paintFigure(Graphics g)
Description copied from class: Figure
Paints this Figure's primary representation, or background. Changes made to the graphics to the graphics current state will not affect the subsequent calls to Figure.paintClientArea(Graphics) and Figure.paintBorder(Graphics). Furthermore, it is safe to call graphics.restoreState() within this method, and doing so will restore the graphics to its original state upon entry.

Overrides:
paintFigure in class Figure
Parameters:
g - The Graphics used to paint
See Also:
Figure.paintFigure(Graphics)

prependJoiner

public String prependJoiner(String text)
Prepends the Zero-Width Joiner character to the beginning of the given text if required.

Parameters:
text - the String that needs to be formatted for shaping
Returns:
the given text with shaping character prepended if needed
Since:
3.1
See Also:
setPrependJoiner(boolean)

setAppendJoiner

public void setAppendJoiner(boolean append)
Description copied from class: FlowFigure
This method is invoked by the BidiProcessor if it determines that a shaping character needs to be appended to the text contributed by this Figure for it to appear properly on the screen.

This method does nothing by default. Sub-classes should override as needed.

Overrides:
setAppendJoiner in class FlowFigure
Parameters:
append - the ZWJ will be appended if true
See Also:
FlowFigure.setAppendJoiner(boolean)

setPrependJoiner

public void setPrependJoiner(boolean prepend)
Description copied from class: FlowFigure
This method is invoked by the BidiProcessor if it determines that a shaping character needs to be prepended to the text contributed by this Figure for it to appear properly on the screen.

This method does nothing by default. Sub-classes should override as needed.

Overrides:
setPrependJoiner in class FlowFigure
Parameters:
prepend - the ZWJ will be prepended if true
See Also:
FlowFigure.setPrependJoiner(boolean)

setSelection

public void setSelection(int begin,
                         int end)
Sets the extent of selection. The selection range is inclusive. For example, the range [0, 0] indicates that the first character is selected.

Parameters:
begin - the begin offset
end - the end offset
Since:
3.1

setText

public void setText(String s)
Sets the string being displayed. Causes a revalidate() to occur.

Parameters:
s - The new String. It cannot be null.

Eclipse Draw2d
3.0

Copyright (c) IBM Corp. and others 2000, 2004. All Rights Reserved.