sk.uniba.euromath.editor.textEditor
Class CaretManager

java.lang.Object
  extended by sk.uniba.euromath.editor.textEditor.CaretManager

public class CaretManager
extends Object

Each TextEditor can have its own CaretManager. CaretManager holds an instance of Caret and shows it on Canvas, that is stated in constructor. Using CaretManager can be divided into two parts

  1. Model is not changed - For example activating Caret at some position when clicking in text or moving Caret by pressing arrows. In this case no Command is used and no undo and redo is available for this operations.
  2. Model is changed - When moving or activating Caret is trigered by text inserting or deleting, then the model is changed and undo and redo is needed. Also Caret have to be activated after undo or redo operation on the correct location. How to do this is left on the Command.

Author:
Martin Kollar 3.2.2006

Constructor Summary
CaretManager(Canvas canvas, XMLAccess xmlAccess)
          Constructor
CaretManager(Canvas canvas, XMLAccess xmlAccess, ITextPieceKeeper keeper, int offset)
          Constructor
 
Method Summary
 void activateCaret(ITextPieceKeeper keeper, int offset)
          Activates Caret and shows it in keeper before character at offset offset.
protected  boolean checkCaret()
          Checks if Caret is ready to use
 void deactivateCaret()
          Deactivates and hides Caret
static int directionToKeyCode(String s)
          Converts direction string to key code
 ITextPieceKeeper getActiveTextPieceKeeper()
           
 int getCaretOffset()
           
 sk.baka.ikslibs.ptr.DomPointer getDOMPointer()
           
 org.eclipse.draw2d.geometry.Point getLocation()
          see Caret.getLocation()
protected  void hideCaret()
           
 void moveCaret(String direction)
          Moves Caret from the current position to one positions further in LEFT,RIGHT,UP,DOWN or to the end or start of the current line.
protected  void showCaret()
           
protected  void showCaretBefore(int index, ITextPieceKeeper keeper)
          Shows caret before character at index index in ITextPieceKeeper keeper
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CaretManager

public CaretManager(Canvas canvas,
                    XMLAccess xmlAccess)
Constructor

Parameters:
canvas - Canvas on that the Caret will be painted
xmlAccess - The source document accessor

CaretManager

public CaretManager(Canvas canvas,
                    XMLAccess xmlAccess,
                    ITextPieceKeeper keeper,
                    int offset)
Constructor

Parameters:
canvas - Canvas on that the Caret will be painted
xmlAccess - The source document accessor
keeper - ITextPieceKeeper in that the Caret will be activated
offset - Index of character in ITextPieceKeeper before that Caret will be activated
Method Detail

directionToKeyCode

public static int directionToKeyCode(String s)
Converts direction string to key code

Parameters:
s - One of RequestConstants.LEFT[RIGHT,UP,DOWN,HOME,END]
Returns:
SWT key code of relevant key

getActiveTextPieceKeeper

public ITextPieceKeeper getActiveTextPieceKeeper()
Returns:
TextPieceKeeper in that is the Caret activated. If it is not active, then returns null

getLocation

public org.eclipse.draw2d.geometry.Point getLocation()
see Caret.getLocation()

Returns:
Location of the Caret or null if it is not active

getDOMPointer

public sk.baka.ikslibs.ptr.DomPointer getDOMPointer()
Returns:
DOMPointer in that is Caret activated. If it is not active, then returns null

getCaretOffset

public int getCaretOffset()
Returns:
Caret offset in ITextPieceKeeper in that is active

activateCaret

public void activateCaret(ITextPieceKeeper keeper,
                          int offset)
Activates Caret and shows it in keeper before character at offset offset. Use this when, clicking in the text or when the model is changed and Caret have to be activated in this new model

Parameters:
keeper - ITextPieceKeeper in that Caret will be shown
offset - Offset of character before that the Caret will be shown. If offset is less then 0 or more then last valid index, then IllegalArgumentException will be thrown

deactivateCaret

public void deactivateCaret()
Deactivates and hides Caret


moveCaret

public void moveCaret(String direction)
Moves Caret from the current position to one positions further in LEFT,RIGHT,UP,DOWN or to the end or start of the current line. Use this method only when moving Caret using arrows or HOME,END. This is not suitable when inserting or deleting text, because the model is changed(use ActivateCaret insted).

Parameters:
direction - One of RequestConstants.LEFT[RIGHT,UP,DOWN,HOME,END]

checkCaret

protected boolean checkCaret()
Checks if Caret is ready to use

Returns:
true if caret is not null and is not disposed

showCaret

protected void showCaret()

hideCaret

protected void hideCaret()

showCaretBefore

protected void showCaretBefore(int index,
                               ITextPieceKeeper keeper)
Shows caret before character at index index in ITextPieceKeeper keeper

Parameters:
index - Offset of charecter in ITextPieceKeeper before that the Caret will be shown
keeper - ITextPieceKeeper where to show Caret


Copyright © 2003-2006 null. All Rights Reserved.