BE LIABLE FOR ANY
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. autocomplete-2.5.0/distfiles/readme.txt 0000664 0000000 0000000 00000010202 12207001023 0020161 0 ustar 00root root 0000000 0000000 AutoComplete Readme
-------------------
Please contact me if you are using AutoComplete in your project! I like to
know when people are finding it useful. Please send mail to:
robert -at- fifesoft dot com.
* About AutoComplete
AutoComplete is a Swing library that facilitates adding auto-completion
(aka "code completion, "Intellisense") to any JTextComponent. Special
integration is added for RSyntaxTextArea (a programmer's text editor, see
http://fifesoft.com/rsyntaxtextarea/ for more information), since this feature
is commonly needed when editing source code.
* Example Usage
See the AutoComplete example(s) on the RSyntaxTextArea examples page here:
http://fifesoft.com/rsyntaxtextarea/examples/index.php
They provide a good example of basic usage of the library, showing how to
auto-complete a simple, fixed set of words (function names).
Also see the AutoCompleteDemo project, which lives here in SVN:
http://svn.fifesoft.com/svn/RSyntaxTextArea/
It provides an example of loading completions from an XML file. It
demonstrates a code editor with completion support for the C Standard library,
and demos the parameter assistance feature.
* Compiling
If you wish to compile AutoComplete from source, the easiest way to do so
is via the included Ant build script. The default target builds the jar.
This project depends on its sister RSyntaxTextArea project. It is recommended
that you check the two projects out side by side. Then, to build:
cd RSyntaxTextArea
ant
cd ../AutoComplete
ant
* License
AutoComplete is licensed under a modified BSD license. Please see the
included AutoComplete.License.txt file.
* Feedback
I hope you find AutoComplete useful. Bug reports, feature requests, and
just general questions are always welcome. Ways you can submit feedback:
* http://forum.fifesoft.com (preferred)
Has a forum for AutoComplete and related projects, where you can
ask questions and get feedback quickly.
* https://github.com/bobbylight/AutoComplete
Here you can submit bug reports or enhancement requests, peruse the
Wiki, etc.
* Other Links
* http://fifesoft.com/autocomplete
Project home page, which contains general information and example
source code.
* http://fifesoft.com/rsyntaxtextarea
The source code editor you're (probably) already using if you're
using this AutoComplete library.
* http://javadoc.fifesoft.com/rsyntaxtextarea/
* http://javadoc.fifesoft.com/autocomplete/
API documentation for the package. Note that this *will* change as
the library matures.
* Thanks
The left and right arrow icons in the Help "tooltip" window are from the
"Silk" icon set, under the Creative Commons 3.0 License. This is a wonderful
icon set, found here:
http://famfamfam.com/lab/icons/silk/
The "bullet_black.png" icon is an edited version of "bullet_black.png" in the
Silk icon set noted above. It can be considered to be distributed under the
same Creative Commons 3.0 License.
"osx_sizegrip.png" is a reproduction of the size grip used on native OS X
windows. It is distributed under the same modified BSD license as the meat
of the AutoComplete library.
* Translators
Arabic: Mawaheb, Linostar
Chinese: Terrance, peter_barnes, Sunquan, sonyichi, zvest
Chinese (Traditional): kin Por Fok, liou xiao
Dutch: Roel, Sebastiaan, lovepuppy
French: Pat, PivWan
German: Domenic, bikerpete
Hungarian: Zityi, flatron
Indonesian: azis, Sonny
Italian: Luca, stepagweb
Japanese: Josh, izumi, tomoM
Korean: Changkyoon, sbrownii
Polish: Chris, Maciej Mrug
Portuguese (Brazil): Pat, Marcos Parmeggiani, Leandro
Russian: Nadiya, Vladimir
Spanish: Leonardo, phrodo, daloporhecho
Turkish: Cahit, Burak
autocomplete-2.5.0/i18n/ 0000775 0000000 0000000 00000000000 12207001023 0014761 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/i18n/org/ 0000775 0000000 0000000 00000000000 12207001023 0015550 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/i18n/org/fife/ 0000775 0000000 0000000 00000000000 12207001023 0016461 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/i18n/org/fife/ui/ 0000775 0000000 0000000 00000000000 12207001023 0017076 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/ 0000775 0000000 0000000 00000000000 12207001023 0021577 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow.properties 0000664 0000000 0000000 00000000052 12207001023 0030302 0 ustar 00root root 0000000 0000000 NoDescAvailable=No description available
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_ar.properties 0000664 0000000 0000000 00000000143 12207001023 0030765 0 ustar 00root root 0000000 0000000 NoDescAvailable=\u0644\u0627 \u064a\u0648\u062c\u062f \u0634\u0631\u062d \u0645\u062a\u0627\u062d
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_de.properties 0000664 0000000 0000000 00000000063 12207001023 0030754 0 ustar 00root root 0000000 0000000 NoDescAvailable=Keine Beschreibung verf\u00fcgbar
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_es.properties 0000664 0000000 0000000 00000000064 12207001023 0030774 0 ustar 00root root 0000000 0000000 NoDescAvailable=No hay descripci\u00f3n disponible
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_fr.properties 0000664 0000000 0000000 00000000057 12207001023 0030776 0 ustar 00root root 0000000 0000000 NoDescAvailable=Aucune description disponible
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_hu.properties 0000664 0000000 0000000 00000000073 12207001023 0031001 0 ustar 00root root 0000000 0000000 NoDescAvailable=Nincs el\u00e9rhet\u0151 le\u00edr\u00e1s
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_in.properties 0000664 0000000 0000000 00000000052 12207001023 0030770 0 ustar 00root root 0000000 0000000 NoDescAvailable=No description available
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_it.properties 0000664 0000000 0000000 00000000061 12207001023 0030776 0 ustar 00root root 0000000 0000000 NoDescAvailable=Nessuna descrizione disponibile
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_ja.properties 0000664 0000000 0000000 00000000074 12207001023 0030760 0 ustar 00root root 0000000 0000000 NoDescAvailable=\u8a18\u8ff0\u306f\u4e0d\u660e\u3067\u3059
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_ko.properties 0000664 0000000 0000000 00000000070 12207001023 0030773 0 ustar 00root root 0000000 0000000 NoDescAvailable=\ud574\ub2f9 \uc124\uba85 \uc5c6\uc74c
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_nl.properties 0000664 0000000 0000000 00000000052 12207001023 0030773 0 ustar 00root root 0000000 0000000 NoDescAvailable=No description available
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_pl.properties 0000664 0000000 0000000 00000000055 12207001023 0031000 0 ustar 00root root 0000000 0000000 NoDescAvailable=Opis nie jest dost\u0119pny
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_pt_BR.properties 0000664 0000000 0000000 00000000073 12207001023 0031373 0 ustar 00root root 0000000 0000000 NoDescAvailable=Nenhuma descri\u00e7\u00e3o dispon\u00edvel autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_ru.properties 0000664 0000000 0000000 00000000125 12207001023 0031011 0 ustar 00root root 0000000 0000000 NoDescAvailable=\u041d\u0435\u0442 \u043e\u043f\u0438\u0441\u0430\u043d\u0438\u044f
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_tr.properties 0000664 0000000 0000000 00000000066 12207001023 0031014 0 ustar 00root root 0000000 0000000 NoDescAvailable=A\u00e7\u0131klama mevcut de\u011fil
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_zh_CN.properties 0000664 0000000 0000000 00000000052 12207001023 0031363 0 ustar 00root root 0000000 0000000 NoDescAvailable=\u6ca1\u6709\u63cf\u8ff0
autocomplete-2.5.0/i18n/org/fife/ui/autocomplete/AutoCompleteDescWindow_zh_TW.properties 0000664 0000000 0000000 00000000052 12207001023 0031415 0 ustar 00root root 0000000 0000000 NoDescAvailable=No description available
autocomplete-2.5.0/src/ 0000775 0000000 0000000 00000000000 12207001023 0014771 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/src/org/ 0000775 0000000 0000000 00000000000 12207001023 0015560 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/src/org/fife/ 0000775 0000000 0000000 00000000000 12207001023 0016471 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/src/org/fife/ui/ 0000775 0000000 0000000 00000000000 12207001023 0017106 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/src/org/fife/ui/autocomplete/ 0000775 0000000 0000000 00000000000 12207001023 0021607 5 ustar 00root root 0000000 0000000 autocomplete-2.5.0/src/org/fife/ui/autocomplete/AbstractCompletion.java 0000664 0000000 0000000 00000007104 12207001023 0026251 0 ustar 00root root 0000000 0000000 /*
* 12/21/2008
*
* AbstractCompletion.java - Base class for possible completions.
*
* This library is distributed under a modified BSD license. See the included
* RSyntaxTextArea.License.txt file for details.
*/
package org.fife.ui.autocomplete;
import javax.swing.Icon;
import javax.swing.text.JTextComponent;
/**
* Base class for possible completions. Most, if not all, {@link Completion}
* implementations can extend this class. It remembers the
* CompletionProvider that returns this completion, and also implements
* Comparable, allowing such completions to be compared
* lexicographically (ignoring case).
*
* This implementation assumes the input text and replacement text are the
* same value. It also returns the input text from its {@link #toString()}
* method (which is what DefaultListCellRenderer
uses to render
* objects). Subclasses that wish to override any of this behavior can simply
* override the corresponding method(s) needed to do so.
*
* @author Robert Futrell
* @version 1.0
*/
public abstract class AbstractCompletion implements Completion {
/**
* The provider that created this completion;
*/
private CompletionProvider provider;
/**
* The relevance of this completion. Completion instances with higher
* "relevance" values are inserted higher into the list of possible
* completions than those with lower values. Completion instances with
* equal relevance values are sorted alphabetically.
*/
private int relevance;
/**
* Constructor.
*
* @param provider The provider that created this completion.
*/
public AbstractCompletion(CompletionProvider provider) {
this.provider = provider;
}
/**
* {@inheritDoc}
*/
public int compareTo(Completion c2) {
if (c2==this) {
return 0;
}
else if (c2!=null) {
return toString().compareToIgnoreCase(c2.toString());
}
return -1;
}
/**
* {@inheritDoc}
*/
public String getAlreadyEntered(JTextComponent comp) {
return provider.getAlreadyEnteredText(comp);
}
/**
* The default implementation returns null
. Subclasses
* who wish to display an icon can override this method.
*
* @return The icon for this completion.
*/
public Icon getIcon() {
return null;
}
/**
* Returns the text the user has to (start) typing for this completion
* to be offered. The default implementation simply returns
* {@link #getReplacementText()}.
*
* @return The text the user has to (start) typing for this completion.
* @see #getReplacementText()
*/
public String getInputText() {
return getReplacementText();
}
/**
* {@inheritDoc}
*/
public CompletionProvider getProvider() {
return provider;
}
/**
* {@inheritDoc}
*/
public int getRelevance() {
return relevance;
}
/**
* The default implementation returns null
. Subclasses
* can override this method.
*
* @return The tool tip text.
*/
public String getToolTipText() {
return null;
}
/**
* Sets the relevance of this completion.
*
* @param relevance The new relevance of this completion.
* @see #getRelevance()
*/
public void setRelevance(int relevance) {
this.relevance = relevance;
}
/**
* Returns a string representation of this completion. The default
* implementation returns {@link #getInputText()}.
*
* @return A string representation of this completion.
*/
@Override
public String toString() {
return getInputText();
}
} autocomplete-2.5.0/src/org/fife/ui/autocomplete/AbstractCompletionProvider.java 0000664 0000000 0000000 00000015073 12207001023 0027770 0 ustar 00root root 0000000 0000000 /*
* 12/21/2008
*
* AbstractCompletionProvider.java - Base class for completion providers.
*
* This library is distributed under a modified BSD license. See the included
* RSyntaxTextArea.License.txt file for details.
*/
package org.fife.ui.autocomplete;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.swing.text.JTextComponent;
/**
* A base class for completion providers. {@link Completion}s are kept in
* a sorted list. To get the list of completions that match a given input,
* a binary search is done to find the first matching completion, then all
* succeeding completions that also match are also returned.
*
* @author Robert Futrell
* @version 1.0
*/
public abstract class AbstractCompletionProvider
extends CompletionProviderBase {
/**
* The completions this provider is aware of. Subclasses should ensure
* that this list is sorted alphabetically (case-insensitively).
*/
protected List completions;
/**
* Compares a {@link Completion} against a String.
*/
protected CaseInsensitiveComparator comparator;
/**
* Constructor.
*/
public AbstractCompletionProvider() {
comparator = new CaseInsensitiveComparator();
clearParameterizedCompletionParams();
}
/**
* Adds a single completion to this provider. If you are adding multiple
* completions to this provider, for efficiency reasons please consider
* using {@link #addCompletions(List)} instead.
*
* @param c The completion to add.
* @throws IllegalArgumentException If the completion's provider isn't
* this CompletionProvider.
* @see #addCompletions(List)
* @see #removeCompletion(Completion)
* @see #clear()
*/
public void addCompletion(Completion c) {
checkProviderAndAdd(c);
Collections.sort(completions);
}
/**
* Adds {@link Completion}s to this provider.
*
* @param completions The completions to add. This cannot be
* null
.
* @throws IllegalArgumentException If a completion's provider isn't
* this CompletionProvider.
* @see #addCompletion(Completion)
* @see #removeCompletion(Completion)
* @see #clear()
*/
public void addCompletions(List completions) {
//this.completions.addAll(completions);
for (Completion c : completions) {
checkProviderAndAdd(c);
}
Collections.sort(this.completions);
}
/**
* Adds simple completions for a list of words.
*
* @param words The words.
* @see BasicCompletion
*/
protected void addWordCompletions(String[] words) {
int count = words==null ? 0 : words.length;
for (int i=0; iCompletionProvider, if there is one.
*
* @see #addCompletion(Completion)
* @see #addCompletions(List)
* @see #removeCompletion(Completion)
*/
public void clear() {
completions.clear();
}
/**
* Returns a list of Completions in this provider with the
* specified input text.
*
* @param inputText The input text to search for.
* @return A list of {@link Completion}s, or null
if there
* are no matching Completions.
*/
@SuppressWarnings("unchecked")
public List getCompletionByInputText(String inputText) {
// Find any entry that matches this input text (there may be > 1).
int end = Collections.binarySearch(completions, inputText, comparator);
if (end<0) {
return null;
}
// There might be multiple entries with the same input text.
int start = end;
while (start>0 &&
comparator.compare(completions.get(start-1), inputText)==0) {
start--;
}
int count = completions.size();
while (++end getCompletionsImpl(JTextComponent comp) {
List retVal = new ArrayList();
String text = getAlreadyEnteredText(comp);
if (text!=null) {
int index = Collections.binarySearch(completions, text, comparator);
if (index<0) { // No exact match
index = -index - 1;
}
else {
// If there are several overloads for the function being
// completed, Collections.binarySearch() will return the index
// of one of those overloads, but we must return all of them,
// so search backward until we find the first one.
int pos = index - 1;
while (pos>0 &&
comparator.compare(completions.get(pos), text)==0) {
retVal.add(completions.get(pos));
pos--;
}
}
while (indextrue if this provider contained the specified
* completion.
* @see #clear()
* @see #addCompletion(Completion)
* @see #addCompletions(List)
*/
public boolean removeCompletion(Completion c) {
// Don't just call completions.remove(c) as it'll be a linear search.
int index = Collections.binarySearch(completions, c);
if (index<0) {
return false;
}
completions.remove(index);
return true;
}
/**
* A comparator that compares the input text of a {@link Completion}
* against a String lexicographically, ignoring case.
*/
@SuppressWarnings("rawtypes")
protected static class CaseInsensitiveComparator implements Comparator,
Serializable {
public int compare(Object o1, Object o2) {
Completion c = (Completion)o1;
// o2.toString() needed to help compile with 1.5+.
return String.CASE_INSENSITIVE_ORDER.compare(
c.getInputText(), o2.toString());
}
}
} autocomplete-2.5.0/src/org/fife/ui/autocomplete/AutoCompleteDescWindow.java 0000664 0000000 0000000 00000036527 12207001023 0027057 0 ustar 00root root 0000000 0000000 /*
* 12/21/2008
*
* AutoCompleteDescWindow.java - A window containing a description of the
* currently selected completion.
*
* This library is distributed under a modified BSD license. See the included
* RSyntaxTextArea.License.txt file for details.
*/
package org.fife.ui.autocomplete;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.ComponentOrientation;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Window;
import java.awt.event.ActionEvent;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.ResourceBundle;
import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.BorderFactory;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JToolBar;
import javax.swing.JWindow;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import org.fife.ui.rsyntaxtextarea.PopupWindowDecorator;
/**
* The optional "description" window that describes the currently selected
* item in the auto-completion window.
*
* @author Robert Futrell
* @version 1.0
*/
class AutoCompleteDescWindow extends JWindow implements HyperlinkListener,
DescWindowCallback {
/**
* The parent AutoCompletion instance.
*/
private AutoCompletion ac;
/**
* Renders the HTML description.
*/
private JEditorPane descArea;
/**
* The scroll pane that {@link #descArea} is in.
*/
private JScrollPane scrollPane;
/**
* The bottom panel, containing the toolbar and size grip.
*/
private JPanel bottomPanel;
/**
* The toolbar with "back" and "forward" buttons.
*/
private JToolBar descWindowNavBar;
/**
* Action that goes to the previous description displayed.
*/
private Action backAction;
/**
* Action that goes to the next description displayed.
*/
private Action forwardAction;
/**
* History of descriptions displayed.
*/
private List history;
/**
* The current position in {@link #history}.
*/
private int historyPos;
/**
* Provides a slight delay between asking to set a description and actually
* displaying it, so that if the user is scrolling quickly through
* completions, those with slow-to-calculate summaries won't bog down the
* scrolling.
*/
private Timer timer;
/**
* The action that listens for the timer to fire.
*/
private TimerAction timerAction;
/**
* The resource bundle for this window.
*/
private ResourceBundle bundle;
/**
* The amount of time to wait after the user changes the selected
* completion to refresh the description. This delay is in place to help
* performance for {@link Completion}s that may be slow to compute their
* summary text.
*/
private static final int INITIAL_TIMER_DELAY = 120;
/**
* The resource bundle name.
*/
private static final String MSG =
"org.fife.ui.autocomplete.AutoCompleteDescWindow";
/**
* Constructor.
*
* @param owner The parent window.
* @param ac The parent auto-completion.
*/
public AutoCompleteDescWindow(Window owner, AutoCompletion ac) {
super(owner);
this.ac = ac;
ComponentOrientation o = ac.getTextComponentOrientation();
JPanel cp = new JPanel(new BorderLayout());
cp.setBorder(TipUtil.getToolTipBorder());
descArea = new JEditorPane("text/html", null);
TipUtil.tweakTipEditorPane(descArea);
descArea.addHyperlinkListener(this);
scrollPane = new JScrollPane(descArea);
Border b = BorderFactory.createEmptyBorder();
scrollPane.setBorder(b);
scrollPane.setViewportBorder(b);
scrollPane.setBackground(descArea.getBackground());
scrollPane.getViewport().setBackground(descArea.getBackground());
cp.add(scrollPane);
descWindowNavBar = new JToolBar();
backAction = new ToolBarBackAction(o.isLeftToRight());
forwardAction = new ToolBarForwardAction(o.isLeftToRight());
descWindowNavBar.setFloatable(false);
descWindowNavBar.add(new JButton(backAction));
descWindowNavBar.add(new JButton(forwardAction));
bottomPanel = new JPanel(new BorderLayout());
b = new AbstractBorder() {
@Override
public Insets getBorderInsets(Component c) {
return new Insets(1, 0, 0, 0);
}
@Override
public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {
g.setColor(UIManager.getColor("controlDkShadow"));
g.drawLine(x,y, x+w-1,y);
}
};
bottomPanel.setBorder(b);
SizeGrip rp = new SizeGrip();
bottomPanel.add(descWindowNavBar, BorderLayout.LINE_START);
bottomPanel.add(rp, BorderLayout.LINE_END);
cp.add(bottomPanel, BorderLayout.SOUTH);
setContentPane(cp);
applyComponentOrientation(o);
setFocusableWindowState(false);
// Give apps a chance to decorate us with drop shadows, etc.
if (Util.getShouldAllowDecoratingMainAutoCompleteWindows()) {
PopupWindowDecorator decorator = PopupWindowDecorator.get();
if (decorator!=null) {
decorator.decorate(this);
}
}
history = new ArrayList(1); // Usually small
historyPos = -1;
timerAction = new TimerAction();
timer = new Timer(INITIAL_TIMER_DELAY, timerAction);
timer.setRepeats(false);
}
/**
* Sets the currently displayed description and updates the history.
*
* @param historyItem The item to add to the history.
*/
private void addToHistory(HistoryEntry historyItem) {
history.add(++historyPos, historyItem);
clearHistoryAfterCurrentPos();
setActionStates();
}
/**
* Clears the history of viewed descriptions.
*/
private void clearHistory() {
history.clear(); // Try to free some memory.
historyPos = -1;
if (descWindowNavBar!=null) {
setActionStates();
}
}
/**
* Makes the current history page the last one in the history.
*/
private void clearHistoryAfterCurrentPos() {
for (int i=history.size()-1; i>historyPos; i--) {
history.remove(i);
}
setActionStates();
}
/**
* Copies from the description text area, if it is visible and there is
* a selection.
*
* @return Whether a copy occurred.
*/
public boolean copy() {
if (isVisible() &&
descArea.getSelectionStart()!=descArea.getSelectionEnd()) {
descArea.copy();
return true;
}
return false;
}
/**
* Returns the localized message for the specified key.
*
* @param key The key.
* @return The localized message.
*/
private String getString(String key) {
if (bundle==null) {
bundle = ResourceBundle.getBundle(MSG);
}
return bundle.getString(key);
}
/**
* Called when a hyperlink is clicked.
*
* @param e The event.
*/
public void hyperlinkUpdate(HyperlinkEvent e) {
HyperlinkEvent.EventType type = e.getEventType();
if (!type.equals(HyperlinkEvent.EventType.ACTIVATED)) {
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());
}
}
}
// Custom hyperlink handler for this completion type
ExternalURLHandler handler = ac.getExternalURLHandler();
if (handler!=null) {
HistoryEntry current = 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 { // 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 = l.get(0);
setDescriptionFor(c, true);
}
else {
UIManager.getLookAndFeel().provideErrorFeedback(descArea);
}
}
}
}
/**
* Enables or disables the back and forward actions as appropriate.
*/
private void setActionStates() {
// TODO: Localize this text!
String desc = null;
if (historyPos>0) {
backAction.setEnabled(true);
desc = "Back to " + history.get(historyPos-1);
}
else {
backAction.setEnabled(false);
}
backAction.putValue(Action.SHORT_DESCRIPTION, desc);
if (historyPos>-1 && historyPosnull if none.
* @param addToHistory Whether to add this page to the page history
* (as opposed to clearing it and starting anew).
*/
protected void setDescriptionFor(Completion item, String anchor,
boolean addToHistory) {
timer.stop();
timerAction.setCompletion(item, anchor, addToHistory);
timer.start();
}
private void setDisplayedDesc(Completion completion, final String anchor,
boolean addToHistory) {
String desc = completion==null ? null : completion.getSummary();
if (desc==null) {
desc = "" + getString("NoDescAvailable") + "";
}
descArea.setText(desc);
if (anchor!=null) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
descArea.scrollToReference(anchor);
}
});
}
else {
descArea.setCaretPosition(0); // In case of scrolling
}
if (!addToHistory) {
// Remove everything first if this is going to be the only
// thing in history.
clearHistory();
}
addToHistory(new HistoryEntry(completion, desc, null));
}
/**
* {@inheritDoc}
*/
@Override
public void setVisible(boolean visible) {
if (!visible) {
clearHistory();
}
super.setVisible(visible);
}
/**
* Callback for custom ExternalURLHandler
s.
*
* @param completion The completion to display.
* @param anchor The anchor in the HTML to jump to, or null
* if none.
*/
public void showSummaryFor(Completion completion, String anchor) {
setDescriptionFor(completion, anchor, true);
}
/**
* Called by the parent completion popup window the LookAndFeel is updated.
*/
public void updateUI() {
SwingUtilities.updateComponentTreeUI(this);
// Update editor pane for new font, bg, selection colors, etc.
TipUtil.tweakTipEditorPane(descArea);
scrollPane.setBackground(descArea.getBackground());
scrollPane.getViewport().setBackground(descArea.getBackground());
((JPanel)getContentPane()).setBorder(TipUtil.getToolTipBorder());
}
/**
* A completion and its cached summary text.
*/
private static class HistoryEntry {
public Completion completion;
public String summary;
public String anchor;
public HistoryEntry(Completion completion, String summary,
String anchor) {
this.completion = completion;
this.summary = summary;
this.anchor = anchor;
}
/**
* Overridden to display a short name for the completion, since it's
* used in the tool tips for the "back" and "forward" buttons.
*
* @return A string representation of this history entry.
*/
@Override
public String toString() {
return completion.getInputText();
}
}
/**
* Action that actually updates the summary text displayed.
*/
private class TimerAction extends AbstractAction {
private Completion completion;
private String anchor;
private boolean addToHistory;
/**
* Called when the timer is fired.
*/
public void actionPerformed(ActionEvent e) {
setDisplayedDesc(completion, anchor, addToHistory);
}
public void setCompletion(Completion c, String anchor,
boolean addToHistory) {
this.completion = c;
this.anchor = anchor;
this.addToHistory = addToHistory;
}
}
/**
* Action that moves to the previous description displayed.
*/
class ToolBarBackAction extends AbstractAction {
public ToolBarBackAction(boolean ltr) {
String img = "org/fife/ui/autocomplete/arrow_" +
(ltr ? "left.png" : "right.png");
ClassLoader cl = getClass().getClassLoader();
Icon icon = new ImageIcon(cl.getResource(img));
putValue(Action.SMALL_ICON, icon);
}
public void actionPerformed(ActionEvent e) {
if (historyPos>0) {
HistoryEntry pair = history.get(--historyPos);
descArea.setText(pair.summary);
if (pair.anchor!=null) {
//System.out.println("Scrolling to: " + pair.anchor);
descArea.scrollToReference(pair.anchor);
}
else {
descArea.setCaretPosition(0);
}
setActionStates();
}
}
}
/**
* Action that moves to the previous description displayed.
*/
class ToolBarForwardAction extends AbstractAction {
public ToolBarForwardAction(boolean ltr) {
String img = "org/fife/ui/autocomplete/arrow_" +
(ltr ? "right.png" : "left.png");
ClassLoader cl = getClass().getClassLoader();
Icon icon = new ImageIcon(cl.getResource(img));
putValue(Action.SMALL_ICON, icon);
}
public void actionPerformed(ActionEvent e) {
if (history!=null && historyPos