This is an automated email from the git hooks/post-receive script. ben pushed a commit to branch master in repository autocomplete.
commit 957b086c4c12a1a1d07dde0b359e6fcd6ec5872c Author: bobbylight <[email protected]> Date: Tue Jan 11 23:28:05 2011 +0000 AutoComplete: Hopefully improved sizing and behavior of ParameterizedComletionChoicesWindow. AutoComplete: Added "PopupWindowDecorator" hook to allow hosting applications to style AutoComplete's popup windows (e.g. with drop shadows). RSTALanguageSupport: Added CodeBlock class and friends, to enable simple parsing for simple LanguageSupports resembling C. RSTALanguageSupport: Updated Perl support to only suggest variables that are in scope at caret position. RSTALanguageSupport: Added beginnings of Groovy support. Very broken at the moment. RSTALanguageSupport: Fixed bug in SourceParamChoicesProvider when parent TypeDeclaration had no modifiers (NPE). --- .../ui/autocomplete/ParameterChoicesProvider.java | 2 +- .../ParameterizedCompletionChoicesWindow.java | 47 +++++++++-- .../ParameterizedCompletionDescriptionToolTip.java | 66 ++++++++++++---- .../fife/ui/autocomplete/PopupWindowDecorator.java | 82 ++++++++++++++++++++ 4 files changed, 174 insertions(+), 23 deletions(-) diff --git a/src/org/fife/ui/autocomplete/ParameterChoicesProvider.java b/src/org/fife/ui/autocomplete/ParameterChoicesProvider.java index 9e38ad1..723d893 100644 --- a/src/org/fife/ui/autocomplete/ParameterChoicesProvider.java +++ b/src/org/fife/ui/autocomplete/ParameterChoicesProvider.java @@ -43,7 +43,7 @@ public interface ParameterChoicesProvider { * Returns a list of choices for a specific parameter. * * @param tc The text component. - * @param p The currently focused parameter. + * @param param The currently focused parameter. * @return The list of parameters. This may be <code>null</code> for * "no parameters," but might also be an empty list. */ diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java index 34e89ed..e54b895 100644 --- a/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java +++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionChoicesWindow.java @@ -24,8 +24,11 @@ package org.fife.ui.autocomplete; import java.awt.ComponentOrientation; +import java.awt.Dimension; import java.awt.Rectangle; import java.awt.Window; +import java.awt.event.MouseAdapter; +import java.awt.event.MouseEvent; import java.util.ArrayList; import java.util.Collections; import java.util.Comparator; @@ -73,6 +76,11 @@ public class ParameterizedCompletionChoicesWindow extends JWindow { private List choicesListList; /** + * The scroll pane containing the list. + */ + private JScrollPane sp; + + /** * Comparator used to sort completions by their relevance before sorting * them lexicographically. */ @@ -85,9 +93,11 @@ public class ParameterizedCompletionChoicesWindow extends JWindow { * * @param parent The parent window (hosting the text component). * @param ac The auto-completion instance. + * @param tip The parent parameter description tool tip. */ public ParameterizedCompletionChoicesWindow(Window parent, - AutoCompletion ac) { + AutoCompletion ac, + final ParameterizedCompletionDescriptionToolTip tip) { super(parent); this.ac = ac; @@ -98,14 +108,25 @@ public class ParameterizedCompletionChoicesWindow extends JWindow { if (ac.getParamChoicesRenderer()!=null) { list.setCellRenderer(ac.getParamChoicesRenderer()); } - JScrollPane sp = new JScrollPane(list); - // Required to easily keep popup wide enough for no horiz. scroll bar - sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); + list.addMouseListener(new MouseAdapter() { + public void mouseClicked(MouseEvent e) { + if (e.getClickCount()==2) { + tip.insertSelectedChoice(); + } + } + }); + sp = new JScrollPane(list); setContentPane(sp); applyComponentOrientation(o); setFocusableWindowState(false); + // Give apps a chance to decorate us with drop shadows, etc. + PopupWindowDecorator decorator = PopupWindowDecorator.get(); + if (decorator!=null) { + decorator.decorate(this); + } + } @@ -137,7 +158,7 @@ public class ParameterizedCompletionChoicesWindow extends JWindow { selection %= model.getSize(); } list.setSelectedIndex(selection); - list.setSelectedIndex(selection); + list.ensureIndexIsVisible(selection); } @@ -247,8 +268,22 @@ public class ParameterizedCompletionChoicesWindow extends JWindow { setVisible(false); } else if (visibleRowCount>0) { - pack(); + Dimension size = getPreferredSize(); + if (size.width<150) { + setSize(150, size.height); + } + else { + pack(); + } + // Make sure nothing is ever obscured by vertical scroll bar. + if (sp.getVerticalScrollBar()!=null && + sp.getVerticalScrollBar().isVisible()) { + size = getSize(); + int w = size.width + sp.getVerticalScrollBar().getWidth()+5; + setSize(w, size.height); + } list.setSelectedIndex(0); + list.ensureIndexIsVisible(0); if (!isVisible()) { setVisible(true); } diff --git a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java index e73353f..61f4534 100644 --- a/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java +++ b/src/org/fife/ui/autocomplete/ParameterizedCompletionDescriptionToolTip.java @@ -23,6 +23,7 @@ */ package org.fife.ui.autocomplete; +import java.awt.BorderLayout; import java.awt.Color; import java.awt.Point; import java.awt.Rectangle; @@ -40,6 +41,7 @@ import javax.swing.ActionMap; import javax.swing.BorderFactory; import javax.swing.InputMap; import javax.swing.JLabel; +import javax.swing.JPanel; import javax.swing.JWindow; import javax.swing.KeyStroke; import javax.swing.SwingUtilities; @@ -162,6 +164,7 @@ class ParameterizedCompletionDescriptionToolTip { AutoCompletion ac, ParameterizedCompletion pc) { tooltip = new JWindow(owner); + this.ac = ac; this.pc = pc; @@ -171,7 +174,21 @@ class ParameterizedCompletionDescriptionToolTip { BorderFactory.createEmptyBorder(2, 5, 2, 5))); descLabel.setOpaque(true); descLabel.setBackground(TipUtil.getToolTipBackground()); - tooltip.setContentPane(descLabel); + // It appears that if a JLabel is set as a content pane directly, when + // using the JDK's opacity API's, it won't paint its background, even + // if label.setOpaque(true) is called. You have to have a container + // underneath it for it to paint its background. Thus, we embed our + // label in a parent JPanel to handle this case. + //tooltip.setContentPane(descLabel); + JPanel panel = new JPanel(new BorderLayout()); + panel.add(descLabel); + tooltip.setContentPane(panel); + + // Give apps a chance to decorate us with drop shadows, etc. + PopupWindowDecorator decorator = PopupWindowDecorator.get(); + if (decorator!=null) { + decorator.decorate(tooltip); + } lastSelectedParam = -1; updateText(0); @@ -194,7 +211,8 @@ class ParameterizedCompletionDescriptionToolTip { */ private ParameterizedCompletionChoicesWindow createParamChoicesWindow() { ParameterizedCompletionChoicesWindow pcw = - new ParameterizedCompletionChoicesWindow(tooltip.getOwner(), ac); + new ParameterizedCompletionChoicesWindow(tooltip.getOwner(), + ac, this); pcw.initialize(pc); return pcw; } @@ -255,6 +273,35 @@ class ParameterizedCompletionDescriptionToolTip { /** + * Inserts the choice selected in the parameter choices window. + * + * @return Whether the choice was inserted. This will be <code>false</code> + * if the window is not visible, or no choice is selected. + */ + boolean insertSelectedChoice() { + if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) { + String choice = paramChoicesWindow.getSelectedChoice(); + if (choice!=null) { + JTextComponent tc = ac.getTextComponent(); + Highlight h = getCurrentParameterHighlight(); + if (h!=null) { + // "+1" is a workaround for Java Highlight issues. + tc.setSelectionStart(h.getStartOffset()+1); + tc.setSelectionEnd(h.getEndOffset()); + tc.replaceSelection(choice); + moveToNextParam(); + } + else { + UIManager.getLookAndFeel().provideErrorFeedback(tc); + } + return true; + } + } + return false; + } + + + /** * Installs key bindings on the text component that facilitate the user * editing this completion's parameters. * @@ -704,20 +751,7 @@ class ParameterizedCompletionDescriptionToolTip { // If the param choices window is visible and something is chosen, // replace the parameter with it and move to the next one. if (paramChoicesWindow!=null && paramChoicesWindow.isVisible()) { - String choice = paramChoicesWindow.getSelectedChoice(); - if (choice!=null) { - JTextComponent tc = ac.getTextComponent(); - Highlight h = getCurrentParameterHighlight(); - if (h!=null) { - // "+1" is a workaround for Java Highlight issues. - tc.setSelectionStart(h.getStartOffset()+1); - tc.setSelectionEnd(h.getEndOffset()); - tc.replaceSelection(choice); - moveToNextParam(); - } - else { - UIManager.getLookAndFeel().provideErrorFeedback(tc); - } + if (insertSelectedChoice()) { return; } } diff --git a/src/org/fife/ui/autocomplete/PopupWindowDecorator.java b/src/org/fife/ui/autocomplete/PopupWindowDecorator.java new file mode 100644 index 0000000..0765210 --- /dev/null +++ b/src/org/fife/ui/autocomplete/PopupWindowDecorator.java @@ -0,0 +1,82 @@ +/* + * 01/11/2011 + * + * PopupWindowDecorator.java - Hook allowing hosting applications to decorate + * JWindows created by the AutoComplete library. + * Copyright (C) 2011 Robert Futrell + * robert_futrell at users.sourceforge.net + * http://fifesoft.com/rsyntaxtextarea + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. + */ +package org.fife.ui.autocomplete; + +import javax.swing.JWindow; + + +/** + * A hook allowing hosting applications to decorate JWindows created by the + * AutoComplete library. For example, you could use the + * <a href="http://jgoodies.com/">JGoodies</a> library to add drop shadows + * to the windows. + * + * @author Robert Futrell + * @version 1.0 + */ +public abstract class PopupWindowDecorator { + + /** + * The singleton instance of this class. + */ + private static PopupWindowDecorator decorator; + + + /** + * Callback called whenever an appropriate JWindow is created by the + * AutoComplete library. Implementations can decorate the window however + * they see fit. + * + * @param window The newly-created window. + */ + public abstract void decorate(JWindow window); + + + /** + * Returns the singleton instance of this class. This should only be + * called on the EDT. + * + * @return The singleton instance of this class, or <code>null</code> + * for none. + * @see #set(PopupWindowDecorator) + */ + public static PopupWindowDecorator get() { + return decorator; + } + + + /** + * Sets the singleton instance of this class. This should only be called + * on the EDT. + * + * @param decorator The new instance of this class. This may be + * <code>null</code>. + * @see #get() + */ + public static void set(PopupWindowDecorator decorator) { + PopupWindowDecorator.decorator = decorator; + } + + +} \ No newline at end of file -- 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

