[autocomplete] 33/143: Tidying of completion renderers for C, HTML, PHP. Miscellaneous tweaks under the hood.
Benjamin Mesing
ben at alioth.debian.org
Sat Oct 19 12:53:13 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 28e1929b1aff2fb17a4f0a903b524cfda581d40b
Author: bobbylight <robert at fifesoft.com>
Date: Thu Apr 29 12:39:01 2010 +0000
Tidying of completion renderers for C, HTML, PHP.
Miscellaneous tweaks under the hood.
---
.../ui/autocomplete/CompletionCellRenderer.java | 110 ++++++++++++++++++--
.../fife/ui/autocomplete/CompletionXMLParser.java | 13 +++
.../fife/ui/autocomplete/FunctionCompletion.java | 4 +-
.../fife/ui/autocomplete/VariableCompletion.java | 5 +-
4 files changed, 121 insertions(+), 11 deletions(-)
diff --git a/src/org/fife/ui/autocomplete/CompletionCellRenderer.java b/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
index fa255f6..0ed3bc8 100644
--- a/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
+++ b/src/org/fife/ui/autocomplete/CompletionCellRenderer.java
@@ -26,8 +26,13 @@ package org.fife.ui.autocomplete;
import java.awt.Color;
import java.awt.Component;
import java.awt.Font;
+import java.awt.Graphics;
+import java.awt.Rectangle;
+
import javax.swing.DefaultListCellRenderer;
import javax.swing.JList;
+import javax.swing.plaf.basic.BasicHTML;
+import javax.swing.text.View;
/**
@@ -60,6 +65,16 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
private Font font;
/**
+ * Whether to display the types of fields and return types of functions
+ * in the completion text.
+ */
+ private boolean showTypes;
+
+private boolean selected;
+private Color realBG;
+private Rectangle paintTextR;
+
+ /**
* Keeps the HTML descriptions from "wrapping" in the list, which cuts off
* words.
*/
@@ -71,7 +86,9 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
*/
public CompletionCellRenderer() {
//setDisplayFont(new Font("Monospaced", Font.PLAIN, 12));
- //setAlternateBackground(new Color(0xf4f4f4));
+ setAlternateBackground(new Color(0xf4f4f4));
+ setShowTypes(true);
+ paintTextR = new Rectangle();
}
@@ -115,6 +132,8 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
if (font!=null) {
setFont(font); // Overrides super's setFont(list.getFont()).
}
+this.selected = selected;
+this.realBG = altBG!=null && (index&1)==0 ? altBG : list.getBackground();
if (value instanceof FunctionCompletion) {
FunctionCompletion fc = (FunctionCompletion)value;
@@ -143,6 +162,64 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
/**
+ * Returns whether the types of fields and return types of methods are
+ * shown in the completion text.
+ *
+ * @return Whether to show the types.
+ * @see #setShowTypes(boolean)
+ */
+ public boolean getShowTypes() {
+ return showTypes;
+ }
+
+
+ protected void paintComponent(Graphics g) {
+
+ //super.paintComponent(g);
+
+ g.setColor(realBG);
+ int iconW = 0;
+ if (getIcon()!=null) {
+ iconW = getIcon().getIconWidth();
+ }
+ if (selected && iconW>0) { // The icon area is never in the "selection"
+ g.fillRect(0, 0, iconW, getHeight());
+ g.setColor(getBackground());
+ g.fillRect(iconW,0, getWidth()-iconW,getHeight());
+ }
+ else {
+ g.setColor(getBackground());
+ g.fillRect(0, 0, getWidth(), getHeight());
+ }
+ if (getIcon()!=null) {
+ getIcon().paintIcon(this, g, 0, 0);
+ }
+
+ String text = getText();
+ if (text != null) {
+ paintTextR.setBounds(iconW,0, getWidth()-iconW,getHeight());
+ paintTextR.x += 3; // Force a slight margin
+ int space = paintTextR.height - g.getFontMetrics().getHeight();
+ View v = (View)getClientProperty(BasicHTML.propertyKey);
+ if (v != null) {
+ // HTML rendering doesn't auto-center vertically, for some
+ // reason
+ paintTextR.y += space/2;
+ paintTextR.height -= space;
+ v.paint(g, paintTextR);
+ }
+ else {
+ int textX = paintTextR.x;
+ int textY = paintTextR.y;// + g.getFontMetrics().getAscent();
+ System.out.println(g.getFontMetrics().getAscent());
+ g.drawString(text, textX, textY);
+ }
+ }
+
+ }
+
+
+ /**
* Prepares this renderer to display a function completion.
*
* @param list The list of choices being rendered.
@@ -183,13 +260,16 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
}
sb.append(fc.getProvider().getParameterListEnd());
- sb.append(" : ");
- if (!selected) {
- sb.append("<font color='#808080'>");
- }
- sb.append(fc.getType());
- if (!selected) {
- sb.append("</font>");
+
+ if (getShowTypes() && fc.getType()!=null) {
+ sb.append(" : ");
+ if (!selected) {
+ sb.append("<font color='#808080'>");
+ }
+ sb.append(fc.getType());
+ if (!selected) {
+ sb.append("</font>");
+ }
}
setText(sb.toString());
@@ -253,7 +333,7 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
StringBuffer sb = new StringBuffer(PREFIX);
sb.append(vc.getName());
- if (vc.getType()!=null) {
+ if (getShowTypes() && vc.getType()!=null) {
sb.append(" : ");
if (!selected) {
sb.append("<font color='#808080'>");
@@ -294,4 +374,16 @@ public class CompletionCellRenderer extends DefaultListCellRenderer {
}
+ /**
+ * Sets whether the types of fields and return types of methods are
+ * shown in the completion text.
+ *
+ * @param show Whether to show the types.
+ * @see #getShowTypes()
+ */
+ public void setShowTypes(boolean show) {
+ this.showTypes = show;
+ }
+
+
}
\ No newline at end of file
diff --git a/src/org/fife/ui/autocomplete/CompletionXMLParser.java b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
index abca3f0..226d4da 100644
--- a/src/org/fife/ui/autocomplete/CompletionXMLParser.java
+++ b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
@@ -151,6 +151,16 @@ public class CompletionXMLParser extends DefaultHandler {
}
+ private BasicCompletion createOtherCompletion() {
+ BasicCompletion bc = new BasicCompletion(provider, name);
+ if (desc.length()>0) {
+ bc.setSummary(desc.toString());
+ desc.setLength(0);
+ }
+ return bc;
+ }
+
+
private MarkupTagCompletion createMarkupTagCompletion() {
MarkupTagCompletion mc = new MarkupTagCompletion(provider,
name);
@@ -198,6 +208,9 @@ public class CompletionXMLParser extends DefaultHandler {
else if ("tag".equals(type)) { // Markup tag, such as HTML
c = createMarkupTagCompletion();
}
+ else if ("other".equals(type)) {
+ c = createOtherCompletion();
+ }
else {
throw new InternalError("Unexpected type: " + type);
}
diff --git a/src/org/fife/ui/autocomplete/FunctionCompletion.java b/src/org/fife/ui/autocomplete/FunctionCompletion.java
index ec0f376..421ac27 100644
--- a/src/org/fife/ui/autocomplete/FunctionCompletion.java
+++ b/src/org/fife/ui/autocomplete/FunctionCompletion.java
@@ -192,7 +192,9 @@ public class FunctionCompletion extends VariableCompletion
public String getSummary() {
StringBuffer sb = new StringBuffer();
addDefinitionString(sb);
- possiblyAddDescription(sb);
+ if (!possiblyAddDescription(sb)) {
+ sb.append("<br><br><br>");
+ }
addParameters(sb);
possiblyAddDefinedIn(sb);
return sb.toString();
diff --git a/src/org/fife/ui/autocomplete/VariableCompletion.java b/src/org/fife/ui/autocomplete/VariableCompletion.java
index 20c5c65..89a3e90 100644
--- a/src/org/fife/ui/autocomplete/VariableCompletion.java
+++ b/src/org/fife/ui/autocomplete/VariableCompletion.java
@@ -170,13 +170,16 @@ public class VariableCompletion extends BasicCompletion {
* defined.
*
* @param sb The buffer to append to.
+ * @return Whether there was a description to add.
*/
- protected void possiblyAddDescription(StringBuffer sb) {
+ protected boolean possiblyAddDescription(StringBuffer sb) {
if (getShortDescription()!=null) {
sb.append("<hr><br>");
sb.append(getShortDescription());
sb.append("<br><br><br>");
+ return true;
}
+ return false;
}
--
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