This is an automated email from the git hooks/post-receive script. ben pushed a commit to branch master in repository autocomplete.
commit 2cc629346a5f5b17a362c43b9351fa66015a51bd Author: bobbylight <[email protected]> Date: Thu Feb 5 21:31:20 2009 +0000 Adding ToolTipSupplier to RTextArea so hosting apps can supply tooltips without subclassing RSTA. AutoComplete has optional support for this through CCompletionProvider (to be expanded on later). Fixed recently-broken hyperlinks in description autocomplete window. Made command+c the copy shortcut for the description window on OS X. --- .../fife/ui/autocomplete/AbstractCompletion.java | 11 + .../autocomplete/AbstractCompletionProvider.java | 8 +- .../ui/autocomplete/AutoCompleteDescWindow.java | 2 +- .../ui/autocomplete/AutoCompletePopupWindow.java | 22 +- src/org/fife/ui/autocomplete/AutoCompletion.java | 2 +- .../fife/ui/autocomplete/CCompletionProvider.java | 61 ++++- src/org/fife/ui/autocomplete/Completion.java | 21 ++ .../fife/ui/autocomplete/CompletionProvider.java | 17 +- .../ui/autocomplete/DefaultCompletionProvider.java | 76 +++++- .../fife/ui/autocomplete/FunctionCompletion.java | 23 ++ .../ui/autocomplete/JarCompletionProvider.java | 282 -------------------- .../fife/ui/autocomplete/VariableCompletion.java | 32 ++- 12 files changed, 253 insertions(+), 304 deletions(-) diff --git a/src/org/fife/ui/autocomplete/AbstractCompletion.java b/src/org/fife/ui/autocomplete/AbstractCompletion.java index 4faf659..7a9d36c 100644 --- a/src/org/fife/ui/autocomplete/AbstractCompletion.java +++ b/src/org/fife/ui/autocomplete/AbstractCompletion.java @@ -108,6 +108,17 @@ public abstract class AbstractCompletion implements Completion, Comparable { /** + * The default implementation returns <code>null</code>. Subclasses + * can override this method. + * + * @return The tool tip text. + */ + public String getToolTipText() { + return null; + } + + + /** * Returns a string representation of this completion. The default * implementation returns {@link #getInputText()}. * diff --git a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java index 1113b50..24b098e 100644 --- a/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java +++ b/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java @@ -49,9 +49,9 @@ public abstract class AbstractCompletionProvider protected List completions; /** - * The case-insensitive {@link Completion} comparator. + * Compares a {@link Completion} against a String. */ - private Comparator comparator; + protected Comparator comparator; /** @@ -246,8 +246,8 @@ public abstract class AbstractCompletionProvider /** - * A comparator that compares the input text of two {@link Completion}s - * lexicographically, ignoring case. + * A comparator that compares the input text of a {@link Completion} + * against a String lexicographically, ignoring case. * * @author Robert Futrell * @version 1.0 diff --git a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java index dfed8c5..022a7fa 100644 --- a/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java +++ b/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java @@ -367,7 +367,7 @@ class AutoCompleteDescWindow extends JWindow implements HyperlinkListener { descArea.setSelectionColor(selBG); } -// descArea.setEditable(false); + descArea.setEditable(false); // Required for links to work! // Make selection visible even though we are not focusable. descArea.getCaret().setSelectionVisible(true); diff --git a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java index f96284c..09e2c80 100644 --- a/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java +++ b/src/org/fife/ui/autocomplete/AutoCompletePopupWindow.java @@ -26,9 +26,9 @@ package org.fife.ui.autocomplete; import java.awt.BorderLayout; import java.awt.Dimension; import java.awt.Rectangle; +import java.awt.Toolkit; import java.awt.Window; import java.awt.event.ActionEvent; -import java.awt.event.InputEvent; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; @@ -132,7 +132,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, super(parent); this.ac = ac; - model = new CompletionListModel();//DefaultListModel(); + model = new CompletionListModel(); list = new JList(model); list.setCellRenderer(new DelegatingCellRenderer()); list.addListSelectionListener(this); @@ -242,6 +242,18 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, /** + * Returns the copy keystroke to use for this platform. + * + * @return The copy keystroke. + */ + private static final KeyStroke getCopyKeyStroke() { + int key = KeyEvent.VK_C; + int mask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); + return KeyStroke.getKeyStroke(key, mask); + } + + + /** * Returns the default list cell renderer used when a completion provider * does not supply its own. * @@ -314,8 +326,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, // Make Ctrl+C copy from description window. This isn't done // automagically because the desc. window is not focusable, and copying // from text components can only be done from focused components. - int key = KeyEvent.VK_C; - KeyStroke ks = KeyStroke.getKeyStroke(key, InputEvent.CTRL_MASK); + KeyStroke ks = getCopyKeyStroke(); oldCtrlC.key = im.get(ks); im.put(ks, ctrlCKap.key); oldCtrlC.action = am.get(ctrlCKap.key); @@ -668,8 +679,7 @@ class AutoCompletePopupWindow extends JWindow implements CaretListener, putBackAction(im, am, KeyEvent.VK_PAGE_DOWN, oldPageDown); // Ctrl+C - int key = KeyEvent.VK_C; - KeyStroke ks = KeyStroke.getKeyStroke(key, InputEvent.CTRL_MASK); + KeyStroke ks = getCopyKeyStroke(); am.put(im.get(ks), oldCtrlC.action); // Original action im.put(ks, oldCtrlC.key); // Original key diff --git a/src/org/fife/ui/autocomplete/AutoCompletion.java b/src/org/fife/ui/autocomplete/AutoCompletion.java index a36bce8..cc2802c 100644 --- a/src/org/fife/ui/autocomplete/AutoCompletion.java +++ b/src/org/fife/ui/autocomplete/AutoCompletion.java @@ -941,7 +941,7 @@ try { return; } List completions = provider. - getParameterizedCompletionsAt(textComponent); + getParameterizedCompletions(textComponent); if (completions!=null && completions.size()>0) { // TODO: Have tooltip let you select between multiple, like VS ParameterizedCompletion pc = diff --git a/src/org/fife/ui/autocomplete/CCompletionProvider.java b/src/org/fife/ui/autocomplete/CCompletionProvider.java index 4821122..a237a22 100644 --- a/src/org/fife/ui/autocomplete/CCompletionProvider.java +++ b/src/org/fife/ui/autocomplete/CCompletionProvider.java @@ -23,6 +23,8 @@ */ package org.fife.ui.autocomplete; +import java.awt.Point; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.List; import javax.swing.text.JTextComponent; @@ -31,6 +33,8 @@ import org.fife.ui.rsyntaxtextarea.RSyntaxDocument; import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea; import org.fife.ui.rsyntaxtextarea.RSyntaxUtilities; import org.fife.ui.rsyntaxtextarea.Token; +import org.fife.ui.rtextarea.RTextArea; +import org.fife.ui.rtextarea.ToolTipSupplier; /** @@ -39,19 +43,28 @@ import org.fife.ui.rsyntaxtextarea.Token; * depending on whether the caret is in: * * <ul> + * <li>Code (plain text)</li> * <li>A string</li> * <li>A comment</li> * <li>A documentation comment</li> - * <li>Plain text</li> * </ul> * * This allows for different completion choices in comments than in code, - * for example. + * for example.<p> + * + * This provider also implements the + * <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> interface, which allows it + * to display tooltips for completion choices. Thus the standard + * {@link VariableCompletion} and {@link FunctionCompletion} completions should + * be able to display tooltips with the variable declaration or function + * definition (provided the <tt>RSyntaxTextArea</tt> was registered with the + * <tt>javax.swing.ToolTipManager</tt>). * * @author Robert Futrell * @version 1.0 */ -public class CCompletionProvider extends CompletionProviderBase { +public class CCompletionProvider extends CompletionProviderBase + implements ToolTipSupplier { /** * The provider to use when no provider is assigned to a particular token @@ -124,6 +137,14 @@ public class CCompletionProvider extends CompletionProviderBase { /** + * {@inheritDoc} + */ + public List getCompletionsAt(JTextComponent tc, Point p) { + return defaultProvider==null ? null : + defaultProvider.getCompletionsAt(tc, p); + } + + /** * Does the dirty work of creating a list of completions. * * @param comp The text component to look in. @@ -166,13 +187,13 @@ public class CCompletionProvider extends CompletionProviderBase { /** * {@inheritDoc} */ - public List getParameterizedCompletionsAt(JTextComponent tc) { + public List getParameterizedCompletions(JTextComponent tc) { // Parameterized completions can only come from the "code" completion // provider. We do not do function/method completions while editing // strings or comments. CompletionProvider provider = getProviderFor(tc); return provider==defaultProvider ? - provider.getParameterizedCompletionsAt(tc) : null; + provider.getParameterizedCompletions(tc) : null; } @@ -350,4 +371,34 @@ public class CCompletionProvider extends CompletionProviderBase { } + /** + * Returns the tool tip to display for a mouse event.<p> + * + * For this method to be called, the <tt>RSyntaxTextArea</tt> must be + * registered with the <tt>javax.swing.ToolTipManager</tt> like so: + * + * <pre> + * ToolTipManager.sharedInstance().registerComponent(textArea); + * </pre> + * + * @param textArea The text area. + * @param e The mouse event. + * @return The tool tip text, or <code>null</code> if none. + */ + public String getToolTipText(RTextArea textArea, MouseEvent e) { + + String tip = null; + + List completions = getCompletionsAt(textArea, e.getPoint()); + if (completions!=null && completions.size()>0) { + // Only ever 1 match for us in C... + Completion c = (Completion)completions.get(0); + tip = c.getToolTipText(); + } + + return tip; + + } + + } \ No newline at end of file diff --git a/src/org/fife/ui/autocomplete/Completion.java b/src/org/fife/ui/autocomplete/Completion.java index b912ede..a5b9eb8 100644 --- a/src/org/fife/ui/autocomplete/Completion.java +++ b/src/org/fife/ui/autocomplete/Completion.java @@ -41,6 +41,8 @@ import javax.swing.text.JTextComponent; * completion list. This may be <code>null</code>. It may also be * lazily generated to cut down on memory usage. * <li>The <tt>CompletionProvider</tt> that returned this completion. + * <li>Tool tip text that can be displayed when a mouse hovers over this + * completion in a text component. * </ul> * * @author Robert Futrell @@ -107,4 +109,23 @@ public interface Completion { public String getSummary(); + /** + * Returns the tool tip text to display for mouse hovers over this + * completion.<p> + * + * Note that for this functionality to be enabled, a + * <tt>JTextComponent</tt> must be registered with the + * <tt>ToolTipManager</tt>, and the text component must know to search + * for this value. In the case of an + * <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this + * can be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that + * calls into + * {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}. + * + * @return The tool tip text for this completion, or <code>null</code> if + * none. + */ + public String getToolTipText(); + + } \ No newline at end of file diff --git a/src/org/fife/ui/autocomplete/CompletionProvider.java b/src/org/fife/ui/autocomplete/CompletionProvider.java index db9a9b4..0e9d69b 100644 --- a/src/org/fife/ui/autocomplete/CompletionProvider.java +++ b/src/org/fife/ui/autocomplete/CompletionProvider.java @@ -23,6 +23,7 @@ */ package org.fife.ui.autocomplete; +import java.awt.Point; import java.util.List; import javax.swing.ListCellRenderer; @@ -68,12 +69,24 @@ public interface CompletionProvider { * * @param comp The text component. * @return The list of {@link Completion}s. If no completions are - * available, an empty list is returned. + * available, this may be <code>null</code>. */ public List getCompletions(JTextComponent comp); /** + * Returns the completions that have been entered at the specified visual + * location. This can be used for tool tips when the user hovers the + * mouse over completed text. + * + * @param comp The text component. + * @param p The position, usually from a <tt>MouseEvent</tt>. + * @return The completions, or an empty list if there are none. + */ + public List getCompletionsAt(JTextComponent comp, Point p); + + + /** * Returns the cell renderer for completions returned from this provider. * * @return The cell renderer, or <code>null</code> if the default should @@ -92,7 +105,7 @@ public interface CompletionProvider { * @return The list of {@link ParameterizedCompletion}s. If no completions * are available, this may be <code>null</code>. */ - public List getParameterizedCompletionsAt(JTextComponent tc); + public List getParameterizedCompletions(JTextComponent tc); /** diff --git a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java index f3c8319..62dc1e5 100644 --- a/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java +++ b/src/org/fife/ui/autocomplete/DefaultCompletionProvider.java @@ -22,6 +22,7 @@ */ package org.fife.ui.autocomplete; +import java.awt.Point; import java.io.BufferedInputStream; import java.io.File; import java.io.FileInputStream; @@ -53,6 +54,19 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider { protected Segment seg; + /** + * Used to speed up {@link #getCompletionsAt(JTextComponent, Point)}. + */ + private String lastCompletionsAtText; + + /** + * Used to speed up {@link #getCompletionsAt(JTextComponent, Point)}, + * since this may be called multiple times in succession (this is usually + * called by <tt>JTextComponent.getToolTipText()</tt>, and if the user + * wiggles the mouse while a tool tip is displayed, this method gets + * repeatedly called. It can be costly so we try to speed it up a tad). + */ + private List lastParameterizedCompletionsAt; /** * Constructor. The returned provider will not be aware of any completions. @@ -121,7 +135,67 @@ public class DefaultCompletionProvider extends AbstractCompletionProvider { /** * {@inheritDoc} */ - public List getParameterizedCompletionsAt(JTextComponent tc) { + public List getCompletionsAt(JTextComponent tc, Point p) { + + int offset = tc.viewToModel(p); + if (offset<0 || offset>=tc.getDocument().getLength()) { + lastCompletionsAtText = null; + return lastParameterizedCompletionsAt = null; + } + + Segment s = new Segment(); + Document doc = tc.getDocument(); + Element root = doc.getDefaultRootElement(); + int line = root.getElementIndex(offset); + Element elem = root.getElement(line); + int start = elem.getStartOffset(); + int end = elem.getEndOffset() - 1; + + try { + + doc.getText(start, end-start, s); + + // Get the valid chars before the specified offset. + int startOffs = s.offset + (offset-start) - 1; + while (startOffs>=s.offset && isValidChar(s.array[startOffs])) { + startOffs--; + } + + // Get the valid chars at and after the specified offset. + int endOffs = s.offset; + while (endOffs<s.offset+s.count && isValidChar(s.array[endOffs])) { + endOffs++; + } + + int len = endOffs - startOffs - 1; + if (len<=0) { + return lastParameterizedCompletionsAt = null; + } + String text = new String(s.array, startOffs+1, len); + + if (text.equals(lastCompletionsAtText)) { + return lastParameterizedCompletionsAt; + } + + // Get a list of all Completions matching the text. + List list = getCompletionByInputText(text); + lastCompletionsAtText = text; + return lastParameterizedCompletionsAt = list; + + } catch (BadLocationException ble) { + ble.printStackTrace(); // Never happens + } + + lastCompletionsAtText = null; + return lastParameterizedCompletionsAt = null; + + } + + + /** + * {@inheritDoc} + */ + public List getParameterizedCompletions(JTextComponent tc) { List list = null; diff --git a/src/org/fife/ui/autocomplete/FunctionCompletion.java b/src/org/fife/ui/autocomplete/FunctionCompletion.java index c911a33..25cfd71 100644 --- a/src/org/fife/ui/autocomplete/FunctionCompletion.java +++ b/src/org/fife/ui/autocomplete/FunctionCompletion.java @@ -25,6 +25,8 @@ package org.fife.ui.autocomplete; import java.util.ArrayList; import java.util.List; +import javax.swing.text.JTextComponent; + /** * A completion choice representing a function. @@ -198,6 +200,27 @@ public class FunctionCompletion extends VariableCompletion /** + * Returns the tool tip text to display for mouse hovers over this + * completion.<p> + * + * Note that for this functionality to be enabled, a + * <tt>JTextComponent</tt> must be registered with the + * <tt>ToolTipManager</tt>, and the text component must know to search + * for this value. In the case of an + * <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this + * can be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that + * calls into + * {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}. + * + * @return The tool tip text for this completion, or <code>null</code> if + * none. + */ + public String getToolTipText() { + return getDefinitionString(); + } + + + /** * Sets the parameters to this function. * * @param params The parameters. This should be a list of diff --git a/src/org/fife/ui/autocomplete/JarCompletionProvider.java b/src/org/fife/ui/autocomplete/JarCompletionProvider.java deleted file mode 100644 index b6a0839..0000000 --- a/src/org/fife/ui/autocomplete/JarCompletionProvider.java +++ /dev/null @@ -1,282 +0,0 @@ -package org.fife.ui.autocomplete; - -import java.io.File; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; -import java.util.SortedMap; -import java.util.TreeMap; -import java.util.jar.JarFile; -import java.util.zip.ZipEntry; -import javax.swing.text.BadLocationException; -import javax.swing.text.Document; -import javax.swing.text.Element; -import javax.swing.text.JTextComponent; -import javax.swing.text.Segment; - - -/** - * The beginnings of a provider that uses reflection to offer completions for - * all classes in a jar.<p> - * - * This class is unfinished and should not be used. - * - * @author Robert Futrell - * @version 1.0 - */ -public class JarCompletionProvider extends AbstractCompletionProvider { - - private Segment seg; - private boolean loaded; - private TreeMap packageSet; - - - public JarCompletionProvider() { - seg = new Segment(); - completions = new ArrayList(0); - packageSet = new TreeMap(); - } - - - public String getAlreadyEnteredText(JTextComponent comp) { - - Document doc = comp.getDocument(); - - int dot = comp.getCaretPosition(); - Element root = doc.getDefaultRootElement(); - int index = root.getElementIndex(dot); - Element elem = root.getElement(index); - int start = elem.getStartOffset(); - int len = dot-start; - try { - doc.getText(start, len, seg); - } catch (BadLocationException ble) { - ble.printStackTrace(); - return EMPTY_STRING; - } - - int segEnd = seg.offset + len; - start = segEnd - 1; - while (start>=seg.offset && isValidChar(seg.array[start])) { - start--; - } - start++; - - len = segEnd - start; - return len==0 ? EMPTY_STRING : new String(seg.array, start, len); - - } - - - private String getAlreadyEnteredText2(JTextComponent comp) { - - Document doc = comp.getDocument(); - - int dot = comp.getCaretPosition(); - Element root = doc.getDefaultRootElement(); - int index = root.getElementIndex(dot); - Element elem = root.getElement(index); - int start = elem.getStartOffset(); - int len = dot-start; - try { - doc.getText(start, len, seg); - } catch (BadLocationException ble) { - ble.printStackTrace(); - return EMPTY_STRING; - } - - int segEnd = seg.offset + len; - start = segEnd - 1; - while (start>=seg.offset && isValidChar2(seg.array[start])) { - start--; - } - start++; - - len = segEnd - start; - return len==0 ? EMPTY_STRING : new String(seg.array, start, len); - - } - - - /** - * Does the dirty work of creating a list of completions. - * - * @param comp The text component to look in. - * @return The list of possible completions, or an empty list if there - * are none. - */ - protected List getCompletionsImpl(JTextComponent comp) { - - if (!loaded) { - loadCompletions(); - } - - List retVal = new ArrayList(); - - String text2 = getAlreadyEnteredText2(comp); - String[] pkgNames = splitOnChar(text2, '.'); - - TreeMap map = packageSet; - for (int i=0; i<pkgNames.length-1; i++) { - - Object obj = map.get(pkgNames[i]); - - if (obj==null) { - return retVal; // empty - } - - if (obj instanceof TreeMap) { - map = (TreeMap)obj; - } - else { - return retVal; // Will be empty - } - - } - - String fromKey = pkgNames[pkgNames.length-1]; - String toKey = fromKey + '{'; // Ascii char > largest valid class char - SortedMap sm = map.subMap(fromKey, toKey); - - for (Iterator i=sm.keySet().iterator(); i.hasNext(); ) { - Object obj = i.next(); - retVal.add(new BasicCompletion(this, obj.toString())); - } - - return retVal; - - } - - - /** - * {@inheritDoc} - */ - public List getParameterizedCompletionsAt(JTextComponent tc) { - return null; // This provider knows no functions or methods. - } - - - /** - * Returns whether the specified character is valid in an auto-completion. - * - * @param ch The character. - * @return Whether the character is valid. - */ - protected boolean isValidChar(char ch) { - return Character.isLetterOrDigit(ch) || ch=='_'; - } - - - /** - * Returns whether the specified character is valid in an auto-completion. - * - * @param ch The character. - * @return Whether the character is valid. - */ - protected boolean isValidChar2(char ch) { - return Character.isLetterOrDigit(ch) || ch=='.' || ch=='_'; - } - - - protected void loadCompletions() { - - loaded = true; - - String javaHome = System.getProperty("java.home"); - //System.out.println(javaHome); - JarFile jar = null; - try { - jar = new JarFile(new File(javaHome, "lib/rt.jar")); - } catch (Exception e) { - e.printStackTrace(); - return; - } - - java.util.Enumeration e = jar.entries(); - while (e.hasMoreElements()) { - ZipEntry entry = (ZipEntry)e.nextElement(); - String entryName = entry.getName(); - if (entryName.endsWith(".class")) { - entryName = entryName.substring(0, entryName.length()-6); - String[] items = splitOnChar(entryName, '/'); - TreeMap m = packageSet; - for (int i=0; i<items.length-1; i++) { - TreeMap submap = (TreeMap)m.get(items[i]); - if (submap==null) { - submap = new TreeMap(); - m.put(items[i], submap); - } - m = submap; - } - String className = items[items.length-1]; - m.put(className, null); - } - } - - } - - - /** - * A faster way to split on a single char than String#split(), since - * we'll be doing this in a tight loop possibly thousands of times (rt.jar). - * - * @param str The string to split. - * @return The string, split on '<tt>/</tt>'. - */ - private String[] splitOnChar(String str, int ch) { - List list = new ArrayList(3); - int pos = 0; - int old = 0; - while ((pos=str.indexOf(ch, old))>-1) { - list.add(str.substring(old, pos)); - old = pos+1; - } - // If str ends in ch, this adds an empty item to the end of the list. - // This is what we want. - list.add(str.substring(old)); - String[] array = new String[list.size()]; - return (String[])list.toArray(array); - } - -/* - private class ClassOrInterfaceCompletion extends AbstractCompletion { - - private String replacementText; - - public ClassOrInterfaceCompletion(String name) { - super(JarCompletionProvider.this); - this.replacementText = name; - } - - public String getReplacementText() { - return replacementText; - } - - public String getSummary() { - return null; - } - - } - - - private class PackageCompletion extends AbstractCompletion { - - private String replacementText; - - public PackageCompletion(String name) { - super(JarCompletionProvider.this); - this.replacementText = name; - } - - public String getReplacementText() { - return replacementText; - } - - public String getSummary() { - return null; - } - - } -*/ - -} \ No newline at end of file diff --git a/src/org/fife/ui/autocomplete/VariableCompletion.java b/src/org/fife/ui/autocomplete/VariableCompletion.java index c3fa77f..20c5c65 100644 --- a/src/org/fife/ui/autocomplete/VariableCompletion.java +++ b/src/org/fife/ui/autocomplete/VariableCompletion.java @@ -22,6 +22,8 @@ */ package org.fife.ui.autocomplete; +import javax.swing.text.JTextComponent; + /** * A completion for a variable (or constant) in a programming language.<p> @@ -64,8 +66,13 @@ public class VariableCompletion extends BasicCompletion { protected void addDefinitionString(StringBuffer sb) { + sb.append("<html><b>").append(getDefinitionString()).append("</b>"); + } - sb.append("<html><b>"); + + public String getDefinitionString() { + + StringBuffer sb = new StringBuffer(); // Add the return type if applicable (C macros like NULL have no type). if (type!=null) { @@ -75,7 +82,7 @@ public class VariableCompletion extends BasicCompletion { // Add the item being described's name. sb.append(getName()); - sb.append("</b>"); + return sb.toString(); } @@ -114,6 +121,27 @@ public class VariableCompletion extends BasicCompletion { /** + * Returns the tool tip text to display for mouse hovers over this + * completion.<p> + * + * Note that for this functionality to be enabled, a + * <tt>JTextComponent</tt> must be registered with the + * <tt>ToolTipManager</tt>, and the text component must know to search + * for this value. In the case of an + * <a href="http://fifesoft.com/rsyntaxtextarea">RSyntaxTextArea</a>, this + * can be done with a <tt>org.fife.ui.rtextarea.ToolTipSupplier</tt> that + * calls into + * {@link CompletionProvider#getCompletionsAt(JTextComponent, java.awt.Point)}. + * + * @return The tool tip text for this completion, or <code>null</code> if + * none. + */ + public String getToolTipText() { + return getDefinitionString(); + } + + + /** * Returns the type of this variable. * * @return The type. -- Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-java/autocomplete.git _______________________________________________ pkg-java-commits mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/pkg-java-commits

