[autocomplete] 03/143: Making AutoCompletion.doCompletion() a way to programmatically display the completion popup window.

Benjamin Mesing ben at alioth.debian.org
Sat Oct 19 12:53:07 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 483ec0292f9c3917fc710a824033aefe4eb3c559
Author: bobbylight <robert at fifesoft.com>
Date:   Thu Jan 1 17:36:55 2009 +0000

    Making AutoCompletion.doCompletion() a way to programmatically display the completion popup window.
---
 .../ui/autocomplete/AutoCompletePopupWindow.java   |   15 +++-
 src/org/fife/ui/autocomplete/AutoCompletion.java   |   83 +++++++++++---------
 2 files changed, 60 insertions(+), 38 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index d14c08d..ef5fe05 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -176,9 +176,20 @@ lastLine = -1;
 	}
 
 
+	/**
+	 * Inserts the currently selected completion.
+	 *
+	 * @see #getSelection()
+	 */
+	public void insertSelectedCompletion() {
+		Completion comp = getSelection();
+		ac.insertCompletion(comp);
+	}
+
+
 	public void mouseClicked(MouseEvent e) {
 		if (e.getClickCount()==2) {
-			ac.doCompletion();
+			insertSelectedCompletion();
 		}
 	}
 
@@ -510,7 +521,7 @@ lastLine = -1;
 
 		public void actionPerformed(ActionEvent e) {
 			if (isVisible()) {
-				ac.doCompletion();
+				insertSelectedCompletion();
 			}
 		}
 
diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java
index 88c693b..2f40157 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -134,37 +134,12 @@ public class AutoCompletion implements HierarchyListener, ComponentListener {
 	}
 
 
+	/**
+	 * Displays the popup window.  Hosting applications can call this method
+	 * to programmatically begin an auto-completion operation.
+	 */
 	public void doCompletion() {
-		Completion comp = popupWindow.getSelection();
-		doCompletionImpl(comp);
-	}
-
-
-	private void doCompletionImpl(Completion c) {
-
-		JTextComponent textComp = getTextComponent();
-		String alreadyEntered = c.getAlreadyEntered(textComp);
-		hidePopupWindow();
-		Caret caret = textComp.getCaret();
-
-		int dot = caret.getDot();
-		caret.setDot(dot - alreadyEntered.length());
-		caret.moveDot(dot);
-		textComp.replaceSelection(c.getReplacementText());
-/*
-		Document doc = textComp.getDocument();
-		int end = caret.getDot();
-		int start = end - alreadyEntered.length();
-try {
-		if (doc instanceof AbstractDocument) {
-			((AbstractDocument)doc).replace(start, end-start, c.getReplacementText(), null);
-		}
-		else {
-			doc.remove(start, end-start);
-			doc.insertString(start, c.getReplacementText(), null);
-		}
-} catch (javax.swing.text.BadLocationException ble) { ble.printStackTrace(); }
-*/
+		refreshPopupWindow();
 	}
 
 
@@ -280,6 +255,9 @@ try {
 	}
 
 
+	/**
+	 * Hides the popup window, if it is visible.
+	 */
 	private void hidePopupWindow() {
 		if (popupWindow!=null) {
 			if (popupWindow.isVisible()) {
@@ -290,6 +268,39 @@ try {
 
 
 	/**
+	 * Inserts a completion.
+	 *
+	 * @param c A completion to insert.  This cannot be <code>null</code>.
+	 */
+	void insertCompletion(Completion c) {
+
+		JTextComponent textComp = getTextComponent();
+		String alreadyEntered = c.getAlreadyEntered(textComp);
+		hidePopupWindow();
+		Caret caret = textComp.getCaret();
+
+		int dot = caret.getDot();
+		caret.setDot(dot - alreadyEntered.length());
+		caret.moveDot(dot);
+		textComp.replaceSelection(c.getReplacementText());
+/*
+		Document doc = textComp.getDocument();
+		int end = caret.getDot();
+		int start = end - alreadyEntered.length();
+try {
+		if (doc instanceof AbstractDocument) {
+			((AbstractDocument)doc).replace(start, end-start, c.getReplacementText(), null);
+		}
+		else {
+			doc.remove(start, end-start);
+			doc.insertString(start, c.getReplacementText(), null);
+		}
+} catch (javax.swing.text.BadLocationException ble) { ble.printStackTrace(); }
+*/
+	}
+
+
+	/**
 	 * Installs this autocompletion on a text component.  If this
 	 * {@link AutoCompletion} is already installed on another text component,
 	 * it is uninstalled first.
@@ -336,6 +347,11 @@ try {
 	}
 
 
+	/**
+	 * Returns whether the popup window is visible.
+	 *
+	 * @return Whether the popup window is visible.
+	 */
 	private boolean isPopupVisible() {
 		return popupWindow!=null && popupWindow.isVisible();
 	}
@@ -364,11 +380,6 @@ try {
 			}
 
 			popupWindow.setCompletions(completions);
-//			popupWindow.clear();
-//			for (int i=0; i<completions.size(); i++) {
-//				
-//				popupWindow.addItem((Completion)completions.get(i));
-//			}
 			popupWindow.selectFirstItem();
 
 			if (!popupWindow.isVisible()) {
@@ -393,7 +404,7 @@ try {
 		else if (count==1) { // !isPopupVisible && autoCompleteSingleChoices
 			SwingUtilities.invokeLater(new Runnable() {
 				public void run() {
-					doCompletionImpl((Completion)completions.get(0));
+					insertCompletion((Completion)completions.get(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