Extension SDK 10.1.2

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.


Method Summary
 int getOffset()
          Fetches the offset that this mark is currently pointing to.
 void setOffset(int offset)
          Sets the offset that this mark sticks to.
 

Method Detail

getOffset

public int getOffset()
Fetches the offset that this mark is currently pointing to.

Returns:
the offset that this OffsetMark points to

setOffset

public 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

Extension SDK

 

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