[autocomplete] 11/143: Fixing keybinding bug when switching from autocomplete choices to parameter assistance. Making size grip look better on OS X.

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 5656fca92951db207778390e49741a04c4e71674
Author: bobbylight <robert at fifesoft.com>
Date:   Fri Jan 16 00:05:49 2009 +0000

    Fixing keybinding bug when switching from autocomplete choices to parameter assistance.  Making size grip look better on OS X.
---
 .../ui/autocomplete/AutoCompleteDescWindow.java    |    5 +-
 .../ui/autocomplete/AutoCompletePopupWindow.java   |   10 +-
 src/org/fife/ui/autocomplete/AutoCompletion.java   |  113 +++++++++++++++-----
 .../ParameterizedCompletionDescriptionToolTip.java |    9 ++
 src/org/fife/ui/autocomplete/SizeGrip.java         |   91 +++++++++++++---
 src/org/fife/ui/autocomplete/osx_sizegrip.png      |  Bin 0 -> 4876 bytes
 6 files changed, 180 insertions(+), 48 deletions(-)

diff --git a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
index 32567a1..1284db3 100644
--- a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java
@@ -115,9 +115,6 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 	private static final String MSG =
 					"org.fife.ui.autocomplete.AutoCompleteDescWindow";
 
-//	private static final boolean IS_OS_X = System.getProperty("os.name").
-//													indexOf("OS X")>-1;
-
 
 	/**
 	 * Constructor.
@@ -131,7 +128,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener {
 		this.ac = ac;
 
 		JPanel cp = new JPanel(new BorderLayout());
-		cp.setBorder(BorderFactory.createLineBorder(Color.BLACK));
+//		cp.setBorder(BorderFactory.createLineBorder(Color.BLACK));
 
 		descArea = new JEditorPane("text/html", null);
 		tweakDescArea();
diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
index 6d4adc3..100ed45 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java
@@ -88,8 +88,6 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener,
 	private AutoCompleteDescWindow descWindow;
 	private boolean aboveCaret;
 
-	private static final boolean DEBUG = true;
-
 
 	public AutoCompletePopupWindow(Window parent, AutoCompletion ac) {
 
@@ -146,7 +144,7 @@ lastLine = -1;
 				doAutocomplete();
 			}
 		}
-		else if (DEBUG) {
+		else if (AutoCompletion.DEBUG) {
 			Thread.dumpStack();
 		}
 	}
@@ -236,7 +234,7 @@ lastLine = -1;
 	 */
 	private void installKeyBindings() {
 
-		if (DEBUG) {
+		if (AutoCompletion.DEBUG) {
 			System.out.println("PopupWindow: Installing keybindings");
 		}
 
@@ -249,7 +247,7 @@ lastLine = -1;
 		ActionMap am = comp.getActionMap();
 
 		replaceAction(im, am, KeyEvent.VK_ESCAPE, escapeKap, oldEscape);
-		if (DEBUG && oldEscape.action==escapeKap.action) {
+		if (AutoCompletion.DEBUG && oldEscape.action==escapeKap.action) {
 			Thread.dumpStack();
 		}
 		replaceAction(im, am, KeyEvent.VK_UP, upKap, oldUp);
@@ -522,7 +520,7 @@ lastLine = -1;
 	 */
 	public void uninstallKeyBindings() {
 
-		if (DEBUG) {
+		if (AutoCompletion.DEBUG) {
 			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 2727327..9df2c65 100644
--- a/src/org/fife/ui/autocomplete/AutoCompletion.java
+++ b/src/org/fife/ui/autocomplete/AutoCompletion.java
@@ -137,6 +137,18 @@ public class AutoCompletion implements HierarchyListener {
 	private Action oldTriggerAction;
 
 	/**
+	 * The previous key in the text component's <code>InputMap</code> for the
+	 * parameter completion trigger key.
+	 */
+	private Object oldParenKey;
+
+	/**
+	 * The action previously assigned to the parameter completion key, so we
+	 * can reset it when we uninstall.
+	 */
+	private Action oldParenAction;
+
+	/**
 	 * Listens for events in the parent window that affect the visibility of
 	 * the popup window.
 	 */
@@ -145,7 +157,14 @@ public class AutoCompletion implements HierarchyListener {
 	/**
 	 * The key used in the input map for the AutoComplete action.
 	 */
-	private static final String ACTION_MAP_KEY	= "AutoComplete";
+	private static final String PARAM_TRIGGER_KEY	= "AutoComplete";
+
+	/**
+	 * Key used in the input map for the parameter completion action.
+	 */
+	private static final String PARAM_COMPLETE_KEY = "AutoCompletion.FunctionStart";
+
+	static final boolean DEBUG = true;
 
 
 	/**
@@ -443,27 +462,18 @@ try {
 		this.textComponent = c;
 		installTriggerKey(getTriggerKey());
 
-		// TODO: Fix me
-		InputMap im = c.getInputMap();
-		ActionMap am = c.getActionMap();
-		KeyStroke ks = KeyStroke.getKeyStroke('(');
-		Object oldParenKey = im.get(ks);
-		im.put(ks, "AutoCompletion.FunctionStart");
-		Action oldParenAction = am.get("AutoCompletion.FunctionStart");
-		am.put("AutoCompletion.FunctionStart", new javax.swing.AbstractAction() {
-			public void actionPerformed(java.awt.event.ActionEvent e) {
-				textComponent.replaceSelection("(");
-				if (!isParameterAssistanceEnabled()) {
-					return;
-				}
-				List completions = provider.getParameterizedCompletionsAt(textComponent);
-				if (completions!=null && completions.size()>0) {
-					// TODO: Have tooltip let you select between multiple, like VS
-					ParameterizedCompletion pc = (ParameterizedCompletion)completions.get(0);
-					displayDescriptionToolTip(pc, false);
-				}
-			}
-		});
+		// Install the function completion key, if there is one.
+		char start = provider.getParameterListStart();
+		if (start!=0) {
+			InputMap im = c.getInputMap();
+			ActionMap am = c.getActionMap();
+			KeyStroke ks = KeyStroke.getKeyStroke(start);
+			oldParenKey = im.get(ks);
+			im.put(ks, PARAM_COMPLETE_KEY);
+			oldParenAction = am.get(PARAM_COMPLETE_KEY);
+			am.put(PARAM_COMPLETE_KEY,
+							new ParameterizedCompletionStartAction(start));
+		}
 
 		this.textComponent.addHierarchyListener(this);
 		hierarchyChanged(null); // In case textComponent is already in a window
@@ -480,10 +490,10 @@ try {
 	private void installTriggerKey(KeyStroke ks) {
 		InputMap im = textComponent.getInputMap();
 		oldTriggerKey = im.get(ks);
-		im.put(ks, ACTION_MAP_KEY);
+		im.put(ks, PARAM_TRIGGER_KEY);
 		ActionMap am = textComponent.getActionMap();
-		oldTriggerAction = am.get(ACTION_MAP_KEY);
-		am.put(ACTION_MAP_KEY, new AutoCompleteAction());
+		oldTriggerAction = am.get(PARAM_TRIGGER_KEY);
+		am.put(PARAM_TRIGGER_KEY, new AutoCompleteAction());
 	}
 
 
@@ -718,15 +728,32 @@ try {
 	 * @see #install(JTextComponent)
 	 */
 	public void uninstall() {
+
 		if (textComponent!=null) {
+
 			hidePopupWindow(); // Unregisters listeners, actions, etc.
+
 			uninstallTriggerKey();
+
+			// Uninstall the function completion key.
+			char start = provider.getParameterListStart();
+			if (start!=0) {
+				KeyStroke ks = KeyStroke.getKeyStroke(start);
+				InputMap im = textComponent.getInputMap();
+				im.put(ks, oldParenKey);
+				ActionMap am = textComponent.getActionMap();
+				am.put(PARAM_COMPLETE_KEY, oldParenAction);
+			}
+
 			textComponent.removeHierarchyListener(this);
 			if (parentWindow!=null) {
 				parentWindowListener.removeFrom(parentWindow);
 			}
+
 			textComponent = null;
+
 		}
+
 	}
 
 
@@ -740,7 +767,7 @@ try {
 		InputMap im = textComponent.getInputMap();
 		im.put(trigger, oldTriggerKey);
 		ActionMap am = textComponent.getActionMap();
-		am.put(ACTION_MAP_KEY, oldTriggerAction);
+		am.put(PARAM_TRIGGER_KEY, oldTriggerAction);
 	}
 
 
@@ -826,4 +853,38 @@ try {
 	}
 
 
+	/**
+	 * Action that starts a parameterized completion, e.g. after '(' is
+	 * typed.
+	 *
+	 * @author Robert Futrell
+	 * @version 1.0
+	 */
+	private class ParameterizedCompletionStartAction extends AbstractAction {
+
+		private String start;
+
+		public ParameterizedCompletionStartAction(char ch) {
+			this.start = Character.toString(ch);
+		}
+
+		public void actionPerformed(ActionEvent e) {
+			hidePopupWindow(); // Prevents keystrokes from messing up
+			textComponent.replaceSelection(start);
+			if (!isParameterAssistanceEnabled()) {
+				return;
+			}
+			List completions = provider.
+								getParameterizedCompletionsAt(textComponent);
+			if (completions!=null && completions.size()>0) {
+				// TODO: Have tooltip let you select between multiple, like VS
+				ParameterizedCompletion pc =
+								(ParameterizedCompletion)completions.get(0);
+				displayDescriptionToolTip(pc, false);
+			}
+		}
+
+	}
+
+
 }
\ No newline at end of file
diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
index df89cb2..5d1d3c2 100644
--- a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
+++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java
@@ -209,6 +209,10 @@ class ParameterizedCompletionDescriptionToolTip {
 	 */
 	private void installKeyBindings() {
 
+		if (AutoCompletion.DEBUG) {
+			System.out.println("ToolTip: Installing keybindings");
+		}
+
 		JTextComponent tc = ac.getTextComponent();
 		InputMap im = tc.getInputMap();
 		ActionMap am = tc.getActionMap();
@@ -410,6 +414,11 @@ class ParameterizedCompletionDescriptionToolTip {
 	 */
 	private void uninstallKeyBindings() {
 
+		if (AutoCompletion.DEBUG) {
+			System.out.println("PopupWindow: Installing keybindings");
+		}
+
+
 		JTextComponent tc = ac.getTextComponent();
 		InputMap im = tc.getInputMap();
 		ActionMap am = tc.getActionMap();
diff --git a/src/org/fife/ui/autocomplete/SizeGrip.java b/src/org/fife/ui/autocomplete/SizeGrip.java
index 0552b82..00ade96 100644
--- a/src/org/fife/ui/autocomplete/SizeGrip.java
+++ b/src/org/fife/ui/autocomplete/SizeGrip.java
@@ -28,9 +28,16 @@ import java.awt.ComponentOrientation;
 import java.awt.Cursor;
 import java.awt.Dimension;
 import java.awt.Graphics;
+import java.awt.Image;
 import java.awt.Point;
 import java.awt.Window;
 import java.awt.event.MouseEvent;
+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;
@@ -45,6 +52,11 @@ import javax.swing.UIManager;
  */
 class SizeGrip extends JPanel {
 
+	/**
+	 * The size grip to use if we're on OS X.
+	 */
+	private Image osxSizeGrip;
+
 
 	public SizeGrip() {
 		MouseHandler adapter = new MouseHandler();
@@ -56,6 +68,52 @@ class SizeGrip extends JPanel {
 
 
 	/**
+	 * Overridden to ensure that the cursor for this component is appropriate
+	 * for the orientation.
+	 *
+	 * @param o The new orientation.
+	 */
+	public void applyComponentOrientation(ComponentOrientation o) {
+		possiblyFixCursor(o);
+		super.applyComponentOrientation(o);
+	}
+
+
+	/**
+	 * Creates and returns the OS X size grip image.
+	 *
+	 * @return The OS X size grip.
+	 */
+	private Image createOSXSizeGrip() {
+		ClassLoader cl = getClass().getClassLoader();
+		URL url = cl.getResource("org.fife.ui.autocomplete.osx_sizegrip.png");
+		if (url==null) {
+			// We're not running in a jar - we may be debugging in Eclipse,
+			// for example
+			File f = new File("../AutoComplete/src/org/fife/ui/autocomplete/osx_sizegrip.png");
+			if (f.isFile()) {
+				try {
+					url = f.toURI().toURL();
+				} catch (MalformedURLException mue) { // Never happens
+					mue.printStackTrace();
+					return null;
+				}
+			}
+			else {
+				return null; // Can't find resource or image file
+			}
+		}
+		Image image = null;
+		try {
+			image = ImageIO.read(url);
+		} catch (IOException ioe) { // Never happens
+			ioe.printStackTrace();
+		}
+		return image;
+	}
+
+
+	/**
 	 * Paints this panel.
 	 *
 	 * @param g The graphics context.
@@ -68,6 +126,11 @@ class SizeGrip extends JPanel {
 		Color c1 = UIManager.getColor("Label.disabledShadow");
 		Color c2 = UIManager.getColor("Label.disabledForeground");
 
+		if (osxSizeGrip!=null) {
+			g.drawImage(osxSizeGrip, dim.width-16, dim.height-16, null);
+			return;
+		}
+
 		ComponentOrientation orientation = getComponentOrientation();
 
 		if (orientation.isLeftToRight()) {
@@ -110,18 +173,6 @@ class SizeGrip extends JPanel {
 
 
 	/**
-	 * Overridden to ensure that the cursor for this component is appropriate
-	 * for the orientation.
-	 *
-	 * @param o The new orientation.
-	 */
-	public void applyComponentOrientation(ComponentOrientation o) {
-		possiblyFixCursor(o);
-		super.applyComponentOrientation(o);
-	}
-
-
-	/**
 	 * Ensures that the cursor for this component is appropriate for the
 	 * orientation.
 	 *
@@ -138,6 +189,22 @@ class SizeGrip extends JPanel {
 	}
 
 
+	public void updateUI() {
+		super.updateUI();
+		// TODO: Key off of Aqua LaF, not just OS X, as this size grip looks
+		// bad on other LaFs on Mac such as Nimbus.
+		if (System.getProperty("os.name").indexOf("OS X")>-1) {
+			if (osxSizeGrip==null) {
+				osxSizeGrip = createOSXSizeGrip();
+			}
+		}
+		else { // Clear memory in case of runtime LaF change.
+			osxSizeGrip = null;
+		}
+
+	}
+
+
 	/**
 	 * Listens for mouse events on this panel and resizes the parent window
 	 * appropriately.
diff --git a/src/org/fife/ui/autocomplete/osx_sizegrip.png b/src/org/fife/ui/autocomplete/osx_sizegrip.png
new file mode 100644
index 0000000..07fa8b1
Binary files /dev/null and b/src/org/fife/ui/autocomplete/osx_sizegrip.png differ

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