|
Eclipse Platform Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.graphics.TextLayout
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 Summary | |
TextLayout(Device device)
Constructs a new instance of this class on the given device. |
Method Summary | |
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 |
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[] |
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. |
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 |
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. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
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 layout
IllegalArgumentException
- dispose()
Method Detail |
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 drawn
SWTException
- 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 color
SWTException
- 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 offset
SWTException
- public int getDescent()
SWTException
- getAscent()
,
setAscent(int)
,
setDescent(int)
,
getLineMetrics(int)
public Font getFont()
SWTException
- public int getLevel(int offset)
offset
- the charecter offset
IllegalArgumentException
- SWTException
- public Rectangle getLineBounds(int lineIndex)
lineIndex
- the line index
IllegalArgumentException
- SWTException
- public int getLineCount()
SWTException
- public int getLineIndex(int offset)
offset
- the character offset
IllegalArgumentException
- SWTException
- public FontMetrics getLineMetrics(int lineIndex)
lineIndex
- the line index
IllegalArgumentException
- 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 flag
SWTException
- 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 type
IllegalArgumentException
- SWTException
- getPreviousOffset(int, int)
public int getOffset(Point point, int[] trailing)
point
- the pointtrailing
- the trailing buffer
IllegalArgumentException
- 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 buffer
IllegalArgumentException
- 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 type
IllegalArgumentException
- SWTException
- getNextOffset(int, int)
public int[] getSegments()
SWTException
- public int getSpacing()
SWTException
- public TextStyle getStyle(int offset)
offset
- the text offset
null
if not set
IllegalArgumentException
- SWTException
- 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.
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 alignment
SWTException
- setWidth(int)
public void setAscent(int ascent)
-1
which means that the
ascent is calculated from the line fonts.
ascent
- the new ascent
IllegalArgumentException
- -1
SWTException
- setDescent(int)
,
#getLineMetrics()
public void setDescent(int descent)
-1
which means that the
descent is calculated from the line fonts.
descent
- the new descent
IllegalArgumentException
- -1
SWTException
- setAscent(int)
,
#getLineMetrics()
public void setFont(Font font)
font
- the new font for the receiver, or null to indicate a default font
IllegalArgumentException
- SWTException
- public void setOrientation(int orientation)
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
orientation
- new orientation style
SWTException
- public void setSegments(int[] segments)
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 offset
SWTException
- public void setSpacing(int spacing)
spacing
- the new line spacing
IllegalArgumentException
- SWTException
- public void setStyle(TextStyle style, int start, int end)
style
- the stylestart
- the start offsetend
- the end offset
SWTException
- public void setTabs(int[] tabs)
tabs
- the new tab list
SWTException
- public void setText(String text)
text
- the new text
IllegalArgumentException
- SWTException
- public void setWidth(int width)
-1
which means wrapping is disabled.
width
- the new width
IllegalArgumentException
- 0
or less than -1
SWTException
- setAlignment(int)
|
Eclipse Platform Release 3.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Guidelines for using Eclipse APIs.
Copyright (c) IBM Corp. and others 2000, 2004. All rights reserved.