- All Implemented Interfaces:
Completion
,ParameterizedCompletion
,Comparable<Completion>
The format of a template is similar to those in Eclipse. The following example would be the format for a for-loop template:
for (int ${i} = 0; ${i} < ${array}.length; ${i}++) { ${cursor} }In the above example, the first
${i}
is a parameter for the
user to type into; all the other ${i}
instances are
automatically changed to what the user types in the first one. The parameter
named ${cursor}
is the "ending position" of the template. It's
where the caret moves after it cycles through all other parameters. If the
user types into it, template mode terminates. If more than one
${cursor}
parameter is specified, behavior is undefined.
Two dollar signs in a row ("$$
") will be evaluated as a single
dollar sign. Otherwise, the template parsing is pretty straightforward and
fault-tolerant.
Leading whitespace is automatically added to lines if the template spans
more than one line, and if used with a text component using a
PlainDocument
, tabs will be converted to spaces if requested.
In order to use any instance of a ParameterizedCompletion
, you need
to call AutoCompletion#setParameterAssistanceEnabled(boolean)
with
a value of true
first. Otherwise, any completion choices will be
visible in the completion list, but won't insert anything when selected.
- Version:
- 1.0
- Author:
- Robert Futrell
-
Nested Class Summary
Nested classes/interfaces inherited from interface de.grogra.pf.ui.autocomplete.impl.ParameterizedCompletion
ParameterizedCompletion.Parameter
-
Constructor Summary
ConstructorDescriptionTemplateCompletion
(CompletionProvider provider, String inputText, String definitionString, String template) TemplateCompletion
(CompletionProvider provider, String inputText, String definitionString, String template, String shortDescription, String summary) -
Method Summary
Modifier and TypeMethodDescriptionReturns the "definition string" for this completion.Returns the text the user has to (start) typing for this completion to be offered.getInsertionInfo
(AutoCompletableTextArea tc, boolean replaceTabsWithSpaces) Returns completion information for this parameterized completion, given the specified text component.static String
getLeadingWhitespace
(AutoCompletableTextArea doc, int offs) Returns the leading whitespace of a specific line in a document.static String
getLeadingWhitespace
(String text) Returns the leading whitespace of a string.static String
getLeadingWhitespace
(String text, int upTo) Returns the leading whitespace of a string.getParam
(int index) Returns the specifiedParameterizedCompletion.Parameter
.int
Returns the number of parameters this completion takes.Returnsnull
; template completions insert all of their text viagetInsertionInfo()
.boolean
Returns whether a tool tip displaying assistance for each parameter while it is being edited is appropriate for this completion.Returns the description of this auto-complete choice.static boolean
isWhitespace
(char ch) Returns whether a character is a whitespace character (either a space ' ' or tab '\t').void
setShortDescription
(String shortDesc) Sets the short description of this template completion.toString()
Returns a string representation of this completion.Methods inherited from class de.grogra.pf.ui.autocomplete.impl.AbstractCompletion
compareTo, getAlreadyEntered, getCompareString, getIcon, getProvider, getRelevance, getToolTipText, setIcon, setRelevance
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface de.grogra.pf.ui.autocomplete.impl.Completion
compareTo, getAlreadyEntered, getCompareString, getIcon, getProvider, getRelevance, getToolTipText
-
Constructor Details
-
TemplateCompletion
public TemplateCompletion(CompletionProvider provider, String inputText, String definitionString, String template) -
TemplateCompletion
-
-
Method Details
-
getInputText
Description copied from class:AbstractCompletion
Returns the text the user has to (start) typing for this completion to be offered. The default implementation simply returnsCompletion.getReplacementText()
.- Specified by:
getInputText
in interfaceCompletion
- Overrides:
getInputText
in classAbstractCompletion
- Returns:
- The text the user has to (start) typing for this completion.
- See Also:
-
getReplacementText
Returnsnull
; template completions insert all of their text viagetInsertionInfo()
.- Specified by:
getReplacementText
in interfaceCompletion
- Returns:
null
always.- See Also:
-
getSummary
Description copied from interface:Completion
Returns the description of this auto-complete choice. This can be used in a popup "description window."- Specified by:
getSummary
in interfaceCompletion
- Returns:
- This item's description. This should be HTML. It may be
null
if there is no description for this completion.
-
getDefinitionString
Description copied from interface:ParameterizedCompletion
Returns the "definition string" for this completion. For example, for the C "printf
" function, this would return "int printf(const char *, ...)
".- Specified by:
getDefinitionString
in interfaceParameterizedCompletion
- Returns:
- The definition string.
-
getShortDescription
-
getShowParameterToolTip
public boolean getShowParameterToolTip()Description copied from interface:ParameterizedCompletion
Returns whether a tool tip displaying assistance for each parameter while it is being edited is appropriate for this completion.- Specified by:
getShowParameterToolTip
in interfaceParameterizedCompletion
- Returns:
- Whether the tool tip is appropriate to display.
-
getInsertionInfo
public ParameterizedCompletionInsertionInfo getInsertionInfo(AutoCompletableTextArea tc, boolean replaceTabsWithSpaces) Description copied from interface:ParameterizedCompletion
Returns completion information for this parameterized completion, given the specified text component.- Specified by:
getInsertionInfo
in interfaceParameterizedCompletion
- Parameters:
tc
- The text component.replaceTabsWithSpaces
- Whether to replace tabs with spaces.- Returns:
- The completion info.
-
getParam
Description copied from interface:ParameterizedCompletion
Returns the specifiedParameterizedCompletion.Parameter
.- Specified by:
getParam
in interfaceParameterizedCompletion
- Parameters:
index
- The index of the parameter to retrieve.- Returns:
- The parameter.
- See Also:
-
getParamCount
public int getParamCount()Description copied from interface:ParameterizedCompletion
Returns the number of parameters this completion takes.- Specified by:
getParamCount
in interfaceParameterizedCompletion
- Returns:
- The number of parameters this completion takes.
- See Also:
-
setShortDescription
Sets the short description of this template completion.- Parameters:
shortDesc
- The new short description.- See Also:
-
toString
Description copied from class:AbstractCompletion
Returns a string representation of this completion. The default implementation returnsAbstractCompletion.getInputText()
.- Overrides:
toString
in classAbstractCompletion
- Returns:
- A string representation of this completion.
-
getLeadingWhitespace
Returns the leading whitespace of a string.- Parameters:
text
- The String to check.- Returns:
- The leading whitespace.
- See Also:
-
getLeadingWhitespace(String, int)
#getLeadingWhitespace(Document, int)
-
getLeadingWhitespace
Returns the leading whitespace of a string.- Parameters:
text
- The String to check.upTo
- Stops checking at the specified offset.- Returns:
- The leading whitespace.
- See Also:
-
getLeadingWhitespace
public static String getLeadingWhitespace(AutoCompletableTextArea doc, int offs) throws BadLocationException Returns the leading whitespace of a specific line in a document.- Parameters:
doc
- The document.offs
- The offset whose line to get the leading whitespace for.- Returns:
- The leading whitespace.
- Throws:
BadLocationException
- Ifoffs
is not a valid offset in the document.- See Also:
-
isWhitespace
public static boolean isWhitespace(char ch) Returns whether a character is a whitespace character (either a space ' ' or tab '\t'). This checks for the Unicode character values 0x0020 and 0x0009.- Parameters:
ch
- The character to check.- Returns:
- Whether the character is a whitespace character.
-