4
* AbstractCompletion.java - Base class for possible completions.
6
* This library is distributed under a modified BSD license. See the included
7
* RSyntaxTextArea.License.txt file for details.
9
package org.fife.ui.autocomplete;
11
import javax.swing.Icon;
12
import javax.swing.text.JTextComponent;
16
* Base class for possible completions. Most, if not all, {@link Completion}
17
* implementations can extend this class. It remembers the
18
* <tt>CompletionProvider</tt> that returns this completion, and also implements
19
* <tt>Comparable</tt>, allowing such completions to be compared
20
* lexicographically (ignoring case).<p>
22
* This implementation assumes the input text and replacement text are the
23
* same value. It also returns the input text from its {@link #toString()}
24
* method (which is what <code>DefaultListCellRenderer</code> uses to render
25
* objects). Subclasses that wish to override any of this behavior can simply
26
* override the corresponding method(s) needed to do so.
28
* @author Robert Futrell
31
public abstract class AbstractCompletion implements Completion {
34
* The provider that created this completion;
36
private CompletionProvider provider;
39
* The relevance of this completion. Completion instances with higher
40
* "relevance" values are inserted higher into the list of possible
41
* completions than those with lower values. Completion instances with
42
* equal relevance values are sorted alphabetically.
44
private int relevance;
50
* @param provider The provider that created this completion.
52
public AbstractCompletion(CompletionProvider provider) {
53
this.provider = provider;
60
public int compareTo(Completion c2) {
65
return toString().compareToIgnoreCase(c2.toString());
74
public String getAlreadyEntered(JTextComponent comp) {
75
return provider.getAlreadyEnteredText(comp);
80
* The default implementation returns <code>null</code>. Subclasses
81
* who wish to display an icon can override this method.
83
* @return The icon for this completion.
85
public Icon getIcon() {
91
* Returns the text the user has to (start) typing for this completion
92
* to be offered. The default implementation simply returns
93
* {@link #getReplacementText()}.
95
* @return The text the user has to (start) typing for this completion.
96
* @see #getReplacementText()
98
public String getInputText() {
99
return getReplacementText();
106
public CompletionProvider getProvider() {
114
public int getRelevance() {
120
* The default implementation returns <code>null</code>. Subclasses
121
* can override this method.
123
* @return The tool tip text.
125
public String getToolTipText() {
131
* Sets the relevance of this completion.
133
* @param relevance The new relevance of this completion.
134
* @see #getRelevance()
136
public void setRelevance(int relevance) {
137
this.relevance = relevance;
142
* Returns a string representation of this completion. The default
143
* implementation returns {@link #getInputText()}.
145
* @return A string representation of this completion.
148
public String toString() {
149
return getInputText();
b'\\ No newline at end of file'