Package org.fife.ui.autocomplete
Class AutoCompletion
- java.lang.Object
-
- org.fife.ui.autocomplete.AutoCompletion
-
- Direct Known Subclasses:
RoundRobinAutoCompletion
public class AutoCompletion extends java.lang.ObjectAdds auto-completion to a text component. Provides a popup window with a list of auto-complete choices on a given keystroke, such as Ctrl+Space.Depending on the
CompletionProviderinstalled, the following auto-completion features may be enabled:- An auto-complete choices list made visible via e.g. Ctrl+Space
- A "description" window displayed alongside the choices list that provides documentation on the currently selected completion choice (as seen in Eclipse and NetBeans).
- Parameter assistance. If this is enabled, if the user enters a "parameterized" completion, such as a method or a function, then they will receive a tool tip describing the arguments they have to enter to the completion. Also, the arguments can be navigated via tab and shift+tab (a la Eclipse and NetBeans).
- Version:
- 1.0
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description private classAutoCompletion.AutoActivationListenerListens for events in the text component to auto-activate the code completion popup.protected classAutoCompletion.AutoCompleteActionTheActionthat displays the popup window if auto-completion is enabled.private classAutoCompletion.LookAndFeelChangeListenerListens for LookAndFeel changes and updates the various popup windows involved in auto-completion accordingly.private classAutoCompletion.ParameterizedCompletionStartActionAction that starts a parameterized completion, e.g.private classAutoCompletion.ParentWindowListenerListens for events in the parent window of the text component with auto-completion enabled.private classAutoCompletion.PopupWindowListenerListens for events from the popup window.private classAutoCompletion.TextComponentListenerListens for events from the text component we're installed on.
-
Field Summary
Fields Modifier and Type Field Description private booleanautoActivationEnabledWhether the auto-activation of auto-complete (after a delay, after the user types an appropriate character) is enabled.private AutoCompletion.AutoActivationListenerautoActivationListenerListens for events in the text component that cause the popup windows to automatically activate.private booleanautoCompleteEnabledWhether auto-complete is enabled.private booleanautoCompleteSingleChoicesWhether, when there is only a single auto-complete option that matches the text at the current text position, that text should be auto-inserted, instead of the completion window displaying.private static booleanDEBUGWhether debug messages should be printed to stdout as AutoCompletion runs.private java.awt.ColordescWindowColorThe background color of the description window.private static java.lang.StringDOCUMENT_CHANGED_PROPERTYFired byJTextComponents when theirDocumentchanges.private ExternalURLHandlerexternalURLHandlerThe handler to use when an external URL is clicked in the help documentation.private booleanhideOnCompletionProviderChangeWhether the popup should be hidden when the CompletionProvider changes.private booleanhideOnNoTextWhether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions").private AutoCompletion.LookAndFeelChangeListenerlafListenerListens for LAF changes so the auto-complete windows automatically update themselves accordingly.private static LinkRedirectorlinkRedirectorAn optional redirector that converts URL's to some other location before being handed over toexternalURLHandler.private javax.swing.event.EventListenerListlistenersAll listeners registered on this component.private javax.swing.ActionoldParenActionThe action previously assigned to the parameter completion key, so we can reset it when we uninstall.private java.lang.ObjectoldParenKeyThe previous key in the text component'sInputMapfor the parameter completion trigger key.private javax.swing.ActionoldTriggerActionThe action previously assigned totrigger, so we can reset it if the user disables auto-completion.private java.lang.ObjectoldTriggerKeyThe previous key in the text component'sInputMapfor the trigger key.private static java.lang.StringPARAM_COMPLETE_KEYKey used in the input map for the parameter completion action.private static java.lang.StringPARAM_TRIGGER_KEYThe key used in the input map for the AutoComplete action.private javax.swing.ListCellRenderer<java.lang.Object>paramChoicesRendererA renderer used forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed).private booleanparameterAssistanceEnabledWhether parameter assistance is enabled.private intparameterDescriptionTruncateThresholdThe maximum length to attempt to display the 'full' parameter description for before truncating.private java.awt.WindowparentWindowThe parent window oftextComponent.private AutoCompletion.ParentWindowListenerparentWindowListenerListens for events in the parent window that affect the visibility of the popup windows.private ParameterizedCompletionContextpccManages any parameterized completions that are inserted.private AutoCompletePopupWindowpopupWindowThe popup window containing completion choices.private AutoCompletion.PopupWindowListenerpopupWindowListenerListens for events from the popup window.private java.awt.DimensionpreferredChoicesWindowSizeThe preferred size of the completion choices window.private java.awt.DimensionpreferredDescWindowSizeThe preferred size of the optional description window.private CompletionProviderproviderProvides the completion options relevant to the current caret position.private javax.swing.ListCellRenderer<java.lang.Object>rendererThe renderer to use for the completion choices.private booleanshowDescWindowWhether the description window should be displayed along with the completion choice window.private static AutoCompletionStyleContextSTYLE_CONTEXTStores how to render auto-completion-specific highlights in text components.private javax.swing.text.JTextComponenttextComponentThe text component we're providing completion for.private AutoCompletion.TextComponentListenertextComponentListenerListens for events from the text component that affect the visibility of the popup windows.private javax.swing.KeyStroketriggerThe keystroke that triggers the completion window.
-
Constructor Summary
Constructors Constructor Description AutoCompletion(CompletionProvider provider)Constructor.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddAutoCompletionListener(AutoCompletionListener l)Adds a listener interested in popup window events from this instance.protected javax.swing.ActioncreateAutoCompleteAction()Creates and returns the action to call when the user presses the auto-completion trigger key (e.g.voiddoCompletion()Displays the popup window.protected voidfireAutoCompletionEvent(AutoCompletionEvent.Type type)Fires anAutoCompletionEventof the specified type.intgetAutoActivationDelay()Returns the delay between when the user types a character and when the code completion popup should automatically appear (if applicable).booleangetAutoCompleteSingleChoices()Returns whether, if a single auto-complete choice is available, it should be automatically inserted, without displaying the popup menu.CompletionProvidergetCompletionProvider()Returns the completion provider.(package private) static booleangetDebug()Returns whether debug is enabled for AutoCompletion.static javax.swing.KeyStrokegetDefaultTriggerKey()Returns the default auto-complete "trigger key" for this OS.java.awt.ColorgetDescWindowColor()Returns the background color for the description window.ExternalURLHandlergetExternalURLHandler()Returns the handler to use when an external URL is clicked in the description window.(package private) intgetLineOfCaret()static LinkRedirectorgetLinkRedirector()Returns the link redirector, if any.javax.swing.ListCellRenderergetListCellRenderer()Returns the default list cell renderer used when a completion provider does not supply its own.javax.swing.ListCellRenderer<java.lang.Object>getParamChoicesRenderer()Returns the renderer to use forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed).intgetParameterDescriptionTruncateThreshold()Returns the maximum number of characters that theParameterizedCompletionDescriptionToolTipwill attempt to display on one line before truncating to a short-form representation.protected java.lang.StringgetReplacementText(Completion c, javax.swing.text.Document doc, int start, int len)Returns the text to replace with in the document.booleangetShowDescWindow()Returns whether the "description window" should be shown alongside the completion window.static AutoCompletionStyleContextgetStyleContext()Returns the style context describing how auto-completion related highlights in the editor are rendered.javax.swing.text.JTextComponentgetTextComponent()Returns the text component for which auto-completion is enabled.(package private) java.awt.ComponentOrientationgetTextComponentOrientation()Returns the orientation of the text component we're installed to.javax.swing.KeyStrokegetTriggerKey()Returns the "trigger key" used for auto-complete.booleanhideChildWindows()Hides any child windows being displayed by the auto-completion system.private booleanhideParameterCompletionPopups()Hides and disposes of any parameter completion-related popups.protected booleanhidePopupWindow()Hides the popup window, if it is visible.private static booleaninitDebug()Determines whether debug should be enabled for the AutoCompletion library.protected voidinsertCompletion(Completion c)Inserts a completion.protected voidinsertCompletion(Completion c, boolean typedParamListStartChar)Inserts a completion.voidinstall(javax.swing.text.JTextComponent c)Installs this auto-completion on a text component.private voidinstallTriggerKey(javax.swing.KeyStroke ks)Installs a "trigger key" action onto the current text component.booleanisAutoActivationEnabled()Returns whether auto-activation is enabled (that is, whether the completion popup will automatically appear after a delay when the user types an appropriate character).booleanisAutoCompleteEnabled()Returns whether auto-completion is enabled.protected booleanisHideOnCompletionProviderChange()Whether the popup should be hidden when the CompletionProvider changes.protected booleanisHideOnNoText()Whether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions").booleanisParameterAssistanceEnabled()Returns whether parameter assistance is enabled.booleanisPopupVisible()Returns whether the completion popup window is visible.protected intrefreshPopupWindow()Refreshes the popup window.voidremoveAutoCompletionListener(AutoCompletionListener l)Removes a listener interested in popup window events from this instance.voidsetAutoActivationDelay(int ms)Sets the delay between when the user types a character and when the code completion popup should automatically appear (if applicable).voidsetAutoActivationEnabled(boolean enabled)Toggles whether auto-activation is enabled.voidsetAutoCompleteEnabled(boolean enabled)Sets whether auto-completion is enabled.voidsetAutoCompleteSingleChoices(boolean autoComplete)Sets whether, if a single auto-complete choice is available, it should be automatically inserted, without displaying the popup menu.voidsetChoicesWindowSize(int w, int h)Sets the size of the completion choices window.voidsetCompletionProvider(CompletionProvider provider)Sets the completion provider being used.voidsetDescriptionWindowColor(java.awt.Color c)Sets the color of the description window.voidsetDescriptionWindowSize(int w, int h)Sets the size of the description window.voidsetExternalURLHandler(ExternalURLHandler handler)Sets the handler to use when an external URL is clicked in the description window.protected voidsetHideOnCompletionProviderChange(boolean hideOnCompletionProviderChange)Sets whether the popup should be hidden when the CompletionProvider changes.protected voidsetHideOnNoText(boolean hideOnNoText)Sets whether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions").static voidsetLinkRedirector(LinkRedirector linkRedirector)Sets the redirector for external URL's found in code completion documentation.voidsetListCellRenderer(javax.swing.ListCellRenderer<java.lang.Object> renderer)Sets the default list cell renderer to use when a completion provider does not supply its own.voidsetParamChoicesRenderer(javax.swing.ListCellRenderer<java.lang.Object> r)Sets the renderer to use forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed).voidsetParameterAssistanceEnabled(boolean enabled)Sets whether parameter assistance is enabled.voidsetParameterDescriptionTruncateThreshold(int truncateThreshold)Sets the maximum number of characters that theParameterizedCompletionDescriptionToolTipwill attempt to display on one line before truncating to a short-form representation.protected voidsetPopupVisible(boolean visible)Toggles the visibility of the auto-completion popup window.voidsetShowDescWindow(boolean show)Sets whether the "description window" should be shown beside the completion window.voidsetTriggerKey(javax.swing.KeyStroke ks)Sets the keystroke that should be used to trigger the auto-complete popup window.private voidstartParameterizedCompletionAssistance(ParameterizedCompletion pc, boolean typedParamListStartChar)Displays a "tool tip" detailing the inputs to the function just entered.voiduninstall()Uninstalls this auto-completion from its text component.private voiduninstallTriggerKey()Replaces the "trigger key" action with the one that was there before auto-completion was installed.private voidupdateUI()Updates the LookAndFeel of the popup window.
-
-
-
Field Detail
-
textComponent
private javax.swing.text.JTextComponent textComponent
The text component we're providing completion for.
-
parentWindow
private java.awt.Window parentWindow
The parent window oftextComponent.
-
popupWindow
private AutoCompletePopupWindow popupWindow
The popup window containing completion choices.
-
preferredChoicesWindowSize
private java.awt.Dimension preferredChoicesWindowSize
The preferred size of the completion choices window. This field exists because the user will likely set the preferred size of the window before it is actually created.
-
preferredDescWindowSize
private java.awt.Dimension preferredDescWindowSize
The preferred size of the optional description window. This field only exists because the user may (and usually will) set the size of the description window before it exists (it must be parented to a Window).
-
descWindowColor
private java.awt.Color descWindowColor
The background color of the description window.
-
pcc
private ParameterizedCompletionContext pcc
Manages any parameterized completions that are inserted.
-
provider
private CompletionProvider provider
Provides the completion options relevant to the current caret position.
-
renderer
private javax.swing.ListCellRenderer<java.lang.Object> renderer
The renderer to use for the completion choices. If this isnull, then a default renderer is used.
-
externalURLHandler
private ExternalURLHandler externalURLHandler
The handler to use when an external URL is clicked in the help documentation.
-
linkRedirector
private static LinkRedirector linkRedirector
An optional redirector that converts URL's to some other location before being handed over toexternalURLHandler.
-
showDescWindow
private boolean showDescWindow
Whether the description window should be displayed along with the completion choice window.
-
autoCompleteEnabled
private boolean autoCompleteEnabled
Whether auto-complete is enabled.
-
autoActivationEnabled
private boolean autoActivationEnabled
Whether the auto-activation of auto-complete (after a delay, after the user types an appropriate character) is enabled.
-
autoCompleteSingleChoices
private boolean autoCompleteSingleChoices
Whether, when there is only a single auto-complete option that matches the text at the current text position, that text should be auto-inserted, instead of the completion window displaying.
-
parameterAssistanceEnabled
private boolean parameterAssistanceEnabled
Whether parameter assistance is enabled.
-
parameterDescriptionTruncateThreshold
private int parameterDescriptionTruncateThreshold
The maximum length to attempt to display the 'full' parameter description for before truncating.
-
paramChoicesRenderer
private javax.swing.ListCellRenderer<java.lang.Object> paramChoicesRenderer
A renderer used forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed). If this isn't set, a default renderer is used.
-
trigger
private javax.swing.KeyStroke trigger
The keystroke that triggers the completion window.
-
oldTriggerKey
private java.lang.Object oldTriggerKey
The previous key in the text component'sInputMapfor the trigger key.
-
oldTriggerAction
private javax.swing.Action oldTriggerAction
The action previously assigned totrigger, so we can reset it if the user disables auto-completion.
-
oldParenKey
private java.lang.Object oldParenKey
The previous key in the text component'sInputMapfor the parameter completion trigger key.
-
oldParenAction
private javax.swing.Action oldParenAction
The action previously assigned to the parameter completion key, so we can reset it when we uninstall.
-
parentWindowListener
private AutoCompletion.ParentWindowListener parentWindowListener
Listens for events in the parent window that affect the visibility of the popup windows.
-
textComponentListener
private AutoCompletion.TextComponentListener textComponentListener
Listens for events from the text component that affect the visibility of the popup windows.
-
autoActivationListener
private AutoCompletion.AutoActivationListener autoActivationListener
Listens for events in the text component that cause the popup windows to automatically activate.
-
lafListener
private AutoCompletion.LookAndFeelChangeListener lafListener
Listens for LAF changes so the auto-complete windows automatically update themselves accordingly.
-
popupWindowListener
private AutoCompletion.PopupWindowListener popupWindowListener
Listens for events from the popup window.
-
listeners
private javax.swing.event.EventListenerList listeners
All listeners registered on this component.
-
hideOnNoText
private boolean hideOnNoText
Whether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions"). Defaults to true.
-
hideOnCompletionProviderChange
private boolean hideOnCompletionProviderChange
Whether the popup should be hidden when the CompletionProvider changes. If set to false, caller has to ensure refresh of the popup content. Defaults to true.
-
PARAM_TRIGGER_KEY
private static final java.lang.String PARAM_TRIGGER_KEY
The key used in the input map for the AutoComplete action.- See Also:
- Constant Field Values
-
PARAM_COMPLETE_KEY
private static final java.lang.String PARAM_COMPLETE_KEY
Key used in the input map for the parameter completion action.- See Also:
- Constant Field Values
-
STYLE_CONTEXT
private static final AutoCompletionStyleContext STYLE_CONTEXT
Stores how to render auto-completion-specific highlights in text components.
-
DEBUG
private static final boolean DEBUG
Whether debug messages should be printed to stdout as AutoCompletion runs.
-
DOCUMENT_CHANGED_PROPERTY
private static final java.lang.String DOCUMENT_CHANGED_PROPERTY
Fired byJTextComponents when theirDocumentchanges.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AutoCompletion
public AutoCompletion(CompletionProvider provider)
Constructor.- Parameters:
provider- The completion provider. This cannot benull
-
-
Method Detail
-
addAutoCompletionListener
public void addAutoCompletionListener(AutoCompletionListener l)
Adds a listener interested in popup window events from this instance.- Parameters:
l- The listener to add.- See Also:
removeAutoCompletionListener(AutoCompletionListener)
-
doCompletion
public void doCompletion()
Displays the popup window. Hosting applications can call this method to programmatically begin an auto-completion operation.
-
fireAutoCompletionEvent
protected void fireAutoCompletionEvent(AutoCompletionEvent.Type type)
Fires anAutoCompletionEventof the specified type.- Parameters:
type- The type of event to fire.
-
getAutoActivationDelay
public int getAutoActivationDelay()
Returns the delay between when the user types a character and when the code completion popup should automatically appear (if applicable).- Returns:
- The delay, in milliseconds.
- See Also:
setAutoActivationDelay(int)
-
getAutoCompleteSingleChoices
public boolean getAutoCompleteSingleChoices()
Returns whether, if a single auto-complete choice is available, it should be automatically inserted, without displaying the popup menu.- Returns:
- Whether to auto-complete single choices.
- See Also:
setAutoCompleteSingleChoices(boolean)
-
getCompletionProvider
public CompletionProvider getCompletionProvider()
Returns the completion provider.- Returns:
- The completion provider.
-
getDebug
static boolean getDebug()
Returns whether debug is enabled for AutoCompletion.- Returns:
- Whether debug is enabled.
-
getDefaultTriggerKey
public static javax.swing.KeyStroke getDefaultTriggerKey()
Returns the default auto-complete "trigger key" for this OS. For Windows, for example, it is Ctrl+Space.- Returns:
- The default auto-complete trigger key.
-
getExternalURLHandler
public ExternalURLHandler getExternalURLHandler()
Returns the handler to use when an external URL is clicked in the description window.- Returns:
- The handler.
- See Also:
setExternalURLHandler(ExternalURLHandler),getLinkRedirector()
-
getLineOfCaret
int getLineOfCaret()
-
getLinkRedirector
public static LinkRedirector getLinkRedirector()
Returns the link redirector, if any.- Returns:
- The link redirector, or
nullif none. - See Also:
setLinkRedirector(LinkRedirector)
-
getListCellRenderer
public javax.swing.ListCellRenderer getListCellRenderer()
Returns the default list cell renderer used when a completion provider does not supply its own.- Returns:
- The default list cell renderer.
- See Also:
setListCellRenderer(ListCellRenderer)
-
getParamChoicesRenderer
public javax.swing.ListCellRenderer<java.lang.Object> getParamChoicesRenderer()
Returns the renderer to use forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed). If this returnsnull, a default renderer is used.- Returns:
- The renderer to use.
- See Also:
setParamChoicesRenderer(ListCellRenderer),isParameterAssistanceEnabled()
-
getReplacementText
protected java.lang.String getReplacementText(Completion c, javax.swing.text.Document doc, int start, int len)
Returns the text to replace with in the document. This is a "last-chance" hook for subclasses to make special modifications to the completion text inserted. The default implementation simply returnsc.getReplacementText(). You usually will not need to modify this method.- Parameters:
c- The completion being inserted.doc- The document being modified.start- The start of the text being replaced.len- The length of the text being replaced.- Returns:
- The text to replace with.
-
getShowDescWindow
public boolean getShowDescWindow()
Returns whether the "description window" should be shown alongside the completion window.- Returns:
- Whether the description window should be shown.
- See Also:
setShowDescWindow(boolean)
-
getStyleContext
public static AutoCompletionStyleContext getStyleContext()
Returns the style context describing how auto-completion related highlights in the editor are rendered.- Returns:
- The style context.
-
getDescWindowColor
public java.awt.Color getDescWindowColor()
Returns the background color for the description window.- Returns:
- The color.
-
getParameterDescriptionTruncateThreshold
public int getParameterDescriptionTruncateThreshold()
Returns the maximum number of characters that theParameterizedCompletionDescriptionToolTipwill attempt to display on one line before truncating to a short-form representation.- Returns:
- The number of characters.
- See Also:
setParameterDescriptionTruncateThreshold(int)
-
getTextComponent
public javax.swing.text.JTextComponent getTextComponent()
Returns the text component for which auto-completion is enabled.- Returns:
- The text component, or
nullif thisAutoCompletionis not installed on any text component. - See Also:
install(JTextComponent)
-
getTextComponentOrientation
java.awt.ComponentOrientation getTextComponentOrientation()
Returns the orientation of the text component we're installed to.- Returns:
- The orientation of the text component, or
nullif we are not installed on one.
-
getTriggerKey
public javax.swing.KeyStroke getTriggerKey()
Returns the "trigger key" used for auto-complete.- Returns:
- The trigger key.
- See Also:
setTriggerKey(KeyStroke)
-
hideChildWindows
public boolean hideChildWindows()
Hides any child windows being displayed by the auto-completion system.- Returns:
- Whether any windows were visible.
-
hideParameterCompletionPopups
private boolean hideParameterCompletionPopups()
Hides and disposes of any parameter completion-related popups.- Returns:
- Whether any such windows were visible (and thus hidden).
-
hidePopupWindow
protected boolean hidePopupWindow()
Hides the popup window, if it is visible.- Returns:
- Whether the popup window was visible.
-
initDebug
private static boolean initDebug()
Determines whether debug should be enabled for the AutoCompletion library. This method checks a system property, but takes care ofSecurityExceptions in case we're in an applet or WebStart.- Returns:
- Whether debug should be enabled.
-
insertCompletion
protected final void insertCompletion(Completion c)
Inserts a completion. Any time a code completion event occurs, the actual text insertion happens through this method.- Parameters:
c- A completion to insert. This cannot benull.
-
insertCompletion
protected void insertCompletion(Completion c, boolean typedParamListStartChar)
Inserts a completion. Any time a code completion event occurs, the actual text insertion happens through this method.- Parameters:
c- A completion to insert. This cannot benull.typedParamListStartChar- Whether the parameterized completion start character was typed (typically'(').
-
install
public void install(javax.swing.text.JTextComponent c)
Installs this auto-completion on a text component. If thisAutoCompletionis already installed on another text component, it is uninstalled first.- Parameters:
c- The text component.- See Also:
uninstall()
-
installTriggerKey
private void installTriggerKey(javax.swing.KeyStroke ks)
Installs a "trigger key" action onto the current text component.- Parameters:
ks- The keystroke that should trigger the action.- See Also:
uninstallTriggerKey()
-
createAutoCompleteAction
protected javax.swing.Action createAutoCompleteAction()
Creates and returns the action to call when the user presses the auto-completion trigger key (e.g. ctrl+space). This is a hook for subclasses that want to provide their own behavior in this scenario. The default implementation returns anAutoCompletion.AutoCompleteAction.- Returns:
- The action to use.
- See Also:
AutoCompletion.AutoCompleteAction
-
isAutoActivationEnabled
public boolean isAutoActivationEnabled()
Returns whether auto-activation is enabled (that is, whether the completion popup will automatically appear after a delay when the user types an appropriate character). Note that this parameter will be ignored if auto-completion is disabled.- Returns:
- Whether auto-activation is enabled.
- See Also:
setAutoActivationEnabled(boolean),getAutoActivationDelay(),isAutoCompleteEnabled()
-
isAutoCompleteEnabled
public boolean isAutoCompleteEnabled()
Returns whether auto-completion is enabled.- Returns:
- Whether auto-completion is enabled.
- See Also:
setAutoCompleteEnabled(boolean)
-
isHideOnCompletionProviderChange
protected boolean isHideOnCompletionProviderChange()
Whether the popup should be hidden when the CompletionProvider changes. If set to false, caller has to ensure refresh of the popup content.- Returns:
- Whether the popup should be hidden when the completion provider changes.
- See Also:
setHideOnCompletionProviderChange(boolean)
-
isHideOnNoText
protected boolean isHideOnNoText()
Whether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions").- Returns:
- Whether the popup should be hidden when the completion list is reset to show all completions.
- See Also:
setHideOnNoText(boolean)
-
isParameterAssistanceEnabled
public boolean isParameterAssistanceEnabled()
Returns whether parameter assistance is enabled.- Returns:
- Whether parameter assistance is enabled.
- See Also:
setParameterAssistanceEnabled(boolean)
-
isPopupVisible
public boolean isPopupVisible()
Returns whether the completion popup window is visible.- Returns:
- Whether the completion popup window is visible.
-
refreshPopupWindow
protected int refreshPopupWindow()
Refreshes the popup window. First, this method gets the possible completions for the current caret position. If there are none, and the popup is visible, it is hidden. If there are some completions and the popup is hidden, it is made visible and made to display the completions. If there are some completions and the popup is visible, its list is updated to the current set of completions.- Returns:
- The current line number of the caret.
-
removeAutoCompletionListener
public void removeAutoCompletionListener(AutoCompletionListener l)
Removes a listener interested in popup window events from this instance.- Parameters:
l- The listener to remove.- See Also:
addAutoCompletionListener(AutoCompletionListener)
-
setAutoActivationDelay
public void setAutoActivationDelay(int ms)
Sets the delay between when the user types a character and when the code completion popup should automatically appear (if applicable).- Parameters:
ms- The delay, in milliseconds. This should be greater than zero.- See Also:
getAutoActivationDelay()
-
setAutoActivationEnabled
public void setAutoActivationEnabled(boolean enabled)
Toggles whether auto-activation is enabled. Note that auto-activation also depends on auto-completion itself being enabled.- Parameters:
enabled- Whether auto-activation is enabled.- See Also:
isAutoActivationEnabled(),setAutoActivationDelay(int)
-
setAutoCompleteEnabled
public void setAutoCompleteEnabled(boolean enabled)
Sets whether auto-completion is enabled.- Parameters:
enabled- Whether auto-completion is enabled.- See Also:
isAutoCompleteEnabled()
-
setAutoCompleteSingleChoices
public void setAutoCompleteSingleChoices(boolean autoComplete)
Sets whether, if a single auto-complete choice is available, it should be automatically inserted, without displaying the popup menu.- Parameters:
autoComplete- Whether to auto-complete single choices.- See Also:
getAutoCompleteSingleChoices()
-
setCompletionProvider
public void setCompletionProvider(CompletionProvider provider)
Sets the completion provider being used.- Parameters:
provider- The new completion provider. This cannot benull.- Throws:
java.lang.IllegalArgumentException- Ifproviderisnull.
-
setChoicesWindowSize
public void setChoicesWindowSize(int w, int h)Sets the size of the completion choices window.- Parameters:
w- The new width.h- The new height.- See Also:
setDescriptionWindowSize(int, int)
-
setDescriptionWindowSize
public void setDescriptionWindowSize(int w, int h)Sets the size of the description window.- Parameters:
w- The new width.h- The new height.- See Also:
setChoicesWindowSize(int, int)
-
setDescriptionWindowColor
public void setDescriptionWindowColor(java.awt.Color c)
Sets the color of the description window.- Parameters:
c- The new color.
-
setExternalURLHandler
public void setExternalURLHandler(ExternalURLHandler handler)
Sets the handler to use when an external URL is clicked in the description window. This handler can perform some action, such as open the URL in a web browser. The default implementation will open the URL in a browser, but only if running in Java 6. If you want browser support for Java 5 and below, or otherwise want to respond to hyperlink clicks, you will have to install your own handler to do so.- Parameters:
handler- The new handler.- See Also:
getExternalURLHandler()
-
setHideOnCompletionProviderChange
protected void setHideOnCompletionProviderChange(boolean hideOnCompletionProviderChange)
Sets whether the popup should be hidden when the CompletionProvider changes. If set to false, caller has to ensure refresh of the popup content.- Parameters:
hideOnCompletionProviderChange- Whether the popup should be hidden when the completion provider changes.- See Also:
isHideOnCompletionProviderChange()
-
setHideOnNoText
protected void setHideOnNoText(boolean hideOnNoText)
Sets whether the popup should be hidden when user types a space (or any character that resets the completion list to "all completions").- Parameters:
hideOnNoText- Whether the popup should be hidden when the completion list is reset to show all completions.- See Also:
isHideOnNoText()
-
setLinkRedirector
public static void setLinkRedirector(LinkRedirector linkRedirector)
Sets the redirector for external URL's found in code completion documentation. When a non-local link in completion popups is clicked, this redirector is given the chance to modify the URL fetched and displayed.- Parameters:
linkRedirector- The link redirector, ornullfor none.- See Also:
getLinkRedirector()
-
setListCellRenderer
public void setListCellRenderer(javax.swing.ListCellRenderer<java.lang.Object> renderer)
Sets the default list cell renderer to use when a completion provider does not supply its own.- Parameters:
renderer- The renderer to use. If this isnull, a default renderer is used.- See Also:
getListCellRenderer()
-
setParamChoicesRenderer
public void setParamChoicesRenderer(javax.swing.ListCellRenderer<java.lang.Object> r)
Sets the renderer to use forCompletions in the optional parameter choices popup window (displayed when aParameterizedCompletionis code-completed). If this isn't set, a default renderer is used.- Parameters:
r- The renderer to use.- See Also:
getParamChoicesRenderer(),setParameterAssistanceEnabled(boolean)
-
setParameterAssistanceEnabled
public void setParameterAssistanceEnabled(boolean enabled)
Sets whether parameter assistance is enabled. If parameter assistance is enabled, and a "parameterized" completion (such as a function or method) is inserted, the user will get "assistance" in inserting the parameters in the form of a popup window with documentation and easy tabbing through the arguments (as seen in Eclipse and NetBeans).- Parameters:
enabled- Whether parameter assistance should be enabled.- See Also:
isParameterAssistanceEnabled()
-
setPopupVisible
protected void setPopupVisible(boolean visible)
Toggles the visibility of the auto-completion popup window. This fires anAutoCompletionEventof the appropriate type.- Parameters:
visible- Whether the window should be made visible or hidden.- See Also:
isPopupVisible()
-
setShowDescWindow
public void setShowDescWindow(boolean show)
Sets whether the "description window" should be shown beside the completion window.- Parameters:
show- Whether to show the description window.- See Also:
getShowDescWindow()
-
setTriggerKey
public void setTriggerKey(javax.swing.KeyStroke ks)
Sets the keystroke that should be used to trigger the auto-complete popup window.- Parameters:
ks- The keystroke.- Throws:
java.lang.IllegalArgumentException- Ifksisnull.- See Also:
getTriggerKey()
-
startParameterizedCompletionAssistance
private void startParameterizedCompletionAssistance(ParameterizedCompletion pc, boolean typedParamListStartChar)
Displays a "tool tip" detailing the inputs to the function just entered.- Parameters:
pc- The completion.typedParamListStartChar- Whether the parameterized completion list starting character was typed.
-
uninstall
public void uninstall()
Uninstalls this auto-completion from its text component. If it is not installed on any text component, nothing happens.- See Also:
install(JTextComponent)
-
uninstallTriggerKey
private void uninstallTriggerKey()
Replaces the "trigger key" action with the one that was there before auto-completion was installed.- See Also:
installTriggerKey(KeyStroke)
-
updateUI
private void updateUI()
Updates the LookAndFeel of the popup window. Applications can call this method as appropriate if they support changing the LookAndFeel at runtime.
-
setParameterDescriptionTruncateThreshold
public void setParameterDescriptionTruncateThreshold(int truncateThreshold)
Sets the maximum number of characters that theParameterizedCompletionDescriptionToolTipwill attempt to display on one line before truncating to a short-form representation.- Parameters:
truncateThreshold- The number of characters before truncation occurs.- See Also:
getParameterDescriptionTruncateThreshold()
-
-