[autocomplete] 12/143: Making parameter completion chars editable in XML. Better formatting of param descriptions for function and markup completions. Removing debug printing to stdout. Better paren handling when in param completion mode. Demo can now run as an applet and in webstart, in addition to a standalone app. Adding license and readme file.

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:09 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 e6d4e4a44db92f3f8a3e24dfc0fffe37641a4bd4
Author: bobbylight <robert at fifesoft.com>
Date:   Sun Jan 18 00:53:59 2009 +0000

    Making parameter completion chars editable in XML.  Better formatting of param descriptions for function and markup completions.  Removing debug printing to stdout.  Better paren handling when in param completion mode.  Demo can now run as an applet and in webstart, in addition to a standalone app.  Adding license and readme file.
---
 distfiles/AutoComplete.License.txt                 |  165 ++++++++++++++++++++
 distfiles/readme.txt                               |   32 ++++
 .../autocomplete/AbstractCompletionProvider.java   |   13 +-
 .../ui/autocomplete/AutoCompleteDescWindow.java    |   19 +--
 .../ui/autocomplete/AutoCompletePopupWindow.java   |    8 +-
 src/org/fife/ui/autocomplete/AutoCompletion.java   |   34 +++-
 .../fife/ui/autocomplete/CompletionProvider.java   |    3 +
 .../fife/ui/autocomplete/CompletionXMLParser.java  |   43 +++++
 .../ui/autocomplete/DefaultCompletionProvider.java |    9 +-
 .../fife/ui/autocomplete/FunctionCompletion.java   |   15 +-
 .../fife/ui/autocomplete/MarkupTagCompletion.java  |   12 +-
 .../ui/autocomplete/OutlineHighlightPainter.java   |    3 +-
 .../ParameterizedCompletionDescriptionToolTip.java |   81 +++++++---
 src/org/fife/ui/autocomplete/SizeGrip.java         |    4 +-
 14 files changed, 385 insertions(+), 56 deletions(-)

diff --git a/distfiles/AutoComplete.License.txt b/distfiles/AutoComplete.License.txt
new file mode 100644
index 0000000..b87303c
--- /dev/null
+++ b/distfiles/AutoComplete.License.txt
@@ -0,0 +1,165 @@
+		   GNU LESSER GENERAL PUBLIC LICENSE
+                       Version 3, 29 June 2007
+
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
+ Everyone is permitted to copy and distribute verbatim copies
+ of this license document, but changing it is not allowed.
+
+
+  This version of the GNU Lesser General Public License incorporates
+the terms and conditions of version 3 of the GNU General Public
+License, supplemented by the additional permissions listed below.
+
+  0. Additional Definitions. 
+
+  As used herein, "this License" refers to version 3 of the GNU Lesser
+General Public License, and the "GNU GPL" refers to version 3 of the GNU
+General Public License.
+
+  "The Library" refers to a covered work governed by this License,
+other than an Application or a Combined Work as defined below.
+
+  An "Application" is any work that makes use of an interface provided
+by the Library, but which is not otherwise based on the Library.
+Defining a subclass of a class defined by the Library is deemed a mode
+of using an interface provided by the Library.
+
+  A "Combined Work" is a work produced by combining or linking an
+Application with the Library.  The particular version of the Library
+with which the Combined Work was made is also called the "Linked
+Version".
+
+  The "Minimal Corresponding Source" for a Combined Work means the
+Corresponding Source for the Combined Work, excluding any source code
+for portions of the Combined Work that, considered in isolation, are
+based on the Application, and not on the Linked Version.
+
+  The "Corresponding Application Code" for a Combined Work means the
+object code and/or source code for the Application, including any data
+and utility programs needed for reproducing the Combined Work from the
+Application, but excluding the System Libraries of the Combined Work.
+
+  1. Exception to Section 3 of the GNU GPL.
+
+  You may convey a covered work under sections 3 and 4 of this License
+without being bound by section 3 of the GNU GPL.
+
+  2. Conveying Modified Versions.
+
+  If you modify a copy of the Library, and, in your modifications, a
+facility refers to a function or data to be supplied by an Application
+that uses the facility (other than as an argument passed when the
+facility is invoked), then you may convey a copy of the modified
+version:
+
+   a) under this License, provided that you make a good faith effort to
+   ensure that, in the event an Application does not supply the
+   function or data, the facility still operates, and performs
+   whatever part of its purpose remains meaningful, or
+
+   b) under the GNU GPL, with none of the additional permissions of
+   this License applicable to that copy.
+
+  3. Object Code Incorporating Material from Library Header Files.
+
+  The object code form of an Application may incorporate material from
+a header file that is part of the Library.  You may convey such object
+code under terms of your choice, provided that, if the incorporated
+material is not limited to numerical parameters, data structure
+layouts and accessors, or small macros, inline functions and templates
+(ten or fewer lines in length), you do both of the following:
+
+   a) Give prominent notice with each copy of the object code that the
+   Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the object code with a copy of the GNU GPL and this license
+   document.
+
+  4. Combined Works.
+
+  You may convey a Combined Work under terms of your choice that,
+taken together, effectively do not restrict modification of the
+portions of the Library contained in the Combined Work and reverse
+engineering for debugging such modifications, if you also do each of
+the following:
+
+   a) Give prominent notice with each copy of the Combined Work that
+   the Library is used in it and that the Library and its use are
+   covered by this License.
+
+   b) Accompany the Combined Work with a copy of the GNU GPL and this license
+   document.
+
+   c) For a Combined Work that displays copyright notices during
+   execution, include the copyright notice for the Library among
+   these notices, as well as a reference directing the user to the
+   copies of the GNU GPL and this license document.
+
+   d) Do one of the following:
+
+       0) Convey the Minimal Corresponding Source under the terms of this
+       License, and the Corresponding Application Code in a form
+       suitable for, and under terms that permit, the user to
+       recombine or relink the Application with a modified version of
+       the Linked Version to produce a modified Combined Work, in the
+       manner specified by section 6 of the GNU GPL for conveying
+       Corresponding Source.
+
+       1) Use a suitable shared library mechanism for linking with the
+       Library.  A suitable mechanism is one that (a) uses at run time
+       a copy of the Library already present on the user's computer
+       system, and (b) will operate properly with a modified version
+       of the Library that is interface-compatible with the Linked
+       Version. 
+
+   e) Provide Installation Information, but only if you would otherwise
+   be required to provide such information under section 6 of the
+   GNU GPL, and only to the extent that such information is
+   necessary to install and execute a modified version of the
+   Combined Work produced by recombining or relinking the
+   Application with a modified version of the Linked Version. (If
+   you use option 4d0, the Installation Information must accompany
+   the Minimal Corresponding Source and Corresponding Application
+   Code. If you use option 4d1, you must provide the Installation
+   Information in the manner specified by section 6 of the GNU GPL
+   for conveying Corresponding Source.)
+
+  5. Combined Libraries.
+
+  You may place library facilities that are a work based on the
+Library side by side in a single library together with other library
+facilities that are not Applications and are not covered by this
+License, and convey such a combined library under terms of your
+choice, if you do both of the following:
+
+   a) Accompany the combined library with a copy of the same work based
+   on the Library, uncombined with any other library facilities,
+   conveyed under the terms of this License.
+
+   b) Give prominent notice with the combined library that part of it
+   is a work based on the Library, and explaining where to find the
+   accompanying uncombined form of the same work.
+
+  6. Revised Versions of the GNU Lesser General Public License.
+
+  The Free Software Foundation may publish revised and/or new versions
+of the GNU Lesser General Public License from time to time. Such new
+versions will be similar in spirit to the present version, but may
+differ in detail to address new problems or concerns.
+
+  Each version is given a distinguishing version number. If the
+Library as you received it specifies that a certain numbered version
+of the GNU Lesser General Public License "or any later version"
+applies to it, you have the option of following the terms and
+conditions either of that published version or of any later version
+published by the Free Software Foundation. If the Library as you
+received it does not specify a version number of the GNU Lesser
+General Public License, you may choose any version of the GNU Lesser
+General Public License ever published by the Free Software Foundation.
+
+  If the Library as you received it specifies that a proxy can decide
+whether future versions of the GNU Lesser General Public License shall
+apply, that proxy's public statement of acceptance of any version is
+permanent authorization for you to choose that version for the
+Library.
diff --git a/distfiles/readme.txt b/distfiles/readme.txt
new file mode 100644
index 0000000..a728e2d
--- /dev/null
+++ b/distfiles/readme.txt
@@ -0,0 +1,32 @@
+AutoComplete Readme
+-------------------
+
+* About AutoComplete
+
+  AutoComplete is a Swing library that facilitates adding auto-completion
+  (aka "code completion, "Intellisense") to any JTextComponent.  Special
+  integration is added for RSyntaxTextArea (a programmer's text editor, see
+  http://fifesoft.com/rsyntaxtextarea/ for more information), since this feature
+  is commonly needed when editing source code.
+
+* Example Usage
+
+  TODO
+
+* License
+
+  AutoComplete is licensed under the LGPL.  Please see the included license
+  file.
+
+* Feedback
+
+  I hope you find AutoComplete useful.  Bug reports, feature requests, and
+  just general questions are always welcome.  Ways you can submit feedback:
+
+    * http://forum.fifesoft.com (preferred)
+         Has a forum for AutoComplete and related projects, where you can
+         ask questions and get feedback quickly.
+
+    * http://fifesoft.com/autocomplete
+         Project home page, which contains general information and example
+         source code.
diff --git a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
index 2ddc480..0ece74c 100644
--- a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
@@ -74,9 +74,7 @@ public abstract class AbstractCompletionProvider
 	 */
 	public AbstractCompletionProvider() {
 		comparator = new CaseInsensitiveComparator();
-		paramListStart = '(';
-		paramListEnd = ')';
-		paramListSeparator = ", ";
+		clearParameterizedCompletionParams();
 	}
 
 
@@ -276,6 +274,15 @@ public abstract class AbstractCompletionProvider
 	 */
 	public void setParameterizedCompletionParams(char listStart,
 										String separator, char listEnd) {
+		if (listStart<0x20 || listStart==0x7F) {
+			throw new IllegalArgumentException("Invalid listStart");
+		}
+		if (listEnd<0x20 || listEnd==0x7F) {
+			throw new IllegalArgumentException("Invalid listEnd");
+		}
+		if (separator==null || separator.length()==0) {
+			throw new IllegalArgumentException("Invalid separator");
+		}
 		paramListStart = listStart;
 		paramListSeparator = separator;
 		paramListEnd = listEnd;
diff --git a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
index 1284db3..311e4e9 100644
--- a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
@@ -80,6 +80,11 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 	private JScrollPane scrollPane;
 
 	/**
+	 * The bottom panel, containing the toolbar and size grip.
+	 */
+	private JPanel bottomPanel;
+
+	/**
 	 * The toolbar with "back" and "forward" buttons.
 	 */
 	private JToolBar descWindowNavBar;
@@ -132,6 +137,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 
 		descArea = new JEditorPane("text/html", null);
 		tweakDescArea();
+		descArea.addHyperlinkListener(this);
 		scrollPane = new JScrollPane(descArea);
 		scrollPane.setViewportBorder(BorderFactory.createEmptyBorder(5,5,5,5));
 		scrollPane.setBackground(descArea.getBackground());
@@ -145,12 +151,11 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 		descWindowNavBar.add(new JButton(backAction));
 		descWindowNavBar.add(new JButton(forwardAction));
 
-		JPanel temp = new JPanel(new BorderLayout());
+		bottomPanel = new JPanel(new BorderLayout());
 		SizeGrip rp = new SizeGrip();
-		temp.add(descWindowNavBar, BorderLayout.LINE_START);
-		temp.add(rp, BorderLayout.LINE_END);
-		cp.add(temp, BorderLayout.SOUTH);
-
+		bottomPanel.add(descWindowNavBar, BorderLayout.LINE_START);
+		bottomPanel.add(rp, BorderLayout.LINE_END);
+		cp.add(bottomPanel, BorderLayout.SOUTH);
 		setContentPane(cp);
 
 		setFocusableWindowState(false);
@@ -331,7 +336,6 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 		super.setVisible(visible);
 	}
 
-
 	/**
 	 * Tweaks the description text area to look good in the current Look
 	 * and Feel.
@@ -340,7 +344,6 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 
 		// Jump through a few hoops to get things looking nice in Nimbus
 		if (UIManager.getLookAndFeel().getName().equals("Nimbus")) {
-			System.out.println("DEBUG: Creating Nimbus-specific changes");
 			Color selBG = descArea.getSelectionColor();
 			Color selFG = descArea.getSelectedTextColor();
 			descArea.setUI(new javax.swing.plaf.basic.BasicEditorPaneUI());
@@ -353,8 +356,6 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 		// Make selection visible even though we are not editable.
 		descArea.getCaret().setSelectionVisible(true);
 
-		descArea.addHyperlinkListener(this);
-
 		// Make it use "tooltip" background color.
 		descArea.setBackground(getDefaultBackground());
 
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index 100ed45..f7fda51 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -144,7 +144,7 @@ lastLine = -1;
 				doAutocomplete();
 			}
 		}
-		else if (AutoCompletion.DEBUG) {
+		else if (AutoCompletion.getDebug()) {
 			Thread.dumpStack();
 		}
 	}
@@ -234,7 +234,7 @@ lastLine = -1;
 	 */
 	private void installKeyBindings() {
 
-		if (AutoCompletion.DEBUG) {
+		if (AutoCompletion.getDebug()) {
 			System.out.println("PopupWindow: Installing keybindings");
 		}
 
@@ -247,7 +247,7 @@ lastLine = -1;
 		ActionMap am = comp.getActionMap();
 
 		replaceAction(im, am, KeyEvent.VK_ESCAPE, escapeKap, oldEscape);
-		if (AutoCompletion.DEBUG && oldEscape.action==escapeKap.action) {
+		if (AutoCompletion.getDebug() && oldEscape.action==escapeKap.action) {
 			Thread.dumpStack();
 		}
 		replaceAction(im, am, KeyEvent.VK_UP, upKap, oldUp);
@@ -520,7 +520,7 @@ lastLine = -1;
 	 */
 	public void uninstallKeyBindings() {
 
-		if (AutoCompletion.DEBUG) {
+		if (AutoCompletion.getDebug()) {
 			System.out.println("PopupWindow: Removing keybindings");
 		}
 
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java
index 9df2c65..cf9cd65 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -164,7 +164,11 @@ public class AutoCompletion implements HierarchyListener {
 	 */
 	private static final String PARAM_COMPLETE_KEY = "AutoCompletion.FunctionStart";
 
-	static final boolean DEBUG = true;
+	/**
+	 * Whether debug messages should be printed to stdout as AutoCompletion
+	 * runs.
+	 */
+	private static final boolean DEBUG = initDebug();
 
 
 	/**
@@ -259,6 +263,16 @@ public class AutoCompletion implements HierarchyListener {
 
 
 	/**
+	 * Returns whether debug is enabled for AutoCompletion.
+	 *
+	 * @return Whether debug is enabled.
+	 */
+	static boolean getDebug() {
+		return DEBUG;
+	}
+
+
+	/**
 	 * Returns the default autocomplete "trigger key" for this OS.  For
 	 * Windows, for example, it is Ctrl+Space.
 	 *
@@ -403,6 +417,24 @@ public class AutoCompletion implements HierarchyListener {
 
 
 	/**
+	 * Determines whether debug should be enabled for the AutoCompletion
+	 * library.  This method checks a system property, but takes care of
+	 * {@link SecurityException}s in case we're in an applet or WebStart.
+	 *
+	 * @return Whether debug should be enabled.
+	 */
+	private static final boolean initDebug() {
+		boolean debug = false;
+		try {
+			debug = Boolean.getBoolean("AutoCompletion.debug");
+		} catch (SecurityException se) { // We're in an applet or WebStart.
+			debug = false;
+		}
+		return debug;
+	}
+
+
+	/**
 	 * Inserts a completion.
 	 *
 	 * @param c A completion to insert.  This cannot be <code>null</code>.
diff --git a/src/org/fife/ui/autocomplete/CompletionProvider.java b/src/org/fife/ui/autocomplete/CompletionProvider.java
index cf51934..db9a9b4 100644
--- a/src/org/fife/ui/autocomplete/CompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/CompletionProvider.java
@@ -162,6 +162,9 @@ public interface CompletionProvider {
 	 *        list when one is inserted.  For example, "<tt>, </tt>".
 	 * @param listEnd The character that marks the end of a list of parameters,
 	 *        such as '<tt>)</tt>' in C or Java.
+	 * @throws IllegalArgumentException If either <tt>listStart</tt> or
+	 *         <tt>listEnd</tt> is not printable ASCII, or if
+	 *         <tt>separator</tt> is <code>null</code> or an empty string.
 	 * @see #clearParameterizedCompletionParams()
 	 */
 	public void setParameterizedCompletionParams(char listStart,
diff --git a/src/org/fife/ui/autocomplete/CompletionXMLParser.java b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
index 5d74e0b..aeb6b1f 100644
--- a/src/org/fife/ui/autocomplete/CompletionXMLParser.java
+++ b/src/org/fife/ui/autocomplete/CompletionXMLParser.java
@@ -41,6 +41,9 @@ class CompletionXMLParser extends DefaultHandler {
 	private boolean gettingParams;
 	private boolean inParam;
 	private boolean gettingParamDesc;
+	private char paramStartChar;
+	private char paramEndChar;
+	private String paramSeparator;
 
 
 	/**
@@ -56,6 +59,8 @@ class CompletionXMLParser extends DefaultHandler {
 		desc = new StringBuffer();
 		paramDesc = new StringBuffer();
 		returnValDesc = new StringBuffer();
+		paramStartChar = paramEndChar = 0;
+		paramSeparator = null;
 	}
 
 
@@ -191,6 +196,36 @@ class CompletionXMLParser extends DefaultHandler {
 
 
 	/**
+	 * Returns the parameter end character specified.
+	 *
+	 * @return The character, or 0 if none was specified.
+	 */
+	public char getParamEndChar() {
+		return paramEndChar;
+	}
+
+
+	/**
+	 * Returns the parameter end string specified.
+	 *
+	 * @return The string, or <code>null</code> if none was specified.
+	 */
+	public String getParamSeparator() {
+		return paramSeparator;
+	}
+
+
+	/**
+	 * Returns the parameter start character specified.
+	 *
+	 * @return The character, or 0 if none was specified.
+	 */
+	public char getParamStartChar() {
+		return paramStartChar;
+	}
+
+
+	/**
 	 * Resets this parser to grab more completions.
 	 *
 	 * @param provider The new provider to get completions for.
@@ -200,6 +235,8 @@ class CompletionXMLParser extends DefaultHandler {
 		completions.clear();
 		doingKeywords = inKeyword = gettingDesc = gettingParams =  inParam = 
 				gettingParamDesc = false;
+		paramStartChar = paramEndChar = 0;
+		paramSeparator = null;
 	}
 
 
@@ -244,6 +281,12 @@ class CompletionXMLParser extends DefaultHandler {
 				}
 			}
 		}
+		else if ("environment".equals(qName)) {
+			paramStartChar = attrs.getValue("paramStartChar").charAt(0);
+			paramEndChar = attrs.getValue("paramEndChar").charAt(0);
+			paramSeparator = attrs.getValue("paramSeparator");
+			//paramTerminal = attrs.getValua("terminal");
+		}
 	}
 
 
diff --git a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
index 6fe44e4..364c033 100644
--- a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java
@@ -160,7 +160,6 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
 			}
 
 			String text = new String(s.array, offs+1, end-offs);
-			System.out.println("... ... \"" + text + "\"");
 
 			// Get a list of all Completions matching the text, but then
 			// narrow it down to just the ParameterizedCompletions.
@@ -246,6 +245,14 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider {
 			saxParser.parse(bin, handler);
 			List completions =  handler.getCompletions();
 			addCompletions(completions);
+			char startChar = handler.getParamStartChar();
+			if (startChar!=0) {
+				char endChar = handler.getParamEndChar();
+				String sep = handler.getParamSeparator();
+				if (endChar!=0 && sep!=null && sep.length()>0) { // Sanity
+					setParameterizedCompletionParams(startChar, sep, endChar);
+				}
+			}
 		} catch (SAXException se) {
 			throw new IOException(se.toString());
 		} catch (ParserConfigurationException pce) {
diff --git a/src/org/fife/ui/autocomplete/FunctionCompletion.java b/src/org/fife/ui/autocomplete/FunctionCompletion.java
index 52bdd20..dd161a6 100644
--- a/src/org/fife/ui/autocomplete/FunctionCompletion.java
+++ b/src/org/fife/ui/autocomplete/FunctionCompletion.java
@@ -74,13 +74,14 @@ public class FunctionCompletion extends VariableCompletion
 	protected void addParameters(StringBuffer sb) {
 
 		// TODO: Localize me
-		// TODO: Use tables (?) to improve indentation of long descriptions
 
-		if (params!=null && params.size()>0) {
+		int paramCount = getParamCount();
+		if (paramCount>0) {
 			sb.append("<b>Parameters:</b><br>");
-			for (int i=0; i<getParamCount(); i++) {
+			sb.append("<center><table width='90%'><tr><td>");
+			for (int i=0; i<paramCount; i++) {
 				Parameter param = getParam(i);
-				sb.append("   <b>");
+				sb.append("<b>");
 				sb.append(param.getName()!=null ? param.getName() :
 							param.getType());
 				sb.append("</b> ");
@@ -90,13 +91,13 @@ public class FunctionCompletion extends VariableCompletion
 				}
 				sb.append("<br>");
 			}
-			sb.append("<br><br>");
+			sb.append("</td></tr></table></center><br><br>");
 		}
 
 		if (returnValDesc!=null) {
-			sb.append("<b>Returns:</b><br>   ");
+			sb.append("<b>Returns:</b><br><center><table width='90%'><tr><td>");
 			sb.append(returnValDesc);
-			sb.append("<br><br>");
+			sb.append("</td></tr></table></center><br><br>");
 		}
 
 	}
diff --git a/src/org/fife/ui/autocomplete/MarkupTagCompletion.java b/src/org/fife/ui/autocomplete/MarkupTagCompletion.java
index 113c970..0cdffca 100644
--- a/src/org/fife/ui/autocomplete/MarkupTagCompletion.java
+++ b/src/org/fife/ui/autocomplete/MarkupTagCompletion.java
@@ -66,9 +66,13 @@ public class MarkupTagCompletion extends AbstractCompletion {
 	 */
 	protected void addAttributes(StringBuffer sb) {
 
-		if (attrs!=null && attrs.size()>0) {
-			sb.append("<b>Attributes:</b><br>"); // TODO: Localize me
-			for (int i=0; i<getAttributeCount(); i++) {
+		// TODO: Localize me.
+
+		int attrCount = getAttributeCount();
+		if (attrCount>0) {
+			sb.append("<b>Attributes:</b><br>");
+			sb.append("<center><table width='90%'><tr><td>");
+			for (int i=0; i<attrCount; i++) {
 				Parameter attr = getAttribute(i);
 				sb.append("   <b>");
 				sb.append(attr.getName()!=null ? attr.getName() :
@@ -80,7 +84,7 @@ public class MarkupTagCompletion extends AbstractCompletion {
 				}
 				sb.append("<br>");
 			}
-			sb.append("<br><br>");
+			sb.append("</td></tr></table></center><br><br>");
 		}
 
 	}
diff --git a/src/org/fife/ui/autocomplete/OutlineHighlightPainter.java b/src/org/fife/ui/autocomplete/OutlineHighlightPainter.java
index 1e3b3ee..b9a2cb1 100644
--- a/src/org/fife/ui/autocomplete/OutlineHighlightPainter.java
+++ b/src/org/fife/ui/autocomplete/OutlineHighlightPainter.java
@@ -4,7 +4,6 @@ import java.awt.Color;
 import java.awt.Graphics;
 import java.awt.Rectangle;
 import java.awt.Shape;
-import java.io.Serializable;
 import javax.swing.text.BadLocationException;
 import javax.swing.text.DefaultHighlighter;
 import javax.swing.text.JTextComponent;
@@ -28,7 +27,7 @@ import javax.swing.text.View;
  * paint the Highlight from the 2nd char on.
  */
 class OutlineHighlightPainter extends
-			DefaultHighlighter.DefaultHighlightPainter implements Serializable {
+							DefaultHighlighter.DefaultHighlightPainter {
 
 	/**
 	 * DefaultHighlightPainter doesn't allow changing color, so we must cache
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
index 5d1d3c2..ed32d6a 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
@@ -209,7 +209,7 @@ class ParameterizedCompletionDescriptionToolTip {
 	 */
 	private void installKeyBindings() {
 
-		if (AutoCompletion.DEBUG) {
+		if (AutoCompletion.getDebug()) {
 			System.out.println("ToolTip: Installing keybindings");
 		}
 
@@ -414,8 +414,8 @@ class ParameterizedCompletionDescriptionToolTip {
 	 */
 	private void uninstallKeyBindings() {
 
-		if (AutoCompletion.DEBUG) {
-			System.out.println("PopupWindow: Installing keybindings");
+		if (AutoCompletion.getDebug()) {
+			System.out.println("ToolTip: Uninstalling keybindings");
 		}
 
 
@@ -557,43 +557,78 @@ class ParameterizedCompletionDescriptionToolTip {
 	private class ClosingAction extends AbstractAction {
 
 		public void actionPerformed(ActionEvent e) {
+
 			JTextComponent tc = ac.getTextComponent();
 			int dot = tc.getCaretPosition();
+			char end = pc.getProvider().getParameterListEnd();
+		
+			// Are they at or past the end of the parameters?
 			if (dot>=maxPos.getOffset()-1) { // ">=" for overwrite mode
+
 				if (dot==maxPos.getOffset()) { // Happens in overwrite mode
-					char ch = pc.getProvider().getParameterListEnd();
-					tc.replaceSelection(Character.toString(ch));
+					tc.replaceSelection(Character.toString(end));
 				}
-				else {
+
+				else { // Typical case.
+					// Try to decide if we're closing a paren that is a part
+					// of the (last) arg being typed.
+					String text = getArgumentText(dot);
+					if (text!=null) {
+						char start = pc.getProvider().getParameterListStart();
+						int startCount = getCount(text, start);
+						int endCount = getCount(text, end);
+						if (startCount>endCount) { // Just closing a paren
+							tc.replaceSelection(Character.toString(end));
+							return;
+						}
+					}
 					tc.setCaretPosition(maxPos.getOffset());
 				}
+
 				setVisible(false, false);
+
 			}
+
+			// If not (in the middle of parameters), just insert the paren.
 			else {
-				char ch = pc.getProvider().getParameterListEnd();
-				tc.replaceSelection(Character.toString(ch));
+				tc.replaceSelection(Character.toString(end));
 			}
+
 		}
 
-		public String getArgumentText(int arg) {
-			if (arg<0 || arg>=pc.getParamCount()) {
-				return null;
-			}
+		public String getArgumentText(int offs) {
 			List paramHighlights = getParameterHighlights();
-			if (paramHighlights==null || arg>=paramHighlights.size()) {
+			if (paramHighlights==null || paramHighlights.size()==0) {
 				return null;
 			}
-			Highlight h = (Highlight)paramHighlights.get(arg);
-			int len = h.getEndOffset() - h.getStartOffset();
-			JTextComponent tc = ac.getTextComponent();
-			Document doc = tc.getDocument();
-			try {
-				return doc.getText(h.getStartOffset(), len);
-			} catch (BadLocationException ble) {
-				UIManager.getLookAndFeel().provideErrorFeedback(tc);
-				ble.printStackTrace();
-				return null;
+			for (int i=0; i<paramHighlights.size(); i++) {
+				Highlight h = (Highlight)paramHighlights.get(i);
+				if (offs>=h.getStartOffset() && offs<=h.getEndOffset()) {
+					int len = h.getEndOffset() - h.getStartOffset();
+					JTextComponent tc = ac.getTextComponent();
+					Document doc = tc.getDocument();
+					try {
+						return doc.getText(h.getStartOffset(), len);
+					} catch (BadLocationException ble) {
+						UIManager.getLookAndFeel().provideErrorFeedback(tc);
+						ble.printStackTrace();
+						return null;
+					}
+				}
+			}
+			return null;
+		}
+
+		public int getCount(String text, char ch) {
+			int count = 0;
+			int old = 0;
+			int pos = 0;
+			while ((pos=text.indexOf(ch, old))>-1) {
+				count++;
+				old = pos + 1;
 			}
+			
+			return count;
 		}
 
 	}
diff --git a/src/org/fife/ui/autocomplete/SizeGrip.java b/src/org/fife/ui/autocomplete/SizeGrip.java
index 00ade96..c6b4609 100644
--- a/src/org/fife/ui/autocomplete/SizeGrip.java
+++ b/src/org/fife/ui/autocomplete/SizeGrip.java
@@ -36,11 +36,11 @@ import java.io.File;
 import java.io.IOException;
 import java.net.MalformedURLException;
 import java.net.URL;
-
 import javax.imageio.ImageIO;
 import javax.swing.JPanel;
 import javax.swing.SwingUtilities;
 import javax.swing.UIManager;
+import javax.swing.event.MouseInputAdapter;
 
 
 /**
@@ -218,7 +218,7 @@ class SizeGrip extends JPanel {
 	 * buggy - stretch the window too wide and some kind of arithmetic error
 	 * started happening somewhere - our window would grow way too large.
 	 */
-	private class MouseHandler extends javax.swing.event.MouseInputAdapter {
+	private class MouseHandler extends MouseInputAdapter {
 
 		private Point origPos;
 

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