public class Utilities extends Object
Modifier and Type | Field and Description |
---|---|
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.
|
Modifier and Type | Method and Description |
---|---|
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 JComponent[] |
createSingleLineEditor(String mimeType)
Creates a single line editor pane.
|
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 String |
debugPosition(BaseDocument doc,
int offset,
String separator) |
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)
Deprecated.
|
static int |
getFirstNonWhiteBwd(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getFirstNonWhiteBwd(BaseDocument doc,
int offset,
int limitPos)
Deprecated.
|
static int |
getFirstNonWhiteFwd(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getFirstNonWhiteFwd(BaseDocument doc,
int offset,
int limitPos)
Deprecated.
|
static int |
getFirstNonWhiteRow(BaseDocument doc,
int offset,
boolean downDir)
Deprecated.
|
static int |
getFirstWhiteBwd(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getFirstWhiteBwd(BaseDocument doc,
int offset,
int limitPos)
Deprecated.
|
static int |
getFirstWhiteFwd(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getFirstWhiteFwd(BaseDocument doc,
int offset,
int limitPos)
Deprecated.
|
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)
Deprecated.
|
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)
Deprecated.
|
static int |
getNextWord(JTextComponent c,
int offset)
Deprecated.
|
static int |
getPositionAbove(JTextComponent c,
int offset,
int x)
Deprecated.
|
static int |
getPositionBelow(JTextComponent c,
int offset,
int x)
Deprecated.
|
static int |
getPreviousWord(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getPreviousWord(JTextComponent c,
int offset)
Deprecated.
|
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)
Deprecated.
|
static int |
getRowCount(BaseDocument doc,
int startPos,
int endPos)
Deprecated.
|
static int |
getRowEnd(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getRowEnd(JTextComponent c,
int offset)
Deprecated.
|
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)
Deprecated.
|
static int |
getRowStart(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getRowStart(BaseDocument doc,
int offset,
int lineShift)
Deprecated.
Deprecated without replacement
|
static int |
getRowStart(JTextComponent c,
int offset)
Get the starting position of the row.
|
static int |
getRowStartFromLineOffset(BaseDocument doc,
int lineIndex)
Deprecated.
|
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.
Formatter#insertTabString() editor.deprecated.pre65formatting |
static int |
getVisualColumn(BaseDocument doc,
int offset)
Return visual column (with expanded tabs) on the line.
|
static int |
getVisualColumn(org.netbeans.api.editor.document.LineDocument 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)
Deprecated.
|
static int |
getWordEnd(JTextComponent c,
int offset)
Deprecated.
|
static int |
getWordStart(BaseDocument doc,
int offset)
Deprecated.
|
static int |
getWordStart(JTextComponent c,
int offset)
Deprecated.
|
static void |
insertMark(BaseDocument doc,
Mark mark,
int offset) |
static boolean |
isRowEmpty(BaseDocument doc,
int offset)
Deprecated.
use
LineDocumentUtils.isLineEmpty(org.netbeans.api.editor.document.LineDocument, int) . |
static boolean |
isRowWhite(BaseDocument doc,
int offset)
Deprecated.
|
static boolean |
isSelectionShowing(Caret caret)
Check whether caret's selection is visible and there is at least
one selected character showing.
|
static boolean |
isSelectionShowing(JTextComponent component) |
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 |
runViewHierarchyTransaction(JTextComponent component,
boolean readLockDocument,
Runnable r)
Execute the given runnable with view hierarchy being locked.
|
static <T> T |
runWithOnSaveTasksDisabled(Mutex.Action<T> run)
Don't use unless you know what you are doing.
|
static void |
setStatusBoldText(JTextComponent c,
String text) |
static void |
setStatusText(JTextComponent c,
String text) |
static void |
setStatusText(JTextComponent c,
String text,
Coloring extraColoring) |
static void |
setStatusText(JTextComponent c,
String text,
int importance) |
public static final int CASE_UPPER
public static final int CASE_LOWER
public static final int CASE_SWITCH
public static int getRowStart(JTextComponent c, int offset) throws BadLocationException
c
- text component to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getRowStart(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated 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 linesBadLocationException
public static int getRowFirstNonWhite(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the lineBadLocationException
@Deprecated public static int getRowLastNonWhite(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document anywhere on the lineBadLocationException
public static int getRowIndent(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document anywhere on the lineBadLocationException
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
@Deprecated public static int getRowEnd(JTextComponent c, int offset) throws BadLocationException
LineDocumentUtils
c
- text component to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getRowEnd(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- offset
- BadLocationException
@Deprecated public static int getPositionAbove(JTextComponent c, int offset, int x) throws BadLocationException
LineDocumentUtils
c
- component to operate onoffset
- position in document from which the current line is determinedx
- float x-coordinate valueBadLocationException
@Deprecated public static int getPositionBelow(JTextComponent c, int offset, int x) throws BadLocationException
LineDocumentUtils
c
- text component to operate onoffset
- position in document from which the current line is determinedx
- float x-coordinate valueBadLocationException
@Deprecated public static int getWordStart(JTextComponent c, int offset) throws BadLocationException
LineDocumentUtils
c
- text component to operate onoffset
- position in document from which the current line is determinedBadLocationException
@Deprecated public static int getWordStart(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getWordEnd(JTextComponent c, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getWordEnd(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getNextWord(JTextComponent c, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getNextWord(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getPreviousWord(JTextComponent c, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getPreviousWord(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
@Deprecated public static int getFirstWhiteFwd(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getFirstWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
LineDocumentUtils
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 -1BadLocationException
@Deprecated public static int getFirstNonWhiteFwd(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getFirstNonWhiteFwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
LineDocumentUtils
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 -1BadLocationException
@Deprecated public static int getFirstWhiteBwd(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getFirstWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
LineDocumentUtils
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 -1BadLocationException
@Deprecated public static int getFirstNonWhiteBwd(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getFirstNonWhiteBwd(BaseDocument doc, int offset, int limitPos) throws BadLocationException
LineDocumentUtils
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 -1BadLocationException
@Deprecated public static int getLineOffset(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position in document where to start searchingBadLocationException
@Deprecated public static int getRowStartFromLineOffset(BaseDocument doc, int lineIndex)
LineDocumentUtils
lineIndex
- line index starting from 0public static int getVisualColumn(BaseDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document for which the visual column should be foundBadLocationException
public static int getVisualColumn(org.netbeans.api.editor.document.LineDocument doc, int offset) throws BadLocationException
doc
- document to operate onoffset
- position in document for which the visual column should be foundBadLocationException
public static String getIdentifier(BaseDocument doc, int offset) throws BadLocationException
BadLocationException
Utilities.getIdentifierBlock(BaseDocument,int)
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_SWITCHBadLocationException
@Deprecated public static boolean isRowEmpty(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils.isLineEmpty(org.netbeans.api.editor.document.LineDocument, int)
.doc
- document to operate onoffset
- position anywhere on the tested lineBadLocationException
@Deprecated public static int getFirstNonEmptyRow(BaseDocument doc, int offset, boolean downDir) throws BadLocationException
BadLocationException
@Deprecated public static boolean isRowWhite(BaseDocument doc, int offset) throws BadLocationException
LineDocumentUtils
doc
- document to operate onoffset
- position anywhere on the tested lineBadLocationException
@Deprecated 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 endsBadLocationException
public static void reformatLine(BaseDocument doc, int pos) throws BadLocationException
BadLocationException
@Deprecated public static int getRowCount(BaseDocument doc, int startPos, int endPos) throws BadLocationException
BadLocationException
@Deprecated public static int getRowCount(BaseDocument doc)
@Deprecated public static String getTabInsertString(BaseDocument doc, int offset) throws BadLocationException
Formatter#insertTabString()
editor.deprecated.pre65formattingBadLocationException
public static int getNextTabColumn(BaseDocument doc, int offset) throws BadLocationException
doc
- document to work withoffset
- position at which the TAB was pressedBadLocationException
public static void setStatusText(JTextComponent c, String text)
public static void setStatusText(JTextComponent c, String text, int importance)
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 debugPosition(BaseDocument doc, int offset, String separator)
doc
- non-null document.offset
- offset to translate to line and column info.separator
- non-null separator of line and column info (either single charater or a string).spublic 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 obtainedpublic static BaseKit getKit(JTextComponent target)
target
- JTextComponent for which the editor kit should be obtainedpublic 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 obtainedpublic static SyntaxSupport getSyntaxSupport(JTextComponent target)
target
- JTextComponent for which the syntax-support should be obtainedpublic 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 void runViewHierarchyTransaction(JTextComponent component, boolean readLockDocument, Runnable r)
component
- non-null text component of which the view hierarchy is being explored.readLockDocument
- if true lock the document before locking the view hierarchy.
This parameter should only be false if it's known that the document was already read/write-locked
prior calling this method.r
- non-null runnable to execute.public static String keySequenceToString(KeyStroke[] seq)
seq
- Array of KeyStrokes representing the actual sequence.public static String keyStrokeToString(KeyStroke stroke)
stroke
- the KeyStroke to get description of@Deprecated 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.public static boolean isSelectionShowing(Caret caret)
caret
- non-null caret.public static boolean isSelectionShowing(JTextComponent component)
component
- non-null component.Utilities.isSelectionShowing(Caret)
public static JComponent[] createSingleLineEditor(String mimeType) throws IllegalArgumentException
mimeType
- The mimetype of the editor's content.JComponent
and
the second one is the editor JTextComponent
.IllegalArgumentException
- when EditorKit is not found for the given mime type.public static <T> T runWithOnSaveTasksDisabled(Mutex.Action<T> run)