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

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

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

org.netbeans.editor
Class Utilities

java.lang.Object
  extended by org.netbeans.editor.Utilities

public class Utilities
extends Object

Various useful editor functions. Some of the methods have the same names and signatures like in javax.swing.Utilities but there is also many other useful methods. All the methods are static so there's no reason to instantiate Utilities. All the methods working with the document rely on that it is locked against modification so they don't acquire document read/write lock by themselves to guarantee the full thread safety of the execution. It's the user's task to lock the document appropriately before using methods described here. Most of the methods require org.netbeans.editor.BaseDocument instance not just the javax.swing.text.Document. The reason for that is to mark that the methods work on BaseDocument instances only, not on generic documents. To convert the Document to BaseDocument the simple conversion (BaseDocument)target.getDocument() can be done or the method getDocument(target) can be called. There are also other conversion methods like getEditorUI(), getKit() or getKitClass().


Field Summary
static int CASE_LOWER
          Switch the case to small letters.
static int CASE_SWITCH
          Switch the case to reverse.
static int CASE_UPPER
          Switch the case to capital letters.
 
Method Summary
static void annotateLoggable(Throwable t)
          Deprecated. Use java.util.logging.Logger instead with the proper name, log level and message.
static boolean changeCase(BaseDocument doc, int offset, int len, int type)
          Change the case for specified part of document
static void clearStatusText(JTextComponent c)
           
static String debugDocument(Document doc)
          Display the identity of the document together with the title property and stream-description property.
static String debugPosition(BaseDocument doc, int offset)
           
static BaseDocument getDocument(JTextComponent target)
          Helper method to obtain instance of BaseDocument from JTextComponent.
static View getDocumentView(JTextComponent component)
          Get the view that covers the whole area of the document and holds a child view for each line in the document (or for a bunch of lines in case there is a code folding present).
static EditorUI getEditorUI(JTextComponent target)
          Helper method to obtain instance of EditorUI (extended UI) from the existing JTextComponent.
static int getFirstNonEmptyRow(BaseDocument doc, int offset, boolean downDir)
           
static int getFirstNonWhiteBwd(BaseDocument doc, int offset)
          Get first non-white character in document in backward direction.
static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos)
          Get first non-white character in document in backward direction.
static int getFirstNonWhiteFwd(BaseDocument doc, int offset)
          Get first non-white character in document in forward direction
static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos)
          Get first non-white character in document in forward direction
static int getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir)
           
static int getFirstWhiteBwd(BaseDocument doc, int offset)
          Get first white character in document in backward direction.
static int getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos)
          Get first white character in document in backward direction.
static int getFirstWhiteFwd(BaseDocument doc, int offset)
          Get first white character in document in forward direction
static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos)
          Get first white character in document in forward direction
static JTextComponent getFocusedComponent()
          Fetches the text component that currently has focus.
static String getIdentifier(BaseDocument doc, int offset)
          Get the identifier around the given position or null if there's no identifier
static String getIdentifierBefore(BaseDocument doc, int offset)
          Get the identifier before the given position (ending at given offset) or null if there's no identifier
static int[] getIdentifierBlock(BaseDocument doc, int offset)
          Get the identifier around the given position or null if there's no identifier around the given position.
static int[] getIdentifierBlock(JTextComponent c, int offset)
          Get the identifier around the given position or null if there's no identifier around the given position.
static BaseKit getKit(JTextComponent target)
          Helper method to obtain instance of editor kit from existing JTextComponent.
static Class getKitClass(JTextComponent target)
          Gets the class of an editor kit installed in JTextComponent.
static JTextComponent getLastActiveComponent()
          Returns last activated component.
static int getLineOffset(BaseDocument doc, int offset)
          Return line offset (line number - 1) for some position in the document
static int getNextTabColumn(BaseDocument doc, int offset)
          Get the visual column corresponding to the position after pressing the TAB key.
static int getNextWord(BaseDocument doc, int offset)
           
static int getNextWord(JTextComponent c, int offset)
           
static int getPositionAbove(JTextComponent c, int offset, int x)
          Get the position that is one line above and visually at some x-coordinate value.
static int getPositionBelow(JTextComponent c, int offset, int x)
          Get the position that is one line above and visually at some x-coordinate value.
static int getPreviousWord(BaseDocument doc, int offset)
           
static int getPreviousWord(JTextComponent c, int offset)
           
static View getRootView(JTextComponent component, Class rootViewClass)
          Get first view in the hierarchy that is an instance of the given class.
static int getRowCount(BaseDocument doc)
          Get the total count of lines in the document
static int getRowCount(BaseDocument doc, int startPos, int endPos)
          Count of rows between these two positions
static int getRowEnd(BaseDocument doc, int offset)
           
static int getRowEnd(JTextComponent c, int offset)
          Get the end position of the row right before the new-line character.
static int getRowFirstNonWhite(BaseDocument doc, int offset)
          Get the first non-white character on the line.
static int getRowIndent(BaseDocument doc, int offset)
          Get indentation on the current line.
static int getRowIndent(BaseDocument doc, int offset, boolean downDir)
          Get indentation on the current line.
static int getRowLastNonWhite(BaseDocument doc, int offset)
          Get the last non-white character on the line.
static int getRowStart(BaseDocument doc, int offset)
          Get the starting position of the row.
static int getRowStart(BaseDocument doc, int offset, int lineShift)
          Get the starting position of the row while providing relative count of row how the given position should be shifted.
static int getRowStart(JTextComponent c, int offset)
          Get the starting position of the row.
static int getRowStartFromLineOffset(BaseDocument doc, int lineIndex)
          Return start offset of the line
static String getSelectionOrIdentifier(JTextComponent c)
          Get the selection or identifier at the current caret position
static String getSelectionOrIdentifier(JTextComponent c, int offset)
          Get the selection if there's any or get the identifier around the position if there's no selection.
static int[] getSelectionOrIdentifierBlock(JTextComponent c)
          Get the selection or identifier at the current caret position
static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset)
          Get the selection if there's any or get the identifier around the position if there's no selection.
static String getStatusText(JTextComponent c)
           
static SyntaxSupport getSyntaxSupport(JTextComponent target)
          Get the syntax-support class that belongs to the document of the given component.
static String getTabInsertString(BaseDocument doc, int offset)
          Deprecated.  
static int getVisualColumn(BaseDocument doc, int offset)
          Return visual column (with expanded tabs) on the line.
static String getWord(BaseDocument doc, int offset)
          Get the word at given position.
static String getWord(JTextComponent c, int offset)
          Get the word around the given position .
static int getWordEnd(BaseDocument doc, int offset)
           
static int getWordEnd(JTextComponent c, int offset)
           
static int getWordStart(BaseDocument doc, int offset)
           
static int getWordStart(JTextComponent c, int offset)
          Get start of the current word.
static void insertMark(BaseDocument doc, Mark mark, int offset)
           
static boolean isRowEmpty(BaseDocument doc, int offset)
          Tests whether the line contains no characters except the ending new-line.
static boolean isRowWhite(BaseDocument doc, int offset)
          Tests whether the line contains only whitespace characters.
static String keySequenceToString(KeyStroke[] seq)
          Creates nice textual description of sequence of KeyStrokes.
static String keyStrokeToString(KeyStroke stroke)
          Creates nice textual representation of KeyStroke.
static void moveMark(BaseDocument doc, Mark mark, int newOffset)
           
static String offsetToLineColumnString(BaseDocument doc, int offset)
           
static void performAction(Action a, ActionEvent evt, JTextComponent target)
           
static int reformat(BaseDocument doc, int startOffset, int endOffset)
          Reformat a block of code.
static void reformatLine(BaseDocument doc, int pos)
          Reformat the line around the given position.
static void requestFocus(JTextComponent c)
           
static void returnFocus()
           
static void runInEventDispatchThread(Runnable r)
           
static void setStatusBoldText(JTextComponent c, String text)
           
static void setStatusText(JTextComponent c, String text)
           
static void setStatusText(JTextComponent c, String text, Coloring extraColoring)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CASE_UPPER

public static final int CASE_UPPER
Switch the case to capital letters. Used in changeCase()

See Also:
Constant Field Values

CASE_LOWER

public static final int CASE_LOWER
Switch the case to small letters. Used in changeCase()

See Also:
Constant Field Values

CASE_SWITCH

public static final int CASE_SWITCH
Switch the case to reverse. Used in changeCase()

See Also:
Constant Field Values
Method Detail

getRowStart

public static int getRowStart(JTextComponent c,
                              int offset)
                       throws BadLocationException
Get the starting position of the row.

Parameters:
c - text component to operate on
offset - position in document where to start searching
Returns:
position of the start of the row or -1 for invalid position
Throws:
BadLocationException

getRowStart

public static int getRowStart(BaseDocument doc,
                              int offset)
                       throws BadLocationException
Get the starting position of the row.

Parameters:
doc - document to operate on
offset - position in document where to start searching
Returns:
position of the start of the row or -1 for invalid position
Throws:
BadLocationException

getRowStart

public static int getRowStart(BaseDocument doc,
                              int offset,
                              int lineShift)
                       throws BadLocationException
Get the starting position of the row while providing relative count of row how the given position should be shifted. This is the most efficient way how to move by lines in the document based on some position. There is no similair getRowEnd() method that would have shifting parameter.

Parameters:
doc - document to operate on
offset - position in document where to start searching
lineShift - shift the given offset forward/back relatively by some amount of lines
Returns:
position of the start of the row or -1 for invalid position
Throws:
BadLocationException

getRowFirstNonWhite

public static int getRowFirstNonWhite(BaseDocument doc,
                                      int offset)
                               throws BadLocationException
Get the first non-white character on the line. The document.isWhitespace() is used to test whether the particular character is white space or not.

Parameters:
doc - document to operate on
offset - position in document anywhere on the line
Returns:
position of the first non-white char on the line or -1 if there's no non-white character on that line.
Throws:
BadLocationException

getRowLastNonWhite

public static int getRowLastNonWhite(BaseDocument doc,
                                     int offset)
                              throws BadLocationException
Get the last non-white character on the line. The document.isWhitespace() is used to test whether the particular character is white space or not.

Parameters:
doc - document to operate on
offset - position in document anywhere on the line
Returns:
position of the last non-white char on the line or -1 if there's no non-white character on that line.
Throws:
BadLocationException

getRowIndent

public static int getRowIndent(BaseDocument doc,
                               int offset)
                        throws BadLocationException
Get indentation on the current line. If this line is white then return -1.

Parameters:
doc - document to operate on
offset - position in document anywhere on the line
Returns:
indentation or -1 if the line is white
Throws:
BadLocationException

getRowIndent

public static int getRowIndent(BaseDocument doc,
                               int offset,
                               boolean downDir)
                        throws BadLocationException
Get indentation on the current line. If this line is white then go either up or down an return indentation of the first non-white row. The getRowFirstNonWhite() is used to find the indentation on particular line.

Parameters:
doc - document to operate on
offset - position in document anywhere on the line
downDir - if this flag is set to true then if the row is white then the indentation of the next first non-white row is returned. If it's false then the indentation of the previous first non-white row is returned.
Returns:
indentation or -1 if there's no non-white line in the specified direction
Throws:
BadLocationException

getRowEnd

public static int getRowEnd(JTextComponent c,
                            int offset)
                     throws BadLocationException
Get the end position of the row right before the new-line character.

Parameters:
c - text component to operate on
offset - position in document where to start searching
relLine - shift offset forward/back by some amount of lines
Returns:
position of the end of the row or -1 for invalid position
Throws:
BadLocationException

getRowEnd

public static int getRowEnd(BaseDocument doc,
                            int offset)
                     throws BadLocationException
Throws:
BadLocationException

getPositionAbove

public static int getPositionAbove(JTextComponent c,
                                   int offset,
                                   int x)
                            throws BadLocationException
Get the position that is one line above and visually at some x-coordinate value.

Parameters:
doc - document to operate on
offset - position in document from which the current line is determined
x - float x-coordinate value
Returns:
position of the character that is at the one line above at the required x-coordinate value
Throws:
BadLocationException

getPositionBelow

public static int getPositionBelow(JTextComponent c,
                                   int offset,
                                   int x)
                            throws BadLocationException
Get the position that is one line above and visually at some x-coordinate value.

Parameters:
c - text component to operate on
offset - position in document from which the current line is determined
x - float x-coordinate value
Returns:
position of the character that is at the one line above at the required x-coordinate value
Throws:
BadLocationException

getWordStart

public static int getWordStart(JTextComponent c,
                               int offset)
                        throws BadLocationException
Get start of the current word. If there are no more words till the begining of the document, this method returns -1.

Parameters:
c - text component to operate on
offset - position in document from which the current line is determined
Throws:
BadLocationException

getWordStart

public static int getWordStart(BaseDocument doc,
                               int offset)
                        throws BadLocationException
Throws:
BadLocationException

getWordEnd

public static int getWordEnd(JTextComponent c,
                             int offset)
                      throws BadLocationException
Throws:
BadLocationException

getWordEnd

public static int getWordEnd(BaseDocument doc,
                             int offset)
                      throws BadLocationException
Throws:
BadLocationException

getNextWord

public static int getNextWord(JTextComponent c,
                              int offset)
                       throws BadLocationException
Throws:
BadLocationException

getNextWord

public static int getNextWord(BaseDocument doc,
                              int offset)
                       throws BadLocationException
Throws:
BadLocationException

getPreviousWord

public static int getPreviousWord(JTextComponent c,
                                  int offset)
                           throws BadLocationException
Throws:
BadLocationException

getPreviousWord

public static int getPreviousWord(BaseDocument doc,
                                  int offset)
                           throws BadLocationException
Throws:
BadLocationException

getFirstWhiteFwd

public static int getFirstWhiteFwd(BaseDocument doc,
                                   int offset)
                            throws BadLocationException
Get first white character in document in forward direction

Parameters:
doc - document to operate on
offset - position in document where to start searching
Returns:
position of the first white character or -1
Throws:
BadLocationException

getFirstWhiteFwd

public static int getFirstWhiteFwd(BaseDocument doc,
                                   int offset,
                                   int limitPos)
                            throws BadLocationException
Get first white character in document in forward direction

Parameters:
doc - document to operate on
offset - position in document where to start searching
limitPos - position in document (greater or equal than offset) where the search will stop reporting unsuccessful search by returning -1
Returns:
position of the first non-white character or -1
Throws:
BadLocationException

getFirstNonWhiteFwd

public static int getFirstNonWhiteFwd(BaseDocument doc,
                                      int offset)
                               throws BadLocationException
Get first non-white character in document in forward direction

Parameters:
doc - document to operate on
offset - position in document where to start searching
Returns:
position of the first non-white character or -1
Throws:
BadLocationException

getFirstNonWhiteFwd

public static int getFirstNonWhiteFwd(BaseDocument doc,
                                      int offset,
                                      int limitPos)
                               throws BadLocationException
Get first non-white character in document in forward direction

Parameters:
doc - document to operate on
offset - position in document where to start searching
limitPos - position in document (greater or equal than offset) where the search will stop reporting unsuccessful search by returning -1
Returns:
position of the first non-white character or -1
Throws:
BadLocationException

getFirstWhiteBwd

public static int getFirstWhiteBwd(BaseDocument doc,
                                   int offset)
                            throws BadLocationException
Get first white character in document in backward direction. The character right before the character at position offset will be searched as first.

Parameters:
doc - document to operate on
offset - position in document where to start searching
Returns:
position of the first white character or -1
Throws:
BadLocationException

getFirstWhiteBwd

public static int getFirstWhiteBwd(BaseDocument doc,
                                   int offset,
                                   int limitPos)
                            throws BadLocationException
Get first white character in document in backward direction. The character right before the character at position offset will be searched as first.

Parameters:
doc - document to operate on
offset - position in document where to start searching
limitPos - position in document (lower or equal than offset) where the search will stop reporting unsuccessful search by returning -1
Returns:
position of the first white character or -1
Throws:
BadLocationException

getFirstNonWhiteBwd

public static int getFirstNonWhiteBwd(BaseDocument doc,
                                      int offset)
                               throws BadLocationException
Get first non-white character in document in backward direction. The character right before the character at position offset will be searched as first.

Parameters:
doc - document to operate on
offset - position in document where to start searching
Returns:
position of the first non-white character or -1
Throws:
BadLocationException

getFirstNonWhiteBwd

public static int getFirstNonWhiteBwd(BaseDocument doc,
                                      int offset,
                                      int limitPos)
                               throws BadLocationException
Get first non-white character in document in backward direction. The character right before the character at position offset will be searched as first.

Parameters:
doc - document to operate on
offset - position in document where to start searching
limitPos - position in document (lower or equal than offset) where the search will stop reporting unsuccessful search by returning -1
Returns:
position of the first non-white character or -1
Throws:
BadLocationException

getLineOffset

public static int getLineOffset(BaseDocument doc,
                                int offset)
                         throws BadLocationException
Return line offset (line number - 1) for some position in the document

Parameters:
doc - document to operate on
offset - position in document where to start searching
Throws:
BadLocationException

getRowStartFromLineOffset

public static int getRowStartFromLineOffset(BaseDocument doc,
                                            int lineIndex)
Return start offset of the line

Parameters:
lineIndex - line index starting from 0
Returns:
start position of the line or -1 if lineIndex was invalid

getVisualColumn

public static int getVisualColumn(BaseDocument doc,
                                  int offset)
                           throws BadLocationException
Return visual column (with expanded tabs) on the line.

Parameters:
doc - document to operate on
offset - position in document for which the visual column should be found
Returns:
visual column on the line determined by position
Throws:
BadLocationException

getIdentifier

public static String getIdentifier(BaseDocument doc,
                                   int offset)
                            throws BadLocationException
Get the identifier around the given position or null if there's no identifier

Throws:
BadLocationException
See Also:
getIdentifierBlock()

getIdentifierBlock

public static int[] getIdentifierBlock(JTextComponent c,
                                       int offset)
                                throws BadLocationException
Get the identifier around the given position or null if there's no identifier around the given position. The identifier is not verified against SyntaxSupport.isIdentifier().

Parameters:
c - JTextComponent to work on
offset - position in document - usually the caret.getDot()
Returns:
the block (starting and ending position) enclosing the identifier or null if no identifier was found
Throws:
BadLocationException

getIdentifierBlock

public static int[] getIdentifierBlock(BaseDocument doc,
                                       int offset)
                                throws BadLocationException
Get the identifier around the given position or null if there's no identifier around the given position. The identifier must be accepted by SyntaxSupport.isIdnetifier() otherwise null is returned.

Parameters:
doc - document to work on
offset - position in document - usually the caret.getDot()
Returns:
the block (starting and ending position) enclosing the identifier or null if no identifier was found
Throws:
BadLocationException

getWord

public static String getWord(JTextComponent c,
                             int offset)
                      throws BadLocationException
Get the word around the given position .

Parameters:
c - component to work with
offset - position in document - usually the caret.getDot()
Returns:
the word.
Throws:
BadLocationException

getSelectionOrIdentifierBlock

public static int[] getSelectionOrIdentifierBlock(JTextComponent c,
                                                  int offset)
                                           throws BadLocationException
Get the selection if there's any or get the identifier around the position if there's no selection.

Parameters:
c - component to work with
offset - position in document - usually the caret.getDot()
Returns:
the block (starting and ending position) enclosing the identifier or null if no identifier was found
Throws:
BadLocationException

getSelectionOrIdentifierBlock

public static int[] getSelectionOrIdentifierBlock(JTextComponent c)
Get the selection or identifier at the current caret position

See Also:
getSelectionOrIdentifierBlock(JTextComponent, int)

getIdentifierBefore

public static String getIdentifierBefore(BaseDocument doc,
                                         int offset)
                                  throws BadLocationException
Get the identifier before the given position (ending at given offset) or null if there's no identifier

Throws:
BadLocationException

getSelectionOrIdentifier

public static String getSelectionOrIdentifier(JTextComponent c,
                                              int offset)
                                       throws BadLocationException
Get the selection if there's any or get the identifier around the position if there's no selection.

Throws:
BadLocationException

getSelectionOrIdentifier

public static String getSelectionOrIdentifier(JTextComponent c)
Get the selection or identifier at the current caret position


getWord

public static String getWord(BaseDocument doc,
                             int offset)
                      throws BadLocationException
Get the word at given position.

Throws:
BadLocationException

changeCase

public static boolean changeCase(BaseDocument doc,
                                 int offset,
                                 int len,
                                 int type)
                          throws BadLocationException
Change the case for specified part of document

Parameters:
doc - document to operate on
offset - position in document determines the changed area begining
len - number of chars to change
type - either CASE_CAPITAL, CASE_SMALL or CASE_SWITCH
Throws:
BadLocationException

isRowEmpty

public static boolean isRowEmpty(BaseDocument doc,
                                 int offset)
                          throws BadLocationException
Tests whether the line contains no characters except the ending new-line.

Parameters:
doc - document to operate on
offset - position anywhere on the tested line
Returns:
whether the line is empty or not
Throws:
BadLocationException

getFirstNonEmptyRow

public static int getFirstNonEmptyRow(BaseDocument doc,
                                      int offset,
                                      boolean downDir)
                               throws BadLocationException
Throws:
BadLocationException

isRowWhite

public static boolean isRowWhite(BaseDocument doc,
                                 int offset)
                          throws BadLocationException
Tests whether the line contains only whitespace characters.

Parameters:
doc - document to operate on
offset - position anywhere on the tested line
Returns:
whether the line is empty or not
Throws:
BadLocationException

getFirstNonWhiteRow

public static int getFirstNonWhiteRow(BaseDocument doc,
                                      int offset,
                                      boolean downDir)
                               throws BadLocationException
Throws:
BadLocationException

reformat

public static int reformat(BaseDocument doc,
                           int startOffset,
                           int endOffset)
                    throws BadLocationException
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

reformatLine

public static void reformatLine(BaseDocument doc,
                                int pos)
                         throws BadLocationException
Reformat the line around the given position.

Throws:
BadLocationException

getRowCount

public static int getRowCount(BaseDocument doc,
                              int startPos,
                              int endPos)
                       throws BadLocationException
Count of rows between these two positions

Throws:
BadLocationException

getRowCount

public static int getRowCount(BaseDocument doc)
Get the total count of lines in the document


getTabInsertString

public static String getTabInsertString(BaseDocument doc,
                                        int offset)
                                 throws BadLocationException
Deprecated. 

Throws:
BadLocationException
See Also:
Formatter.insertTabString()

getNextTabColumn

public static int getNextTabColumn(BaseDocument doc,
                                   int offset)
                            throws BadLocationException
Get the visual column corresponding to the position after pressing the TAB key.

Parameters:
doc - document to work with
offset - position at which the TAB was pressed
Throws:
BadLocationException

setStatusText

public static void setStatusText(JTextComponent c,
                                 String text)

setStatusText

public static void setStatusText(JTextComponent c,
                                 String text,
                                 Coloring extraColoring)

setStatusBoldText

public static void setStatusBoldText(JTextComponent c,
                                     String text)

getStatusText

public static String getStatusText(JTextComponent c)

clearStatusText

public static void clearStatusText(JTextComponent c)

insertMark

public static void insertMark(BaseDocument doc,
                              Mark mark,
                              int offset)
                       throws BadLocationException,
                              InvalidMarkException
Throws:
BadLocationException
InvalidMarkException

moveMark

public static void moveMark(BaseDocument doc,
                            Mark mark,
                            int newOffset)
                     throws BadLocationException,
                            InvalidMarkException
Throws:
BadLocationException
InvalidMarkException

returnFocus

public static void returnFocus()

requestFocus

public static void requestFocus(JTextComponent c)

runInEventDispatchThread

public static void runInEventDispatchThread(Runnable r)

debugPosition

public static String debugPosition(BaseDocument doc,
                                   int offset)

offsetToLineColumnString

public static String offsetToLineColumnString(BaseDocument doc,
                                              int offset)

debugDocument

public static String debugDocument(Document doc)
Display the identity of the document together with the title property and stream-description property.


performAction

public static void performAction(Action a,
                                 ActionEvent evt,
                                 JTextComponent target)

getLastActiveComponent

public static JTextComponent getLastActiveComponent()
Returns last activated component. If the component was closed, then previous component is returned


getFocusedComponent

public static JTextComponent getFocusedComponent()
Fetches the text component that currently has focus. It delegates to TextAction.getFocusedComponent().

Returns:
the component

getEditorUI

public static EditorUI getEditorUI(JTextComponent target)
Helper method to obtain instance of EditorUI (extended UI) from the existing JTextComponent. It doesn't require any document locking.

Parameters:
target - JTextComponent for which the extended UI should be obtained
Returns:
extended ui instance or null if the component.getUI() does not return BaseTextUI instance.

getKit

public static BaseKit getKit(JTextComponent target)
Helper method to obtain instance of editor kit from existing JTextComponent. If the kit of the component is not an instance of the org.netbeans.editor.BaseKit the method returns null. The method doesn't require any document locking.

Parameters:
target - JTextComponent for which the editor kit should be obtained
Returns:
BaseKit instance or null

getKitClass

public static Class getKitClass(JTextComponent target)
Gets the class of an editor kit installed in JTextComponent. The method doesn't require any document locking.

WARNING: The implementation class of an editor kit is most likely not what you want. Please see BaseKit.getKit(Class) for more details.

Unfortunatelly, there are still places in editor libraries where an editor kit class is required. One of them is the editor settings infrastructure built around the Settings class. So, if you really need it go ahead and use it, there is nothing wrong with the method itself.

Parameters:
target - The JTextComponent to get the kit class for. Can be null.
Returns:
The implementation class of the editor kit or null if the target is null.

getDocument

public static BaseDocument getDocument(JTextComponent target)
Helper method to obtain instance of BaseDocument from JTextComponent. If the document of the component is not an instance of the org.netbeans.editor.BaseDocument the method returns null. The method doesn't require any document locking.

Parameters:
target - JTextComponent for which the document should be obtained
Returns:
BaseDocument instance or null

getSyntaxSupport

public static SyntaxSupport getSyntaxSupport(JTextComponent target)
Get the syntax-support class that belongs to the document of the given component. Besides using directly this method, the SyntaxSupport can be obtained by calling doc.getSyntaxSupport(). The method can return null in case the document is not an instance of the BaseDocument. The method doesn't require any document locking.

Parameters:
target - JTextComponent for which the syntax-support should be obtained
Returns:
SyntaxSupport instance or null

getRootView

public static View getRootView(JTextComponent component,
                               Class rootViewClass)
Get first view in the hierarchy that is an instance of the given class. It allows to skip various wrapper-views around the doc-view that holds the child views for the lines.

Parameters:
component - component from which the root view is fetched.
rootViewClass - class of the view to return.
Returns:
view being instance of the requested class or null if there is not one.

getDocumentView

public static View getDocumentView(JTextComponent component)
Get the view that covers the whole area of the document and holds a child view for each line in the document (or for a bunch of lines in case there is a code folding present).


keySequenceToString

public static String keySequenceToString(KeyStroke[] seq)
Creates nice textual description of sequence of KeyStrokes. Usable for displaying MultiKeyBindings. The keyStrokes are delimited by space.

Parameters:
Array - of KeyStrokes representing the actual sequence.
Returns:
String describing the KeyStroke sequence.

keyStrokeToString

public static String keyStrokeToString(KeyStroke stroke)
Creates nice textual representation of KeyStroke. Modifiers and an actual key label are concated by plus signs

Parameters:
the - KeyStroke to get description of
Returns:
String describing the KeyStroke

annotateLoggable

public static void annotateLoggable(Throwable t)
Deprecated. Use java.util.logging.Logger instead with the proper name, log level and message.

Writes a Throwable to a log file.

The method is internally using org.netbeans.editor logger and Level.INFO.

Parameters:
t - The exception that will be logged.

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.