oracle.javatools.buffer
Interface OffsetMark

The OffsetMark is used by the TextBuffer
to provide bookmark services. An OffsetMark is
created by the client for a given offset, and will stick to
that offset across buffer modications.

As an example, let's suppose that a client (such as a Caret, for
marking the beginning and ending of a selection region for
highlighting) creates an OffsetMark #1 at offset 10 and OffsetMark
#2 at offset 20. If a subsequent insert of 5 characters occurs at
offset 15, then OffsetMark #1 will still point to offset 10, but
OffsetMark #2 will now point to offset 25.

When removal of text occurs from the buffer, OffsetMarks which are
located within the removed region will be adjusted to point to the
beginning of the region. In the above example, if (after the
insert) a subsequent remove of 10 characters occurs at offset 5,
then OffsetMark #1 will now point to offset 5 (since it was in the
removed region), while OffsetMark #2 will point to offset 15.

OffsetMarks are created by calling TextBuffer.addOffsetMark with
the requested offset. They are maintained until clients explicitly
remove them by calling TextBuffer.removeOffsetMark. It is the clients
responsibility to ensure removal of unneeded OffsetMarks. This
frees the buffer from maintaining the removed Offsetmarks and also
allows the object to be properly garbage collected.

OffsetMarks do not have finalizers to guarantee removal as
finalizers are expensive (20-40 bytes per object with finalizer),
and because both the client and buffer both maintain a
reference to the mark. Because of the latter case, a separate
object is required if proper release is implemented through
finalizers (which means higher resource/object cost.) The moral of
the story is that clients must remove OffsetMarks they no longer
need.

Note that by default, marks bias to the right, or after the offset.
This means that insertions at the offset will cause the offset mark
to shift to the right. You can specify BIAS_LEFT when creating
the mark to cause the bias to be to the left, or before the offset.

Field Summary

static boolean

BIAS_AFTER
Constant indicating that the bias of the mark is after the
offset.

static boolean

BIAS_BEFORE
Constant indicating that the bias of the mark is before the
offset.

BIAS_DEFAULT

getBias

Fetches the bias of the mark. This returns either BIAS_LEFT
(BIAS_BEFORE), or BIAS_RIGHT (BIAS_AFTER).

Returns:

the bias of this offset mark

setBias

void setBias(boolean bias)

Sets the bias of the mark. You can specify BIAS_LEFT (BIAS_BEFORE),
or BIAS_RIGHT (BIAS_AFTER).

Parameters:

bias - the bias to set for this mark

getOffset

int getOffset()

Fetches the offset that this mark is currently pointing to.

Returns:

the offset that this OffsetMark points to

setOffset

void setOffset(int offset)

Sets the offset that this mark sticks to. This can be used, for
example, by a Caret which uses marks to track selection regions.
When the selection is moved, the marks can be updated instead of
removing and recreating them.