[autocomplete] 61/143: Parameter choice completions sorted by relevance. ParameterizedCompletion.Parameter can now take an arbitrary Object "type", so language supports can provide more data than just a string representation of the type. JavaLanguageSupport: Tweaked relevance values of the various completions. JavaLanguageSupport: Modified parameter choice completion renderer to look like standard Java completion renderer.
Benjamin Mesing
ben at alioth.debian.org
Sat Oct 19 12:53:18 UTC 2013
This is an automated email from the git hooks/post-receive script.
ben pushed a commit to branch master
in repository autocomplete.
commit d27dd1fa5581e333c5c768a091351e065d5dced6
Author: bobbylight <robert at fifesoft.com>
Date: Sat Dec 18 16:18:45 2010 +0000
Parameter choice completions sorted by relevance.
ParameterizedCompletion.Parameter can now take an arbitrary Object "type", so language supports can provide more data than just a string representation of the type.
JavaLanguageSupport: Tweaked relevance values of the various completions.
JavaLanguageSupport: Modified parameter choice completion renderer to look like standard Java completion renderer.
---
.../ui/autocomplete/CompletionProviderBase.java | 18 -------
.../ui/autocomplete/ParameterizedCompletion.java | 29 +++++++++++-
.../ParameterizedCompletionChoicesWindow.java | 27 +++++++++--
.../ui/autocomplete/SortByRelevanceComparator.java | 49 ++++++++++++++++++++
4 files changed, 99 insertions(+), 24 deletions(-)
diff --git a/src/org/fife/ui/autocomplete/CompletionProviderBase.java b/src/org/fife/ui/autocomplete/CompletionProviderBase.java
index dd861f8..e98117a 100644
--- a/src/org/fife/ui/autocomplete/CompletionProviderBase.java
+++ b/src/org/fife/ui/autocomplete/CompletionProviderBase.java
@@ -272,22 +272,4 @@ 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
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletion.java b/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
index 05ccc41..0f776c8 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletion.java
@@ -48,10 +48,21 @@ public interface ParameterizedCompletion extends Completion {
public static class Parameter {
private String name;
- private String type;
+ private Object type;
private String desc;
- public Parameter(String type, String name) {
+ /**
+ * Constructor.
+ *
+ * @param type The type of this parameter. This may be
+ * <code>null</code> for languages without specific types,
+ * dynamic typing, etc. Usually you'll pass a String for this
+ * value, but you may pass any object representing a type in
+ * your language, as long as its <code>toString()</code> method
+ * returns a string representation of the type.
+ * @param name The name of the parameter.
+ */
+ public Parameter(Object type, String name) {
this.name = name;
this.type = type;
}
@@ -64,7 +75,21 @@ public interface ParameterizedCompletion extends Completion {
return name;
}
+ /**
+ * Returns the type of this parameter, as a string.
+ *
+ * @return The type of the parameter, or <code>null</code> for none.
+ */
public String getType() {
+ return type==null ? null : type.toString();
+ }
+
+ /**
+ * Returns the object used to describe the type of this parameter.
+ *
+ * @return The type object, or <code>null</code> for none.
+ */
+ public Object getTypeObject() {
return type;
}
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java
index e9aba1c..34e89ed 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java
@@ -27,6 +27,8 @@ import java.awt.ComponentOrientation;
import java.awt.Rectangle;
import java.awt.Window;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Iterator;
import java.util.List;
@@ -70,6 +72,13 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
*/
private List choicesListList;
+ /**
+ * Comparator used to sort completions by their relevance before sorting
+ * them lexicographically.
+ */
+ private static final Comparator sortByRelevanceComparator =
+ new SortByRelevanceComparator();
+
/**
* Constructor.
@@ -207,6 +216,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
public void setParameter(int param, String prefix) {
model.clear();
+ List temp = new ArrayList();
if (choicesListList!=null && param>=0 && param<choicesListList.size()) {
@@ -214,15 +224,24 @@ public class ParameterizedCompletionChoicesWindow extends JWindow {
for (Iterator i=choices.iterator(); i.hasNext(); ) {
Completion c = (Completion)i.next();
String choice = c.getReplacementText();
- if (prefix==null ||
- Util.startsWithIgnoreCase(choice, prefix)) {
- model.addElement(c);
+ if (prefix==null || Util.startsWithIgnoreCase(choice, prefix)) {
+ temp.add(c);
}
}
+ // Sort completions appropriately.
+ Comparator c = null;
+ if (/*sortByRelevance*/true) {
+ c = sortByRelevanceComparator;
+ }
+ Collections.sort(temp, c);
+ for (int i=0; i<temp.size(); i++) {
+ model.addElement(temp.get(i));
+ }
+
int visibleRowCount = Math.min(model.size(), 10);
list.setVisibleRowCount(visibleRowCount);
-//list.setPreferredSize(list.getPreferredScrollableViewportSize());
+
// Toggle visibility, if necessary.
if (visibleRowCount==0 && isVisible()) {
setVisible(false);
diff --git a/src/org/fife/ui/autocomplete/SortByRelevanceComparator.java b/src/org/fife/ui/autocomplete/SortByRelevanceComparator.java
new file mode 100644
index 0000000..82039bb
--- /dev/null
+++ b/src/org/fife/ui/autocomplete/SortByRelevanceComparator.java
@@ -0,0 +1,49 @@
+/*
+ * 12/17/2010
+ *
+ * SortByRelevanceComparator.java - Sorts two Completions by relevance before
+ * sorting them lexicographically.
+ * Copyright (C) 2020 Robert Futrell
+ * robert_futrell at users.sourceforge.net
+ * http://fifesoft.com/rsyntaxtextarea
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
+ */
+package org.fife.ui.autocomplete;
+
+import java.util.Comparator;
+
+
+/**
+ * Compares two <code>Completion</code>s by their relevance before
+ * sorting them lexicographically.
+ *
+ * @author Robert Futrell
+ * @version 1.0
+ */
+public 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
More information about the pkg-java-commits
mailing list