~ubuntu-branches/ubuntu/vivid/drmips/vivid-backports

« back to all changes in this revision

Viewing changes to src/pc/DrMIPS/src/org/fife/ui/autocomplete/AbstractCompletion.java

  • Committer: Package Import Robot
  • Author(s): Bruno Nova
  • Date: 2014-09-27 12:24:17 UTC
  • Revision ID: package-import@ubuntu.com-20140927122417-2gadkwt9k0u7j4zu
Tags: upstream-1.2.3
Import upstream version 1.2.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * 12/21/2008
 
3
 *
 
4
 * AbstractCompletion.java - Base class for possible completions.
 
5
 * 
 
6
 * This library is distributed under a modified BSD license.  See the included
 
7
 * RSyntaxTextArea.License.txt file for details.
 
8
 */
 
9
package org.fife.ui.autocomplete;
 
10
 
 
11
import javax.swing.Icon;
 
12
import javax.swing.text.JTextComponent;
 
13
 
 
14
 
 
15
/**
 
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>
 
21
 *
 
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.
 
27
 *
 
28
 * @author Robert Futrell
 
29
 * @version 1.0
 
30
 */
 
31
public abstract class AbstractCompletion implements Completion {
 
32
 
 
33
        /**
 
34
         * The provider that created this completion;
 
35
         */
 
36
        private CompletionProvider provider;
 
37
 
 
38
        /**
 
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.
 
43
         */
 
44
        private int relevance;
 
45
 
 
46
 
 
47
        /**
 
48
         * Constructor.
 
49
         *
 
50
         * @param provider The provider that created this completion.
 
51
         */
 
52
        public AbstractCompletion(CompletionProvider provider) {
 
53
                this.provider = provider;
 
54
        }
 
55
 
 
56
 
 
57
        /**
 
58
         * {@inheritDoc}
 
59
         */
 
60
        public int compareTo(Completion c2) {
 
61
                if (c2==this) {
 
62
                        return 0;
 
63
                }
 
64
                else if (c2!=null) {
 
65
                        return toString().compareToIgnoreCase(c2.toString());
 
66
                }
 
67
                return -1;
 
68
        }
 
69
 
 
70
 
 
71
        /**
 
72
         * {@inheritDoc}
 
73
         */
 
74
        public String getAlreadyEntered(JTextComponent comp) {
 
75
                return provider.getAlreadyEnteredText(comp);
 
76
        }
 
77
 
 
78
 
 
79
        /**
 
80
         * The default implementation returns <code>null</code>.  Subclasses
 
81
         * who wish to display an icon can override this method.
 
82
         *
 
83
         * @return The icon for this completion.
 
84
         */
 
85
        public Icon getIcon() {
 
86
                return null;
 
87
        }
 
88
 
 
89
 
 
90
        /**
 
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()}.
 
94
         *
 
95
         * @return The text the user has to (start) typing for this completion.
 
96
         * @see #getReplacementText()
 
97
         */
 
98
        public String getInputText() {
 
99
                return getReplacementText();
 
100
        }
 
101
 
 
102
 
 
103
        /**
 
104
         * {@inheritDoc}
 
105
         */
 
106
        public CompletionProvider getProvider() {
 
107
                return provider;
 
108
        }
 
109
 
 
110
 
 
111
        /**
 
112
         * {@inheritDoc}
 
113
         */
 
114
        public int getRelevance() {
 
115
                return relevance;
 
116
        }
 
117
 
 
118
 
 
119
        /**
 
120
         * The default implementation returns <code>null</code>.  Subclasses
 
121
         * can override this method.
 
122
         *
 
123
         * @return The tool tip text.
 
124
         */
 
125
        public String getToolTipText() {
 
126
                return null;
 
127
        }
 
128
 
 
129
 
 
130
        /**
 
131
         * Sets the relevance of this completion.
 
132
         *
 
133
         * @param relevance The new relevance of this completion.
 
134
         * @see #getRelevance()
 
135
         */
 
136
        public void setRelevance(int relevance) {
 
137
                this.relevance = relevance;
 
138
        }
 
139
 
 
140
 
 
141
        /**
 
142
         * Returns a string representation of this completion.  The default
 
143
         * implementation returns {@link #getInputText()}.
 
144
         *
 
145
         * @return A string representation of this completion.
 
146
         */
 
147
        @Override
 
148
        public String toString() {
 
149
                return getInputText();
 
150
        }
 
151
 
 
152
 
 
153
}
 
 
b'\\ No newline at end of file'