站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

ExtFormatter (Editor Library) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib/1 1.14.0 3

org.netbeans.editor.ext
Class ExtFormatter

java.lang.Object
  extended by org.netbeans.editor.Formatter
      extended by org.netbeans.editor.ext.ExtFormatter
All Implemented Interfaces:
EventListener, FormatLayer, SettingsChangeListener
Direct Known Subclasses:
ExtFormatter.Simple

public class ExtFormatter
extends Formatter
implements FormatLayer

Unlike the formatter class, the ExtFormatter concentrates on providing a support for the real formatting process. Each formatter (there's only one per each kit) can contain one or more formatting layers. The FormatLayer operates over the chain of the tokens provided by the FormatWriter. The formatting consist of changing the chain of the tokens until it gets the desired look. Each formatting requires a separate instance of FormatWriter but the same set of format-layers is used for all the format-writers. Although the base implementation is synchronized so that only one format-writer at time is processed by each format-writer, in general it's not necessary. The basic implementation processes all the format-layers sequentialy in the order they were added to the formatter but this can be redefined. The getSettingValue enables to get the up-to-date value for the particular setting.


Nested Class Summary
static class ExtFormatter.Simple
          Simple formatter
 
Constructor Summary
ExtFormatter(Class kitClass)
           
 
Method Summary
protected  boolean acceptSyntax(Syntax syntax)
          Whether the formatter accepts the given syntax that will be used for parsing the text passed to the FormatWriter.
 void addFormatLayer(FormatLayer layer)
          Add the new format layer to the layer hierarchy.
 Writer createWriter(Document doc, int offset, Writer writer)
          Create the indentation writer.
 void format(FormatWriter fw)
          Called by format-writer to do the format
 Iterator formatLayerIterator()
          Get the iterator over the format layers.
protected  int getEOLOffset(BaseDocument bdoc, int offset)
          Returns offset of EOL for the white line
 String getName()
          Return the name of this formatter.
 int[] getReformatBlock(JTextComponent target, String typedText)
          Get the block to be reformatted after keystroke was pressed.
 Object getSettingValue(String settingName)
          Get the value of the given setting.
protected  boolean hasTextBefore(JTextComponent target, String typedText)
           
 int indentLine(Document doc, int offset)
          Indents the current line.
 int indentNewLine(Document doc, int offset)
          Inserts new line at given position and indents the new line with spaces.
protected  void initFormatLayers()
          Add the desired format-layers to the formatter
 boolean isSimple()
          Whether do no formatting at all.
 int reformat(BaseDocument doc, int startOffset, int endOffset)
          Fix of #5620 - same method exists in Formatter (predecessor
 Writer reformat(BaseDocument doc, int startOffset, int endOffset, boolean indentOnly)
          Reformat a block of code.
 void removeFormatLayer(String layerName)
          Remove the first layer which has the same name as the given one.
 boolean replaceFormatLayer(String layerName, FormatLayer layer)
          Replace the format-layer with the layerName with the the given layer.
 void setSettingValue(String settingName, Object settingValue)
          This method allows to set a custom value to a setting thus overriding the value retrieved from the Settings.
 void settingsChange(SettingsChangeEvent evt)
           
 
Methods inherited from class org.netbeans.editor.Formatter
changeBlockIndent, changeRowIndent, expandTabs, getFormatter, getIndentString, getIndentString, getKitClass, getShiftWidth, getSpacesPerTab, getTabSize, insertTabString, setExpandTabs, setFormatter, setShiftWidth, setSpacesPerTab, setTabSize, shiftLine
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExtFormatter

public ExtFormatter(Class kitClass)
Method Detail

initFormatLayers

protected void initFormatLayers()
Add the desired format-layers to the formatter


getName

public String getName()
Return the name of this formatter. By default it's the name of the kit-class for which it's created without the package name.

Specified by:
getName in interface FormatLayer

settingsChange

public void settingsChange(SettingsChangeEvent evt)
Specified by:
settingsChange in interface SettingsChangeListener
Overrides:
settingsChange in class Formatter

getSettingValue

public Object getSettingValue(String settingName)
Get the value of the given setting.

Parameters:
settingName - name of the setting to get.

setSettingValue

public void setSettingValue(String settingName,
                            Object settingValue)
This method allows to set a custom value to a setting thus overriding the value retrieved from the Settings. Once done the value is no longer synchronized with the changes in Settings for the particular setting. There's a map holding the names of all the custom settings.


addFormatLayer

public void addFormatLayer(FormatLayer layer)
Add the new format layer to the layer hierarchy.


replaceFormatLayer

public boolean replaceFormatLayer(String layerName,
                                  FormatLayer layer)
Replace the format-layer with the layerName with the the given layer. If there's no such layer with the same name, the layer is not replaced and false is returned.


removeFormatLayer

public void removeFormatLayer(String layerName)
Remove the first layer which has the same name as the given one.


formatLayerIterator

public Iterator formatLayerIterator()
Get the iterator over the format layers.


isSimple

public boolean isSimple()
Whether do no formatting at all. If this method returns true, the FormatWriter will simply write its input into the underlying writer.


format

public void format(FormatWriter fw)
Called by format-writer to do the format

Specified by:
format in interface FormatLayer
Parameters:
fw - format-writer to be formatted. The format-layer will usually create the format-support as an abstraction level over the format-layer.

reformat

public Writer reformat(BaseDocument doc,
                       int startOffset,
                       int endOffset,
                       boolean indentOnly)
                throws BadLocationException,
                       IOException
Reformat a block of code.

Parameters:
doc - document to work with
startOffset - position at which the formatting starts
endOffset - position at which the formatting ends
indentOnly - whether just the indentation should be changed or regular formatting should be performed.
Returns:
formatting writer. The text was already reformatted but the writer can contain useful information.
Throws:
BadLocationException
IOException

reformat

public int reformat(BaseDocument doc,
                    int startOffset,
                    int endOffset)
             throws BadLocationException
Fix of #5620 - same method exists in Formatter (predecessor

Overrides:
reformat in class Formatter
Parameters:
doc - document to work with
startOffset - offset at which the formatting starts
endOffset - offset at which the formatting ends
Returns:
length of the reformatted code
Throws:
BadLocationException

getReformatBlock

public int[] getReformatBlock(JTextComponent target,
                              String typedText)
Get the block to be reformatted after keystroke was pressed.

Parameters:
target - component to which the text was typed. Caaret position can be checked etc.
typedText - text (usually just one character) that the user has typed.
Returns:
block of the code to be reformatted or null if nothing should reformatted. It can return block containing just one character. The caller usually expands even one character to the whole line because less than the whole line usually doesn't provide enough possibilities for formatting.
See Also:
ExtKit.ExtDefaultKeyTypedAction.checkIndentHotChars()

hasTextBefore

protected boolean hasTextBefore(JTextComponent target,
                                String typedText)

createWriter

public Writer createWriter(Document doc,
                           int offset,
                           Writer writer)
Create the indentation writer.

Overrides:
createWriter in class Formatter
Parameters:
doc - document
offset - position to begin inserts at
writer - writer to write to
Returns:
new writer that will format written text and pass it into the writer

indentLine

public int indentLine(Document doc,
                      int offset)
Indents the current line. Should not affect any other lines.

Overrides:
indentLine in class Formatter
Parameters:
doc - the document to work on
offset - the offset of a character on the line
Returns:
new offset of the original character

getEOLOffset

protected int getEOLOffset(BaseDocument bdoc,
                           int offset)
                    throws BadLocationException
Returns offset of EOL for the white line

Throws:
BadLocationException

indentNewLine

public int indentNewLine(Document doc,
                         int offset)
Inserts new line at given position and indents the new line with spaces.

Overrides:
indentNewLine in class Formatter
Parameters:
doc - the document to work on
offset - the offset of a character on the line
Returns:
new offset to place cursor to

acceptSyntax

protected boolean acceptSyntax(Syntax syntax)
Whether the formatter accepts the given syntax that will be used for parsing the text passed to the FormatWriter.

Parameters:
syntax - syntax to be tested.
Returns:
true whether this formatter is able to process the tokens created by the syntax or false otherwise.

org.netbeans.modules.editor.lib/1 1.14.0 3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.