public interface DeletedTextInterceptor
KeyEvent
s that reach the default editor actions bound to
VK_DELETE
and VK_BACK_SPACE
events.
Registration: DeletedTextInterceptor
s can be plugged in the editor infrastructure
by implementing the DeletedTextInterceptor.Factory
interface and registering it in MimeLookup
under the appropriate mimetype (ie. MimePath
).
The instances created from the Factory
will be reused for processing
the relevant key events received by all documents of the same mime type, which the interceptor
instances were registered for (including documents that contain embedded sections
of that mime type). As described in the general concepts of Typing Hooks SPI
the interceptors are guaranteed to be called in AWT thread only, which means that
they should not need any internal synchronization model.
Processing rules: If there are multiple instances of DeletedTextInterceptor
registered
for the same mime type the infrastructure will queue them up in their registration
order and when processing an event it will call them all until the processing is done
or terminated.
The interceptor has several methods that are called at different stages of the key typed event processing. When processing an event the infrastructure will call the methods in the order as they are listed below. Moreover if there are multiple interceptors queued up for processing an event each method is first called on all the queued interceptors before moving on to the next stage and calling next method.
DeletedTextInterceptor.beforeRemove(Context)
- It's called before any text is removed
from a document. No document lock is held when this method is called. The method
is not allowed to modify the document (and it's not supposed to do any tricks to
break this rule). An interceptor can stop further processing of the event by returning
true
from this method. If it does so, no other interceptors'
beforeRemove
method will be called and the processing will be terminated
without removing any text.
DeletedTextInterceptor.remove(Context)
- This method is called during the text
removal stage immediately after the text was removed from a document. At this
time the document is already write locked and the interceptors can modify it
if they need to.
DeletedTextInterceptor.afterRemove(Context)
- This is the last method in the processing
chain and it will be called when the text has already been removed from the document.
Similarly as in beforeRemove
the document is not locked when
this method is called.
DeletedTextInterceptor.cancelled(Context)
- This is an additional method that will be called
when the processing is terminated in the before-removal stage (ie. by an interceptor
returning true
from its beforeRemove
method).
The infrastructure will only call this method on interceptors that have already
had their beforeRemove
method called, but not on those that
have not yet been called at all.
Errors recovery: If an exception is thrown from any of the methods when calling an interceptor the infrastructure will catch it and log it, but it will not stop further processing. The infrastructure may blacklist the offending interceptor and exclude it from processing future events.
Modifier and Type | Interface and Description |
---|---|
static class |
DeletedTextInterceptor.Context
The context class providing information about the edited document, its
editor pane and the offset where the delete key event occurred.
|
static interface |
DeletedTextInterceptor.Factory
The factory interface for registering
DeletedTextInterceptor s
in MimeLookup . |
Modifier and Type | Method and Description |
---|---|
void |
afterRemove(DeletedTextInterceptor.Context context)
This method is called after text is removed from a document and its editor's
caret is adjusted.
|
boolean |
beforeRemove(DeletedTextInterceptor.Context context)
This method is called before any text is removed from a document.
|
void |
cancelled(DeletedTextInterceptor.Context context)
This method is called when the normal processing is terminated by some
interceptor's
beforeRemove method. |
void |
remove(DeletedTextInterceptor.Context context)
This method is called immediately after the text is removed from a document.
|
boolean beforeRemove(DeletedTextInterceptor.Context context) throws BadLocationException
This method can be used for stopping further processing of the current
key typed event. If this method returns true
the processing will
be terminated and DeletedTextInterceptor.cancelled(Context)
will be called for all the interceptors
that have already had their beforeRemove
method called (including
the one that terminated the processing). The rest of the interceptors waiting
in the queue will not be called at all.
Locking: When this method is called the document is not locked by the infrastructure.
context
- The context object providing information necessary for processing
the event.true
the further processing will be stopped. Normally
the method should return false
.BadLocationException
- Since the document is not locked prior calling this
method the processing may fail when working with stale context data.void remove(DeletedTextInterceptor.Context context) throws BadLocationException
Context
object
passed in this method. The document is write-locked.
Locking: When this method is called the infrastructure has already write locked the document.
context
- The context object providing information necessary for processing
the event and allowing to modify the edited document.BadLocationException
- If the processing fails.void afterRemove(DeletedTextInterceptor.Context context) throws BadLocationException
Locking: When this method is called the document is not locked by the infrastructure.
context
- The context object providing information necessary for processing
the event. The DeletedTextInterceptor.Context.getText()
method will return text that was
removed from the document at the beginning of the text-removal stage.BadLocationException
- Since the document is not locked prior calling this
method the processing may fail when working with stale context data.void cancelled(DeletedTextInterceptor.Context context)
beforeRemove
method. Please note that this
method will not be called if the beforeRemove
method was not
called.context
- The context object used for calling the beforeRemove
method.