Class StaticCodeTemplate
- java.lang.Object
-
- org.fife.ui.rsyntaxtextarea.templates.AbstractCodeTemplate
-
- org.fife.ui.rsyntaxtextarea.templates.StaticCodeTemplate
-
- All Implemented Interfaces:
java.io.Serializable
,java.lang.Cloneable
,java.lang.Comparable<CodeTemplate>
,CodeTemplate
public class StaticCodeTemplate extends AbstractCodeTemplate
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 typeforb
followed by a trigger (e.g., a space) into a text area with thisCodeTemplate
, the code snippet is added in place offorb
. Further, the caret is placed at the position denoted by<caret>
.- Version:
- 0.1
- See Also:
CodeTemplate
, Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
afterCaret
The code inserted after the caret position.private java.lang.String
beforeCaret
The code inserted before the caret position.private static java.lang.String
EMPTY_STRING
private int
firstAfterNewline
Cached value representing whetherafterCaret
contains one or more newlines.private int
firstBeforeNewline
Cached value representing whetherbeforeCaret
contains one or more newlines.private static long
serialVersionUID
-
Constructor Summary
Constructors Constructor Description StaticCodeTemplate()
Constructor.StaticCodeTemplate(java.lang.String id, java.lang.String beforeCaret, java.lang.String afterCaret)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAfterCaretText()
Returns the text that will be placed after the caret.private java.lang.String
getAfterTextIndented(java.lang.String indent)
Returns the "after caret" text, with each new line indented by the specified amount.java.lang.String
getBeforeCaretText()
Returns the text that will be placed before the caret.private java.lang.String
getBeforeTextIndented(java.lang.String indent)
Returns the "before caret" text, with each new line indented by the specified amount.private java.lang.String
getTextIndented(java.lang.String text, int firstNewline, java.lang.String indent)
Returns text with newlines indented by the specified amount.void
invoke(RSyntaxTextArea textArea)
Invokes this code template.private void
readObject(java.io.ObjectInputStream in)
Called when reading a serialized version of this document.void
setAfterCaretText(java.lang.String afterCaret)
Sets the text to place after the caret.void
setBeforeCaretText(java.lang.String beforeCaret)
Sets the text to place before the caret.java.lang.String
toString()
Returns a string representation of this template for debugging purposes.
-
-
-
Field Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
beforeCaret
private java.lang.String beforeCaret
The code inserted before the caret position.
-
afterCaret
private java.lang.String afterCaret
The code inserted after the caret position.
-
firstBeforeNewline
private transient int firstBeforeNewline
Cached value representing whetherbeforeCaret
contains one or more newlines.
-
firstAfterNewline
private transient int firstAfterNewline
Cached value representing whetherafterCaret
contains one or more newlines.
-
EMPTY_STRING
private static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
StaticCodeTemplate
public StaticCodeTemplate()
Constructor. This constructor only exists to support persistence through serialization.
-
StaticCodeTemplate
public StaticCodeTemplate(java.lang.String id, java.lang.String beforeCaret, java.lang.String afterCaret)
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 Detail
-
getAfterCaretText
public java.lang.String getAfterCaretText()
Returns the text that will be placed after the caret.- Returns:
- The text.
- See Also:
setAfterCaretText(java.lang.String)
-
getBeforeCaretText
public java.lang.String getBeforeCaretText()
Returns the text that will be placed before the caret.- Returns:
- The text.
- See Also:
setBeforeCaretText(java.lang.String)
-
getAfterTextIndented
private java.lang.String getAfterTextIndented(java.lang.String indent)
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
private java.lang.String getBeforeTextIndented(java.lang.String indent)
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
private java.lang.String getTextIndented(java.lang.String text, int firstNewline, java.lang.String indent)
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
public void invoke(RSyntaxTextArea textArea) throws javax.swing.text.BadLocationException
Invokes this code template. The changes are made to the given text area.- Parameters:
textArea
- The text area to operate on.- Throws:
javax.swing.text.BadLocationException
- If something bad happens.
-
readObject
private void readObject(java.io.ObjectInputStream in) throws java.lang.ClassNotFoundException, java.io.IOException
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:
java.lang.ClassNotFoundException
- Never.java.io.IOException
- If an IO error occurs.
-
setAfterCaretText
public void setAfterCaretText(java.lang.String afterCaret)
Sets the text to place after the caret.- Parameters:
afterCaret
- The text.- See Also:
getAfterCaretText()
-
setBeforeCaretText
public void setBeforeCaretText(java.lang.String beforeCaret)
Sets the text to place before the caret.- Parameters:
beforeCaret
- The text.- See Also:
getBeforeCaretText()
-
toString
public java.lang.String toString()
Returns a string representation of this template for debugging purposes.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of this template.
-
-