org.netbeans.modules.editor.lib/1 1.43.0 9

org.netbeans.editor
Class Formatter

java.lang.Object
  extended by org.netbeans.editor.Formatter
Direct Known Subclasses:
ExtFormatter

Deprecated. Please use Editor Indentation API instead, for details see Editor Indentation.

public class Formatter
extends Object

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).


Constructor Summary
Formatter(Class kitClass)
          Deprecated. Construct new formatter.
 
Method Summary
 void changeBlockIndent(BaseDocument doc, int startPos, int endPos, int shiftCnt)
          Deprecated. Increase/decrease indentation of the block of the code.
 void changeRowIndent(BaseDocument doc, int pos, int newIndent)
          Deprecated. Change the indent of the given row.
 Writer createWriter(Document doc, int offset, Writer writer)
          Deprecated. Creates a writer that formats text that is inserted into it.
 boolean expandTabs()
          Deprecated. Should the typed tabs be expanded to the spaces?
static Formatter getFormatter(Class kitClass)
          Deprecated. Use of editor kit's implementation classes is deprecated in favor of mime types.
static Formatter getFormatter(String mimeType)
          Deprecated. Use Editor Indentation API.
 String getIndentString(BaseDocument doc, int indent)
          Deprecated.  
 String getIndentString(int indent)
          Deprecated. Get the string that is appropriate for the requested indentation.
 Class getKitClass()
          Deprecated. Get the kit-class for which this formatter is constructed.
 int getShiftWidth()
          Deprecated. Get the width of one indentation level for non-BaseDocument documents.
 int getSpacesPerTab()
          Deprecated. Get the number of spaces that should be inserted into the document instead of one typed tab.
 int getTabSize()
          Deprecated. Get the number of spaces the TAB character ('\t') visually represents for non-BaseDocument documents.
 int indentLine(Document doc, int offset)
          Deprecated. Indents the current line.
 void indentLock()
          Deprecated. Formatter clients should call this method before acquiring of the document's write lock and using of the indentLine(Document,int) and indentNewLine(Document,int) methods.
 int indentNewLine(Document doc, int offset)
          Deprecated. Inserts new line at given position and indents the new line with spaces.
 void indentUnlock()
          Deprecated. Formatter clients should call this method after releasing of the document's write lock as a counterpart of indentLock().
 void insertTabString(BaseDocument doc, int dotPos)
          Deprecated. Modify the line to move the text starting at dotPos one tab column to the right.
 int reformat(BaseDocument doc, int startOffset, int endOffset)
          Deprecated. Reformat a block of code.
 void reformatLock()
          Deprecated. Formatter clients should call this method before acquiring of the document's write lock before using of reformat(BaseDocument,int,int) method.
 void reformatUnlock()
          Deprecated. Formatter clients should call this method after releasing of the document's write lock as a counterpart of reformatLock().
 void setExpandTabs(boolean expandTabs)
          Deprecated.  
static void setFormatter(Class kitClass, Formatter formatter)
          Deprecated. Use Editor Indentation API.
 void setShiftWidth(int shiftWidth)
          Deprecated. Set the width of one indentation level for non-BaseDocument documents.
 void setSpacesPerTab(int spacesPerTab)
          Deprecated.  
 void setTabSize(int tabSize)
          Deprecated. Set the number of spaces the TAB character ('\t') visually represents for non-BaseDocument documents.
 void shiftLine(BaseDocument doc, int dotPos, boolean right)
          Deprecated. Shift line either left or right
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Formatter

public Formatter(Class kitClass)
Deprecated. 
Construct new formatter.

Parameters:
kitClass - the class of the kit for which this formatter is being constructed.
Method Detail

getFormatter

public static Formatter getFormatter(Class kitClass)
Deprecated. Use of editor kit's implementation classes is deprecated in favor of mime types.

Gets Formatter implementation for given editor kit's implementation class.

Parameters:
kitClass - The editor kit's implementation class to get the Formatter for.
Returns:
Formatter implementation created by the editor kit.

getFormatter

public static Formatter getFormatter(String mimeType)
Deprecated. Use Editor Indentation API.

Gets Formatter implementation for given mime type.

Parameters:
mimeType - The mime type to get the Formatter for.
Returns:
Formatter implementation created by the mime type's editor kit.
Since:
1.18

setFormatter

public static void setFormatter(Class kitClass,
                                Formatter formatter)
Deprecated. Use Editor Indentation API.

Sets the formatter for the given kit-class.

Parameters:
kitClass - class of the kit for which the formatter is being assigned.
formatter - new formatter for the given kit

getKitClass

public Class getKitClass()
Deprecated. 
Get the kit-class for which this formatter is constructed.


getTabSize

public int getTabSize()
Deprecated. 
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()

setTabSize

public void setTabSize(int tabSize)
Deprecated. 
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(), BaseDocument.setTabSize()

getShiftWidth

public int getShiftWidth()
Deprecated. 
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(), getSpacesPerTab()

setShiftWidth

public void setShiftWidth(int shiftWidth)
Deprecated. 
Set the width of one indentation level for non-BaseDocument documents. It doesn't affect BaseDocument based documents.

See Also:
getShiftWidth()

expandTabs

public boolean expandTabs()
Deprecated. 
Should the typed tabs be expanded to the spaces?


setExpandTabs

public void setExpandTabs(boolean expandTabs)
Deprecated. 

getSpacesPerTab

public int getSpacesPerTab()
Deprecated. 
Get the number of spaces that should be inserted into the document instead of one typed tab.


setSpacesPerTab

public void setSpacesPerTab(int spacesPerTab)
Deprecated. 

getIndentString

public String getIndentString(BaseDocument doc,
                              int indent)
Deprecated. 

getIndentString

public String getIndentString(int indent)
Deprecated. 
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.


insertTabString

public void insertTabString(BaseDocument doc,
                            int dotPos)
                     throws BadLocationException
Deprecated. 
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
dotPos - insertion point
Throws:
BadLocationException

changeRowIndent

public void changeRowIndent(BaseDocument doc,
                            int pos,
                            int newIndent)
                     throws BadLocationException
Deprecated. 
Change the indent of the given row. Document is atomically locked during this operation.

Throws:
BadLocationException

changeBlockIndent

public void changeBlockIndent(BaseDocument doc,
                              int startPos,
                              int endPos,
                              int shiftCnt)
                       throws BadLocationException
Deprecated. 
Increase/decrease indentation of the block of the code. Document is atomically locked during the operation.

Parameters:
doc - document to operate on
startPos - starting line position
endPos - ending line position
shiftCnt - positive/negative count of shiftwidths by which indentation should be shifted right/left
Throws:
BadLocationException

shiftLine

public void shiftLine(BaseDocument doc,
                      int dotPos,
                      boolean right)
               throws BadLocationException
Deprecated. 
Shift line either left or right

Throws:
BadLocationException

reformat

public int reformat(BaseDocument doc,
                    int startOffset,
                    int endOffset)
             throws BadLocationException
Deprecated. 
Reformat a block of code.

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

indentLine

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

Parameters:
doc - the document to work on
offset - the offset of a character on the line
Returns:
new offset of the original character

indentNewLine

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

Parameters:
doc - the document to work on
offset - the offset of a character on the line
Returns:
new offset to place cursor to

createWriter

public Writer createWriter(Document doc,
                           int offset,
                           Writer writer)
Deprecated. 
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
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

indentLock

public void indentLock()
Deprecated. 
Formatter clients should call this method before acquiring of the document's write lock and using of the indentLine(Document,int) and indentNewLine(Document,int) methods.
Subclasses may override this method and perform necessary pre-locking (e.g. of java infrastructure).
The following pattern should be used:
 formatter.indentLock();
 try {
     doc.atomicLock();
     try {
         formatter.indentLine(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     formatter.indentUnlock();
 }
 


indentUnlock

public void indentUnlock()
Deprecated. 
Formatter clients should call this method after releasing of the document's write lock as a counterpart of indentLock().
Subclasses may override this method and perform necessary post-unlocking (e.g. of java infrastructure).
The following pattern should be used:
 formatter.indentLock();
 try {
     doc.atomicLock();
     try {
         formatter.indentLine(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     formatter.indentUnlock();
 }
 


reformatLock

public void reformatLock()
Deprecated. 
Formatter clients should call this method before acquiring of the document's write lock before using of reformat(BaseDocument,int,int) method.
Subclasses may override this method and perform necessary pre-locking (e.g. of java infrastructure).
The following pattern should be used:
 formatter.reformatLock();
 try {
     doc.atomicLock();
     try {
         formatter.reformat(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     formatter.reformatUnlock();
 }
 


reformatUnlock

public void reformatUnlock()
Deprecated. 
Formatter clients should call this method after releasing of the document's write lock as a counterpart of reformatLock().
Subclasses may override this method and perform necessary post-unlocking (e.g. of java infrastructure).
The following pattern should be used:
 formatter.reformatLock();
 try {
     doc.atomicLock();
     try {
         formatter.reformat(...);
     } finally {
         doc.atomicUnlock();
     }
 } finally {
     formatter.reformatUnlock();
 }
 


org.netbeans.modules.editor.lib/1 1.43.0 9

Built on November 7 2009.  |  Portions Copyright 1997-2009 Sun Microsystems, Inc. All rights reserved.