JIDE 3.5.15

com.jidesoft.editor.caret
Interface CaretModel

All Known Implementing Classes:
DefaultCaretModel

public interface CaretModel

The model class for the caret position. There are three types of information in this model.

At any time, the three types of information are consistent. It means if you set offset, caret model position and caret view position will be updated immediately. If you set the caret view position or caret model position, the other two positions will be updated immediately as well.

The caret model or view position will consider the virtual space after the line end. If user clicks on two different places after the line end in the code editor, the caret view or model position could be different although the offset will be the same.

If you need to convert among these three positions, you can use several methods on CodeEditor to do it. Please note, it's not always a one to one conversion among those three positions. If an editor supports virtual spaces, a caret model position after the line end will be converted to the same offset at the line end. If an editor supports code folding, all caret view positions in the code folding text will be converted to the same caret model position the start of the code folding.


Method Summary
 void addCaretListener(CaretListener caretListener)
          Adds caret listener to listen to any changes in the caret position.
 CaretListener[] getCaretListeners()
          Returns an array of all the CaretListeners added to this CaretModel with addCaretListener().
 CaretPosition getModelPosition()
          Gets the caret model position as in the document.
 int getOffset()
          Gets the caret offset as in the document.
 CaretPosition getViewPosition()
          Gets the caret caret view position as in the view.
 void moveCaret(int xOffset, int yOffset, boolean select, boolean columnSelection, boolean scrollVisible)
          Moves caret from its current position to another position using the x and y offset.
 void removeCaretListener(CaretListener caretListener)
          Removes caret listener that is added before.
 void setModelPosition(CaretPosition position)
          Sets the caret model position.
 void setOffset(int offset)
          Sets the caret offset.
 void setViewPosition(CaretPosition caretPosition)
          Sets the caret view position.This method will update the caret offset and the caret model position.
 void updateViewPosition()
          Updates the caret view position when folding changes.
 

Method Detail

setOffset

void setOffset(int offset)
Sets the caret offset. This method will update the caret model position and the caret view position.

Parameters:
offset - the new caret offset.

getOffset

int getOffset()
Gets the caret offset as in the document.

Returns:
the caret offset.

setModelPosition

void setModelPosition(CaretPosition position)
Sets the caret model position. This method will update the caret offset and the caret view position.

Parameters:
position - the caret position.

getModelPosition

CaretPosition getModelPosition()
Gets the caret model position as in the document. It has line and column information.

Returns:
the caret model position.

setViewPosition

void setViewPosition(CaretPosition caretPosition)
Sets the caret view position.This method will update the caret offset and the caret model position.

Parameters:
caretPosition - a new caret view position.

getViewPosition

CaretPosition getViewPosition()
Gets the caret caret view position as in the view. It has line and column information.

Returns:
the caret caret view position.

moveCaret

void moveCaret(int xOffset,
               int yOffset,
               boolean select,
               boolean columnSelection,
               boolean scrollVisible)
Moves caret from its current position to another position using the x and y offset.

Parameters:
xOffset - the x offset from its current caret model position. For example, if you move one char left, the xOffset will be -1.
yOffset - the y offset from its current caret model position. For example, if you move one line up, the yOffset will be -1.
select - whether to select from its current caret model position to the new position.
columnSelection - whether the selection is in column selection mode.
scrollVisible - whether scroll to the caret at its new position.

addCaretListener

void addCaretListener(CaretListener caretListener)
Adds caret listener to listen to any changes in the caret position.

Parameters:
caretListener - a CaretListener to be added.

removeCaretListener

void removeCaretListener(CaretListener caretListener)
Removes caret listener that is added before.

Parameters:
caretListener - the CaretListener to be removed.

getCaretListeners

CaretListener[] getCaretListeners()
Returns an array of all the CaretListeners added to this CaretModel with addCaretListener().

Returns:
all of the CaretListeners added or an empty array if no listeners have been added

updateViewPosition

void updateViewPosition()
Updates the caret view position when folding changes.


JIDE 3.5.15