public final class TextLayout extends Resource
TextLayout
is a graphic object that represents
styled text.
Instances of this class provide support for drawing, cursor navigation, hit testing, text wrapping, alignment, tab expansion line breaking, etc. These are aspects required for rendering internationalized text.
Application code must explicitly invoke the TextLayout#dispose()
method to release the operating system resources managed by each instance
when those instances are no longer required.
Constructor and Description |
---|
TextLayout(Device device)
Constructs a new instance of this class on the given device.
|
Modifier and Type | Method and Description |
---|---|
void |
dispose()
Disposes of the operating system resources associated with
the text layout.
|
void |
draw(GC gc,
int x,
int y)
Draws the receiver's text using the specified GC at the specified
point.
|
void |
draw(GC gc,
int x,
int y,
int selectionStart,
int selectionEnd,
Color selectionForeground,
Color selectionBackground)
Draws the receiver's text using the specified GC at the specified
point.
|
int |
getAlignment()
Returns the receiver's horizontal text alignment, which will be one
of
SWT.LEFT , SWT.CENTER or
SWT.RIGHT . |
int |
getAscent()
Returns the ascent of the receiver.
|
Rectangle |
getBounds()
Returns the bounds of the receiver.
|
Rectangle |
getBounds(int start,
int end)
Returns the bounds for the specified range of characters.
|
int |
getDescent()
Returns the descent of the receiver.
|
Font |
getFont()
Returns the default font currently being used by the receiver
to draw and measure text.
|
int |
getIndent()
Returns the receiver's indent.
|
boolean |
getJustify()
Returns the receiver's justification.
|
int |
getLevel(int offset)
Returns the embedding level for the specified character offset.
|
Rectangle |
getLineBounds(int lineIndex)
Returns the bounds of the line for the specified line index.
|
int |
getLineCount()
Returns the receiver's line count.
|
int |
getLineIndex(int offset)
Returns the index of the line that contains the specified
character offset.
|
FontMetrics |
getLineMetrics(int lineIndex)
Returns the font metrics for the specified line index.
|
int[] |
getLineOffsets()
Returns the line offsets.
|
Point |
getLocation(int offset,
boolean trailing)
Returns the location for the specified character offset.
|
int |
getNextOffset(int offset,
int movement)
Returns the next offset for the specified offset and movement
type.
|
int |
getOffset(int x,
int y,
int[] trailing)
Returns the character offset for the specified point.
|
int |
getOffset(Point point,
int[] trailing)
Returns the character offset for the specified point.
|
int |
getOrientation()
Returns the orientation of the receiver.
|
int |
getPreviousOffset(int offset,
int movement)
Returns the previous offset for the specified offset and movement
type.
|
int[] |
getRanges()
Gets the ranges of text that are associated with a
TextStyle . |
int[] |
getSegments()
Returns the text segments offsets of the receiver.
|
int |
getSpacing()
Returns the line spacing of the receiver.
|
TextStyle |
getStyle(int offset)
Gets the style of the receiver at the specified character offset.
|
TextStyle[] |
getStyles()
Gets all styles of the receiver.
|
int[] |
getTabs()
Returns the tab list of the receiver.
|
String |
getText()
Gets the receiver's text, which will be an empty
string if it has never been set.
|
int |
getWidth()
Returns the width of the receiver.
|
boolean |
isDisposed()
Returns
true if the text layout has been disposed,
and false otherwise. |
void |
setAlignment(int alignment)
Sets the text alignment for the receiver.
|
void |
setAscent(int ascent)
Sets the ascent of the receiver.
|
void |
setDescent(int descent)
Sets the descent of the receiver.
|
void |
setFont(Font font)
Sets the default font which will be used by the receiver
to draw and measure text.
|
void |
setIndent(int indent)
Sets the indent of the receiver.
|
void |
setJustify(boolean justify)
Sets the justification of the receiver.
|
void |
setOrientation(int orientation)
Sets the orientation of the receiver, which must be one
of
SWT.LEFT_TO_RIGHT or SWT.RIGHT_TO_LEFT . |
void |
setSegments(int[] segments)
Sets the offsets of the receiver's text segments.
|
void |
setSpacing(int spacing)
Sets the line spacing of the receiver.
|
void |
setStyle(TextStyle style,
int start,
int end)
Sets the style of the receiver for the specified range.
|
void |
setTabs(int[] tabs)
Sets the receiver's tab list.
|
void |
setText(String text)
Sets the receiver's text.
|
void |
setWidth(int width)
Sets the line width of the receiver, which determines how
text should be wrapped and aligned.
|
String |
toString()
Returns a string containing a concise, human-readable
description of the receiver.
|
public TextLayout(Device device)
You must dispose the text layout when it is no longer required.
device
- the device on which to allocate the text layoutIllegalArgumentException
- dispose()
public void dispose()
public void draw(GC gc, int x, int y)
gc
- the GC to drawx
- the x coordinate of the top left corner of the rectangular area where the text is to be drawny
- the y coordinate of the top left corner of the rectangular area where the text is to be drawnSWTException
- IllegalArgumentException
- public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground)
gc
- the GC to drawx
- the x coordinate of the top left corner of the rectangular area where the text is to be drawny
- the y coordinate of the top left corner of the rectangular area where the text is to be drawnselectionStart
- the offset where the selections starts, or -1 indicating no selectionselectionEnd
- the offset where the selections ends, or -1 indicating no selectionselectionForeground
- selection foreground, or NULL to use the system default colorselectionBackground
- selection background, or NULL to use the system default colorSWTException
- IllegalArgumentException
- public int getAlignment()
SWT.LEFT
, SWT.CENTER
or
SWT.RIGHT
.SWTException
- public int getAscent()
SWTException
- getDescent()
,
setDescent(int)
,
setAscent(int)
,
getLineMetrics(int)
public Rectangle getBounds()
SWTException
- public Rectangle getBounds(int start, int end)
start
- the start offsetend
- the end offsetSWTException
- public int getDescent()
SWTException
- getAscent()
,
setAscent(int)
,
setDescent(int)
,
getLineMetrics(int)
public Font getFont()
SWTException
- public int getIndent()
SWTException
- public boolean getJustify()
SWTException
- public int getLevel(int offset)
offset
- the charecter offsetIllegalArgumentException
- SWTException
- public Rectangle getLineBounds(int lineIndex)
lineIndex
- the line indexIllegalArgumentException
- SWTException
- public int getLineCount()
SWTException
- public int getLineIndex(int offset)
offset
- the character offsetIllegalArgumentException
- SWTException
- public FontMetrics getLineMetrics(int lineIndex)
lineIndex
- the line indexIllegalArgumentException
- SWTException
- public int[] getLineOffsets()
SWTException
- public Point getLocation(int offset, boolean trailing)
trailing
argument indicates whether the offset
corresponds to the leading or trailing edge of the cluster.offset
- the character offsettrailing
- the trailing flagSWTException
- getOffset(Point, int[])
,
getOffset(int, int, int[])
public int getNextOffset(int offset, int movement)
SWT.MOVEMENT_CHAR
,
SWT.MOVEMENT_CLUSTER
or SWT.MOVEMENT_WORD
.offset
- the start offsetmovement
- the movement typeIllegalArgumentException
- SWTException
- getPreviousOffset(int, int)
public int getOffset(Point point, int[] trailing)
point
- the pointtrailing
- the trailing bufferIllegalArgumentException
- 1
SWTException
- getLocation(int, boolean)
public int getOffset(int x, int y, int[] trailing)
x
- the x coordinate of the pointy
- the y coordinate of the pointtrailing
- the trailing bufferIllegalArgumentException
- 1
SWTException
- getLocation(int, boolean)
public int getOrientation()
SWTException
- public int getPreviousOffset(int offset, int movement)
SWT.MOVEMENT_CHAR
,
SWT.MOVEMENT_CLUSTER
or SWT.MOVEMENT_WORD
.offset
- the start offsetmovement
- the movement typeIllegalArgumentException
- SWTException
- getNextOffset(int, int)
public int[] getRanges()
TextStyle
.SWTException
- getStyles()
public int[] getSegments()
SWTException
- public int getSpacing()
SWTException
- public TextStyle getStyle(int offset)
offset
- the text offsetnull
if not setIllegalArgumentException
- SWTException
- public TextStyle[] getStyles()
SWTException
- getRanges()
public int[] getTabs()
SWTException
- public String getText()
SWTException
- public int getWidth()
SWTException
- public boolean isDisposed()
true
if the text layout has been disposed,
and false
otherwise.
This method gets the dispose state for the text layout. When a text layout has been disposed, it is an error to invoke any other method using the text layout.
isDisposed
in class Resource
true
when the text layout is disposed and false
otherwisepublic void setAlignment(int alignment)
SWT.LEFT
, SWT.RIGHT
or SWT.CENTER
.
The default alignment is SWT.LEFT
. Note that the receiver's
width must be set in order to use SWT.RIGHT
or SWT.CENTER
alignment.
alignment
- the new alignmentSWTException
- setWidth(int)
public void setAscent(int ascent)
-1
which means that the
ascent is calculated from the line fonts.ascent
- the new ascentIllegalArgumentException
- -1
SWTException
- setDescent(int)
,
getLineMetrics(int)
public void setDescent(int descent)
-1
which means that the
descent is calculated from the line fonts.descent
- the new descentIllegalArgumentException
- -1
SWTException
- setAscent(int)
,
getLineMetrics(int)
public void setFont(Font font)
font
- the new font for the receiver, or null to indicate a default fontIllegalArgumentException
- SWTException
- public void setIndent(int indent)
indent
- new indentSWTException
- public void setJustify(boolean justify)
justify
- new justifySWTException
- public void setOrientation(int orientation)
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.orientation
- new orientation styleSWTException
- public void setSegments(int[] segments)
Each text segment is determined by two consecutive offsets in the
segments
arrays. The first element of the array should
always be zero and the last one should always be equals to length of
the text.
segments
- the text segments offsetSWTException
- public void setSpacing(int spacing)
spacing
- the new line spacingIllegalArgumentException
- SWTException
- public void setStyle(TextStyle style, int start, int end)
style
- the stylestart
- the start offsetend
- the end offsetSWTException
- public void setTabs(int[] tabs)
tabs
- the new tab listSWTException
- public void setText(String text)
text
- the new textIllegalArgumentException
- SWTException
- public void setWidth(int width)
-1
which means wrapping is disabled.width
- the new widthIllegalArgumentException
- 0
or less than -1
SWTException
- setAlignment(int)
Guidelines for using Eclipse APIs. Copyright (c) IBM Corp. and others 2000, 2006. All rights reserved.