public class AutoCompletion extends Object
Depending on the CompletionProvider
installed, the following
auto-completion features may be enabled:
Modifier and Type | Class and Description |
---|---|
protected class |
AutoCompletion.AutoCompleteAction
The
Action that displays the popup window if auto-completion
is enabled. |
Constructor and Description |
---|
AutoCompletion(CompletionProvider provider)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addAutoCompletionListener(AutoCompletionListener l)
Adds a listener interested in popup window events from this instance.
|
protected Action |
createAutoCompleteAction()
Creates and returns the action to call when the user presses the
auto-completion trigger key (e.g. ctrl+space).
|
void |
doCompletion()
Displays the popup window.
|
protected void |
fireAutoCompletionEvent(AutoCompletionEvent.Type type)
Fires an
AutoCompletionEvent of the specified type. |
int |
getAutoActivationDelay()
Returns the delay between when the user types a character and when the
code completion popup should automatically appear (if applicable).
|
boolean |
getAutoCompleteSingleChoices()
Returns whether, if a single auto-complete choice is available, it should
be automatically inserted, without displaying the popup menu.
|
CompletionProvider |
getCompletionProvider()
Returns the completion provider.
|
static KeyStroke |
getDefaultTriggerKey()
Returns the default auto-complete "trigger key" for this OS.
|
ExternalURLHandler |
getExternalURLHandler()
Returns the handler to use when an external URL is clicked in the
description window.
|
static LinkRedirector |
getLinkRedirector()
Returns the link redirector, if any.
|
ListCellRenderer |
getListCellRenderer()
Returns the default list cell renderer used when a completion provider
does not supply its own.
|
ListCellRenderer |
getParamChoicesRenderer()
Returns the renderer to use for
Completion s in the optional
parameter choices popup window (displayed when a
ParameterizedCompletion is code-completed). |
protected String |
getReplacementText(Completion c,
Document doc,
int start,
int len)
Returns the text to replace with in the document.
|
boolean |
getShowDescWindow()
Returns whether the "description window" should be shown alongside the
completion window.
|
static AutoCompletionStyleContext |
getStyleContext()
Returns the style context describing how auto-completion related
highlights in the editor are rendered.
|
JTextComponent |
getTextComponent()
Returns the text component for which auto-completion is enabled.
|
KeyStroke |
getTriggerKey()
Returns the "trigger key" used for auto-complete.
|
boolean |
hideChildWindows()
Hides any child windows being displayed by the auto-completion system.
|
protected boolean |
hidePopupWindow()
Hides the popup window, if it is visible.
|
protected void |
insertCompletion(Completion c)
Inserts a completion.
|
protected void |
insertCompletion(Completion c,
boolean typedParamListStartChar)
Inserts a completion.
|
void |
install(JTextComponent c)
Installs this auto-completion on a text component.
|
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).
|
boolean |
isAutoCompleteEnabled()
Returns whether auto-completion is enabled.
|
protected boolean |
isHideOnCompletionProviderChange()
Whether or not the popup should be hidden when the CompletionProvider
changes.
|
protected boolean |
isHideOnNoText()
Whether or not the popup should be hidden when user types a space (or
any character that resets the completion list to "all completions").
|
boolean |
isParameterAssistanceEnabled()
Returns whether parameter assistance is enabled.
|
boolean |
isPopupVisible()
Returns whether the completion popup window is visible.
|
protected int |
refreshPopupWindow()
Refreshes the popup window.
|
void |
removeAutoCompletionListener(AutoCompletionListener l)
Removes a listener interested in popup window events from this instance.
|
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).
|
void |
setAutoActivationEnabled(boolean enabled)
Toggles whether auto-activation is enabled.
|
void |
setAutoCompleteEnabled(boolean enabled)
Sets whether auto-completion is enabled.
|
void |
setAutoCompleteSingleChoices(boolean autoComplete)
Sets whether, if a single auto-complete choice is available, it should be
automatically inserted, without displaying the popup menu.
|
void |
setChoicesWindowSize(int w,
int h)
Sets the size of the completion choices window.
|
void |
setCompletionProvider(CompletionProvider provider)
Sets the completion provider being used.
|
void |
setDescriptionWindowSize(int w,
int h)
Sets the size of the description window.
|
void |
setExternalURLHandler(ExternalURLHandler handler)
Sets the handler to use when an external URL is clicked in the
description window.
|
protected void |
setHideOnCompletionProviderChange(boolean hideOnCompletionProviderChange)
Sets whether or not the popup should be hidden when the
CompletionProvider changes.
|
protected void |
setHideOnNoText(boolean hideOnNoText)
Sets whether or not the popup should be hidden when user types a space
(or any character that resets the completion list to "all completions").
|
static void |
setLinkRedirector(LinkRedirector linkRedirector)
Sets the redirector for external URL's found in code completion
documentation.
|
void |
setListCellRenderer(ListCellRenderer renderer)
Sets the default list cell renderer to use when a completion provider
does not supply its own.
|
void |
setParamChoicesRenderer(ListCellRenderer r)
Sets the renderer to use for
Completion s in the optional
parameter choices popup window (displayed when a
ParameterizedCompletion is code-completed). |
void |
setParameterAssistanceEnabled(boolean enabled)
Sets whether parameter assistance is enabled.
|
protected void |
setPopupVisible(boolean visible)
Toggles the visibility of the auto-completion popup window.
|
void |
setShowDescWindow(boolean show)
Sets whether the "description window" should be shown beside the
completion window.
|
void |
setTriggerKey(KeyStroke ks)
Sets the keystroke that should be used to trigger the auto-complete popup
window.
|
void |
uninstall()
Uninstalls this auto-completion from its text component.
|
public AutoCompletion(CompletionProvider provider)
provider
- The completion provider. This cannot be null
public void addAutoCompletionListener(AutoCompletionListener l)
l
- The listener to add.removeAutoCompletionListener(AutoCompletionListener)
public void doCompletion()
protected void fireAutoCompletionEvent(AutoCompletionEvent.Type type)
AutoCompletionEvent
of the specified type.type
- The type of event to fire.public int getAutoActivationDelay()
setAutoActivationDelay(int)
public boolean getAutoCompleteSingleChoices()
setAutoCompleteSingleChoices(boolean)
public CompletionProvider getCompletionProvider()
public static KeyStroke getDefaultTriggerKey()
public ExternalURLHandler getExternalURLHandler()
setExternalURLHandler(ExternalURLHandler)
,
getLinkRedirector()
public static LinkRedirector getLinkRedirector()
null
if none.setLinkRedirector(LinkRedirector)
public ListCellRenderer getListCellRenderer()
setListCellRenderer(ListCellRenderer)
public ListCellRenderer getParamChoicesRenderer()
Completion
s in the optional
parameter choices popup window (displayed when a
ParameterizedCompletion
is code-completed). If this returns
null
, a default renderer is used.setParamChoicesRenderer(ListCellRenderer)
,
isParameterAssistanceEnabled()
protected String getReplacementText(Completion c, Document doc, int start, int len)
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.public boolean getShowDescWindow()
setShowDescWindow(boolean)
public static AutoCompletionStyleContext getStyleContext()
public JTextComponent getTextComponent()
null
if this
AutoCompletion
is not installed on any text component.install(JTextComponent)
public KeyStroke getTriggerKey()
setTriggerKey(KeyStroke)
public boolean hideChildWindows()
protected boolean hidePopupWindow()
protected final void insertCompletion(Completion c)
c
- A completion to insert. This cannot be null
.protected void insertCompletion(Completion c, boolean typedParamListStartChar)
c
- A completion to insert. This cannot be null
.typedParamListStartChar
- Whether the parameterized completion start
character was typed (typically '('
).public void install(JTextComponent c)
AutoCompletion
is already installed on another text component,
it is uninstalled first.c
- The text component.uninstall()
protected Action createAutoCompleteAction()
AutoCompletion.AutoCompleteAction
.AutoCompletion.AutoCompleteAction
public boolean isAutoActivationEnabled()
setAutoActivationEnabled(boolean)
,
getAutoActivationDelay()
,
isAutoCompleteEnabled()
public boolean isAutoCompleteEnabled()
setAutoCompleteEnabled(boolean)
protected boolean isHideOnCompletionProviderChange()
protected boolean isHideOnNoText()
setHideOnNoText(boolean)
public boolean isParameterAssistanceEnabled()
setParameterAssistanceEnabled(boolean)
public boolean isPopupVisible()
protected int refreshPopupWindow()
public void removeAutoCompletionListener(AutoCompletionListener l)
l
- The listener to remove.addAutoCompletionListener(AutoCompletionListener)
public void setAutoActivationDelay(int ms)
ms
- The delay, in milliseconds. This should be greater than zero.getAutoActivationDelay()
public void setAutoActivationEnabled(boolean enabled)
enabled
- Whether auto-activation is enabled.isAutoActivationEnabled()
,
setAutoActivationDelay(int)
public void setAutoCompleteEnabled(boolean enabled)
enabled
- Whether auto-completion is enabled.isAutoCompleteEnabled()
public void setAutoCompleteSingleChoices(boolean autoComplete)
autoComplete
- Whether to auto-complete single choices.getAutoCompleteSingleChoices()
public void setCompletionProvider(CompletionProvider provider)
provider
- The new completion provider. This cannot be
null
.IllegalArgumentException
- If provider
is
null
.public void setChoicesWindowSize(int w, int h)
w
- The new width.h
- The new height.setDescriptionWindowSize(int, int)
public void setDescriptionWindowSize(int w, int h)
w
- The new width.h
- The new height.setChoicesWindowSize(int, int)
public void setExternalURLHandler(ExternalURLHandler handler)
handler
- The new handler.getExternalURLHandler()
protected void setHideOnCompletionProviderChange(boolean hideOnCompletionProviderChange)
isHideOnCompletionProviderChange()
protected void setHideOnNoText(boolean hideOnNoText)
isHideOnNoText()
public static void setLinkRedirector(LinkRedirector linkRedirector)
linkRedirector
- The link redirector, or null
for none.getLinkRedirector()
public void setListCellRenderer(ListCellRenderer renderer)
renderer
- The renderer to use. If this is null
, a
default renderer is used.getListCellRenderer()
public void setParamChoicesRenderer(ListCellRenderer r)
Completion
s in the optional
parameter choices popup window (displayed when a
ParameterizedCompletion
is code-completed). If this isn't set, a
default renderer is used.r
- The renderer to use.getParamChoicesRenderer()
,
setParameterAssistanceEnabled(boolean)
public void setParameterAssistanceEnabled(boolean enabled)
enabled
- Whether parameter assistance should be enabled.isParameterAssistanceEnabled()
protected void setPopupVisible(boolean visible)
AutoCompletionEvent
of the appropriate type.visible
- Whether the window should be made visible or hidden.isPopupVisible()
public void setShowDescWindow(boolean show)
show
- Whether to show the description window.getShowDescWindow()
public void setTriggerKey(KeyStroke ks)
ks
- The keystroke.IllegalArgumentException
- If ks
is null
.getTriggerKey()
public void uninstall()
install(JTextComponent)