|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.gnu.glib.Struct
org.gnu.glib.GObject
org.gnu.gtk.GtkObject
org.gnu.gtk.Widget
org.gnu.gtk.Container
org.gnu.gtk.TextView
public class TextView
Widget for displaying textual data.
java-gnome has an extremely powerful framework for multiline text editing.
The primary objects involved in the process are TextBuffer
, which
represents the text being edited, and TextView
, a widget which can
display a TextBuffer. Each buffer can be displayed by any number of views.
One of the important things to remember about text in java-gnome is that it's in the UTF-8 encoding. This means that one character can be encoded as multiple bytes. Character counts are usually referred to as offsets, while byte counts are called indexes. If you confuse these two, things will work fine with ASCII, but as soon as your buffer contains multibyte characters, bad things will happen.
Text in a buffer can be marked with tags. A tag is an attribute that can be
applied to some range of text. For example, a tag might be called "bold" and
make the text inside the tag bold. However, the tag concept is more general
than that; tags don't have to affect appearance. They can instead affect the
behavior of mouse and key presses, "lock" a range of text so the user can't
edit it, or countless other things. A tag is represented by a TextTag
object. One TextTag can be applied to any number of text ranges in any number
of buffers.
Each tag is stored in a TextTagTable
. A tag table defines a set of
tags that can be used together. Each buffer has one tag table associated with
it; only tags from that tag table can be used with the buffer. A single tag
table can be shared between multiple buffers, however.
Tags can have names, which is convenient sometimes (for example, you can name your tag that makes things bold "bold"), but they can also be anonymous (which is convenient if you're creating tags on-the-fly).
Most text manipulation is accomplished with iterators, represented by a
TextIter
. An iterator represents a position between two characters
in the text buffer. Iterators are not valid indefinitely; whenever the buffer
is modified in a way that affects the number of characters in the buffer, all
outstanding iterators become invalid. (Note that deleting 5 characters and
then reinserting 5 still invalidates iterators, though you end up with the
same number of characters you pass through a state with a different number).
Because of this, iterators can't be used to preserve positions across buffer
modifications. To preserve a position, the TextMark
object is ideal.
You can think of a mark as an invisible cursor or insertion point; it floats
in the buffer, saving a position. If the text surrounding the mark is
deleted, the mark remains in the position the text once occupied; if text is
inserted at the mark, the mark ends up either to the left or to the right of
the new text, depending on its gravity. The standard text cursor in
left-to-right languages is a mark with right gravity, because it stays to the
right of inserted text.
Like tags, marks can be either named or anonymous. There are two marks
built-in to TextBuffer
; these are named "insert" and
"selection_bound" and refer to the insertion point and the boundary of the
selection which is not the insertion point, respectively. If no text is
selected, these two marks will be in the same position. You can manipulate
what is selected and where the cursor appears by moving these marks around.
Text buffers always contain at least one line, but may be empty (that is, buffers can contain zero characters). The last line in the text buffer never ends in a line separator (such as newline); the other lines in the buffer always end in a line separator. Line separators count as characters when computing character counts and character offsets. Note that some Unicode line separators are represented with multiple bytes in UTF-8, and the two-character sequence "\r\n" is also considered a line separator.
Nested Class Summary | |
---|---|
static class |
TextView.VerticalLineRange
Class to handle returns from getLineYRange(org.gnu.gtk.TextIter) . |
Constructor Summary | |
---|---|
TextView()
Constructs a new TextView. |
|
TextView(org.gnu.glib.Handle handle)
Construct a TextView from a handle to a native resource. |
|
TextView(TextBuffer buffer)
Creates a new TextView widget displaying the buffer buffer. |
Method Summary | |
---|---|
void |
addChild(Widget child,
TextChildAnchor anchor)
Adds a child widget in the text buffer, at the given anchor. |
void |
addListener(TextViewListener listener)
Register an object to receive text view event notification. |
Point |
bufferToWindowCoords(TextWindowType winType,
int xCoord,
int yCoord)
Converts coordinate (xCoord, yCoord) to coordinates for the window winType . |
boolean |
getAcceptsTab()
Returns whether pressing the Tab key inserts a tab characters. |
int |
getBorderWindowSize(TextWindowType type)
Gets the width of the specified border window. |
TextBuffer |
getBuffer()
Returns the buffer being used |
boolean |
getCursorVisible()
Find out whether the cursor is being displayed. |
TextAttributes |
getDefaultAttributes()
Obtains a copy of the default text attributes. |
boolean |
getEditable()
Returns the default editability of the GtkTextView. |
java.lang.Class |
getEventListenerClass(java.lang.String signal)
|
EventType |
getEventType(java.lang.String signal)
|
Adjustment |
getHAdjustment()
|
int |
getIndent()
Gets the default indentation of paragraphs in text_view. |
TextIter |
getIterAtLocation(int x,
int y)
Returns an iterator for the location pointed to by the coordinates x and y within the buffer. |
TextIter |
getIterAtLocation(Point bufferCoords)
Returns an iterator for the location pointed to by bufferCoords, representing coordinates within the buffer. |
Justification |
getJustification()
Gets the default justification of text in this TextView. |
int |
getLeftMargin()
Gets the default left margin size of paragraphs in the TextView. |
TextView.VerticalLineRange |
getLineYRange(TextIter iter)
Gets the y coordinate of the top of the line containing iter ,
and the height of the line. |
boolean |
getOverwrite()
Returns whether the TextView is in overwrite mode or not. |
int |
getPixelsAboveLines()
Gets the default number of pixels to put above paragraphs. |
int |
getPixelsBelowLines()
Gets the default number of pixels of blank space to put below paragraphs. |
int |
getPixelsInsideWrap()
Gets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. |
int |
getRightMargin()
Gets the default right margin size of paragraphs in the TextView. |
TabArray |
getTabs()
Gets the default tabs for text_view. |
static TextView |
getTextView(org.gnu.glib.Handle handle)
Internal static factory method to be used by Java-Gnome only. |
static Type |
getType()
Retrieve the runtime type used by the GLib library. |
Adjustment |
getVAdjustment()
|
Rectangle |
getVisibleRectangle()
Returns a Rectangle with the currently-visible region of the buffer, in buffer coordinates. |
Window |
getWindow(TextWindowType type)
Retrieves the Window corresponding to an area of the
text view; possible windows include the overall widget window, child
windows on the left, right, top, bottom, and the window that displays the
text buffer. |
TextWindowType |
getWindowType(Window win)
Usually used to find out which window an event corresponds to. |
WrapMode |
getWrapMode()
Gets the line wrapping for the view. |
boolean |
moveCursorOnScreen()
Moves the cursor to the currently visible region of the buffer, it it isn't there already. |
boolean |
moveMarkOnScreen(TextMark mark)
Moves a mark within the buffer so that it's located within the currently-visible text area. |
void |
removeListener(TextViewListener listener)
Unregister an object that was receiving text view event notification. |
void |
scrollMarkOnScreen(TextMark mark)
Scrolls this the minimum distance such that mark is contained within the visible area of the widget. |
boolean |
scrollToIter(TextIter iter,
double withinMargin)
Scrolls text view so that iter is on the screen. |
boolean |
scrollToIter(TextIter iter,
double withinMargin,
double xAlign,
double yAlign)
Scrolls text view so that iter is on the screen in the position indicated by xalign and yalign. |
void |
scrollToMark(TextMark mark,
double withinMargin)
Scrolls the view so that mark is on the screen. |
void |
scrollToMark(TextMark mark,
double withinMargin,
boolean useAlign,
double xAlign,
double yAlign)
Scrolls the view so that mark is on the screen in the position indicated by xAlign and yAlign. |
void |
setAcceptsTab(boolean acceptsTab)
Sets the behavior of the text widget when the Tab key is pressed. |
void |
setBorderWindowSize(TextWindowType type,
int size)
Sets the width of the TextWindowType.LEFT or
TextWindowType.RIGHT windows, or the height of
TextWindowType.TOP or TextWindowType.BOTTOM Windows. |
void |
setBuffer(TextBuffer buffer)
Sets buffer as the buffer being displayed by the view. |
void |
setCursorVisible(boolean setting)
Toggles whether the insertion point is displayed. |
void |
setEditable(boolean setting)
Sets the default editability of the GtkTextView. |
void |
setIndent(int indent)
Sets the default indentation for paragraphs in text_view. |
void |
setJustification(Justification justification)
Sets the default justification of text in text_view. |
void |
setLeftMargin(int leftMargin)
Sets the default left margin for text in text_view. |
void |
setOverwrite(boolean overwrite)
Changes the overwrite mode (whether text is overwritten) |
void |
setPixelsAboveLines(int pixelsAboveLines)
Sets the default number of blank pixels above paragraphs in text_view. |
void |
setPixelsBelowLine(int pixelsBelowLines)
Deprecated. Use setPixelsBelowLines(int) instead. |
void |
setPixelsBelowLines(int pixelsBelowLines)
Sets the default number of pixels of blank space to put below paragraphs in text_view. |
void |
setPixelsInsideWrap(int pixelsInsideWrap)
Sets the default number of pixels of blank space to leave between display/wrapped lines within a paragraph. |
void |
setRightMargin(int rightMargin)
Sets the default right margin for text in text_view. |
void |
setTabs(TabArray tabStops)
Sets the default tab stops for paragraphs in text_view. |
void |
setWrapMode(WrapMode wrapMode)
Sets the line wrapping for the view. |
Point |
windowToBufferCoords(TextWindowType winType,
int xCoord,
int yCoord)
Converts coordinates on the window identified by the winType
to buffer coordinates. |
Methods inherited from class org.gnu.gtk.Container |
---|
add, addListener, getBooleanChildProperty, getBorderWidth, getChildProperty, getChildren, getIntChildProperty, getResizeMode, remove, removeListener, resizeChildren, setBooleanChildProperty, setBorderWidth, setChildProperty, setIntChildProperty, setResizeMode |
Methods inherited from class org.gnu.gtk.GtkObject |
---|
destroy, sink |
Methods inherited from class org.gnu.glib.Struct |
---|
equals, getHandle, getNullHandle, hashCode |
Methods inherited from class java.lang.Object |
---|
getClass, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public TextView()
public TextView(TextBuffer buffer)
buffer
- Buffer to usepublic TextView(org.gnu.glib.Handle handle)
Method Detail |
---|
public static TextView getTextView(org.gnu.glib.Handle handle)
public void setBuffer(TextBuffer buffer)
buffer
- The new buffer to displaypublic TextBuffer getBuffer()
public void scrollToMark(TextMark mark, double withinMargin, boolean useAlign, double xAlign, double yAlign)
mark
- A TextMark
withinMargin
- Margin as a fraction of screen sizeuseAlign
- Whether to use alignment arguments.xAlign
- Horizontal alignment of mark within visible area.yAlign
- :
vertical alignment of mark within visible areapublic void scrollToMark(TextMark mark, double withinMargin)
mark
- A TextMark
withinMargin
- Margin as a fraction of screen sizepublic TextIter getIterAtLocation(int x, int y)
x
and y
within the buffer. Coordinates
obtained in relation to the widget must be converted to buffer
coordinates using windowToBufferCoords before passing them into this
method.
x
- x buffer coordinatey
- y buffer coordinate
public TextIter getIterAtLocation(Point bufferCoords)
bufferCoords
- a Point representing a pair of buffer coordinates
public Point windowToBufferCoords(TextWindowType winType, int xCoord, int yCoord)
winType
to buffer coordinates.
winType
- a TextWindowType
.xCoord
- the x-coordinate in relation to the Window winyCoord
- the y-coordinate in relation to the Window win
public boolean scrollToIter(TextIter iter, double withinMargin, double xAlign, double yAlign)
scrollToMark(TextMark, double, boolean, double, double)
which
saves a point to be scrolled to after line validation.
iter
- a TextIterwithinMargin
- Margin as a [0.0,0.5) fraction of screen size.xAlign
- :
horizontal alignment of mark within visible area.yAlign
- :
vertical alignment of mark within visible area
public boolean scrollToIter(TextIter iter, double withinMargin)
iter
- a TextIterwithinMargin
- Margin as a [0.0,0.5) fraction of screen size.
public boolean moveCursorOnScreen()
public boolean moveMarkOnScreen(TextMark mark)
public void addChild(Widget child, TextChildAnchor anchor)
child
- A Widgetanchor
- A TextChildAnchor in the TextBuffer for his viewpublic WrapMode getWrapMode()
public void setWrapMode(WrapMode wrapMode)
wrapMode
- A WrapModepublic void setEditable(boolean setting)
setting
- Whether it's editablepublic boolean getEditable()
public boolean getCursorVisible()
public void setCursorVisible(boolean setting)
setting
- Whether to show the insertion cursorpublic int getPixelsAboveLines()
public int getPixelsBelowLines()
public int getPixelsInsideWrap()
public void setPixelsAboveLines(int pixelsAboveLines)
pixelsAboveLines
- Pixels above paragraphspublic void setPixelsBelowLine(int pixelsBelowLines)
setPixelsBelowLines(int)
instead.
pixelsBelowLines
- Pixels below paragraphspublic void setPixelsBelowLines(int pixelsBelowLines)
pixelsBelowLines
- Pixels below paragraphspublic void setPixelsInsideWrap(int pixelsInsideWrap)
pixelsInsideWrap
- Default number of pixels between wrapped linespublic Justification getJustification()
public void setJustification(Justification justification)
justification
- The justification to use.public int getLeftMargin()
public int getRightMargin()
public void setLeftMargin(int leftMargin)
leftMargin
- Size of left margin, in pixelspublic void setRightMargin(int rightMargin)
rightMargin
- Size of right margin, in pixelspublic int getIndent()
public void setIndent(int indent)
indent
- Indentation in pixelspublic TabArray getTabs()
public void setTabs(TabArray tabStops)
tabStops
- tabs as a PangoTabArraypublic TextAttributes getDefaultAttributes()
public void setAcceptsTab(boolean acceptsTab)
acceptsTab
- TRUE if pressing the Tab key should insert a tab character,
FALSE, if pressing the Tab key should move the keyboard focuspublic boolean getAcceptsTab()
setAcceptsTab(boolean)
public void setOverwrite(boolean overwrite)
overwrite
- TRUE to turn on overwrite mode, FALSE to turn it offpublic boolean getOverwrite()
setOverwrite(boolean)
public Adjustment getHAdjustment()
public Adjustment getVAdjustment()
public java.lang.Class getEventListenerClass(java.lang.String signal)
getEventListenerClass
in class Container
public EventType getEventType(java.lang.String signal)
getEventType
in class Container
public TextView.VerticalLineRange getLineYRange(TextIter iter)
iter
,
and the height of the line. The coordinate is a buffer coordinate;
convert to window coordinates with
windowToBufferCoords(TextWindowType, int, int)
.
iter
- A valid TextIter
public Point bufferToWindowCoords(TextWindowType winType, int xCoord, int yCoord)
winType
. Note that you can't convert coordinates for a
non-existing window (see
setBorderWindowSize(TextWindowType, int)
.
winType
- a TextWindowType
xCoord
- buffer X coordinateyCoord
- buffer Y coordinate
public void setBorderWindowSize(TextWindowType type, int size)
TextWindowType.LEFT
or
TextWindowType.RIGHT
windows, or the height of
TextWindowType.TOP
or TextWindowType.BOTTOM
Windows.
Automatically destroys the corresponding window if the size is set to 0,
and creates the window if the size is set to non-zero. This function can
only be used for the "border windows," it doesn't work with
TextWindowType.WIDGET
, TextWindowType.TEXT
, or
TextWindowType.PRIVATE
.
type
- The window to affectsize
- Width or height of the windowpublic int getBorderWindowSize(TextWindowType type)
type
- The window to return size from
setBorderWindowSize(TextWindowType, int).
public Window getWindow(TextWindowType type)
Window
corresponding to an area of the
text view; possible windows include the overall widget window, child
windows on the left, right, top, bottom, and the window that displays the
text buffer. Windows are null and nonexistent if their width or height is
0, and are nonexistent before the widget has been realized.
type
- The window to get
public TextWindowType getWindowType(Window win)
win
- A window
public void scrollMarkOnScreen(TextMark mark)
mark
- a mark in the buffer of the TextView.public Rectangle getVisibleRectangle()
bufferToWindowCoords(TextWindowType, int, int)
.
public void addListener(TextViewListener listener)
listener
- The object that has implemented the TextViewListener interface
that is to receive the text view events.public void removeListener(TextViewListener listener)
listener
- The object that is to no longer receive text view events.public static Type getType()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |