| java.lang.Object org.netbeans.editor.Utilities
Utilities | public class Utilities (Code) | | 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().
author: Miloslav Metelka version: 0.10 |
Field Summary | |
final public static int | CASE_LOWER Switch the case to small letters. | final public static int | CASE_SWITCH Switch the case to reverse. | final public static int | CASE_UPPER Switch the case to capital letters. |
Method Summary | |
public static boolean | changeCase(BaseDocument doc, int offset, int len, int type) | public static void | clearStatusText(JTextComponent c) | public static String | debugDocument(Document doc) Display the identity of the document together with the title property and
stream-description property. | public static String | debugPosition(BaseDocument doc, int offset) | public static BaseDocument | getDocument(JTextComponent target) Helper method to obtain instance of BaseDocument from JTextComponent. | public static EditorUI | getEditorUI(JTextComponent target) Helper method to obtain instance of EditorUI (extended UI) from the
existing JTextComponent. | public static int | getFirstNonEmptyRow(BaseDocument doc, int offset, boolean downDir) | public static int | getFirstNonWhiteBwd(BaseDocument doc, int offset) Get first non-white character in document in backward direction. | public static int | getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) Get first non-white character in document in backward direction. | public static int | getFirstNonWhiteFwd(BaseDocument doc, int offset) | public static int | getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) | public static int | getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir) | public static int | getFirstWhiteBwd(BaseDocument doc, int offset) Get first white character in document in backward direction. | public static int | getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos) Get first white character in document in backward direction. | public static int | getFirstWhiteFwd(BaseDocument doc, int offset) | public static int | getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) | public static String | getIdentifier(BaseDocument doc, int offset) | public static String | getIdentifierBefore(BaseDocument doc, int offset) | public 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. | public static BaseKit | getKit(JTextComponent target) Helper method to obtain instance of editor kit from existing
JTextComponent. | public static Class | getKitClass(JTextComponent target) Helper method to obtain editor kit class from existing JTextComponent.
This method is useful for example when dealing with Settings. | public static JTextComponent | getLastActiveComponent() | public static int | getLineOffset(BaseDocument doc, int offset) | public static int | getNextTabColumn(BaseDocument doc, int offset) Get the visual column corresponding to the position after pressing the
TAB key. | public static int | getNextWord(JTextComponent c, int offset) | public static int | getNextWord(BaseDocument doc, int offset) | public static int | getPositionAbove(JTextComponent c, int offset, int x) Get the position that is one line above and visually at some x-coordinate
value. | public static int | getPositionBelow(JTextComponent c, int offset, int x) Get the position that is one line above and visually at some x-coordinate
value. | public static int | getPreviousWord(JTextComponent c, int offset) | public static int | getPreviousWord(BaseDocument doc, int offset) | public static int | getRowCount(BaseDocument doc, int startPos, int endPos) | public static int | getRowCount(BaseDocument doc) | public static int | getRowEnd(JTextComponent c, int offset) Get the end position of the row right before the new-line character. | public static int | getRowEnd(BaseDocument doc, int offset) | public static int | getRowFirstNonWhite(BaseDocument doc, int offset) Get the first non-white character on the line. | public static int | getRowIndent(BaseDocument doc, int offset) Get indentation on the current line. | public static int | getRowIndent(BaseDocument doc, int offset, boolean downDir) Get indentation on the current line. | public static int | getRowLastNonWhite(BaseDocument doc, int offset) Get the last non-white character on the line. | public static int | getRowStart(JTextComponent c, int offset) Get the starting position of the row. | public static int | getRowStart(BaseDocument doc, int offset) Get the starting position of the row. | public 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. | public static int | getRowStartFromLineOffset(BaseDocument doc, int lineOffset) | public 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. | public static String | getSelectionOrIdentifier(JTextComponent c) | public 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. | public static int[] | getSelectionOrIdentifierBlock(JTextComponent c) | public static String | getStatusText(JTextComponent c) | public static SyntaxSupport | getSyntaxSupport(JTextComponent target) Get the syntax-support class that belongs to the document of the given
component. | public static String | getTabInsertString(BaseDocument doc, int offset) | public static int | getVisualColumn(BaseDocument doc, int offset) Return visual column (with expanded tabs) on the line. | public static String | getWord(JTextComponent c, int offset) Get the word around the given position . | public static String | getWord(BaseDocument doc, int offset) Get the word at given position. | public static int | getWordEnd(JTextComponent c, int offset) | public static int | getWordEnd(BaseDocument doc, int offset) | public static int | getWordStart(JTextComponent c, int offset) Get start of the current word. | public static int | getWordStart(BaseDocument doc, int offset) | public static void | insertMark(BaseDocument doc, Mark mark, int offset) | public static boolean | isEOL(BaseDocument doc, int offset) | public static boolean | isRowEmpty(BaseDocument doc, int offset) Tests whether the line contains no characters except the ending new-line. | public static boolean | isRowWhite(BaseDocument doc, int offset) Tests whether the line contains only whitespace characters. | public static String | keySequenceToString(KeyStroke[] seq) Creates nice textual description of sequence of KeyStrokes. | public static String | keyStrokeToString(KeyStroke stroke) Creates nice textual representation of KeyStroke. | public static void | moveMark(BaseDocument doc, Mark mark, int newOffset) | public static void | performAction(Action a, ActionEvent evt, JTextComponent target) | public static int | reformat(BaseDocument doc, int startOffset, int endOffset) Reformat a block of code. | public static void | reformatLine(BaseDocument doc, int pos) Reformat the line around the given position. | public static void | requestFocus(JTextComponent c) | public static void | returnFocus() | public static void | runInEventDispatchThread(Runnable r) | public static void | setStatusBoldText(JTextComponent c, String text) | public static void | setStatusText(JTextComponent c, String text) | public static void | setStatusText(JTextComponent c, String text, Coloring extraColoring) |
CASE_LOWER | final public static int CASE_LOWER(Code) | | Switch the case to small letters. Used in changeCase()
|
CASE_SWITCH | final public static int CASE_SWITCH(Code) | | Switch the case to reverse. Used in changeCase()
|
CASE_UPPER | final public static int CASE_UPPER(Code) | | Switch the case to capital letters. Used in changeCase()
|
changeCase | public static boolean changeCase(BaseDocument doc, int offset, int len, int type) throws BadLocationException(Code) | | Change the case for specified part of document
Parameters: doc - document to operate on Parameters: offset - position in document determines the changed area begining Parameters: len - number of chars to change Parameters: type - either CASE_CAPITAL, CASE_SMALL or CASE_SWITCH |
debugDocument | public static String debugDocument(Document doc)(Code) | | Display the identity of the document together with the title property and
stream-description property.
|
getDocument | public static BaseDocument getDocument(JTextComponent target)(Code) | | 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 BaseDocument instance or null |
getEditorUI | public static EditorUI getEditorUI(JTextComponent target)(Code) | | 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 extended ui instance or null if the component.getUI() does notreturn BaseTextUI instance. |
getFirstNonWhiteBwd | public static int getFirstNonWhiteBwd(BaseDocument doc, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document where to start searching position of the first non-white character or -1 |
getFirstNonWhiteBwd | public static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException(Code) | | 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 Parameters: offset - position in document where to start searching Parameters: limitPos - position in document (lower or equal than offset) where thesearch will stop reporting unsuccessful search by returning -1 position of the first non-white character or -1 |
getFirstNonWhiteFwd | public static int getFirstNonWhiteFwd(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get first non-white character in document in forward direction
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching position of the first non-white character or -1 |
getFirstNonWhiteFwd | public static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException(Code) | | Get first non-white character in document in forward direction
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching Parameters: limitPos - position in document (greater or equal than offset) where thesearch will stop reporting unsuccessful search by returning -1 position of the first non-white character or -1 |
getFirstWhiteBwd | public static int getFirstWhiteBwd(BaseDocument doc, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document where to start searching position of the first white character or -1 |
getFirstWhiteBwd | public static int getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException(Code) | | 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 Parameters: offset - position in document where to start searching Parameters: limitPos - position in document (lower or equal than offset) where thesearch will stop reporting unsuccessful search by returning -1 position of the first white character or -1 |
getFirstWhiteFwd | public static int getFirstWhiteFwd(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get first white character in document in forward direction
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching position of the first white character or -1 |
getFirstWhiteFwd | public static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException(Code) | | Get first white character in document in forward direction
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching Parameters: limitPos - position in document (greater or equal than offset) where thesearch will stop reporting unsuccessful search by returning -1 position of the first non-white character or -1 |
getIdentifier | public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get the identifier around the given position or null if there's no
identifier
See Also: getIdentifierBlock() |
getIdentifierBefore | public static String getIdentifierBefore(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get the identifier before the given position (ending at given offset) or
null if there's no identifier
|
getIdentifierBlock | public static int[] getIdentifierBlock(BaseDocument doc, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document - usually the caret.getDot() the block (starting and ending position) enclosing the identifieror null if no identifier was found |
getKit | public static BaseKit getKit(JTextComponent target)(Code) | | 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 BaseKit instance or null |
getKitClass | public static Class getKitClass(JTextComponent target)(Code) | | Helper method to obtain editor kit class from existing JTextComponent.
This method is useful for example when dealing with Settings. The method
doesn't require any document locking.
Parameters: target - JTextComponent for which the editor kit should be obtained editor kit class |
getLineOffset | public static int getLineOffset(BaseDocument doc, int offset) throws BadLocationException(Code) | | Return line offset (line number - 1) for some position in the document
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching |
getNextTabColumn | public static int getNextTabColumn(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get the visual column corresponding to the position after pressing the
TAB key.
Parameters: doc - document to work with Parameters: offset - position at which the TAB was pressed |
getPositionAbove | public static int getPositionAbove(JTextComponent c, int offset, int x) throws BadLocationException(Code) | | Get the position that is one line above and visually at some x-coordinate
value.
Parameters: doc - document to operate on Parameters: offset - position in document from which the current line is determined Parameters: x - float x-coordinate value position of the character that is at the one line above at therequired x-coordinate value |
getPositionBelow | public static int getPositionBelow(JTextComponent c, int offset, int x) throws BadLocationException(Code) | | Get the position that is one line above and visually at some x-coordinate
value.
Parameters: c - text component to operate on Parameters: offset - position in document from which the current line is determined Parameters: x - float x-coordinate value position of the character that is at the one line above at therequired x-coordinate value |
getRowCount | public static int getRowCount(BaseDocument doc)(Code) | | Get the total count of lines in the document
|
getRowEnd | public static int getRowEnd(JTextComponent c, int offset) throws BadLocationException(Code) | | Get the end position of the row right before the new-line character.
Parameters: c - text component to operate on Parameters: offset - position in document where to start searching Parameters: relLine - shift offset forward/back by some amount of lines position of the end of the row or -1 for invalid position |
getRowFirstNonWhite | public static int getRowFirstNonWhite(BaseDocument doc, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document anywhere on the line position of the first non-white char on the line or -1 if there'sno non-white character on that line. |
getRowIndent | public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get indentation on the current line. If this line is white then return
-1.
Parameters: doc - document to operate on Parameters: offset - position in document anywhere on the line indentation or -1 if the line is white |
getRowIndent | public static int getRowIndent(BaseDocument doc, int offset, boolean downDir) throws BadLocationException(Code) | | 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 Parameters: offset - position in document anywhere on the line Parameters: downDir - if this flag is set to true then if the row is white then theindentation of the next first non-white row is returned. Ifit's false then the indentation of the previous firstnon-white row is returned. indentation or -1 if there's no non-white line in the specifieddirection |
getRowLastNonWhite | public static int getRowLastNonWhite(BaseDocument doc, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document anywhere on the line position of the last non-white char on the line or -1 if there'sno non-white character on that line. |
getRowStart | public static int getRowStart(JTextComponent c, int offset) throws BadLocationException(Code) | | Get the starting position of the row.
Parameters: c - text component to operate on Parameters: offset - position in document where to start searching position of the start of the row or -1 for invalid position |
getRowStart | public static int getRowStart(BaseDocument doc, int offset) throws BadLocationException(Code) | | Get the starting position of the row.
Parameters: doc - document to operate on Parameters: offset - position in document where to start searching position of the start of the row or -1 for invalid position |
getRowStart | public static int getRowStart(BaseDocument doc, int offset, int lineShift) throws BadLocationException(Code) | | 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 Parameters: offset - position in document where to start searching Parameters: lineShift - shift the given offset forward/back relatively by some amountof lines position of the start of the row or -1 for invalid position |
getRowStartFromLineOffset | public static int getRowStartFromLineOffset(BaseDocument doc, int lineOffset)(Code) | | Return start offset of the line
Parameters: lineOffset - line offset starting from 0 start position of the line or -1 if lineOffset was invalid |
getSelectionOrIdentifier | public static String getSelectionOrIdentifier(JTextComponent c, int offset) throws BadLocationException(Code) | | Get the selection if there's any or get the identifier around the
position if there's no selection.
|
getSelectionOrIdentifier | public static String getSelectionOrIdentifier(JTextComponent c)(Code) | | Get the selection or identifier at the current caret position
|
getSelectionOrIdentifierBlock | public static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document - usually the caret.getDot() the block (starting and ending position) enclosing the identifieror null if no identifier was found |
getSelectionOrIdentifierBlock | public static int[] getSelectionOrIdentifierBlock(JTextComponent c)(Code) | | Get the selection or identifier at the current caret position
See Also: getSelectionOrIdentifierBlock(JTextComponent, int) |
getSyntaxSupport | public static SyntaxSupport getSyntaxSupport(JTextComponent target)(Code) | | 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 SyntaxSupport instance or null |
getVisualColumn | public static int getVisualColumn(BaseDocument doc, int offset) throws BadLocationException(Code) | | Return visual column (with expanded tabs) on the line.
Parameters: doc - document to operate on Parameters: offset - position in document for which the visual column should befound visual column on the line determined by position |
getWord | public static String getWord(JTextComponent c, int offset) throws BadLocationException(Code) | | Get the word around the given position .
Parameters: c - component to work with Parameters: offset - position in document - usually the caret.getDot() the word. |
getWordStart | public static int getWordStart(JTextComponent c, int offset) throws BadLocationException(Code) | | 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 Parameters: offset - position in document from which the current line is determined |
isRowEmpty | public static boolean isRowEmpty(BaseDocument doc, int offset) throws BadLocationException(Code) | | Tests whether the line contains no characters except the ending new-line.
Parameters: doc - document to operate on Parameters: offset - position anywhere on the tested line whether the line is empty or not |
isRowWhite | public static boolean isRowWhite(BaseDocument doc, int offset) throws BadLocationException(Code) | | Tests whether the line contains only whitespace characters.
Parameters: doc - document to operate on Parameters: offset - position anywhere on the tested line whether the line is empty or not |
keySequenceToString | public static String keySequenceToString(KeyStroke[] seq)(Code) | | 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. String describing the KeyStroke sequence. |
keyStrokeToString | public static String keyStrokeToString(KeyStroke stroke)(Code) | | Creates nice textual representation of KeyStroke. Modifiers and an actual
key label are concated by plus signs
Parameters: the - KeyStroke to get description of String describing the KeyStroke |
reformat | public static 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 |
returnFocus | public static void returnFocus()(Code) | | |
runInEventDispatchThread | public static void runInEventDispatchThread(Runnable r)(Code) | | |
|
|