[autocomplete] 96/143: AutoCompletion class now has static LinkRedirector field, allowing consumers to intercept link events in completion windows and redirect to other URL's (such as local copies of documentation). Fixed up dual SizeGrip classes. Tidied Javadoc.

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:24 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 ada56dccc957f8e393529e3f0664478d8a895871
Author: bobbylight <robert at fifesoft.com>
Date:   Sat Jul 7 15:33:28 2012 +0000

    AutoCompletion class now has static LinkRedirector field, allowing consumers to intercept link events in completion windows and redirect to other URL's (such as local copies of documentation).
    Fixed up dual SizeGrip classes.
    Tidied Javadoc.
---
 .../autocomplete/AbstractCompletionProvider.java   |    3 -
 .../ui/autocomplete/AutoCompleteDescWindow.java    |   88 +++++++++++---------
 .../ui/autocomplete/AutoCompletePopupWindow.java   |    3 -
 src/org/fife/ui/autocomplete/AutoCompletion.java   |   56 +++++++++----
 src/org/fife/ui/autocomplete/SizeGrip.java         |    4 +-
 5 files changed, 93 insertions(+), 61 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
index c9a7237..bfd2a06 100644
--- a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
+++ b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java
@@ -225,9 +225,6 @@ public abstract class AbstractCompletionProvider
 	/**
 	 * A comparator that compares the input text of a {@link Completion}
 	 * against a String lexicographically, ignoring case.
-	 *
-	 * @author Robert Futrell
-	 * @version 1.0
 	 */
 	private static class CaseInsensitiveComparator implements Comparator,
 														Serializable {
diff --git a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
index 8f2c471..d141dce 100644
--- a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
@@ -277,50 +277,62 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener,
 	public void hyperlinkUpdate(HyperlinkEvent e) {
 
 		HyperlinkEvent.EventType type = e.getEventType();
+		if (!type.equals(HyperlinkEvent.EventType.ACTIVATED)) {
+			return;
+		}
 
-		if (type.equals(HyperlinkEvent.EventType.ACTIVATED)) {
-
-			// Custom hyperlink handler for this completion type
-			ExternalURLHandler handler = ac.getExternalURLHandler();
-			if (handler!=null) {
-				HistoryEntry current = (HistoryEntry)history.
-												get(historyPos);
-				handler.urlClicked(e, current.completion, this);
-				return;
+		// Users can redirect URL's, perhaps to a local copy of documentation.
+		URL url = e.getURL();
+		if (url!=null) {
+			LinkRedirector redirector = AutoCompletion.getLinkRedirector();
+			if (redirector!=null) {
+				URL newUrl = redirector.possiblyRedirect(url);
+				if (newUrl!=null && newUrl!=url) {
+					url = newUrl;
+					e = new HyperlinkEvent(e.getSource(), e.getEventType(),
+							newUrl, e.getDescription(), e.getSourceElement());
+				}
 			}
+		}
 
-			// No custom handler...
-			URL url = e.getURL();
-			if (url!=null) {
-				// Try loading in external browser (Java 6+ only).
-				try {
-					Util.browse(new URI(url.toString()));
-				} catch (/*IO*/URISyntaxException ioe) {
-					UIManager.getLookAndFeel().provideErrorFeedback(descArea);
-					ioe.printStackTrace();
-				}
+		// Custom hyperlink handler for this completion type
+		ExternalURLHandler handler = ac.getExternalURLHandler();
+		if (handler!=null) {
+			HistoryEntry current = (HistoryEntry)history.
+											get(historyPos);
+			handler.urlClicked(e, current.completion, this);
+			return;
+		}
+
+		// No custom handler...
+		if (url!=null) {
+			// Try loading in external browser (Java 6+ only).
+			try {
+				Util.browse(new URI(url.toString()));
+			} catch (/*IO*/URISyntaxException ioe) {
+				UIManager.getLookAndFeel().provideErrorFeedback(descArea);
+				ioe.printStackTrace();
 			}
-			else { // Simple function name text, like in c.xml
-				// FIXME: This is really a hack, and we assume we can find the
-				// linked-to item in the same CompletionProvider.
-				AutoCompletePopupWindow parent =
-								(AutoCompletePopupWindow)getParent();
-				CompletionProvider p = parent.getSelection().getProvider();
-				if (p instanceof AbstractCompletionProvider) {
-					String name = e.getDescription();
-					List l = ((AbstractCompletionProvider)p).
-										getCompletionByInputText(name);
-					if (l!=null && !l.isEmpty()) {
-						// Just use the 1st one if there's more than 1
-						Completion c = (Completion)l.get(0);
-						setDescriptionFor(c, true);
-					}
-					else {
-						UIManager.getLookAndFeel().provideErrorFeedback(descArea);
-					}
+		}
+		else { // Assume simple function name text, like in c.xml
+			// FIXME: This is really a hack, and we assume we can find the
+			// linked-to item in the same CompletionProvider.
+			AutoCompletePopupWindow parent =
+							(AutoCompletePopupWindow)getParent();
+			CompletionProvider p = parent.getSelection().getProvider();
+			if (p instanceof AbstractCompletionProvider) {
+				String name = e.getDescription();
+				List l = ((AbstractCompletionProvider)p).
+									getCompletionByInputText(name);
+				if (l!=null && !l.isEmpty()) {
+					// Just use the 1st one if there's more than 1
+					Completion c = (Completion)l.get(0);
+					setDescriptionFor(c, true);
+				}
+				else {
+					UIManager.getLookAndFeel().provideErrorFeedback(descArea);
 				}
 			}
-
 		}
 
 	}
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index a58be47..fb505c7 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -858,9 +858,6 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
 
 	/**
 	 * A mapping from a key (an Object) to an Action.
-	 *
-	 * @author Robert Futrell
-	 * @version 1.0
 	 */
 	private static class KeyActionPair {
 
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java
index b5f5141..2677253 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -104,6 +104,12 @@ public class AutoCompletion {
 	private ExternalURLHandler externalURLHandler;
 
 	/**
+	 * An optional redirector that converts URL's to some other location before
+	 * being handed over to <code>externalURLHandler</code>.
+	 */
+	private static LinkRedirector linkRedirector;
+
+	/**
 	 * Whether the description window should be displayed along with the
 	 * completion choice window.
 	 */
@@ -266,7 +272,7 @@ public class AutoCompletion {
 	 * Returns whether, if a single auto-complete choice is available, it
 	 * should be automatically inserted, without displaying the popup menu.
 	 *
-	 * @return Whether to autocomplete single choices.
+	 * @return Whether to auto-complete single choices.
 	 * @see #setAutoCompleteSingleChoices(boolean)
 	 */
 	public boolean getAutoCompleteSingleChoices() {
@@ -295,10 +301,10 @@ public class AutoCompletion {
 
 
 	/**
-	 * Returns the default autocomplete "trigger key" for this OS.  For
+	 * Returns the default auto-complete "trigger key" for this OS.  For
 	 * Windows, for example, it is Ctrl+Space.
 	 *
-	 * @return The default autocomplete trigger key.
+	 * @return The default auto-complete trigger key.
 	 */
 	public static KeyStroke getDefaultTriggerKey() {
 		// Default to CTRL, even on Mac, since Ctrl+Space activates Spotlight
@@ -313,6 +319,7 @@ public class AutoCompletion {
 	 *
 	 * @return The handler.
 	 * @see #setExternalURLHandler(ExternalURLHandler)
+	 * @see #getLinkRedirector()
 	 */
 	public ExternalURLHandler getExternalURLHandler() {
 		return externalURLHandler;
@@ -327,6 +334,17 @@ public class AutoCompletion {
 
 
 	/**
+	 * Returns the link redirector, if any.
+	 *
+	 * @return The link redirector, or <code>null</code> if none.
+	 * @see #setLinkRedirector(LinkRedirector)
+	 */
+	public static LinkRedirector getLinkRedirector() {
+		return linkRedirector;
+	}
+
+
+	/**
 	 * Returns the default list cell renderer used when a completion provider
 	 * does not supply its own.
 	 *
@@ -420,7 +438,7 @@ public class AutoCompletion {
 
 
 	/**
-	 * Returns the "trigger key" used for autocomplete.
+	 * Returns the "trigger key" used for auto-complete.
 	 *
 	 * @return The trigger key.
 	 * @see #setTriggerKey(KeyStroke)
@@ -845,8 +863,8 @@ public class AutoCompletion {
 	 * description window.  This handler can perform some action, such as
 	 * open the URL in a web browser.  The default implementation will open
 	 * the URL in a browser, but only if running in Java 6.  If you want
-	 * browser support for Java 5 and below, you will have to install your own
-	 * handler to do so.
+	 * browser support for Java 5 and below, or otherwise want to respond to
+	 * hyperlink clicks, you will have to install your own handler to do so.
 	 *
 	 * @param handler The new handler.
 	 * @see #getExternalURLHandler()
@@ -857,6 +875,21 @@ public class AutoCompletion {
 
 
 	/**
+	 * Sets the redirector for external URL's found in code completion
+	 * documentation.  When a non-local link in completion popups is clicked,
+	 * this redirector is given the chance to modify the URL fetched and
+	 * displayed.
+	 *
+	 * @param linkRedirector The link redirector, or <code>null</code> for
+	 *        none.
+	 * @see #getLinkRedirector()
+	 */
+	public static void setLinkRedirector(LinkRedirector linkRedirector) {
+		AutoCompletion.linkRedirector = linkRedirector;
+	}
+
+
+	/**
 	 * Sets the default list cell renderer to use when a completion provider
 	 * does not supply its own.
 	 *
@@ -1126,11 +1159,8 @@ public class AutoCompletion {
 	/**
 	 * The <code>Action</code> that displays the popup window if
 	 * auto-completion is enabled.
-	 *
-	 * @author Robert Futrell
-	 * @version 1.0
 	 */
-	class AutoCompleteAction extends AbstractAction {
+	private class AutoCompleteAction extends AbstractAction {
 
 		public void actionPerformed(ActionEvent e) {
 			if (isAutoCompleteEnabled()) {
@@ -1163,9 +1193,6 @@ public class AutoCompletion {
 	/**
 	 * Action that starts a parameterized completion, e.g. after '(' is
 	 * typed.
-	 *
-	 * @author Robert Futrell
-	 * @version 1.0
 	 */
 	private class ParameterizedCompletionStartAction extends AbstractAction {
 
@@ -1200,9 +1227,6 @@ public class AutoCompletion {
 	/**
 	 * Listens for events in the parent window of the text component with
 	 * auto-completion enabled.
-	 *
-	 * @author Robert Futrell
-	 * @version 1.0
 	 */
 	private class ParentWindowListener extends ComponentAdapter
 									implements WindowFocusListener {
diff --git a/src/org/fife/ui/autocomplete/SizeGrip.java b/src/org/fife/ui/autocomplete/SizeGrip.java
index 3f90b84..17db235 100644
--- a/src/org/fife/ui/autocomplete/SizeGrip.java
+++ b/src/org/fife/ui/autocomplete/SizeGrip.java
@@ -31,7 +31,9 @@ import javax.swing.event.MouseInputAdapter;
 
 /**
  * A component that allows its parent window to be resizable, similar to the
- * size grip seen on status bars.
+ * size grip seen on status bars.  This is essentially a copy of the class with
+ * the same name in RSyntaxTextArea, but is duplicated to prevent a dependency
+ * on that library.
  *
  * @author Robert Futrell
  * @version 1.0

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