-
Notifications
You must be signed in to change notification settings - Fork 61
Expand file tree
/
Copy pathAbstractCompletion.java
More file actions
178 lines (146 loc) · 3.93 KB
/
AbstractCompletion.java
File metadata and controls
178 lines (146 loc) · 3.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
* 12/21/2008
*
* AbstractCompletion.java - Base class for possible completions.
*
* This library is distributed under a modified BSD license. See the included
* RSyntaxTextArea.License.txt file for details.
*/
package org.fife.ui.autocomplete;
import javax.swing.Icon;
import javax.swing.text.JTextComponent;
/**
* Base class for possible completions. Most, if not all, {@link Completion}
* implementations can extend this class. It remembers the
* <tt>CompletionProvider</tt> that returns this completion, and also implements
* <tt>Comparable</tt>, allowing such completions to be compared
* lexicographically (ignoring case).<p>
*
* This implementation assumes the input text and replacement text are the
* same value. It also returns the input text from its {@link #toString()}
* method (which is what <code>DefaultListCellRenderer</code> uses to render
* objects). Subclasses that wish to override any of this behavior can simply
* override the corresponding method(s) needed to do so.
*
* @author Robert Futrell
* @version 1.0
*/
public abstract class AbstractCompletion implements Completion {
/**
* The provider that created this completion;
*/
private CompletionProvider provider;
/**
* The icon to use for this completion.
*/
private Icon icon;
/**
* 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.
*/
private int relevance;
/**
* Constructor.
*
* @param provider The provider that created this completion.
*/
protected AbstractCompletion(CompletionProvider provider) {
this.provider = provider;
}
/**
* Constructor.
*
* @param provider The provider that created this completion.
* @param icon The icon for this completion.
*/
protected AbstractCompletion(CompletionProvider provider, Icon icon) {
this(provider);
setIcon(icon);
}
/**
* {@inheritDoc}
*/
public int compareTo(Completion c2) {
if (c2==this) {
return 0;
}
else if (c2!=null) {
return getInputText().compareToIgnoreCase(c2.getInputText());
}
return -1;
}
/**
* {@inheritDoc}
*/
public String getAlreadyEntered(JTextComponent comp) {
return provider.getAlreadyEnteredText(comp);
}
/**
* {@inheritDoc}
*/
public Icon getIcon() {
return icon;
}
/**
* Returns the text the user has to (start) typing for this completion
* to be offered. The default implementation simply returns
* {@link #getReplacementText()}.
*
* @return The text the user has to (start) typing for this completion.
* @see #getReplacementText()
*/
public String getInputText() {
return getReplacementText();
}
/**
* {@inheritDoc}
*/
public CompletionProvider getProvider() {
return provider;
}
/**
* {@inheritDoc}
*/
public int getRelevance() {
return relevance;
}
/**
* The default implementation returns <code>null</code>. Subclasses
* can override this method.
*
* @return The tool tip text.
*/
public String getToolTipText() {
return null;
}
/**
* Sets the icon to use for this completion.
*
* @param icon The icon to use.
* @see #getIcon()
*/
public void setIcon(Icon icon) {
this.icon = icon;
}
/**
* Sets the relevance of this completion.
*
* @param relevance The new relevance of this completion.
* @see #getRelevance()
*/
public void setRelevance(int relevance) {
this.relevance = relevance;
}
/**
* Returns a string representation of this completion. The default
* implementation returns {@link #getInputText()}.
*
* @return A string representation of this completion.
*/
@Override
public String toString() {
return getInputText();
}
}