Class StaticCodeTemplate
java.lang.Object
org.fife.ui.rsyntaxtextarea.templates.AbstractCodeTemplate
org.fife.ui.rsyntaxtextarea.templates.StaticCodeTemplate
- All Implemented Interfaces:
Serializable
,Cloneable
,Comparable<CodeTemplate>
,CodeTemplate
A code template that inserts static text before and after the caret.
For example, you can associate the identifier forb
(short for "for-block") with the following code:
for (<caret>) { }Then, whenever you type
forb
followed by a trigger
(e.g., a space) into a text area with this CodeTemplate
,
the code snippet is added in place of forb
. Further,
the caret is placed at the position denoted by <caret>
.- Version:
- 0.1
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate String
The code inserted after the caret position.private String
The code inserted before the caret position.private static final String
private int
Cached value representing whetherafterCaret
contains one or more newlines.private int
Cached value representing whetherbeforeCaret
contains one or more newlines.private static final long
-
Constructor Summary
ConstructorsConstructorDescriptionConstructor.StaticCodeTemplate
(String id, String beforeCaret, String afterCaret) Constructor. -
Method Summary
Modifier and TypeMethodDescriptionReturns the text that will be placed after the caret.private String
getAfterTextIndented
(String indent) Returns the "after caret" text, with each new line indented by the specified amount.Returns the text that will be placed before the caret.private String
getBeforeTextIndented
(String indent) Returns the "before caret" text, with each new line indented by the specified amount.private String
getTextIndented
(String text, int firstNewline, String indent) Returns text with newlines indented by the specified amount.void
invoke
(RSyntaxTextArea textArea) Invokes this code template.private void
Called when reading a serialized version of this document.void
setAfterCaretText
(String afterCaret) Sets the text to place after the caret.void
setBeforeCaretText
(String beforeCaret) Sets the text to place before the caret.toString()
Returns a string representation of this template for debugging purposes.
-
Field Details
-
serialVersionUID
private static final long serialVersionUID- See Also:
-
beforeCaret
The code inserted before the caret position. -
afterCaret
The code inserted after the caret position. -
firstBeforeNewline
private transient int firstBeforeNewlineCached value representing whetherbeforeCaret
contains one or more newlines. -
firstAfterNewline
private transient int firstAfterNewlineCached value representing whetherafterCaret
contains one or more newlines. -
EMPTY_STRING
- See Also:
-
-
Constructor Details
-
StaticCodeTemplate
public StaticCodeTemplate()Constructor. This constructor only exists to support persistence through serialization. -
StaticCodeTemplate
Constructor.- Parameters:
id
- The ID of this code template.beforeCaret
- The text to place before the caret.afterCaret
- The text to place after the caret.
-
-
Method Details
-
getAfterCaretText
Returns the text that will be placed after the caret.- Returns:
- The text.
- See Also:
-
getBeforeCaretText
Returns the text that will be placed before the caret.- Returns:
- The text.
- See Also:
-
getAfterTextIndented
Returns the "after caret" text, with each new line indented by the specified amount.- Parameters:
indent
- The amount to indent.- Returns:
- The "after caret" text.
-
getBeforeTextIndented
Returns the "before caret" text, with each new line indented by the specified amount.- Parameters:
indent
- The amount to indent.- Returns:
- The "before caret" text.
-
getTextIndented
Returns text with newlines indented by the specified amount.- Parameters:
text
- The original text.firstNewline
- The index of the first '\n' character.indent
- The amount to indent.- Returns:
- The indented text.
-
invoke
Invokes this code template. The changes are made to the given text area.- Parameters:
textArea
- The text area to operate on.- Throws:
BadLocationException
- If something bad happens.
-
readObject
Called when reading a serialized version of this document. This is overridden to initialize the transient members of this class.- Parameters:
in
- The input stream to read from.- Throws:
ClassNotFoundException
- Never.IOException
- If an IO error occurs.
-
setAfterCaretText
Sets the text to place after the caret.- Parameters:
afterCaret
- The text.- See Also:
-
setBeforeCaretText
Sets the text to place before the caret.- Parameters:
beforeCaret
- The text.- See Also:
-
toString
Returns a string representation of this template for debugging purposes.
-