| java.lang.Object java.io.Writer org.netbeans.editor.ext.FormatWriter
FormatWriter | final public class FormatWriter extends Writer (Code) | | Formatting writter accepts the input-text, formats it and writes the output
to the underlying writer. The data written to the writer are immediately
splitted into token-items and the chain of token-items is created from them.
Then the writer then waits for the flush() or close() method call which then
makes the real formatting. The formatting is done through going through the
format-layers registered in ExtFormatter and asking them for
formatting. These layers go through the chain and possibly add or remove the
tokens as necessary. The good thing is that the layers can ask the tokens
before those written to the writer. In that case they will get the tokens
from the document at point the formatting should be done. The advantage is
that the chain is compact so the border between the tokens written to the
writer and those that come from the document is invisible.
author: Miloslav Metelka version: 1.00 |
Inner Class :interface ExtTokenItem extends TokenItem | |
Field Summary | |
final public static boolean | debug | final public static boolean | debugModify |
Constructor Summary | |
| FormatWriter(ExtFormatter formatter, Document doc, int offset, Writer underWriter, boolean indentOnly) The format writers should not be extended to enable operating of the
layers on all the writers even for different languages. |
Method Summary | |
public boolean | canInsertToken(TokenItem beforeToken) Check whether a new token can be inserted into the chain before the given
token-item. | public boolean | canModifyToken(TokenItem token, int offset) Whether the token can be modified either by insertion or removal at the
given offset. | public boolean | canRemoveToken(TokenItem token) Whether the token-item can be removed. | public boolean | canSplitEnd(TokenItem token, int endLength) | public boolean | canSplitStart(TokenItem token, int startLength) | public String | chainToString(TokenItem token) | public String | chainToString(TokenItem token, int maxDocumentTokens) Debug the current state of the chain.
Parameters: token - mark this token as current one. | public void | checkChain() Check the chain whether it's OK. | public void | close() | public TokenItem | findFirstToken(TokenItem token) Find the first token in the chain. | public TokenItem | findNonEmptyToken(TokenItem token, boolean backward) Check whether the given token has empty text and if so start searching
for token with non-empty text in the given direction. | public void | flush() | final public Document | getDocument() | public FormatTokenPosition | getFormatStartPosition() Get the first token that should be formatted. | final public ExtFormatter | getFormatter() | public int | getIndentShift() | public TokenItem | getLastToken() Get the last token in the chain. | final public int | getOffset() | public FormatTokenPosition | getPosition(TokenItem token, int offset, Position.Bias bias) Get the token-position that corresponds to the given offset inside the
given token. | public FormatTokenPosition | getTextStartPosition() Get the first position that doesn't belong to the document. | public void | insertString(TokenItem token, int offset, String text) Insert the text at the offset inside the given token. | public TokenItem | insertToken(TokenItem beforeToken, TokenID tokenID, TokenContextPath tokenContextPath, String tokenImage) Create a new token-item and insert it before the token-item given as
parameter. | public boolean | isAfter(TokenItem testedToken, TokenItem afterToken) It checks whether the tested token is after some other token in the
chain.
Parameters: testedToken - token to test (whether it's after afterToken or not) Parameters: afterToken - token to be compared to the testedToken true whether the testedToken is after afterToken or not. | public boolean | isAfter(FormatTokenPosition testedPosition, FormatTokenPosition afterPosition) Checks whether the tested position is after some other position. | public boolean | isChainModified() Return the flag that is set automatically if the new removal or insertion
into chain occurs. | public boolean | isChainStartPosition(FormatTokenPosition pos) Check whether this is the first position in the chain of tokens. | final public boolean | isIndentOnly() Whether the purpose of this writer is to find the proper indentation
instead of formatting the tokens. | public boolean | isRestartFormat() Return whether the layer requested to restart the format. | public void | remove(TokenItem token, int offset, int length) Remove the length of the characters at the given offset inside the given
token. | public void | removeToken(TokenItem token) Remove the token-item from the chain. | public void | setChainModified(boolean chainModified) | public void | setIndentOnly(boolean indentOnly) Sets whether the purpose of this writer is to find the proper indentation
instead of formatting the tokens. | public void | setIndentShift(int indentShift) | void | setReformatting(boolean reformatting) | public void | setRestartFormat(boolean restartFormat) | public TokenItem | splitEnd(TokenItem token, int endLength, TokenID newTokenID, TokenContextPath newTokenContextPath) Create the additional token from the text at the end of the given token. | public TokenItem | splitStart(TokenItem token, int startLength, TokenID newTokenID, TokenContextPath newTokenContextPath) Create the additional token from the text at the start of the given
token. | public void | write(char[] cbuf, int off, int len) | public synchronized void | write(char[] cbuf, int off, int len, int[] saveOffsets, Position.Bias[] saveBiases) |
debug | final public static boolean debug(Code) | | Whether debug messages should be displayed
|
debugModify | final public static boolean debugModify(Code) | | Whether debug messages should be displayed
|
FormatWriter | FormatWriter(ExtFormatter formatter, Document doc, int offset, Writer underWriter, boolean indentOnly)(Code) | | The format writers should not be extended to enable operating of the
layers on all the writers even for different languages.
Parameters: underWriter - underlying writer |
canInsertToken | public boolean canInsertToken(TokenItem beforeToken)(Code) | | Check whether a new token can be inserted into the chain before the given
token-item. The token can be inserted only into the tokens that come from
the text that was written to the format-writer but was not yet written to
the underlying writer.
Parameters: beforeToken - token-item before which the new token-item is about to beinserted. It can be null to append the new token to the end ofthe chain. |
canModifyToken | public boolean canModifyToken(TokenItem token, int offset)(Code) | | Whether the token can be modified either by insertion or removal at the
given offset.
|
canRemoveToken | public boolean canRemoveToken(TokenItem token)(Code) | | Whether the token-item can be removed. It can be removed only in case it
doesn't come from the document's text and it wasn't yet written to the
underlying writer.
|
canSplitEnd | public boolean canSplitEnd(TokenItem token, int endLength)(Code) | | |
canSplitStart | public boolean canSplitStart(TokenItem token, int startLength)(Code) | | |
chainToString | public String chainToString(TokenItem token, int maxDocumentTokens)(Code) | | Debug the current state of the chain.
Parameters: token - mark this token as current one. It can be null. Parameters: maxDocumentTokens - how many document tokens should be shown. |
checkChain | public void checkChain()(Code) | | Check the chain whether it's OK.
|
findFirstToken | public TokenItem findFirstToken(TokenItem token)(Code) | | Find the first token in the chain. It should be used only when necessary
and possibly in situations when the start of the chain was already
reached by other methods, because this method will extend the chain till
the begining of the document.
Parameters: token - token from which the search for previous tokens will start. Itcan be null in which case the last document token or lasttoken are attempted instead. |
findNonEmptyToken | public TokenItem findNonEmptyToken(TokenItem token, boolean backward)(Code) | | Check whether the given token has empty text and if so start searching
for token with non-empty text in the given direction. If there's no
non-empty token in the given direction the method returns null.
Parameters: token - token to start to search from. If it has zero length, thesearch for non-empty token is performed in the givendirection. |
getDocument | final public Document getDocument()(Code) | | Get the document being formatted
|
getFormatStartPosition | public FormatTokenPosition getFormatStartPosition()(Code) | | Get the first token that should be formatted. This can change as the
format-layers continue to change the token-chain. If the caller calls
flush(), this method will return null. After additional writing to the
writer, new tokens will be added and the first one of them will become
the first token to be formatted.
the first token that should be formatted. It can be null in casesome layer removes all the tokens that should be formatted. Mostof the layers probably do nothing in case this value is null. |
getIndentShift | public int getIndentShift()(Code) | | |
getLastToken | public TokenItem getLastToken()(Code) | | Get the last token in the chain. It can be null if there are no tokens in
the chain.
|
getOffset | final public int getOffset()(Code) | | Get the starting offset of the formatting
|
getPosition | public FormatTokenPosition getPosition(TokenItem token, int offset, Position.Bias bias)(Code) | | Get the token-position that corresponds to the given offset inside the
given token. The returned position is persistent and if the token is
removed from chain the position is assigned to the end of the previous
token or to the begining of the next token if there's no previous token.
Parameters: token - token in which the position is created. Parameters: offset - inside the token at which the position will be created. Parameters: bias - forward or backward bias |
getTextStartPosition | public FormatTokenPosition getTextStartPosition()(Code) | | Get the first position that doesn't belong to the document. Initially
it's the same as the getFormatStartPosition() but if there are
multiple flushes performed on the writer they will differ.
|
insertString | public void insertString(TokenItem token, int offset, String text)(Code) | | Insert the text at the offset inside the given token. All the
token-positions at and after the offset will be increased by
text.length(). IllegalArgumentException is thrown
if offset is wrong.
Parameters: token - token in which the text is inserted. Parameters: offset - offset at which the text will be inserted. Parameters: text - text that will be inserted at the offset. |
insertToken | public TokenItem insertToken(TokenItem beforeToken, TokenID tokenID, TokenContextPath tokenContextPath, String tokenImage)(Code) | | Create a new token-item and insert it before the token-item given as
parameter. The canInsertToken() should be called first to
determine whether the given token can be inserted into the chain or not.
The token can be inserted only into the tokens that come from the text
that was written to the format-writer but was not yet written to the
underlying writer.
Parameters: beforeToken - token-item before which the new token-item is about to beinserted. It can be null to append the new token to the end ofthe chain. Parameters: tokenID - token-id of the new token-item Parameters: tokenContextPath - token-context-path of the new token-item Parameters: tokenImage - image of the new token-item |
isAfter | public boolean isAfter(TokenItem testedToken, TokenItem afterToken)(Code) | | It checks whether the tested token is after some other token in the
chain.
Parameters: testedToken - token to test (whether it's after afterToken or not) Parameters: afterToken - token to be compared to the testedToken true whether the testedToken is after afterToken or not. Returnsfalse if the token == afterToken or not or if token is before theafterToken or not. |
isChainModified | public boolean isChainModified()(Code) | | Return the flag that is set automatically if the new removal or insertion
into chain occurs. The formatter can use this flag to detect whether a
particular format-layer changed the chain or not.
|
isChainStartPosition | public boolean isChainStartPosition(FormatTokenPosition pos)(Code) | | Check whether this is the first position in the chain of tokens.
|
isIndentOnly | final public boolean isIndentOnly()(Code) | | Whether the purpose of this writer is to find the proper indentation
instead of formatting the tokens. It allows to have a modified formatting
behavior for the cases when user presses Enter or a key that causes
immediate reformatting of the line.
|
isRestartFormat | public boolean isRestartFormat()(Code) | | Return whether the layer requested to restart the format. The formatter
can use this flag to restart the formatting from the first layer.
|
remove | public void remove(TokenItem token, int offset, int length)(Code) | | Remove the length of the characters at the given offset inside the given
token. IllegalArgumentException is thrown if offset or length
are wrong.
Parameters: token - token in which the text is removed. Parameters: offset - offset at which the text will be removed. Parameters: length - length of the removed text. |
removeToken | public void removeToken(TokenItem token)(Code) | | Remove the token-item from the chain. It can be removed only in case it
doesn't come from the document's text and it wasn't yet written to the
underlying writer.
|
setChainModified | public void setChainModified(boolean chainModified)(Code) | | |
setIndentOnly | public void setIndentOnly(boolean indentOnly)(Code) | | Sets whether the purpose of this writer is to find the proper indentation
instead of formatting the tokens.
See Also: isIndentOnly() |
setIndentShift | public void setIndentShift(int indentShift)(Code) | | |
setReformatting | void setReformatting(boolean reformatting)(Code) | | Added to fix #5620
|
setRestartFormat | public void setRestartFormat(boolean restartFormat)(Code) | | |
splitEnd | public TokenItem splitEnd(TokenItem token, int endLength, TokenID newTokenID, TokenContextPath newTokenContextPath)(Code) | | Create the additional token from the text at the end of the given token.
Parameters: token - token being split. Parameters: endLength - length of the text at the end of the token for which theadditional token will be created. Parameters: tokenID - token-id that will be assigned to the new token Parameters: tokenContextPath - token-context-path that will be assigned to the new token |
splitStart | public TokenItem splitStart(TokenItem token, int startLength, TokenID newTokenID, TokenContextPath newTokenContextPath)(Code) | | Create the additional token from the text at the start of the given
token.
Parameters: token - token being split. Parameters: startLength - length of the text at the begining of the token for which theadditional token will be created. Parameters: tokenID - token-id that will be assigned to the new token Parameters: tokenContextPath - token-context-path that will be assigned to the new token |
|
|