|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.wolfram.jlink.ui.BracketMatcher
public class BracketMatcher
A utility class that detects matching open/close bracket pairs in Mathematica input. This class is used by MathSessionPane to implement its bracket-matching (also called bracket balancing) feature, but you can also use it directly in your own programs.
BracketMatcher detects matching bracket pairs of the following types: (), {}, [], (**). It ignores brackets within strings and within Mathematica comments. It can acommodate nested comments. It searches in the typical way--expanding the current selection left and right to find the first enclosing matching brackets. If this description is not clear enough, simply create a MathSessionPane and investigate how its bracket-matching feature behaves.
To use it, create an instance and supply the input text either in the constructor or by using the setText() method. Then call the balance() method, supplying the character position of the left end of the current selection (or the position of the caret if there is no selection) and the length of the selection in characters (0 if there is no selected region). The balance() method returns a Point, which acts simply as a container for two integers: the x value is the character position of the left-most matching bracket and the y value is the character position just to the right of the rightmost bracket. That means that these numbers mark the beginning and end of a selection region that encompasses a matched bracket pair. Null is returned if there is no block larger than the current selection that is enclosed by a matched pair and has no unclosed brackets within it.
A single BracketMatcher instance can be reused with different text by calling the setText() method each time.
MathSessionPane| Constructor Summary | |
|---|---|
BracketMatcher()
|
|
BracketMatcher(java.lang.String text)
|
|
| Method Summary | |
|---|---|
java.awt.Point |
balance(int leftEndOfSelection,
int selectionLength)
Performs the search for matching brackets. |
void |
setText(java.lang.String text)
Sets the string of input that will be searched for matches. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BracketMatcher()
public BracketMatcher(java.lang.String text)
text - the string of input that will be searched for matches| Method Detail |
|---|
public void setText(java.lang.String text)
text -
public java.awt.Point balance(int leftEndOfSelection,
int selectionLength)
leftEndOfSelection - the character position of the left end of the current selection (or the position of the caret
if there is no selection)selectionLength - the length of the selection in characters (0 if there is no selected region)
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||