| java.lang.Object org.netbeans.editor.Formatter
All known Subclasses: org.netbeans.editor.ext.ExtFormatter,
Formatter | public class Formatter implements SettingsChangeListener(Code) | | Various services related to indentation and text formatting are located here.
Each kit can have different formatter so the first action should be getting
the right formatter for the given kit by calling
Formatter.getFormatter(kitClass).
author: Miloslav Metelka version: 1.00 |
Constructor Summary | |
public | Formatter(Class kitClass) Construct new formatter. |
Method Summary | |
public void | changeBlockIndent(BaseDocument doc, int startPos, int endPos, int shiftCnt) Increase/decrease indentation of the block of the code. | public void | changeRowIndent(BaseDocument doc, int pos, int newIndent) Change the indent of the given row. | public Writer | createWriter(Document doc, int offset, Writer writer) Creates a writer that formats text that is inserted into it. | public boolean | expandTabs() | public static synchronized Formatter | getFormatter(Class kitClass) | static String | getIndentString(int indent, boolean expandTabs, int tabSize) | public String | getIndentString(BaseDocument doc, int indent) | public String | getIndentString(int indent) Get the string that is appropriate for the requested indentation. | public Class | getKitClass() Get the kit-class for which this formatter is constructed. | public int | getShiftWidth() Get the width of one indentation level for non-BaseDocument documents.
The algorithm first checks whether there's a value for the
INDENT_SHIFT_WIDTH setting. | public int | getSpacesPerTab() Get the number of spaces that should be inserted into the document
instead of one typed tab. | public int | getTabSize() Get the number of spaces the TAB character ('\t') visually represents for
non-BaseDocument documents. | public int | indentLine(Document doc, int offset) Indents the current line. | public int | indentNewLine(Document doc, int offset) Inserts new line at given position and indents the new line with spaces. | public void | insertTabString(BaseDocument doc, int dotPos) Modify the line to move the text starting at dotPos one tab column to the
right. | public int | reformat(BaseDocument doc, int startOffset, int endOffset) Reformat a block of code. | public void | setExpandTabs(boolean expandTabs) | public static synchronized void | setFormatter(Class kitClass, Formatter formatter) Set the formatter for the given kit-class. | public void | setShiftWidth(int shiftWidth) Set the width of one indentation level for non-BaseDocument documents. | public void | setSpacesPerTab(int spacesPerTab) | public void | setTabSize(int tabSize) Set the number of spaces the TAB character ('\t') visually represents for
non-BaseDocument documents. | public void | settingsChange(SettingsChangeEvent evt) | public void | shiftLine(BaseDocument doc, int dotPos, boolean right) |
Formatter | public Formatter(Class kitClass)(Code) | | Construct new formatter.
Parameters: kitClass - the class of the kit for which this formatter is beingconstructed. |
changeBlockIndent | public void changeBlockIndent(BaseDocument doc, int startPos, int endPos, int shiftCnt) throws BadLocationException(Code) | | Increase/decrease indentation of the block of the code. Document is
atomically locked during the operation.
Parameters: doc - document to operate on Parameters: startPos - starting line position Parameters: endPos - ending line position Parameters: shiftCnt - positive/negative count of shiftwidths by which indentationshould be shifted right/left |
changeRowIndent | public void changeRowIndent(BaseDocument doc, int pos, int newIndent) throws BadLocationException(Code) | | Change the indent of the given row. Document is atomically locked during
this operation.
|
createWriter | public Writer createWriter(Document doc, int offset, Writer writer)(Code) | | Creates a writer that formats text that is inserted into it. The writer
should not modify the document but use the provided writer to write to.
Usually the underlaying writer will modify the document itself and
optionally it can remember the current position in document. That is why
the newly created writer should do no buffering.
The provided document and pos are only informational, should not be
modified but only used to find correct indentation strategy.
Parameters: doc - document Parameters: offset - position to begin inserts at Parameters: writer - writer to write to new writer that will format written text and pass it into thewriter |
expandTabs | public boolean expandTabs()(Code) | | Should the typed tabs be expanded to the spaces?
|
getFormatter | public static synchronized Formatter getFormatter(Class kitClass)(Code) | | Get the formatter for the given kit-class
|
getIndentString | static String getIndentString(int indent, boolean expandTabs, int tabSize)(Code) | | |
getIndentString | public String getIndentString(int indent)(Code) | | Get the string that is appropriate for the requested indentation. The
returned string respects the expandTabs() and the
getTabSize() and will contain either spaces only or fully or
partially tabs as necessary.
|
getKitClass | public Class getKitClass()(Code) | | Get the kit-class for which this formatter is constructed.
|
getShiftWidth | public int getShiftWidth()(Code) | | Get the width of one indentation level for non-BaseDocument documents.
The algorithm first checks whether there's a value for the
INDENT_SHIFT_WIDTH setting. If so it uses it, otherwise it uses
getSpacesPerTab()
See Also: setShiftWidth() See Also: getSpacesPerTab() |
getSpacesPerTab | public int getSpacesPerTab()(Code) | | Get the number of spaces that should be inserted into the document
instead of one typed tab.
|
getTabSize | public int getTabSize()(Code) | | Get the number of spaces the TAB character ('\t') visually represents for
non-BaseDocument documents. It shouldn't be used for BaseDocument based
documents. The reason for that is that the returned value reflects the
value of the setting for the kit class over which this formatter was
constructed. However it's possible that the kit class of the document
being formatted is different than the kit of the formatter. For example
java document could be formatted by html formatter. Therefore
BaseDocument.getTabSize() must be used for BaseDocuments
to reflect the document's own tabsize.
See Also: BaseDocument.getTabSize() |
indentLine | public int indentLine(Document doc, int offset)(Code) | | Indents the current line. Should not affect any other lines.
Parameters: doc - the document to work on Parameters: offset - the offset of a character on the line new offset of the original character |
indentNewLine | public int indentNewLine(Document doc, int offset)(Code) | | Inserts new line at given position and indents the new line with spaces.
Parameters: doc - the document to work on Parameters: offset - the offset of a character on the line new offset to place cursor to |
insertTabString | public void insertTabString(BaseDocument doc, int dotPos) throws BadLocationException(Code) | | Modify the line to move the text starting at dotPos one tab column to the
right. Whitespace preceeding dotPos may be replaced by a TAB character if
tabs expanding is on.
Parameters: doc - document to operate on Parameters: dotPos - insertion point |
reformat | public int reformat(BaseDocument doc, int startOffset, int endOffset) throws BadLocationException(Code) | | Reformat a block of code.
Parameters: doc - document to work with Parameters: startOffset - offset at which the formatting starts Parameters: endOffset - offset at which the formatting ends length of the reformatted code |
setExpandTabs | public void setExpandTabs(boolean expandTabs)(Code) | | |
setFormatter | public static synchronized void setFormatter(Class kitClass, Formatter formatter)(Code) | | Set the formatter for the given kit-class.
Parameters: kitClass - class of the kit for which the formatter is being assigned. Parameters: formatter - new formatter for the given kit |
setShiftWidth | public void setShiftWidth(int shiftWidth)(Code) | | Set the width of one indentation level for non-BaseDocument documents. It
doesn't affect BaseDocument based documents.
See Also: getShiftWidth() |
setSpacesPerTab | public void setSpacesPerTab(int spacesPerTab)(Code) | | |
setTabSize | public void setTabSize(int tabSize)(Code) | | Set the number of spaces the TAB character ('\t') visually represents for
non-BaseDocument documents. It doesn't affect BaseDocument based
documents.
See Also: getTabSize() See Also: BaseDocument.setTabSize() |
|
|