Package com.simsilica.lemur.text
Class DocumentModelFilter
java.lang.Object
com.simsilica.lemur.text.DocumentModelFilter
- All Implemented Interfaces:
VersionedObject<DocumentModel>
,DocumentModel
A convenient base class for DocumentModel filtering that simply passes
most methods through to the wrapped delegate DocumentModel, while intercepting
others for subclasses to filter. Subclasses can override the filterInput()
and filterOutput() methods to provide simpler filtering or simply set
Function implementations for those transforms.
Advanced output filtering (where the output string maybe a different
size then what is kept by the delegate) would require more extensive overriding
of behavior to track carat location, line, column, and so on.
-
Constructor Summary
ConstructorsConstructorDescriptionDocumentModelFilter
(DocumentModel delegate) DocumentModelFilter
(DocumentModel delegate, Function<Character, Character> inputTransform, Function<String, String> outputTransform) DocumentModelFilter
(Function<Character, Character> inputTransform, Function<String, String> outputTransform) -
Method Summary
Modifier and TypeMethodDescriptionvoid
Deletes the character immediately before the current carat position.clone()
Deep clones this document model.Returns a VersionedReference that can be watched for changes to the carat position.Creates a new VersionedReference that can be used to monitor when this object changes.void
delete()
Deletes the character immediately after the current carat position.void
deleteCharAt
(int pos) Deletes the character at the specified position.int
down()
Moves the carat position to the next line if there is one.int
end
(boolean currentLine) Moves the carat to the document's end position or the current line's end position depending on the specified 'currentLine' value.protected Character
filterInput
(char c) Can be overridden to filter the input provided to insert().protected String
filterInput
(String text) Can be overridden to bulk filter input provided to setText().protected String
filterOutput
(String text) Can be overridden to filter the output from the getText() method, for example replacing all characters with '*' for a password field.int
During text selection, this is one end of the selection where the other end is the carat position.int
Returns the column number of the current anchor position in the line returned by getAnchorLine().int
Returns the line number containing the current anchor position.int
getCarat()
Returns the current 'carat' position.int
Returns the column number of the current carat position in the line returned by getCaratLine().int
Returns the line number containing the current carat position.Returns the delegate document model for which this document model filter is filtering,getLine
(int line) Passes the delegate's getLine() through the local filterOutput() method before returning.int
Returns the current number of lines in this document.Returns the object that is being versioned.getText()
Passes the delegate's getText() through the local filterOutput() method before returning.long
Returns the current version of the versioned object.int
home
(boolean currentLine) Moves the carat to the document's home position or the current line's home position depending on the specified 'currentLine' value.void
insert
(char c) Inserts a character at the current carat position.void
Bulk inserts a string of text.void
Inserts a new line at the current carat position.int
left()
Moves the carat one position to the left, potentially moving it to the previous line depending on the actual DocumentModel implementation.int
right()
Moves the carat one position to the right, potentially moving it to the next line depending on the actual DocumentModel implementation.void
Sets an optional input transform that will be used to convert all input from setText() or insert().void
Sets an optional output transform function that will convert text before returning it from getText().void
Replaces the text contained in this DocumentModel.int
up()
Moves the carat position to the previous line if there is one.
-
Constructor Details
-
DocumentModelFilter
public DocumentModelFilter() -
DocumentModelFilter
-
DocumentModelFilter
-
DocumentModelFilter
-
-
Method Details
-
getDelegate
Returns the delegate document model for which this document model filter is filtering, -
setOutputTransform
Sets an optional output transform function that will convert text before returning it from getText(). Note: with the default implementation of DocumentModelFilter, the transformed text must be a character for character replacement or the carat position will be incorrectly reported from the callers' perspective. If the supplied function is null then no output transformation is done by default. -
getOutputTransform
-
setInputTransform
Sets an optional input transform that will be used to convert all input from setText() or insert(). If the function returns null for any character then that character is skipped in the input. If the supplied function is null then no input transformation is done by default. -
getInputTransform
-
clone
Description copied from interface:DocumentModel
Deep clones this document model.- Specified by:
clone
in interfaceDocumentModel
- Overrides:
clone
in classObject
-
filterInput
Can be overridden to bulk filter input provided to setText(). Default implementation returns the text directly unless there is an input transform function set. If there is an input transform function set then each character is first passed through that function to build a new string. -
filterInput
Can be overridden to filter the input provided to insert(). The default implementation returns the character directly. -
filterOutput
Can be overridden to filter the output from the getText() method, for example replacing all characters with '*' for a password field. The default implementation checks for a transform function and uses it or just returns the string directly. -
setText
Description copied from interface:DocumentModel
Replaces the text contained in this DocumentModel.- Specified by:
setText
in interfaceDocumentModel
-
getText
Passes the delegate's getText() through the local filterOutput() method before returning.- Specified by:
getText
in interfaceDocumentModel
-
getLine
Passes the delegate's getLine() through the local filterOutput() method before returning.- Specified by:
getLine
in interfaceDocumentModel
-
getLineCount
public int getLineCount()Description copied from interface:DocumentModel
Returns the current number of lines in this document.- Specified by:
getLineCount
in interfaceDocumentModel
-
getCarat
public int getCarat()Description copied from interface:DocumentModel
Returns the current 'carat' position. The 'carat' is where new text characters will be inserted. It's the current edit position.- Specified by:
getCarat
in interfaceDocumentModel
-
getCaratLine
public int getCaratLine()Description copied from interface:DocumentModel
Returns the line number containing the current carat position.- Specified by:
getCaratLine
in interfaceDocumentModel
-
getCaratColumn
public int getCaratColumn()Description copied from interface:DocumentModel
Returns the column number of the current carat position in the line returned by getCaratLine().- Specified by:
getCaratColumn
in interfaceDocumentModel
-
getAnchorLine
public int getAnchorLine()Description copied from interface:DocumentModel
Returns the line number containing the current anchor position.- Specified by:
getAnchorLine
in interfaceDocumentModel
-
getAnchorColumn
public int getAnchorColumn()Description copied from interface:DocumentModel
Returns the column number of the current anchor position in the line returned by getAnchorLine().- Specified by:
getAnchorColumn
in interfaceDocumentModel
-
getAnchor
public int getAnchor()Description copied from interface:DocumentModel
During text selection, this is one end of the selection where the other end is the carat position.- Specified by:
getAnchor
in interfaceDocumentModel
-
home
public int home(boolean currentLine) Description copied from interface:DocumentModel
Moves the carat to the document's home position or the current line's home position depending on the specified 'currentLine' value. If currentLine is true then the home position is just before the first character in the current line. If the currentLine parameter is false then the home position is just before the first character in the whole document.- Specified by:
home
in interfaceDocumentModel
-
end
public int end(boolean currentLine) Description copied from interface:DocumentModel
Moves the carat to the document's end position or the current line's end position depending on the specified 'currentLine' value. If currentLine is true then the end position is just after the last character in the current line. If the currentLine parameter is false then the end position is just after the last character in the whole document.- Specified by:
end
in interfaceDocumentModel
-
up
public int up()Description copied from interface:DocumentModel
Moves the carat position to the previous line if there is one. After this call, the new column position is implementation dependent.- Specified by:
up
in interfaceDocumentModel
-
down
public int down()Description copied from interface:DocumentModel
Moves the carat position to the next line if there is one. After this call, the new column position is implementation dependent.- Specified by:
down
in interfaceDocumentModel
-
left
public int left()Description copied from interface:DocumentModel
Moves the carat one position to the left, potentially moving it to the previous line depending on the actual DocumentModel implementation.- Specified by:
left
in interfaceDocumentModel
-
right
public int right()Description copied from interface:DocumentModel
Moves the carat one position to the right, potentially moving it to the next line depending on the actual DocumentModel implementation.- Specified by:
right
in interfaceDocumentModel
-
insertNewLine
public void insertNewLine()Description copied from interface:DocumentModel
Inserts a new line at the current carat position.- Specified by:
insertNewLine
in interfaceDocumentModel
-
deleteCharAt
public void deleteCharAt(int pos) Description copied from interface:DocumentModel
Deletes the character at the specified position.- Specified by:
deleteCharAt
in interfaceDocumentModel
-
backspace
public void backspace()Description copied from interface:DocumentModel
Deletes the character immediately before the current carat position. This may move the carat to the previous line if the carat was previously at the beginning of a line.- Specified by:
backspace
in interfaceDocumentModel
-
delete
public void delete()Description copied from interface:DocumentModel
Deletes the character immediately after the current carat position.- Specified by:
delete
in interfaceDocumentModel
-
insert
public void insert(char c) Description copied from interface:DocumentModel
Inserts a character at the current carat position.- Specified by:
insert
in interfaceDocumentModel
-
insert
Description copied from interface:DocumentModel
Bulk inserts a string of text.- Specified by:
insert
in interfaceDocumentModel
-
getVersion
public long getVersion()Description copied from interface:VersionedObject
Returns the current version of the versioned object.- Specified by:
getVersion
in interfaceVersionedObject<DocumentModel>
-
getObject
Description copied from interface:VersionedObject
Returns the object that is being versioned.- Specified by:
getObject
in interfaceVersionedObject<DocumentModel>
-
createReference
Description copied from interface:VersionedObject
Creates a new VersionedReference that can be used to monitor when this object changes.- Specified by:
createReference
in interfaceVersionedObject<DocumentModel>
-
createCaratReference
Description copied from interface:DocumentModel
Returns a VersionedReference that can be watched for changes to the carat position.- Specified by:
createCaratReference
in interfaceDocumentModel
-