This is an automated email from the git hooks/post-receive script.

ben pushed a commit to branch master
in repository autocomplete.

commit 5eeec487dc2f843169bebb4dabc771713454e7d9
Author: bobbylight <[email protected]>
Date:   Sat Dec 11 19:38:11 2010 +0000

    Completion choices are now grouped by relevance, not just sorted 
lexicographically.
---
 .../fife/ui/autocomplete/AbstractCompletion.java   |   35 +++++++++++++++----
 .../ui/autocomplete/AutoCompletePopupWindow.java   |    1 +
 src/org/fife/ui/autocomplete/AutoCompletion.java   |    6 ++--
 src/org/fife/ui/autocomplete/Completion.java       |   29 +++++++++++++++-
 .../ui/autocomplete/CompletionProviderBase.java    |   36 ++++++++++++++++++++
 5 files changed, 98 insertions(+), 9 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AbstractCompletion.java 
b/src/org/fife/ui/autocomplete/AbstractCompletion.java
index 7a9d36c..b657025 100644
--- a/src/org/fife/ui/autocomplete/AbstractCompletion.java
+++ b/src/org/fife/ui/autocomplete/AbstractCompletion.java
@@ -41,13 +41,21 @@ import javax.swing.text.JTextComponent;
  * @author Robert Futrell
  * @version 1.0
  */
-public abstract class AbstractCompletion implements Completion, Comparable {
+public abstract class AbstractCompletion implements Completion {
 
        /**
         * The provider that created this completion;
         */
        private CompletionProvider provider;
 
+       /**
+        * 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.
@@ -60,11 +68,7 @@ public abstract class AbstractCompletion implements 
Completion, Comparable {
 
 
        /**
-        * Compares this completion to another one lexicographically, ignoring
-        * case.
-        *
-        * @param o Another completion instance.
-        * @return How this completion compares to the other one.
+        * {@inheritDoc}
         */
        public int compareTo(Object o) {
                if (o==this) {
@@ -108,6 +112,14 @@ public abstract class AbstractCompletion implements 
Completion, Comparable {
 
 
        /**
+        * {@inheritDoc}
+        */
+       public int getRelevance() {
+               return relevance;
+       }
+
+
+       /**
         * The default implementation returns <code>null</code>.  Subclasses
         * can override this method.
         *
@@ -119,6 +131,17 @@ public abstract class AbstractCompletion implements 
Completion, Comparable {
 
 
        /**
+        * 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()}.
         *
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java 
b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index daa2a7c..68a0952 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -760,6 +760,7 @@ class AutoCompletePopupWindow extends JWindow implements 
CaretListener,
 
        }
 
+
        /**
         * Updates the <tt>LookAndFeel</tt> of this window and the description
         * window.
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java 
b/src/org/fife/ui/autocomplete/AutoCompletion.java
index 0017db8..61ddba0 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -482,9 +482,11 @@ public class AutoCompletion {
 
 
        /**
-        * Hides the parameter tool tip, if it is visible.
+        * Hides the parameter tool tip and/or the parameter choices window, if
+        * either one is visible.
         *
-        * @return Whether the tool tip window was visible.
+        * @return Whether either of the two windows were visible (and thus
+        *         hidden).
         */
        private boolean hideToolTipWindow() {
                if (descToolTip!=null) {
diff --git a/src/org/fife/ui/autocomplete/Completion.java 
b/src/org/fife/ui/autocomplete/Completion.java
index a5b9eb8..924dc80 100644
--- a/src/org/fife/ui/autocomplete/Completion.java
+++ b/src/org/fife/ui/autocomplete/Completion.java
@@ -49,7 +49,17 @@ import javax.swing.text.JTextComponent;
  * @version 1.0
  * @see AbstractCompletion
  */
-public interface Completion {
+public interface Completion extends Comparable {
+
+
+       /**
+        * Compares this completion to another one lexicographically, ignoring
+        * case.
+        *
+        * @param o Another completion instance.
+        * @return How this completion compares to the other one.
+        */
+       public int compareTo(Object o);
 
 
        /**
@@ -88,6 +98,23 @@ public interface Completion {
 
 
        /**
+        * Returns 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.<p>
+        *
+        * By default, all completions have a relevance of <code>0</code>.  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.  <code>Completion</code>s with equal relevance values will be
+        * sorted alphabetically.
+        *
+        * @return The relevance of this completion.
+        */
+       public int getRelevance();
+
+
+       /**
         * Returns the text to insert as the result of this auto-completion.  
This
         * is the "complete" text, including any text that replaces what the 
user
         * has already typed.
diff --git a/src/org/fife/ui/autocomplete/CompletionProviderBase.java 
b/src/org/fife/ui/autocomplete/CompletionProviderBase.java
index 9275755..7a8bcc7 100644
--- a/src/org/fife/ui/autocomplete/CompletionProviderBase.java
+++ b/src/org/fife/ui/autocomplete/CompletionProviderBase.java
@@ -23,6 +23,7 @@
 package org.fife.ui.autocomplete;
 
 import java.util.Collections;
+import java.util.Comparator;
 import java.util.List;
 import javax.swing.ListCellRenderer;
 import javax.swing.text.BadLocationException;
@@ -85,6 +86,13 @@ public abstract class CompletionProviderBase implements 
CompletionProvider {
 
        protected static final String EMPTY_STRING = "";
 
+       /**
+        * Comparator used to sort completions by their relevance before sorting
+        * them lexicographically.
+        */
+       private static final Comparator sortByRelevanceComparator =
+                                                               new 
SortByRelevanceComparator();
+
 
        /**
         * {@inheritDoc}
@@ -99,12 +107,22 @@ public abstract class CompletionProviderBase implements 
CompletionProvider {
         * {@inheritDoc}
         */
        public List getCompletions(JTextComponent comp) {
+
                List completions = getCompletionsImpl(comp);
                if (parent!=null) {
                        completions.addAll(parent.getCompletions(comp));
                        Collections.sort(completions);
                }
+
+               // NOTE: We can't sort by relevance prior to this; we need to 
have
+               // things alphabetical so we can easily narrow down completions 
to
+               // those starting with what was already typed.
+               if (/*sortByRelevance*/true) {
+                       Collections.sort(completions, 
sortByRelevanceComparator);
+               }
+
                return completions;
+
        }
 
 
@@ -226,4 +244,22 @@ public abstract class CompletionProviderBase implements 
CompletionProvider {
        }
 
 
+       /**
+        * Compares two <code>Completion</code>s by their relevance before
+        * sorting them lexicographically.
+        */
+       public static class SortByRelevanceComparator implements Comparator {
+
+               public int compare(Object o1, Object o2) {
+                       Completion c1 = (Completion)o1;
+                       Completion c2 = (Completion)o2;
+                       int rel1 = c1.getRelevance();
+                       int rel2 = c2.getRelevance();
+                       int diff = rel2 - rel1;//rel1 - rel2;
+                       return diff==0 ? c1.compareTo(c2) : diff;
+               }
+
+       }
+
+
 }
\ No newline at end of file

-- 
Alioth's /usr/local/bin/git-commit-notice on 
/srv/git.debian.org/git/pkg-java/autocomplete.git

_______________________________________________
pkg-java-commits mailing list
[email protected]
http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

Reply via email to