Package kiyut.sketsa.canvas.text
Class TextCaret
- java.lang.Object
-
- kiyut.sketsa.canvas.text.TextCaret
-
public class TextCaret extends Object
A place within a document view that represents where things can be inserted into the document model. A caret has a position in the document referred to as a dot. The dot is where the caret is currently located in the model. There is a second position maintained by the caret that represents the other end of a selection called mark. If there is no selection the dot and mark will be equal. If a selection exists, the two values will be different.- Author:
- Kiyut
-
-
Constructor Summary
Constructors Constructor Description TextCaret()Creates a new instance of TextCaret
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description voidaddCaretListener(CaretListener listener)Adds a caret listener for notification of any changes to the caret.protected voiddamage(Rectangle2D r)Repaint the damage areaprotected voidfireCaretUpdate()Notifies all listeners that have registered interest for notification on this event type.intgetDot()Fetches the current position of the caret.intgetMark()Fetches the current position of the mark.voidmoveDot(int dot)Moves the caret position (dot) to some other position, leaving behind the mark.voidpaint(Graphics2D g2d)Render the caret and SelectionHighlightvoidprepareCaret(VectorCanvas canvas, org.apache.batik.bridge.TextNode textNode, int dot)Prepare the caret.voidremoveCaretListener(CaretListener listener)Removes a caret listener.protected voidrepaint()Repaint this objectprotected intsetCaretPosition(int dot)Set caret dotvoidsetDot(int dot)Sets the caret position to some position.voidsetMark(int mark)Deprecated.not to be used anymorevoidsetVisible(boolean visible)Set the caret visibility
-
-
-
Method Detail
-
repaint
protected final void repaint()
Repaint this object- See Also:
paint(Graphics2D)
-
damage
protected void damage(Rectangle2D r)
Repaint the damage area- Parameters:
r-Rectangle2Darea indicate the damage area- See Also:
paint(Graphics2D)
-
paint
public void paint(Graphics2D g2d)
Render the caret and SelectionHighlight- Parameters:
g2d- Graphics2D
-
addCaretListener
public void addCaretListener(CaretListener listener)
Adds a caret listener for notification of any changes to the caret.- Parameters:
listener- the listener to be added
-
removeCaretListener
public void removeCaretListener(CaretListener listener)
Removes a caret listener.- Parameters:
listener- the listener to be removed
-
fireCaretUpdate
protected void fireCaretUpdate()
Notifies all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method. The listener list is processed in a last-to-first manner.
-
prepareCaret
public void prepareCaret(VectorCanvas canvas, org.apache.batik.bridge.TextNode textNode, int dot)
Prepare the caret.- Parameters:
canvas- VectorCanvastextNode- the textNodedot- the new position to set the caret to >= 0
-
setVisible
public void setVisible(boolean visible)
Set the caret visibility- Parameters:
visible- true or false
-
setDot
public void setDot(int dot)
Sets the caret position to some position.- Parameters:
dot- the new position to set the caret to >= 0
-
moveDot
public void moveDot(int dot)
Moves the caret position (dot) to some other position, leaving behind the mark. This is useful for making selections.- Parameters:
dot- the new position to move the caret to >= 0
-
getDot
public int getDot()
Fetches the current position of the caret.- Returns:
- position of the caret
-
setMark
@Deprecated public void setMark(int mark)
Deprecated.not to be used anymore- Parameters:
mark- the mark
-
getMark
public int getMark()
Fetches the current position of the mark. If there is a selection, the mark will not be the same as the dot.- Returns:
- position of mark
-
setCaretPosition
protected int setCaretPosition(int dot)
Set caret dot- Parameters:
dot- the dot- Returns:
- int indicating the dot
-
-