public abstract class AbstractInsight extends java.lang.Object implements ActionHookInvoker, java.awt.event.ActionListener, javax.swing.event.CaretListener, CharacterTypedListener, java.awt.event.FocusListener, Insight, PopupWindowListener
AbstractInsight
class provides some of the common
functionality of all Insight implementations, such as handling the
delayed timer, trapping of editor commands, displaying of the
Insight window, and so on.Notes on when to update Insight:
The following are the ways that the source file can be modified, requiring Insight to be updated:
The main problem is that the CaretEvent and DocumentEvent are not ordered with respective to each other - because of this, there is no way to know which one will fire first. It is undesirable to update Insight twice (especially if it causes "flashing".)
Another possibility is to fire a delayed timer when either of these events are generated so that we only update once - the problem with this is that it is possible for the user to issue a command (i.e., hitting "Enter" to complete Insight) before the timer fires, which could potentially cause incorrect results. This is also undesirable.
So what if we choose to listen to just one of the events? Listening to just DocumentEvents will cause us to miss case (1), while listening to just CaretEvents will cause us to miss case (4). Missing case (1) is bad because the user may navigate out of the insight critical area using the mouse. Missing case (4) is not a huge deal as the Insight information is generated primarily using the information before the cursor.
If you combine the use of OffsetMarks with the CaretEvent, you could guess the approximate location of the document change (if any.)
This implementation, by default, will take care of acquiring a read
lock when
InsightProvider.getInsightData()
and
InsightProvider.updateInsightData()
are called. Subclasses that provide their own custom locking can
override useDefaultReadLock() to opt-out of the default locking
if necessary.
Completion implementations should return COMPLETION_TYPE
in getInsightType()
, while Tooltip implementations should
return TOOLTIP_TYPE
. This will ensure that the correct
action redirection occurs. Currently, for API compatibility, this
abstract class always returns COMPLETION_TYPE
for
getInsightType()
. This will be changed to an abstract
method at some point in the future, so clients should update their
implementations accordingly.
Insight
,
InsightProvider
,
InsightData
,
InsightView
Modifier and Type | Class and Description |
---|---|
protected class |
AbstractInsight.NavigationHook |
protected static class |
AbstractInsight.State |
Modifier and Type | Field and Description |
---|---|
protected static int[] |
COMPLETION_LOCATIONS
The preferred positions for a COMPLETION_TYPE insight.
|
static int |
COMPLETION_TYPE
Constant describing an Insight completion type implementation.
|
static int |
FEEDBACK_MESSAGE_DELAY
Public constant indicating the amount of time we should
display any error or feedback messages.
|
protected static int[] |
TOOLTIP_LOCATIONS
The preferred positions for a TOOLTIP_TYPE insight.
|
static int |
TOOLTIP_TYPE
Constant describing an Insight tooltype type implementation.
|
CLOSED_AUTO, CLOSED_NORMAL
Constructor and Description |
---|
AbstractInsight() |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(java.awt.event.ActionEvent event)
This is invoked when an action is performed.
|
void |
caretUpdate(javax.swing.event.CaretEvent event)
Called when the caret position is updated.
|
void |
characterTyped(BasicEditorPane editorPane,
int offset,
char typedChar)
Providers notification that a character was typed by the user
and inserted into the editor pane.
|
void |
clearPopupTimer()
Clears the delay timer for auto-popping up Insight, effectively
cancelling the request.
|
protected abstract InsightProvider |
createInsightProvider()
Creates an InsightProvider to be used with this Insight instance.
|
protected InsightProvider |
createSmartInsightProvider()
Creates a "smart" InsightProvider to be used for this Insight instance.
|
protected javax.swing.JComponent |
createStatusComponent()
Create the status component that (optionally) appears at the bottom of the
insight window.
|
void |
deinstall(BasicEditorPane editor)
Called when the plugin is being removed from the BasicEditorPane
(for example when the editor is closed.) This is used to notify
plugins that they should unregister any listeners that were
attached.
|
protected void |
deinstallNavigationActionHook() |
void |
focusGained(java.awt.event.FocusEvent event)
Invoked when a component gains the keyboard focus.
|
void |
focusLost(java.awt.event.FocusEvent event)
Invoked when a component loses the keyboard focus.
|
int |
getCaretPosition()
Utility routine to fetch the caret position in the text buffer
associated with a particular pane.
|
BasicDocument |
getDocument()
Fetch the underlying document of the editor pane that this
Insight instance is installed in.
|
BasicEditorPane |
getEditorPane()
Fetches the editor pane that this Insight instance is installed
in.
|
protected InsightProvider |
getInsightProvider() |
protected int |
getInsightType()
Fetches the Insight implementation type, whether completion
or tooltip.
|
protected int[] |
getPreferredLocations()
Fetch an array of preferred locations where this insight
implementation would like to display its view.
|
java.awt.Rectangle |
getShowRectangle()
Get the rectangle (relative to editor) where the insight window
should be shown.
|
TextBuffer |
getTextBuffer()
Utility routine to fetch the text buffer associated with the
particular editor pane.
|
protected boolean |
handleCancelCommand(BasicEditorPane editor)
The default action executed for the cancel command
Derived classes can implement their own complete action.
|
protected boolean |
handleCompleteCommand(BasicEditorPane editor)
The default action executed when the user selected a choice from
the insight list view (the complete command).
|
protected boolean |
handleDownCommand(BasicEditorPane editor)
The default action executed for the down arrow command
Derived classes can implement their own complete action.
|
protected boolean |
handleEndCommand(BasicEditorPane editor)
The default action executed for the end command
Derived classes can implement their own complete action.
|
protected boolean |
handleHomeCommand(BasicEditorPane editor)
The default action executed for the home command
Derived classes can implement their own complete action.
|
protected boolean |
handleInsightCommand(BasicEditorPane editor)
The default action executed for the insight command.
|
protected boolean |
handleLeftCommand(BasicEditorPane editor)
The default action executed for the left arrow command
Derived classes can implement their own complete action.
|
protected boolean |
handlePageDownCommand(BasicEditorPane editor)
The default action executed for the page down command
Derived classes can implement their own complete action.
|
protected boolean |
handlePageUpCommand(BasicEditorPane editor)
The default action executed for the page up command
Derived classes can implement their own complete action.
|
protected boolean |
handleRightCommand(BasicEditorPane editor)
The default action executed for the right arrow command
Derived classes can implement their own complete action.
|
protected boolean |
handleUpCommand(BasicEditorPane editor)
The default action executed for the up arrow command
Derived classes can implement their own complete action.
|
void |
hideFeedback()
Utility routine which hides the feedback message in the
status bar of the editor.
|
void |
hideInsight()
Cancels an existing insight window that is displaying insight
information.
|
void |
install(BasicEditorPane editor)
Called when this plugin is being installed into the BasicEditorPane.
|
protected void |
installNavigationActionHook() |
boolean |
invokeAction(java.lang.String actionKey)
Invokes the Action corresponding to the given actionKey.
|
protected boolean |
invokeCompletionTypeAction(int command)
Implementation specific routine to invoke the given action
that was trapped by the editor.
|
protected boolean |
invokeTooltipTypeAction(int command)
Implementation specific routine to invoke the given action
that was trapped by the editor.
|
protected boolean |
isActive() |
protected boolean |
isAutomaticPartialComplete(InsightData data)
Fetch whether automatic partial complete should be enabled for the
given insight data instance.
|
protected boolean |
isExactMatch(InsightData data)
Fetch whether the current insight data instance represents an
exact match.
|
protected boolean |
isExactMatchSupported(InsightData data)
Fetch whether exact match completion should be enabled for the
given insight data instance.
|
abstract boolean |
isInsightTriggerChar(char typedChar)
Returns whether the given typed character should be treated
as a trigger for firing the auto-popup timer for Insight.
|
boolean |
isInsightVisible()
Returns whether there is an Insight window displayed right now.
|
boolean |
isUseSmartInsight() |
protected static int |
lookupCommand(java.lang.String actionKey)
Utility routine which maps an action name (such as "caret-down")
to one of our private constants (like UP_COMMAND.)
|
void |
parentFocusGained(PopupWindow popupWindow)
Notifies the listener that the editor (or one of its popups) have
regained focus.
|
void |
parentFocusLost(PopupWindow popupWindow,
boolean isTemporary)
Notifies the listener that the editor and any managed popups have
lost focus.
|
void |
popupClosed(PopupWindow popupWindow,
int how)
Notifies the listener that the popup window has been closed.
|
void |
propertyChange(java.beans.PropertyChangeEvent event)
This method gets called when a bound property is changed.
|
protected void |
propertyChangeImpl(java.beans.PropertyChangeEvent event)
Version of propertyChange() for implementations to override if they
choose.
|
void |
restartPopupTimer()
Starts (or restarts) the auto-popup delay timer for this Insight
feature.
|
void |
setAccessibleName(java.lang.String name) |
protected void |
setInsightProvider(InsightProvider insightProvider) |
void |
setUseSmartInsight(boolean useSmartInsight) |
void |
showFeedback(java.lang.String feedbackMessage)
Utility routine which shows feedback in the editor pane until cleared.
|
void |
showFeedback(java.lang.String feedbackMessage,
int hideDelay)
Utility routine which shows feedback in the editor pane for some
delay time.
|
void |
showInsight()
Instructs this insight to check whether there is insight
information availble, and if so, to bring up an insight window.
|
void |
showInsight(boolean wasAutoInvoked)
Instructs this insight instance to check whether there is insight
information available, and if so, to bring up an insight window.
|
protected void |
updateInsight()
Utility routine which takes care of updating the Insight
information which is currently displayed.
|
protected boolean |
useDefaultReadLock()
By default, the AbstractInsight class acquires a read lock on
the underlying Document before calling the getInsightData()
and updateInsightData() implementations provided by subclasses.
|
protected boolean |
usingSmartInsightProvider()
Fetch whether insight is currently intent on using the smart or the normal
InsightProvider.
|
protected boolean |
wasCompletePerformed() |
public static final int COMPLETION_TYPE
public static final int TOOLTIP_TYPE
public static final int FEEDBACK_MESSAGE_DELAY
protected static final int[] COMPLETION_LOCATIONS
protected static final int[] TOOLTIP_LOCATIONS
protected abstract InsightProvider createInsightProvider()
protected InsightProvider createSmartInsightProvider()
Note that the "smart" InsightProvider only applies to COMPLETION_TYPE Insight instances only. TOOLTIP_TYPE Insight instances will only use the regular InsightProvider instance.
It is expected that the InsightView returned by both the "smart" and regular InsightProvider instances can handle the display of InsightData from either InsightProvider type. This allows the user to toggle between the two InsightProvider instances by hitting the appropriate accelerator key.
public abstract boolean isInsightTriggerChar(char typedChar)
typedChar
- the character that was typedprotected boolean isExactMatchSupported(InsightData data)
Note that there global property for whether exact match is enabled still overrides language implementations - if exact-match is disabled globally, this method will never get called.
data
- the current insight data instanceprotected boolean isAutomaticPartialComplete(InsightData data)
data
- the current insight data instanceprotected boolean isExactMatch(InsightData data)
If this indicates that there is a single exact match, and exact-match completion is on, the completion will be performed automatically on the *default* data item.
data
- the current insight data instanceprotected int getInsightType()
public final BasicEditorPane getEditorPane()
public final BasicDocument getDocument()
public TextBuffer getTextBuffer()
public int getCaretPosition()
public void setAccessibleName(java.lang.String name)
protected boolean usingSmartInsightProvider()
COMPLETION_TYPE
insight.public void characterTyped(BasicEditorPane editorPane, int offset, char typedChar)
characterTyped
in interface CharacterTypedListener
editorPane
- the editor pane where the character was typedoffset
- the offset where the character was insertedtypedChar
- the character that was typedpublic boolean invokeAction(java.lang.String actionKey)
invokeAction
in interface ActionHookInvoker
actionKey
- the published key for the actionprotected boolean invokeCompletionTypeAction(int command)
command
- the internal command id, such as UP_COMMANDprotected boolean invokeTooltipTypeAction(int command)
command
- the internal command id, such as UP_COMMANDpublic void actionPerformed(java.awt.event.ActionEvent event)
actionPerformed
in interface java.awt.event.ActionListener
event
- the action eventpublic void install(BasicEditorPane editor)
install
in interface EditorPlugin
editor
- the editor panepublic void deinstall(BasicEditorPane editor)
deinstall
in interface EditorPlugin
editor
- the editor panepublic final void propertyChange(java.beans.PropertyChangeEvent event)
propertyChange
in interface java.beans.PropertyChangeListener
event
- A PropertyChangeEvent object describing the event source
and the property that has changed.protected void propertyChangeImpl(java.beans.PropertyChangeEvent event)
event
- A PropertyChangeEvent object describing the event source
and the property that has changed.public void restartPopupTimer()
restartPopupTimer
in interface Insight
public void clearPopupTimer()
clearPopupTimer
in interface Insight
Insight.restartPopupTimer()
public boolean isInsightVisible()
isInsightVisible
in interface Insight
public java.awt.Rectangle getShowRectangle()
public void showInsight()
showInsight
in interface Insight
public void showInsight(boolean wasAutoInvoked)
wasAutoInvoked
indicates whether code insight
was triggered implicitly by a timer firing after some trigger
character, versus being explicitly invoked by an accelerator or
menu item. The difference is that auto-single-completion (if enabled) only fires for manual invocations, not for automatic invocations.
wasAutoInvoked
- whether code insight was automatically
(implicitly) invokedprotected javax.swing.JComponent createStatusComponent()
protected void installNavigationActionHook()
protected void deinstallNavigationActionHook()
public void hideInsight()
hideInsight
in interface Insight
protected boolean useDefaultReadLock()
public void focusGained(java.awt.event.FocusEvent event)
focusGained
in interface java.awt.event.FocusListener
public void focusLost(java.awt.event.FocusEvent event)
focusLost
in interface java.awt.event.FocusListener
public void popupClosed(PopupWindow popupWindow, int how)
popupClosed
in interface PopupWindowListener
popupWindow
- the popup window that this notification is being
delivered forhow
- how the popup was closed, either CLOSED_NORMAL or
CLOSED_AUTO.public void parentFocusGained(PopupWindow popupWindow)
parentFocusGained
in interface PopupWindowListener
popupWindow
- the popup window that this notification is being
delivered forpublic void parentFocusLost(PopupWindow popupWindow, boolean isTemporary)
parentFocusLost
in interface PopupWindowListener
popupWindow
- the popup window that this notification is being
delivered forisTemporary
- whether the loss of focus is temporarypublic void caretUpdate(javax.swing.event.CaretEvent event)
caretUpdate
in interface javax.swing.event.CaretListener
event
- the caret eventprotected final boolean wasCompletePerformed()
public void showFeedback(java.lang.String feedbackMessage)
feedbackMessage
- the message to displaypublic void showFeedback(java.lang.String feedbackMessage, int hideDelay)
feedbackMessage
- the message to displayhideDelay
- the delay after which to hide the messagepublic void hideFeedback()
protected final boolean isActive()
protected void updateInsight()
protected int[] getPreferredLocations()
protected static int lookupCommand(java.lang.String actionKey)
actionKey
- the name of the actionprotected boolean handleCompleteCommand(BasicEditorPane editor)
editor
- The current editorprotected boolean handleUpCommand(BasicEditorPane editor)
protected boolean handleDownCommand(BasicEditorPane editor)
protected boolean handleLeftCommand(BasicEditorPane editor)
protected boolean handleRightCommand(BasicEditorPane editor)
protected boolean handlePageUpCommand(BasicEditorPane editor)
protected boolean handlePageDownCommand(BasicEditorPane editor)
protected boolean handleHomeCommand(BasicEditorPane editor)
protected boolean handleEndCommand(BasicEditorPane editor)
protected boolean handleCancelCommand(BasicEditorPane editor)
protected boolean handleInsightCommand(BasicEditorPane editor)
editor
- public void setUseSmartInsight(boolean useSmartInsight)
public boolean isUseSmartInsight()
protected InsightProvider getInsightProvider()
protected void setInsightProvider(InsightProvider insightProvider)