|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object jsyntaxpane.actions.ActionUtils
public class ActionUtils
Various utility methods to work on JEditorPane and its SyntaxDocument for use by Actions
Field Summary | |
---|---|
static java.util.regex.Pattern |
PTAGS_PATTERN
The Pattern to use for PTags in insertSimpleTemplate |
static java.lang.String |
TEMPLATE_SELECTION
|
Method Summary | ||
---|---|---|
static
|
getAction(javax.swing.text.JTextComponent target,
java.lang.Class<T> aClass)
Searches all actions of a JTextComponent for ab action of the given class and returns the first one that matches that class, or null if no Action is found |
|
static int |
getColumnNumber(javax.swing.text.JTextComponent editor,
int pos)
Gets the column number at given position of editor. |
|
static int |
getDocumentPosition(javax.swing.text.JTextComponent editor,
int line,
int column)
Get the closest position within the document of the component that has given line and column. |
|
static java.awt.Frame |
getFrameFor(java.awt.Component comp)
Returns the Frame that contains this component or null if the component is not within a Window or the containing window is not a frame |
|
static java.lang.String |
getIndent(java.lang.String line)
Get the indentation of a line of text. |
|
static ActionUtils |
getInstance()
Get the Singleton instance. |
|
static java.lang.String |
getLine(javax.swing.text.JTextComponent target)
Return the line of text at the TextComponent's current position |
|
static java.lang.String |
getLineAt(javax.swing.text.JTextComponent target,
int pos)
Return the line of text at the given position. |
|
static int |
getLineCount(javax.swing.text.JTextComponent pane)
|
|
static int |
getLineNumber(javax.swing.text.JTextComponent editor,
int pos)
Gets the Line Number at the give position of the editor component. |
|
static java.lang.String[] |
getSelectedLines(javax.swing.text.JTextComponent target)
Return the lines that span the selection (split as an array of Strings) if there is no selection then current line is returned. |
|
static SyntaxDocument |
getSyntaxDocument(javax.swing.text.JTextComponent component)
A helper function that will return the SyntaxDocument attached to the given text component. |
|
static DefaultSyntaxKit |
getSyntaxKit(javax.swing.text.JTextComponent target)
Return the DefaultSyntaxKit of this target, or null if the target does not have a DefaultSyntaxKit |
|
static java.lang.String |
getTab(javax.swing.text.JTextComponent target)
Return a string with number of spaces equal to the tab-stop of the TextComponent |
|
static int |
getTabSize(javax.swing.text.JTextComponent text)
Return the TabStop property for the given text component, or 0 if not used |
|
static java.lang.String |
getTokenStringAt(SyntaxDocument doc,
int pos)
Returns the the Token at pos as a String |
|
static void |
insertIntoCombo(javax.swing.JComboBox combo,
java.lang.Object item)
Insert the given item into the combo box, and set it as first selected item. |
|
static void |
insertLinesTemplate(javax.swing.text.JTextComponent target,
java.lang.String[] templateLines)
Expand the string template and replaces the selection with the expansion of the template. |
|
static void |
insertMagicString(javax.swing.text.JTextComponent target,
int dot,
java.lang.String toInsert)
Insert the given String into the textcomponent. |
|
static void |
insertMagicString(javax.swing.text.JTextComponent target,
java.lang.String result)
|
|
static void |
insertSimpleTemplate(javax.swing.text.JTextComponent target,
java.lang.String template)
Expand the string template and replaces the selection with the expansion of the template. |
|
static boolean |
isEmptyOrBlanks(java.lang.String string)
Checks if the given string is null, empty or contains whitespace only |
|
static java.lang.String |
repeatString(java.lang.String source,
int repeat)
Repeat the string source repeat times. |
|
static boolean |
selectLines(javax.swing.text.JTextComponent target)
If the selection is multi lined, then the full lines are selected, otherwise, nothing is done. |
|
static void |
sendKeyPress(javax.swing.text.JTextComponent target,
int v_key,
int modifiers)
Create and send a KeyPress KeyEvent to the component given |
|
static void |
setCaretPosition(javax.swing.text.JTextComponent target,
int line,
int column)
Sets the caret position of the given target to the given line and column |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.util.regex.Pattern PTAGS_PATTERN
public static final java.lang.String TEMPLATE_SELECTION
Method Detail |
---|
public static ActionUtils getInstance()
public static java.lang.String getIndent(java.lang.String line)
line
- the line of text
public static java.lang.String[] getSelectedLines(javax.swing.text.JTextComponent target)
target
-
public static java.lang.String getLine(javax.swing.text.JTextComponent target)
target
-
public static java.lang.String getLineAt(javax.swing.text.JTextComponent target, int pos)
target
- the text componentpos
- char position
public static java.awt.Frame getFrameFor(java.awt.Component comp)
comp
-
public static java.lang.String getTokenStringAt(SyntaxDocument doc, int pos)
doc
- pos
-
public static SyntaxDocument getSyntaxDocument(javax.swing.text.JTextComponent component)
component
-
public static int getLineNumber(javax.swing.text.JTextComponent editor, int pos) throws javax.swing.text.BadLocationException
editor
- pos
-
javax.swing.text.BadLocationException
public static int getColumnNumber(javax.swing.text.JTextComponent editor, int pos) throws javax.swing.text.BadLocationException
editor
- pos
-
javax.swing.text.BadLocationException
public static int getDocumentPosition(javax.swing.text.JTextComponent editor, int line, int column)
editor
- line
- the first being 1column
- the first being 1
public static int getLineCount(javax.swing.text.JTextComponent pane)
public static void insertIntoCombo(javax.swing.JComboBox combo, java.lang.Object item)
combo
- item
- the item to insert. if it's null, then nothing is insertedpublic static void insertMagicString(javax.swing.text.JTextComponent target, java.lang.String result)
public static java.lang.String repeatString(java.lang.String source, int repeat)
source
- repeat
-
public static boolean isEmptyOrBlanks(java.lang.String string)
string
-
public static int getTabSize(javax.swing.text.JTextComponent text)
text
-
public static void insertMagicString(javax.swing.text.JTextComponent target, int dot, java.lang.String toInsert) throws javax.swing.text.BadLocationException
target
- dot
- toInsert
-
javax.swing.text.BadLocationException
public static void insertLinesTemplate(javax.swing.text.JTextComponent target, java.lang.String[] templateLines)
#{selection}
replaced with the selection, if any. If there is
no selection, then the #{selection}
tag will be removed.
#{p:any text}
will be replaced by any text
and then
set selection to any text
This method properly handles indentation as follows:
The indentation of the whole block will match the indentation of the caret
line, or the line with the beginning of the selection, if the selection is
in whole line, i.e.e one or more lines of selected text. selectLines()
target
- JEditorCOmponent to be affectedtemplateLines
- template split as a String array of lines.insertLinesTemplate
public static void insertSimpleTemplate(javax.swing.text.JTextComponent target, java.lang.String template)
#{selection}
replaced with the selection, if any. If there is
no selection, then the #{selection}
tag will be removed.
#{p:AnyText}
will be replaced by any text
and then
set the text selection to AnyText
This methood does NOT perform any indentation and the template should
generally span one line only
target
- template
- public static boolean selectLines(javax.swing.text.JTextComponent target)
target
-
public static void setCaretPosition(javax.swing.text.JTextComponent target, int line, int column)
target
- line
- the first being 1column
- the first being 1public static java.lang.String getTab(javax.swing.text.JTextComponent target)
target
-
public static <T extends javax.swing.Action> T getAction(javax.swing.text.JTextComponent target, java.lang.Class<T> aClass)
T
- target
- aClass
-
public static DefaultSyntaxKit getSyntaxKit(javax.swing.text.JTextComponent target)
target
-
public static void sendKeyPress(javax.swing.text.JTextComponent target, int v_key, int modifiers)
target
- Editor to get the actionv_key
- from KeyEvent.V_ constantsmodifiers
- from KeyEvent.*MASK constants
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |