Package org.fxmisc.richtext.model
Class TextChange<S,Self extends TextChange<S,Self>>
- java.lang.Object
-
- org.fxmisc.richtext.model.TextChange<S,Self>
-
- Type Parameters:
S- type of data that was removed and inserted in theTextEditingArea.Self- a subclass of TextChange
- Direct Known Subclasses:
PlainTextChange,RichTextChange
public abstract class TextChange<S,Self extends TextChange<S,Self>> extends Object
Base change class for style changes (RichTextChange) and non-style changes (PlainTextChange) in aTextEditingArea.
-
-
Constructor Summary
Constructors Constructor Description TextChange(int position, S removed, S inserted)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract Sconcat(S a, S b)protected abstract Selfcreate(int position, S removed, S inserted)booleanequals(Object other)SgetInserted()intgetInsertionEnd()Returns the position where the inserted ends (e.g.intgetNetLength()Gets the net length of this change (i.e.,insertedLength() - removedLength())intgetPosition()Gets the start position of where the replacement happenedintgetRemovalEnd()Returns the position where the removal ends (e.g.SgetRemoved()inthashCode()protected abstract intinsertedLength()Selfinvert()Returns a new subclass ofTextChangethat makes theinsertedthe removed object and theremovedthe inserted objectbooleanisIdentity()Returns true if this change is an identity change: applying it does nothing as it removes what it inserts.Optional<Self>mergeWith(Self latter)Merges this change with the given change, if possible.protected abstract intremovedLength()protected abstract Ssub(S s, int from, int to)StringtoString()
-
-
-
Method Detail
-
getPosition
public int getPosition()
Gets the start position of where the replacement happened
-
getRemoved
public S getRemoved()
-
getInserted
public S getInserted()
-
invert
public Self invert()
Returns a new subclass ofTextChangethat makes theinsertedthe removed object and theremovedthe inserted object
-
getRemovalEnd
public int getRemovalEnd()
Returns the position where the removal ends (e.g.position + removedLength())
-
getInsertionEnd
public int getInsertionEnd()
Returns the position where the inserted ends (e.g.position + insertedLength())
-
getNetLength
public int getNetLength()
Gets the net length of this change (i.e.,insertedLength() - removedLength())
-
removedLength
protected abstract int removedLength()
-
insertedLength
protected abstract int insertedLength()
-
isIdentity
public final boolean isIdentity()
Returns true if this change is an identity change: applying it does nothing as it removes what it inserts. See alsoFunction.identity()
-
mergeWith
public Optional<Self> mergeWith(Self latter)
Merges this change with the given change, if possible. This change is considered to be the former and the given change is considered to be the latter. Changes can be merged if either- the latter's start matches the former's added text end; or
- the latter's removed text end matches the former's added text end.
- Parameters:
latter- change to merge with this change.- Returns:
- a new merged change if changes can be merged,
nullotherwise.
-
-