Package org.fife.ui.autocomplete
Class DefaultCompletionProvider
- java.lang.Object
-
- org.fife.ui.autocomplete.CompletionProviderBase
-
- org.fife.ui.autocomplete.AbstractCompletionProvider
-
- org.fife.ui.autocomplete.DefaultCompletionProvider
-
- All Implemented Interfaces:
CompletionProvider
public class DefaultCompletionProvider extends AbstractCompletionProvider
A basic completion provider implementation. This provider has no understanding of language semantics. It simply checks the text entered up to the caret position for a match against known completions. This is all that is needed in the majority of cases.- Version:
- 1.0
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
AbstractCompletionProvider.CaseInsensitiveComparator
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.String
lastCompletionsAtText
Used to speed upgetCompletionsAt(JTextComponent, Point)
.private java.util.List<Completion>
lastParameterizedCompletionsAt
Used to speed upgetCompletionsAt(JTextComponent, Point)
, since this may be called multiple times in succession (this is usually called byJTextComponent.getToolTipText()
, and if the user wiggles the mouse while a tool tip is displayed, this method gets repeatedly called.protected javax.swing.text.Segment
seg
-
Fields inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
comparator, completions
-
Fields inherited from class org.fife.ui.autocomplete.CompletionProviderBase
EMPTY_STRING
-
-
Constructor Summary
Constructors Constructor Description DefaultCompletionProvider()
Constructor.DefaultCompletionProvider(java.lang.String[] words)
Creates a completion provider that provides completion for a simple list of words.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
getAlreadyEnteredText(javax.swing.text.JTextComponent comp)
Returns the text just before the current caret position that could be the start of something auto-completable.java.util.List<Completion>
getCompletionsAt(javax.swing.text.JTextComponent tc, java.awt.Point p)
Returns the completions that have been entered at the specified visual location.java.util.List<ParameterizedCompletion>
getParameterizedCompletions(javax.swing.text.JTextComponent tc)
Returns a list of parameterized completions that have been entered at the current caret position of a text component (and thus can have their completion choices displayed).protected void
init()
Initializes this completion provider.protected boolean
isValidChar(char ch)
Returns whether the specified character is valid in an auto-completion.void
loadFromXML(java.io.File file)
Loads completions from an XML file.void
loadFromXML(java.io.InputStream in)
Loads completions from an XML input stream.void
loadFromXML(java.io.InputStream in, java.lang.ClassLoader cl)
Loads completions from an XML input stream.void
loadFromXML(java.lang.String resource)
Loads completions from an XML file.-
Methods inherited from class org.fife.ui.autocomplete.AbstractCompletionProvider
addCompletion, addCompletions, addWordCompletions, checkProviderAndAdd, clear, getCompletionByInputText, getCompletionsImpl, removeCompletion
-
Methods inherited from class org.fife.ui.autocomplete.CompletionProviderBase
clearParameterizedCompletionParams, getCompletions, getListCellRenderer, getParameterChoicesProvider, getParameterListEnd, getParameterListSeparator, getParameterListStart, getParent, isAutoActivateOkay, setAutoActivationRules, setListCellRenderer, setParameterChoicesProvider, setParameterizedCompletionParams, setParent
-
-
-
-
Field Detail
-
seg
protected javax.swing.text.Segment seg
-
lastCompletionsAtText
private java.lang.String lastCompletionsAtText
Used to speed upgetCompletionsAt(JTextComponent, Point)
.
-
lastParameterizedCompletionsAt
private java.util.List<Completion> lastParameterizedCompletionsAt
Used to speed upgetCompletionsAt(JTextComponent, Point)
, since this may be called multiple times in succession (this is usually called byJTextComponent.getToolTipText()
, and if the user wiggles the mouse while a tool tip is displayed, this method gets repeatedly called. It can be costly, so we try to speed it up a tad).
-
-
Constructor Detail
-
DefaultCompletionProvider
public DefaultCompletionProvider()
Constructor. The returned provider will not be aware of any completions.
-
DefaultCompletionProvider
public DefaultCompletionProvider(java.lang.String[] words)
Creates a completion provider that provides completion for a simple list of words.- Parameters:
words
- The words to offer as completion suggestions. If this isnull
, no completions will be known.- See Also:
BasicCompletion
-
-
Method Detail
-
getAlreadyEnteredText
public java.lang.String getAlreadyEnteredText(javax.swing.text.JTextComponent comp)
Returns the text just before the current caret position that could be the start of something auto-completable.This method returns all characters before the caret that are matched by
isValidChar(char)
.Returns the text just before the current caret position that could be the start of something auto-completable.
- Parameters:
comp
- The text component.- Returns:
- The text. A return value of
null
means nothing should be auto-completed; a value of an empty string (""
) means auto-completion should still be considered (i.e., all possible choices are valid).
-
getCompletionsAt
public java.util.List<Completion> getCompletionsAt(javax.swing.text.JTextComponent tc, java.awt.Point p)
Description copied from interface:CompletionProvider
Returns the completions that have been entered at the specified visual location. This can be used for tool tips when the user hovers the mouse over completed text.- Parameters:
tc
- The text component.p
- The position, usually from aMouseEvent
.- Returns:
- The completions, or an empty list if there are none.
-
getParameterizedCompletions
public java.util.List<ParameterizedCompletion> getParameterizedCompletions(javax.swing.text.JTextComponent tc)
Description copied from interface:CompletionProvider
Returns a list of parameterized completions that have been entered at the current caret position of a text component (and thus can have their completion choices displayed).- Parameters:
tc
- The text component.- Returns:
- The list of
ParameterizedCompletion
s. If no completions are available, this may benull
.
-
init
protected void init()
Initializes this completion provider.
-
isValidChar
protected boolean isValidChar(char ch)
Returns whether the specified character is valid in an auto-completion. The default implementation is equivalent to "Character.isLetterOrDigit(ch) || ch=='_'
". Subclasses can override this method to change what characters are matched.- Parameters:
ch
- The character.- Returns:
- Whether the character is valid.
-
loadFromXML
public void loadFromXML(java.io.File file) throws java.io.IOException
Loads completions from an XML file. The XML should validate againstCompletionXml.dtd
.- Parameters:
file
- An XML file to load from.- Throws:
java.io.IOException
- If an IO error occurs.
-
loadFromXML
public void loadFromXML(java.io.InputStream in) throws java.io.IOException
Loads completions from an XML input stream. The XML should validate againstCompletionXml.dtd
.- Parameters:
in
- The input stream to read from.- Throws:
java.io.IOException
- If an IO error occurs.
-
loadFromXML
public void loadFromXML(java.io.InputStream in, java.lang.ClassLoader cl) throws java.io.IOException
Loads completions from an XML input stream. The XML should validate againstCompletionXml.dtd
.- Parameters:
in
- The input stream to read from.cl
- The class loader to use when loading any extra classes defined in the XML, such as customFunctionCompletion
s. This may benull
if the default is to be used, or if no custom completions are defined in the XML.- Throws:
java.io.IOException
- If an IO error occurs.
-
loadFromXML
public void loadFromXML(java.lang.String resource) throws java.io.IOException
Loads completions from an XML file. The XML should validate againstCompletionXml.dtd
.- Parameters:
resource
- A resource the current ClassLoader can get to.- Throws:
java.io.IOException
- If an IO error occurs.
-
-