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 java.lang.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 S
concat(S a, S b)
protected abstract Self
create(int position, S removed, S inserted)
boolean
equals(java.lang.Object other)
S
getInserted()
int
getInsertionEnd()
Returns the position where the inserted ends (e.g.int
getNetLength()
Gets the net length of this change (i.e.,insertedLength() - removedLength()
)int
getPosition()
Gets the start position of where the replacement happenedint
getRemovalEnd()
Returns the position where the removal ends (e.g.S
getRemoved()
int
hashCode()
protected abstract int
insertedLength()
Self
invert()
Returns a new subclass ofTextChange
that makes theinserted
the removed object and theremoved
the inserted objectboolean
isIdentity()
Returns true if this change is an identity change: applying it does nothing as it removes what it inserts.java.util.Optional<Self>
mergeWith(Self latter)
Merges this change with the given change, if possible.protected abstract int
removedLength()
protected abstract S
sub(S s, int from, int to)
java.lang.String
toString()
-
-
-
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 ofTextChange
that makes theinserted
the removed object and theremoved
the 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 java.util.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,
null
otherwise.
-
equals
public boolean equals(java.lang.Object other)
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public final java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
-