org.netbeans.modules.editor.lib2/1 1.43.1 10

org.netbeans.spi.editor.typinghooks
Interface DeletedTextInterceptor


public interface DeletedTextInterceptor

An interceptor which is called when user deletes text from a document. You should implement this interface if you want to hook in the keyboard input processing done in the editor infrastructure that would normally result in removing text from a document. Typically, implementations of this interface will be called when processing KeyEvents that reach the default editor actions bound to VK_DELETE and VK_BACK_SPACE events.

Registration: DeletedTextInterceptors 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.

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.

Since:
1.31

Nested Class Summary
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 DeletedTextInterceptors in MimeLookup.
 
Method Summary
 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.
 

Method Detail

beforeRemove

boolean beforeRemove(DeletedTextInterceptor.Context context)
                     throws BadLocationException
This method is called before any text is removed from a document. The context object passed to the method provides access to the document and its editor pane. The interceptors are not allowed to modify the document in this method.

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 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.

Parameters:
context - The context object providing information necessary for processing the event.
Returns:
If true the further processing will be stopped. Normally the method should return false.
Throws:
BadLocationException - Since the document is not locked prior calling this method the processing may fail when working with stale context data.

remove

void remove(DeletedTextInterceptor.Context context)
            throws BadLocationException
This method is called immediately after the text is removed from a document. Implementors can modify the document as they need. The document and all the other useful information is accessible from the 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.

Parameters:
context - The context object providing information necessary for processing the event and allowing to modify the edited document.
Throws:
BadLocationException - If the processing fails.

afterRemove

void afterRemove(DeletedTextInterceptor.Context context)
                 throws BadLocationException
This method is called after text is removed from a document and its editor's caret is adjusted.

Locking: When this method is called the document is not locked by the infrastructure.

Parameters:
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.
Throws:
BadLocationException - Since the document is not locked prior calling this method the processing may fail when working with stale context data.

cancelled

void cancelled(DeletedTextInterceptor.Context context)
This method is called when the normal processing is terminated by some interceptor's beforeRemove method. Please note that this method will not be called if the beforeRemove method was not called.

Parameters:
context - The context object used for calling the beforeRemove method.

org.netbeans.modules.editor.lib2/1 1.43.1 10

Built on December 5 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.