Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

oracle.javatools.buffer
Interface OffsetMark


public 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.
static boolean BIAS_DEFAULT
          Constant for the default bias for marks.
static boolean BIAS_LEFT
          Constant indicating that the bias of the mark is to the left of the mark offset.
static boolean BIAS_RIGHT
          Constant indicating that the bias of the mark is to the right of the mark offset.
 
Method Summary
 boolean getBias()
          Fetches the bias of the mark.
 int getOffset()
          Fetches the offset that this mark is currently pointing to.
 void setBias(boolean bias)
          Sets the bias of the mark.
 void setOffset(int offset)
          Sets the offset that this mark sticks to.
 

Field Detail

BIAS_LEFT

static final boolean BIAS_LEFT
Constant indicating that the bias of the mark is to the left of the mark offset. If an insert in the text occurs at the offset, the mark will not move.

See Also:
Constant Field Values

BIAS_BEFORE

static final boolean BIAS_BEFORE
Constant indicating that the bias of the mark is before the offset. This is the same as BIAS_LEFT.

See Also:
Constant Field Values

BIAS_RIGHT

static final boolean BIAS_RIGHT
Constant indicating that the bias of the mark is to the right of the mark offset. If an insert in the text occurs at the offset, the mark will shift to the right accordingly.

See Also:
Constant Field Values

BIAS_AFTER

static final boolean BIAS_AFTER
Constant indicating that the bias of the mark is after the offset. This is the same as BIAS_RIGHT;

See Also:
Constant Field Values

BIAS_DEFAULT

static final boolean BIAS_DEFAULT
Constant for the default bias for marks. The default is to bias to the right, or after the offset.

See Also:
Constant Field Values
Method Detail

getBias

boolean 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.

Parameters:
offset - the new offset

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK
11g Release 2 (11.1.2.0.0)

E17493-01

Copyright © 1997, 2011, Oracle. All rights reserved.