Class EditCorrectorHooks
- java.lang.Object
-
- org.luwrain.script.controls.EditCorrectorHooks
-
- All Implemented Interfaces:
MultilineEdit.Model
,MultilineEditCorrector
,Lines
public class EditCorrectorHooks extends Object implements MultilineEditCorrector
A translator of text correcting operations to hooks actions. This class can wrap any instance ofMultilineEditCorrector
with calls of the hooks prior and after of the corresponding action of the underlying corrector.The call of the hook prior to the operation may cancel the operation, if it returns
false
. If it returns any other value , includingnull
andundefined
, the processing will be continued. The hooks called after the operation may return any value, it is never taken into account in any way.All hooks handlers must expect the single argument with members, which set depends on the purpose of the particular operation. In the meantime, the argument always has the
lines
andhotPoint
members, since they are actual for any operation.Here is the list of the hooks created by this class where
base
is a string value provided with the constructor:base.delete.char.pre
base.delete.char.post
base.delete.region.pre
base.delete.region.post
base.insert.region.pre
base.insert.region.post
base.insert.chars.pre
base.insert.chars.post
base.merge.lines.pre
base.merge.lines.post
base.split.lines.pre
base.split.lines.post
-
-
Field Summary
Fields Modifier and Type Field Description protected MultilineEditCorrector
base
protected HookContainer
context
protected String
hookNameBase
-
Constructor Summary
Constructors Constructor Description EditCorrectorHooks(HookContainer hookContainer, MultilineEditCorrector base, String hookNameBase)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultilineEdit.ModificationResult
deleteChar(int pos, int lineIndex)
MultilineEdit.ModificationResult
deleteRegion(int fromX, int fromY, int toX, int toY)
MultilineEdit.ModificationResult
doEditAction(TextEditAction action)
int
getHotPointX()
int
getHotPointY()
String
getLine(int index)
int
getLineCount()
String
getTabSeq()
MultilineEdit.ModificationResult
insertRegion(int x, int y, String[] lines)
MultilineEdit.ModificationResult
mergeLines(int firstLineIndex)
MultilineEdit.ModificationResult
putChars(int pos, int lineIndex, String str)
Puts one or several characters at some position.protected void
runPost(String hookName, Map<String,Object> values)
protected boolean
runPre(String hookName, Map<String,Object> values)
MultilineEdit.ModificationResult
splitLine(int pos, int lineIndex)
Splits the specified line at the specified position.
-
-
-
Field Detail
-
context
protected final HookContainer context
-
base
protected final MultilineEditCorrector base
-
hookNameBase
protected final String hookNameBase
-
-
Constructor Detail
-
EditCorrectorHooks
public EditCorrectorHooks(HookContainer hookContainer, MultilineEditCorrector base, String hookNameBase)
-
-
Method Detail
-
getLineCount
public int getLineCount()
- Specified by:
getLineCount
in interfaceLines
-
getHotPointX
public int getHotPointX()
- Specified by:
getHotPointX
in interfaceMultilineEdit.Model
-
getHotPointY
public int getHotPointY()
- Specified by:
getHotPointY
in interfaceMultilineEdit.Model
-
getTabSeq
public String getTabSeq()
- Specified by:
getTabSeq
in interfaceMultilineEdit.Model
-
deleteChar
public MultilineEdit.ModificationResult deleteChar(int pos, int lineIndex)
- Specified by:
deleteChar
in interfaceMultilineEdit.Model
-
deleteRegion
public MultilineEdit.ModificationResult deleteRegion(int fromX, int fromY, int toX, int toY)
- Specified by:
deleteRegion
in interfaceMultilineEdit.Model
-
insertRegion
public MultilineEdit.ModificationResult insertRegion(int x, int y, String[] lines)
- Specified by:
insertRegion
in interfaceMultilineEdit.Model
-
putChars
public MultilineEdit.ModificationResult putChars(int pos, int lineIndex, String str)
Description copied from interface:MultilineEdit.Model
Puts one or several characters at some position. The position expects to be valid in the content of the model, except of the case when there are no lines at all,lineIndex
equals to zero andpos
equals to zero. In this case the method must insert one empty line prior to making any required changes.After performing the operation, the method must prepare the
MultilineEdit.ModificationResult
object. If thechars
arguments has the length greater than one, the string argument of the result must be set to the value ofchars
argument.If
chars
argument has the length equals to one, this single character must be returned as the character argument of the result. If the method is requested to insert a single spacing character, the string argument of the result must contain the last word prior to the inserting position. If there is no any word prior to the inserting position, the result may have the string argument empty.- Specified by:
putChars
in interfaceMultilineEdit.Model
- Parameters:
pos
- The position on the line to put characters atlineIndex
- The index of the line to put characters onstr
- The characters to put- Returns:
- The
MultilineEdit.ModificationResult
object with the flag if the operation was performed and other corresponding information
-
mergeLines
public MultilineEdit.ModificationResult mergeLines(int firstLineIndex)
- Specified by:
mergeLines
in interfaceMultilineEdit.Model
-
splitLine
public MultilineEdit.ModificationResult splitLine(int pos, int lineIndex)
Description copied from interface:MultilineEdit.Model
Splits the specified line at the specified position. This method removes on the line all the content after the specified position and puts the deleted fragment on new line which is inserted just after modified. If the position is given outside of the stored text, the behaviour of this method is undefined.- Specified by:
splitLine
in interfaceMultilineEdit.Model
- Parameters:
pos
- The 0-based position to split line atlineIndex
- The 0-based index of the line to split- Returns:
- The fragment moved onto newly inserted line
-
doEditAction
public MultilineEdit.ModificationResult doEditAction(TextEditAction action)
- Specified by:
doEditAction
in interfaceMultilineEditCorrector
-
-