|
org.netbeans.modules.editor.lib/1 1.14.0 3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.netbeans.editor.Utilities
public class Utilities
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 |
---|
public static final int CASE_UPPER
public static final int CASE_LOWER
public static final int CASE_SWITCH
Method Detail |
---|
public static int getRowStart(JTextComponent c, int offset) throws BadLocationException
c
- text component to operate onoffset
- position in document where to start searching
BadLocationException
public static int getRowStart(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getRowStart(BaseDocument doc, int offset, int lineShift) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searchinglineShift
- shift the given offset forward/back relatively
by some amount of lines
BadLocationException
public static int getRowFirstNonWhite(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the line
BadLocationException
public static int getRowLastNonWhite(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the line
BadLocationException
public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the line
BadLocationException
public static int getRowIndent(BaseDocument doc, int offset, boolean downDir) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the linedownDir
- 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.
BadLocationException
public static int getRowEnd(JTextComponent c, int offset) throws BadLocationException
c
- text component to operate onoffset
- position in document where to start searchingrelLine
- shift offset forward/back by some amount of lines
BadLocationException
public static int getRowEnd(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static int getPositionAbove(JTextComponent c, int offset, int x) throws BadLocationException
doc
- document to operate onoffset
- position in document from which the current line is determinedx
- float x-coordinate value
BadLocationException
public static int getPositionBelow(JTextComponent c, int offset, int x) throws BadLocationException
c
- text component to operate onoffset
- position in document from which the current line is determinedx
- float x-coordinate value
BadLocationException
public static int getWordStart(JTextComponent c, int offset) throws BadLocationException
c
- text component to operate onoffset
- position in document from which the current line is determined
BadLocationException
public static int getWordStart(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static int getWordEnd(JTextComponent c, int offset) throws BadLocationException
BadLocationException
public static int getWordEnd(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static int getNextWord(JTextComponent c, int offset) throws BadLocationException
BadLocationException
public static int getNextWord(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static int getPreviousWord(JTextComponent c, int offset) throws BadLocationException
BadLocationException
public static int getPreviousWord(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static int getFirstWhiteFwd(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searchinglimitPos
- position in document (greater or equal than offset) where
the search will stop reporting unsuccessful search by returning -1
BadLocationException
public static int getFirstNonWhiteFwd(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searchinglimitPos
- position in document (greater or equal than offset) where
the search will stop reporting unsuccessful search by returning -1
BadLocationException
public static int getFirstWhiteBwd(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searchinglimitPos
- position in document (lower or equal than offset) where
the search will stop reporting unsuccessful search by returning -1
BadLocationException
public static int getFirstNonWhiteBwd(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searchinglimitPos
- position in document (lower or equal than offset) where
the search will stop reporting unsuccessful search by returning -1
BadLocationException
public static int getLineOffset(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document where to start searching
BadLocationException
public static int getRowStartFromLineOffset(BaseDocument doc, int lineIndex)
lineIndex
- line index starting from 0
public static int getVisualColumn(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document for which the visual column should be found
BadLocationException
public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
getIdentifierBlock()
public static int[] getIdentifierBlock(JTextComponent c, int offset) throws BadLocationException
c
- JTextComponent to work onoffset
- position in document - usually the caret.getDot()
BadLocationException
public static int[] getIdentifierBlock(BaseDocument doc, int offset) throws BadLocationException
doc
- document to work onoffset
- position in document - usually the caret.getDot()
BadLocationException
public static String getWord(JTextComponent c, int offset) throws BadLocationException
c
- component to work withoffset
- position in document - usually the caret.getDot()
BadLocationException
public static int[] getSelectionOrIdentifierBlock(JTextComponent c, int offset) throws BadLocationException
c
- component to work withoffset
- position in document - usually the caret.getDot()
BadLocationException
public static int[] getSelectionOrIdentifierBlock(JTextComponent c)
public static String getIdentifierBefore(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static String getSelectionOrIdentifier(JTextComponent c, int offset) throws BadLocationException
BadLocationException
public static String getSelectionOrIdentifier(JTextComponent c)
public static String getWord(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
public static boolean changeCase(BaseDocument doc, int offset, int len, int type) throws BadLocationException
doc
- document to operate onoffset
- position in document determines the changed area begininglen
- number of chars to changetype
- either CASE_CAPITAL, CASE_SMALL or CASE_SWITCH
BadLocationException
public static boolean isRowEmpty(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position anywhere on the tested line
BadLocationException
public static int getFirstNonEmptyRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException
BadLocationException
public static boolean isRowWhite(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position anywhere on the tested line
BadLocationException
public static int getFirstNonWhiteRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException
BadLocationException
public static int reformat(BaseDocument doc, int startOffset, int endOffset) throws BadLocationException
doc
- document to work withstartOffset
- offset at which the formatting startsendOffset
- offset at which the formatting ends
BadLocationException
public static void reformatLine(BaseDocument doc, int pos) throws BadLocationException
BadLocationException
public static int getRowCount(BaseDocument doc, int startPos, int endPos) throws BadLocationException
BadLocationException
public static int getRowCount(BaseDocument doc)
public static String getTabInsertString(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
Formatter.insertTabString()
public static int getNextTabColumn(BaseDocument doc, int offset) throws BadLocationException
doc
- document to work withoffset
- position at which the TAB was pressed
BadLocationException
public static void setStatusText(JTextComponent c, String text)
public static void setStatusText(JTextComponent c, String text, Coloring extraColoring)
public static void setStatusBoldText(JTextComponent c, String text)
public static String getStatusText(JTextComponent c)
public static void clearStatusText(JTextComponent c)
public static void insertMark(BaseDocument doc, Mark mark, int offset) throws BadLocationException, InvalidMarkException
public static void moveMark(BaseDocument doc, Mark mark, int newOffset) throws BadLocationException, InvalidMarkException
public static void returnFocus()
public static void requestFocus(JTextComponent c)
public static void runInEventDispatchThread(Runnable r)
public static String debugPosition(BaseDocument doc, int offset)
public static String offsetToLineColumnString(BaseDocument doc, int offset)
public static String debugDocument(Document doc)
public static void performAction(Action a, ActionEvent evt, JTextComponent target)
public static JTextComponent getLastActiveComponent()
public static JTextComponent getFocusedComponent()
public static EditorUI getEditorUI(JTextComponent target)
target
- JTextComponent for which the extended UI should be obtained
public static BaseKit getKit(JTextComponent target)
target
- JTextComponent for which the editor kit should be obtained
public static Class getKitClass(JTextComponent target)
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.
target
- The JTextComponent
to get the kit class for.
Can be null
.
null
if the target
is null
.public static BaseDocument getDocument(JTextComponent target)
target
- JTextComponent for which the document should be obtained
public static SyntaxSupport getSyntaxSupport(JTextComponent target)
target
- JTextComponent for which the syntax-support should be obtained
public static View getRootView(JTextComponent component, Class rootViewClass)
component
- component from which the root view is fetched.rootViewClass
- class of the view to return.
public static View getDocumentView(JTextComponent component)
public static String keySequenceToString(KeyStroke[] seq)
Array
- of KeyStrokes representing the actual sequence.
public static String keyStrokeToString(KeyStroke stroke)
the
- KeyStroke to get description of
public static void annotateLoggable(Throwable t)
Throwable
to a log file.
The method is internally using
org.netbeans.editor
logger and Level.INFO
.
t
- The exception that will be logged.
|
org.netbeans.modules.editor.lib/1 1.14.0 3 | |||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |