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

ben pushed a commit to branch master
in repository autocomplete.

commit 56da0d286b22b459abc9083004625ea20386b6e2
Author: bobbylight <[email protected]>
Date:   Fri Jul 6 18:33:44 2012 +0000

    Added getIcon() method to the Completion interface to attempt to streamline 
icon usage in completions.  Minor warning cleanup.
---
 .../fife/ui/autocomplete/AbstractCompletion.java   |   12 +++++++++
 src/org/fife/ui/autocomplete/Completion.java       |    9 +++++++
 .../ui/autocomplete/CompletionCellRenderer.java    |   27 ++++++++++++++++----
 src/org/fife/ui/autocomplete/EmptyIcon.java        |    5 ++--
 4 files changed, 46 insertions(+), 7 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AbstractCompletion.java 
b/src/org/fife/ui/autocomplete/AbstractCompletion.java
index c700e77..4a10898 100644
--- a/src/org/fife/ui/autocomplete/AbstractCompletion.java
+++ b/src/org/fife/ui/autocomplete/AbstractCompletion.java
@@ -8,6 +8,7 @@
  */
 package org.fife.ui.autocomplete;
 
+import javax.swing.Icon;
 import javax.swing.text.JTextComponent;
 
 
@@ -77,6 +78,17 @@ public abstract class AbstractCompletion implements 
Completion {
 
 
        /**
+        * The default implementation returns <code>null</code>.  Subclasses
+        * who wish to display an icon can override this method.
+        *
+        * @return The icon for this completion.
+        */
+       public Icon getIcon() {
+               return null;
+       }
+
+
+       /**
         * Returns the text the user has to (start) typing for this completion
         * to be offered.  The default implementation simply returns
         * {@link #getReplacementText()}.
diff --git a/src/org/fife/ui/autocomplete/Completion.java 
b/src/org/fife/ui/autocomplete/Completion.java
index a484cfa..dc65995 100644
--- a/src/org/fife/ui/autocomplete/Completion.java
+++ b/src/org/fife/ui/autocomplete/Completion.java
@@ -8,6 +8,7 @@
  */
 package org.fife.ui.autocomplete;
 
+import javax.swing.Icon;
 import javax.swing.text.JTextComponent;
 
 
@@ -62,6 +63,14 @@ public interface Completion extends Comparable {
 
 
        /**
+        * Returns the icon to use for this completion.
+        *
+        * @return The icon, or <code>null</code> for none.
+        */
+       public Icon getIcon();
+
+
+       /**
         * Returns the text that the user has to (start) typing for this 
completion
         * to be offered.  Note that this will usually be the same value as
         * {@link #getReplacementText()}, but not always (a completion could be
diff --git a/src/org/fife/ui/autocomplete/CompletionCellRenderer.java 
b/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
index e3e259f..d67de22 100644
--- a/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
+++ b/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
@@ -15,6 +15,7 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import javax.swing.DefaultListCellRenderer;
+import javax.swing.Icon;
 import javax.swing.JList;
 import javax.swing.plaf.basic.BasicHTML;
 import javax.swing.text.View;
@@ -132,24 +133,26 @@ public class CompletionCellRenderer extends 
DefaultListCellRenderer {
                this.selected = selected;
                this.realBG = altBG!=null && (index&1)==0 ? altBG : 
list.getBackground();
 
-               if (value instanceof FunctionCompletion) {
+               Completion c = (Completion)value;
+               setIcon(c.getIcon());
+
+               if (c instanceof FunctionCompletion) {
                        FunctionCompletion fc = (FunctionCompletion)value;
                        prepareForFunctionCompletion(list, fc, index, selected, 
hasFocus);
                }
-               else if (value instanceof VariableCompletion) {
+               else if (c instanceof VariableCompletion) {
                        VariableCompletion vc = (VariableCompletion)value;
                        prepareForVariableCompletion(list, vc, index, selected, 
hasFocus);
                }
-               else if (value instanceof TemplateCompletion) {
+               else if (c instanceof TemplateCompletion) {
                        TemplateCompletion tc = (TemplateCompletion)value;
                        prepareForTemplateCompletion(list, tc, index, selected, 
hasFocus);
                }
-               else if (value instanceof MarkupTagCompletion) {
+               else if (c instanceof MarkupTagCompletion) {
                        MarkupTagCompletion mtc = (MarkupTagCompletion)value;
                        prepareForMarkupTagCompletion(list, mtc, index, 
selected, hasFocus);
                }
                else {
-                       Completion c = (Completion)value;
                        prepareForOtherCompletion(list, c, index, selected, 
hasFocus);
                }
 
@@ -416,6 +419,20 @@ public class CompletionCellRenderer extends 
DefaultListCellRenderer {
 
 
        /**
+        * Sets the icon to display based off of a completion, falling back to a
+        * default icon if the completion has no icon.
+        *
+        * @param completion The completion to check.
+        * @param defaultIcon The icon to use if <code>completion</code> does 
not
+        *        specify an icon.
+        */
+       protected void setIconWithDefault(Completion completion, Icon 
defaultIcon) {
+               Icon icon = completion.getIcon();
+               setIcon(icon!=null ? icon : defaultIcon);
+       }
+
+
+       /**
         * Sets whether the types of fields and return types of methods are
         * shown in the completion text.
         *
diff --git a/src/org/fife/ui/autocomplete/EmptyIcon.java 
b/src/org/fife/ui/autocomplete/EmptyIcon.java
index fceb4d4..32a2a25 100644
--- a/src/org/fife/ui/autocomplete/EmptyIcon.java
+++ b/src/org/fife/ui/autocomplete/EmptyIcon.java
@@ -15,8 +15,9 @@ import javax.swing.Icon;
 
 
 /**
- * A standard icon that doesn't paint anything.  This can be used to take
- * up an icon's space when no icon is specified.
+ * A standard icon that doesn't paint anything.  This can be used when some
+ * <code>Completion</code>s have icons and others don't, to visually align the
+ * text of all completions.
  *
  * @author Robert Futrell
  * @version 1.0

-- 
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