|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.swt.graphics.Resource
org.eclipse.swt.graphics.TextLayout
public final class 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 |
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. |
void |
draw(GC gc,
int x,
int y,
int selectionStart,
int selectionEnd,
Color selectionForeground,
Color selectionBackground,
int flags)
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 index,
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. |
java.lang.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(java.lang.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. |
java.lang.String |
toString()
Returns a string containing a concise, human-readable description of the receiver. |
Methods inherited from class org.eclipse.swt.graphics.Resource |
---|
dispose, getDevice |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, 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
java.lang.IllegalArgumentException
- Resource.dispose()
Method Detail |
---|
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
- java.lang.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 color
SWTException
- java.lang.IllegalArgumentException
- public void draw(GC gc, int x, int y, int selectionStart, int selectionEnd, Color selectionForeground, Color selectionBackground, int flags)
The parameter flags
can include one of SWT.DELIMITER_SELECTION
or SWT.FULL_SELECTION
to specify the selection behavior on all lines except
for the last line, and can also include SWT.LAST_LINE_SELECTION
to extend
the specified selection behavior to the last line.
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 colorflags
- drawing options
SWTException
- java.lang.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()
setWidth(int)
.
To obtain the text bounds of a line use getLineBounds(int)
.
SWTException
- setWidth(int)
,
getLineBounds(int)
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 getIndent()
SWTException
- public boolean getJustify()
SWTException
- public int getLevel(int offset)
offset
- the character offset
java.lang.IllegalArgumentException
- SWTException
- public Rectangle getLineBounds(int lineIndex)
lineIndex
- the line index
java.lang.IllegalArgumentException
- SWTException
- public int getLineCount()
SWTException
- public int getLineIndex(int offset)
offset
- the character offset
java.lang.IllegalArgumentException
- SWTException
- public FontMetrics getLineMetrics(int lineIndex)
lineIndex
- the line index
java.lang.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
, SWT.MOVEMENT_WORD
,
SWT.MOVEMENT_WORD_END
or SWT.MOVEMENT_WORD_START
.
offset
- the start offsetmovement
- the movement type
java.lang.IllegalArgumentException
- SWTException
- getPreviousOffset(int, int)
public int getOffset(Point point, int[] trailing)
point
- the pointtrailing
- the trailing buffer
java.lang.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
java.lang.IllegalArgumentException
- 1
SWTException
- getLocation(int, boolean)
public int getOrientation()
SWTException
- public int getPreviousOffset(int index, int movement)
SWT.MOVEMENT_CHAR
,
SWT.MOVEMENT_CLUSTER
or SWT.MOVEMENT_WORD
,
SWT.MOVEMENT_WORD_END
or SWT.MOVEMENT_WORD_START
.
offset
- the start offsetmovement
- the movement type
java.lang.IllegalArgumentException
- 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 offset
null
if not set
java.lang.IllegalArgumentException
- SWTException
- public TextStyle[] getStyles()
SWTException
- getRanges()
public int[] getTabs()
SWTException
- public java.lang.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 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
java.lang.IllegalArgumentException
- -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 descent
java.lang.IllegalArgumentException
- -1
SWTException
- setAscent(int)
,
getLineMetrics(int)
public void setFont(Font font)
font
- the new font for the receiver, or null to indicate a default font
java.lang.IllegalArgumentException
- SWTException
- public void setIndent(int indent)
indent
- new indent
SWTException
- public void setJustify(boolean justify)
justify
- new justify
SWTException
- public void setOrientation(int orientation)
SWT.LEFT_TO_RIGHT
or SWT.RIGHT_TO_LEFT
.
orientation
- new orientation style
SWTException
- public void setSpacing(int spacing)
spacing
- the new line spacing
java.lang.IllegalArgumentException
- SWTException
- 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 offset
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(java.lang.String text)
text
- the new text
java.lang.IllegalArgumentException
- SWTException
- public void setWidth(int width)
-1
which means wrapping is disabled.
width
- the new width
java.lang.IllegalArgumentException
- 0
or less than -1
SWTException
- setAlignment(int)
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |