Class CodeTemplateManager
java.lang.Object
org.fife.ui.rsyntaxtextarea.CodeTemplateManager
Manages "code templates."
All methods in this class are synchronized for thread safety, but as a
best practice, you should probably only modify the templates known to a
CodeTemplateManager on the EDT. Modifying a
CodeTemplate retrieved from a CodeTemplateManager
while not on the EDT could cause problems.
For more flexible boilerplate code insertion, consider using the TemplateCompletion class in the AutoComplete add-on library.
- Version:
- 1.0
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classA comparator that takes aCodeTemplateas its first parameter and aSegmentas its second, and knows to compare the template's ID to the segment's text.private static classA file filter that accepts only XML files. -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate Fileprivate intprivate Segmentprivate List<CodeTemplate> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddTemplate(CodeTemplate template) Registers the specified template with this template manager.getTemplate(RSyntaxTextArea textArea) Returns the template that should be inserted at the current caret position, assuming the trigger character was pressed.private intReturns the number of templates this manager knows about.Returns the templates currently available.private static booleanisValidChar(char ch) Returns whether the specified character is a valid character for aCodeTemplateid.removeTemplate(String id) Returns the code template with the specified id.booleanremoveTemplate(CodeTemplate template) Returns the specified code template.voidreplaceTemplates(CodeTemplate[] newTemplates) Replaces the current set of available templates with the ones specified.booleanSaves all templates as XML files in the current template directory.intsetTemplateDirectory(File dir) Sets the directory in which to look for templates.private voidRemoves any null entries in the current set of templates (if any), sorts the remaining templates, and computes the new maximum template ID length.
-
Field Details
-
maxTemplateIDLength
private int maxTemplateIDLength -
templates
-
s
-
comparator
-
directory
-
-
Constructor Details
-
CodeTemplateManager
public CodeTemplateManager()Constructor.
-
-
Method Details
-
addTemplate
Registers the specified template with this template manager.- Parameters:
template- The template to register.- Throws:
IllegalArgumentException- Iftemplateisnull.- See Also:
-
getTemplate
Returns the template that should be inserted at the current caret position, assuming the trigger character was pressed.- Parameters:
textArea- The text area that's getting text inserted into it.- Returns:
- A template that should be inserted, if appropriate, or
nullif no template should be inserted.
-
getTemplateCount
private int getTemplateCount()Returns the number of templates this manager knows about.- Returns:
- The template count.
-
getTemplates
Returns the templates currently available.- Returns:
- The templates available.
-
isValidChar
private static boolean isValidChar(char ch) Returns whether the specified character is a valid character for aCodeTemplateid.- Parameters:
ch- The character to check.- Returns:
- Whether the character is a valid template character.
-
removeTemplate
Returns the specified code template.- Parameters:
template- The template to remove.- Returns:
trueif the template was removed,falseif the template was not in this template manager.- Throws:
IllegalArgumentException- Iftemplateisnull.- See Also:
-
removeTemplate
Returns the code template with the specified id.- Parameters:
id- The id to check for.- Returns:
- The code template that was removed, or
nullif there was no template with the specified ID. - Throws:
IllegalArgumentException- Ifidisnull.- See Also:
-
replaceTemplates
Replaces the current set of available templates with the ones specified.- Parameters:
newTemplates- The new set of templates. Note that we will be taking a shallow copy of these and sorting them.
-
saveTemplates
public boolean saveTemplates()Saves all templates as XML files in the current template directory.- Returns:
- Whether the save was successful.
-
setTemplateDirectory
Sets the directory in which to look for templates. Calling this method adds any new templates found in the specified directory to the templates already registered.- Parameters:
dir- The new directory in which to look for templates.- Returns:
- The new number of templates in this template manager, or
-1if the specified directory does not exist.
-
sortTemplates
private void sortTemplates()Removes any null entries in the current set of templates (if any), sorts the remaining templates, and computes the new maximum template ID length.
-