Package org.fife.ui.autocomplete
Class AbstractCompletion
- java.lang.Object
-
- org.fife.ui.autocomplete.AbstractCompletion
-
- All Implemented Interfaces:
java.lang.Comparable<Completion>,Completion
- Direct Known Subclasses:
BasicCompletion,MarkupTagCompletion,TemplateCompletion
public abstract class AbstractCompletion extends java.lang.Object implements Completion
Base class for possible completions. Most, if not all,Completionimplementations can extend this class. It remembers theCompletionProviderthat returns this completion, and also implementsComparable, allowing such completions to be compared lexicographically (ignoring case).This implementation assumes the input text and replacement text are the same value. It also returns the input text from its
toString()method (which is whatDefaultListCellRendereruses to render objects). Subclasses that wish to override any of this behavior can simply override the corresponding method(s) needed to do so.- Version:
- 1.0
-
-
Field Summary
Fields Modifier and Type Field Description private javax.swing.IconiconThe icon to use for this completion.private CompletionProviderproviderThe provider that created this completion.private intrelevanceThe relevance of this completion.
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractCompletion(CompletionProvider provider)Constructor.protectedAbstractCompletion(CompletionProvider provider, javax.swing.Icon icon)Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intcompareTo(Completion c2)Compares this completion to another one lexicographically, ignoring case.java.lang.StringgetAlreadyEntered(javax.swing.text.JTextComponent comp)Returns the portion of this completion that has already been entered into the text component.javax.swing.IcongetIcon()Returns the icon to use for this completion.java.lang.StringgetInputText()Returns the text the user has to (start) typing for this completion to be offered.CompletionProvidergetProvider()Returns the provider that returned this completion.intgetRelevance()Returns the "relevance" of this completion.java.lang.StringgetToolTipText()The default implementation returnsnull.voidsetIcon(javax.swing.Icon icon)Sets the icon to use for this completion.voidsetRelevance(int relevance)Sets the relevance of this completion.java.lang.StringtoString()Returns a string representation of this completion.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.fife.ui.autocomplete.Completion
getReplacementText, getSummary
-
-
-
-
Field Detail
-
provider
private final CompletionProvider provider
The provider that created this completion.
-
icon
private javax.swing.Icon icon
The icon to use for this completion.
-
relevance
private int relevance
The relevance of this completion. Completion instances with higher "relevance" values are inserted higher into the list of possible completions than those with lower values. Completion instances with equal relevance values are sorted alphabetically.
-
-
Constructor Detail
-
AbstractCompletion
protected AbstractCompletion(CompletionProvider provider)
Constructor.- Parameters:
provider- The provider that created this completion.
-
AbstractCompletion
protected AbstractCompletion(CompletionProvider provider, javax.swing.Icon icon)
Constructor.- Parameters:
provider- The provider that created this completion.icon- The icon for this completion.
-
-
Method Detail
-
compareTo
public int compareTo(Completion c2)
Description copied from interface:CompletionCompares this completion to another one lexicographically, ignoring case.- Specified by:
compareToin interfacejava.lang.Comparable<Completion>- Specified by:
compareToin interfaceCompletion- Parameters:
c2- Another completion instance.- Returns:
- How this completion compares to the other one.
-
getAlreadyEntered
public java.lang.String getAlreadyEntered(javax.swing.text.JTextComponent comp)
Description copied from interface:CompletionReturns the portion of this completion that has already been entered into the text component. The match is case-insensitive.This is a convenience method for:
getProvider().getAlreadyEnteredText(comp).- Specified by:
getAlreadyEnteredin interfaceCompletion- Parameters:
comp- The text component.- Returns:
- The already-entered portion of this completion.
-
getIcon
public javax.swing.Icon getIcon()
Description copied from interface:CompletionReturns the icon to use for this completion.- Specified by:
getIconin interfaceCompletion- Returns:
- The icon, or
nullfor none.
-
getInputText
public java.lang.String getInputText()
Returns the text the user has to (start) typing for this completion to be offered. The default implementation simply returnsCompletion.getReplacementText().- Specified by:
getInputTextin interfaceCompletion- Returns:
- The text the user has to (start) typing for this completion.
- See Also:
Completion.getReplacementText()
-
getProvider
public CompletionProvider getProvider()
Description copied from interface:CompletionReturns the provider that returned this completion.- Specified by:
getProviderin interfaceCompletion- Returns:
- The provider.
-
getRelevance
public int getRelevance()
Description copied from interface:CompletionReturns the "relevance" of this completion. This is used when sorting completions by their relevance. It is an abstract concept that may mean different things to different languages, and may depend on the context of the completion.By default, all completions have a relevance of
0. The higher the value returned by this method, the higher up in the list this completion will be; the lower the value returned, the lower it will be.Completions with equal relevance values will be sorted alphabetically.- Specified by:
getRelevancein interfaceCompletion- Returns:
- The relevance of this completion.
-
getToolTipText
public java.lang.String getToolTipText()
The default implementation returnsnull. Subclasses can override this method.- Specified by:
getToolTipTextin interfaceCompletion- Returns:
- The tool tip text.
-
setIcon
public void setIcon(javax.swing.Icon icon)
Sets the icon to use for this completion.- Parameters:
icon- The icon to use.- See Also:
getIcon()
-
setRelevance
public void setRelevance(int relevance)
Sets the relevance of this completion.- Parameters:
relevance- The new relevance of this completion.- See Also:
getRelevance()
-
toString
public java.lang.String toString()
Returns a string representation of this completion. The default implementation returnsgetInputText().- Overrides:
toStringin classjava.lang.Object- Returns:
- A string representation of this completion.
-
-