Package org.fife.ui.autocomplete
Class CompletionProviderBase
- java.lang.Object
-
- org.fife.ui.autocomplete.CompletionProviderBase
-
- All Implemented Interfaces:
CompletionProvider
- Direct Known Subclasses:
AbstractCompletionProvider,LanguageAwareCompletionProvider
public abstract class CompletionProviderBase extends java.lang.Object implements CompletionProvider
A base class for all standard completion providers. This class implements functionality that should be sharable across allCompletionProviderimplementations.- Version:
- 1.0
- See Also:
AbstractCompletionProvider
-
-
Field Summary
Fields Modifier and Type Field Description private booleanautoActivateAfterLettersWhether auto-activation should occur after letters.private java.lang.StringautoActivateCharsNon-letter chars that should cause auto-activation to occur.protected static java.lang.StringEMPTY_STRINGprivate javax.swing.ListCellRenderer<java.lang.Object>listCellRendererThe renderer to use for completions from this provider.private ParameterChoicesProviderparamChoicesProviderProvides completion choices for a parameterized completion's parameters.private charparamListEndText that marks the end of a parameter list, for example, ')'.private java.lang.StringparamListSeparatorText that separates items in a parameter list, for example, ", ".private charparamListStartText that marks the beginning of a parameter list, for example, '('.private CompletionProviderparentThe parent completion provider.private javax.swing.text.SegmentsA segment to use for fast char access.private static java.util.Comparator<Completion>SORT_BY_RELEVANCE_COMPARATORComparator used to sort completions by their relevance before sorting them lexicographically.
-
Constructor Summary
Constructors Constructor Description CompletionProviderBase()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidclearParameterizedCompletionParams()Clears the values used to identify and insert "parameterized completions" (e.g.java.util.List<Completion>getCompletions(javax.swing.text.JTextComponent comp)Gets the possible completions for the text component at the current caret position.protected abstract java.util.List<Completion>getCompletionsImpl(javax.swing.text.JTextComponent comp)Does the dirty work of creating a list of completions.javax.swing.ListCellRenderer<java.lang.Object>getListCellRenderer()Returns the cell renderer for completions returned from this provider.ParameterChoicesProvidergetParameterChoicesProvider()Returns an object that can return a list of completion choices for parameters.chargetParameterListEnd()Returns the text that marks the end of a list of parameters to a function or method.java.lang.StringgetParameterListSeparator()Returns the text that separates parameters to a function or method.chargetParameterListStart()Returns the text that marks the start of a list of parameters to a function or method.CompletionProvidergetParent()Returns the parent completion provider.booleanisAutoActivateOkay(javax.swing.text.JTextComponent tc)This method is called if auto-activation is enabled in the parentAutoCompletionafter the user types a single character.voidsetAutoActivationRules(boolean letters, java.lang.String others)Sets the characters that auto-activation should occur after.voidsetListCellRenderer(javax.swing.ListCellRenderer<java.lang.Object> r)Sets the renderer to use when displaying completion choices.voidsetParameterChoicesProvider(ParameterChoicesProvider pcp)Sets the param choices provider.voidsetParameterizedCompletionParams(char listStart, java.lang.String separator, char listEnd)Sets the values used to identify and insert "parameterized completions" (e.g.voidsetParent(CompletionProvider parent)Sets the parent completion provider.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.fife.ui.autocomplete.CompletionProvider
getAlreadyEnteredText, getCompletionsAt, getParameterizedCompletions
-
-
-
-
Field Detail
-
parent
private CompletionProvider parent
The parent completion provider.
-
listCellRenderer
private javax.swing.ListCellRenderer<java.lang.Object> listCellRenderer
The renderer to use for completions from this provider. If this isnull, a default renderer is used.
-
paramListStart
private char paramListStart
Text that marks the beginning of a parameter list, for example, '('.
-
paramListEnd
private char paramListEnd
Text that marks the end of a parameter list, for example, ')'.
-
paramListSeparator
private java.lang.String paramListSeparator
Text that separates items in a parameter list, for example, ", ".
-
autoActivateAfterLetters
private boolean autoActivateAfterLetters
Whether auto-activation should occur after letters.
-
autoActivateChars
private java.lang.String autoActivateChars
Non-letter chars that should cause auto-activation to occur.
-
paramChoicesProvider
private ParameterChoicesProvider paramChoicesProvider
Provides completion choices for a parameterized completion's parameters.
-
s
private final javax.swing.text.Segment s
A segment to use for fast char access.
-
EMPTY_STRING
protected static final java.lang.String EMPTY_STRING
- See Also:
- Constant Field Values
-
SORT_BY_RELEVANCE_COMPARATOR
private static final java.util.Comparator<Completion> SORT_BY_RELEVANCE_COMPARATOR
Comparator used to sort completions by their relevance before sorting them lexicographically.
-
-
Method Detail
-
clearParameterizedCompletionParams
public void clearParameterizedCompletionParams()
Description copied from interface:CompletionProviderClears the values used to identify and insert "parameterized completions" (e.g. functions or methods). After this method is called, functions and methods will not have their parameters auto-completed.- Specified by:
clearParameterizedCompletionParamsin interfaceCompletionProvider- See Also:
CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getCompletions
public java.util.List<Completion> getCompletions(javax.swing.text.JTextComponent comp)
Description copied from interface:CompletionProviderGets the possible completions for the text component at the current caret position.- Specified by:
getCompletionsin interfaceCompletionProvider- Parameters:
comp- The text component.- Returns:
- The list of
Completions. If no completions are available, this method should return an empty list.
-
getCompletionsImpl
protected abstract java.util.List<Completion> getCompletionsImpl(javax.swing.text.JTextComponent comp)
Does the dirty work of creating a list of completions.- Parameters:
comp- The text component to look in.- Returns:
- The list of possible completions, or an empty list if there are none.
-
getListCellRenderer
public javax.swing.ListCellRenderer<java.lang.Object> getListCellRenderer()
Description copied from interface:CompletionProviderReturns the cell renderer for completions returned from this provider.- Specified by:
getListCellRendererin interfaceCompletionProvider- Returns:
- The cell renderer, or
nullif the default should be used. - See Also:
CompletionProvider.setListCellRenderer(ListCellRenderer)
-
getParameterChoicesProvider
public ParameterChoicesProvider getParameterChoicesProvider()
Description copied from interface:CompletionProviderReturns an object that can return a list of completion choices for parameters. This is used when a user code-completes a parameterized completion, such as a function or method. For any parameter to the function/method, this object can return possible completions.- Specified by:
getParameterChoicesProviderin interfaceCompletionProvider- Returns:
- The parameter choices provider, or
nullif none is installed.
-
getParameterListEnd
public char getParameterListEnd()
Description copied from interface:CompletionProviderReturns the text that marks the end of a list of parameters to a function or method.- Specified by:
getParameterListEndin interfaceCompletionProvider- Returns:
- The text for a parameter list end, for example,
'
)', or0if none. - See Also:
CompletionProvider.getParameterListStart(),CompletionProvider.getParameterListSeparator(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getParameterListSeparator
public java.lang.String getParameterListSeparator()
Description copied from interface:CompletionProviderReturns the text that separates parameters to a function or method.- Specified by:
getParameterListSeparatorin interfaceCompletionProvider- Returns:
- The text that separates parameters, for example,
"
,". - See Also:
CompletionProvider.getParameterListStart(),CompletionProvider.getParameterListEnd(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getParameterListStart
public char getParameterListStart()
Description copied from interface:CompletionProviderReturns the text that marks the start of a list of parameters to a function or method.- Specified by:
getParameterListStartin interfaceCompletionProvider- Returns:
- The text for a parameter list start, for example,
"
(". - See Also:
CompletionProvider.getParameterListEnd(),CompletionProvider.getParameterListSeparator(),CompletionProvider.setParameterizedCompletionParams(char, String, char)
-
getParent
public CompletionProvider getParent()
Description copied from interface:CompletionProviderReturns the parent completion provider.- Specified by:
getParentin interfaceCompletionProvider- Returns:
- The parent completion provider.
- See Also:
CompletionProvider.setParent(CompletionProvider)
-
isAutoActivateOkay
public boolean isAutoActivateOkay(javax.swing.text.JTextComponent tc)
Description copied from interface:CompletionProviderThis method is called if auto-activation is enabled in the parentAutoCompletionafter the user types a single character. This provider should check the text at the current caret position of the text component, and decide whether auto-activation would be appropriate here. For example, aCompletionProviderfor Java might want to returntruefor this method only if the last character typed was a '.'.- Specified by:
isAutoActivateOkayin interfaceCompletionProvider- Parameters:
tc- The text component.- Returns:
- Whether auto-activation would be appropriate.
-
setAutoActivationRules
public void setAutoActivationRules(boolean letters, java.lang.String others)Sets the characters that auto-activation should occur after. A Java completion provider, for example, might want to setothersto ".", to allow auto-activation for members of an object.- Parameters:
letters- Whether auto-activation should occur after any letter.others- A string of (non-letter) chars that auto-activation should occur after. This may benull.
-
setParameterChoicesProvider
public void setParameterChoicesProvider(ParameterChoicesProvider pcp)
Sets the param choices provider. This is used when a user code-completes a parameterized completion, such as a function or method. For any parameter to the function/method, this object can return possible completions.- Parameters:
pcp- The parameter choices provider, ornullfor none.- See Also:
getParameterChoicesProvider()
-
setListCellRenderer
public void setListCellRenderer(javax.swing.ListCellRenderer<java.lang.Object> r)
Description copied from interface:CompletionProviderSets the renderer to use when displaying completion choices.- Specified by:
setListCellRendererin interfaceCompletionProvider- Parameters:
r- The renderer to use.- See Also:
CompletionProvider.getListCellRenderer()
-
setParameterizedCompletionParams
public void setParameterizedCompletionParams(char listStart, java.lang.String separator, char listEnd)Description copied from interface:CompletionProviderSets the values used to identify and insert "parameterized completions" (e.g. functions or methods). If this method isn't called, functions and methods will not have their parameters auto-completed.- Specified by:
setParameterizedCompletionParamsin interfaceCompletionProvider- Parameters:
listStart- The character that marks the beginning of a list of parameters, such as '(' in C or Java.separator- Text that should separate parameters in a parameter list when one is inserted. For example, ",".listEnd- The character that marks the end of a list of parameters, such as ')' in C or Java.- See Also:
CompletionProvider.clearParameterizedCompletionParams()
-
setParent
public void setParent(CompletionProvider parent)
Description copied from interface:CompletionProviderSets the parent completion provider.- Specified by:
setParentin interfaceCompletionProvider- Parameters:
parent- The parent provider.nullmeans there will be no parent provider.- See Also:
CompletionProvider.getParent()
-
-