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

org.netbeans.spi.editor.typinghooks
Interface TypedTextInterceptor


public interface TypedTextInterceptor

An interceptor which is called when text is typed into 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 inserting text into a document. Typically, implementations of this interface will be called when processing KeyEvents that reach a default keymap action (ie. there is no entry in the editor's keymap for this particular KeyEvent).

Registration: TypedTextInterceptors can be plugged in the editor infrastructure by implementing the TypedTextInterceptor.Factory interface and registering it in MimeLookup under the appropriate mimetype (ie MimePath).

The instances created from the Factory will be reused for processing all keyboard input 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 TypedTextInterceptor 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 TypedTextInterceptor.Context
          The context class providing information about the edited document, its editor pane, insertion offset and text.
static interface TypedTextInterceptor.Factory
          The factory interface for registering TypedTextInterceptors in MimeLookup.
static class TypedTextInterceptor.MutableContext
          This context class allows to modify the insertion text and the caret position after the text is inserted into a document.
 
Method Summary
 void afterInsert(TypedTextInterceptor.Context context)
          This method is called after text is inserted into a document and its editor's caret is adjusted.
 boolean beforeInsert(TypedTextInterceptor.Context context)
          This method is called before any text is inserted into a document.
 void cancelled(TypedTextInterceptor.Context context)
          This method is called when the normal processing is terminated by some interceptor's beforeInsert method.
 void insert(TypedTextInterceptor.MutableContext context)
          This method is called immediately before the text is inserted into a document.
 

Method Detail

beforeInsert

boolean beforeInsert(TypedTextInterceptor.Context context)
                     throws BadLocationException
This method is called before any text is inserted into a document. The context object passed to the method provides access to the editor pane and the edited document, but does not allow to modify the text that will be inserted.

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 intercetors that have already had their beforeInsert 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.

insert

void insert(TypedTextInterceptor.MutableContext context)
            throws BadLocationException
This method is called immediately before the text is inserted into a document. Implementors can use special MutableContext to modify the text that will be inserted into a document. The first interceptor that mutates the insertion text will win and the method will not be called on the rest of the queued interceptors. The interceptors are not supposed to modify the document directly.

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 insertion text.
Throws:
BadLocationException - If the processing fails.

afterInsert

void afterInsert(TypedTextInterceptor.Context context)
                 throws BadLocationException
This method is called after text is inserted into 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 TypedTextInterceptor.Context.getText() method will return text that was inserted into the document at the end of the text-insertion 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(TypedTextInterceptor.Context context)
This method is called when the normal processing is terminated by some interceptor's beforeInsert method. Please note that this method will not be called if the beforeInsert method was not called.

Parameters:
context - The context object used for calling the beforeInsert 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.