org.netbeans.modules.editor.indent/2 1.28

org.netbeans.modules.editor.indent.spi.support
Class AutomatedIndenting

java.lang.Object
  extended by org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting

public final class AutomatedIndenting
extends Object

This class contains factory methods for typing interceptor implementations that can be used for automated text indenting.

The interceptors provided by this class are implementations of Typing Hooks SPI interfaces that can be registered in MimeLookup. Typically there are two factory methods for each interceptor implementation. One factory method creates the implementated interceptor and is suitable for direct use from java code. The other factory method creates a factory object that can be registred in an XML layer as an .instance file.

Since:
1.11

Constructor Summary
AutomatedIndenting()
           
 
Method Summary
static TypedTextInterceptor.Factory createHotCharsIndenter(Map<Object,Object> fileAttributes)
          This is a version of createHotCharsIndenter(java.util.regex.Pattern[]) method suitable for XML layers registration.
static TypedTextInterceptor createHotCharsIndenter(Pattern... linePatterns)
          Creates TypedTextInterceptor that automatically indents a line depending on text typed on that line.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AutomatedIndenting

public AutomatedIndenting()
Method Detail

createHotCharsIndenter

public static TypedTextInterceptor createHotCharsIndenter(Pattern... linePatterns)
Creates TypedTextInterceptor that automatically indents a line depending on text typed on that line.

The text patterns recognized by the intercetor are defined in form of regular expressions passed to this method. The interceptor will match all text before the caret on the line where a user is typing (including the last typed character) against the regular expression patterns. If the text matches at least one pattern the interceptor will reindent the line by calling Indent.reindent(int) method.

Parameters:
linePatterns - The regular expressions that will be used for matching text typed on a line. Any matching pattern will trigger the line reindentation.
Returns:
The interceptor that checks text typed on a line and reindents the line if it matches any of the linePatterns.
Since:
1.11

createHotCharsIndenter

public static TypedTextInterceptor.Factory createHotCharsIndenter(Map<Object,Object> fileAttributes)
This is a version of createHotCharsIndenter(java.util.regex.Pattern[]) method suitable for XML layers registration.

Here is an example of an XML layer registration done for text/x-java mime type. The registered interceptor will indent any line that contains whitespace followed by 'else'. The ending 'e' character is the last character typed on the line.

 <folder name="Editors">
  <folder name="text">
   <folder name="x-java">
    <file name="org-something-AutoIndenter.instance">
     <attr name="instanceOf" stringvalue="org.netbeans.spi.editor.typinghooks.TypedTextInterceptor$Factory"/>
     <attr name="instanceCreate"
              methodvalue="org.netbeans.modules.editor.indent.spi.support.AutomatedIndenting.createHotCharsIndenter"/>
     <attr name="regex1" stringvalue="\s*else"/>
    </file>
   </folder>
  </folder>
 </folder>
 

Parameters:
fileAttributes - The map of FileObject attributes. This method will recognize any attributes, which name starts with regex and will try to interpret their value as a regular expression. These regular expressions will then be used as linePatterns when calling createHotCharsIndenter(Pattern...) method.
Returns:
The interceptor factory that will provide a regular expressions based automated indenter returned from the createHotCharsIndenter(java.util.regex.Pattern[]) method. The list of line patterns will be recovered from the fileAttributes.
Since:
1.11

org.netbeans.modules.editor.indent/2 1.28

Built on May 22 2012.  |  Portions Copyright 1997-2012 Oracle. All rights reserved.