public class SyntaxDocument
extends javax.swing.text.PlainDocument
javax.swing.text.AbstractDocument.AbstractElement, javax.swing.text.AbstractDocument.AttributeContext, javax.swing.text.AbstractDocument.BranchElement, javax.swing.text.AbstractDocument.Content, javax.swing.text.AbstractDocument.DefaultDocumentEvent, javax.swing.text.AbstractDocument.ElementEdit, javax.swing.text.AbstractDocument.LeafElement| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
CAN_REDO |
static java.lang.String |
CAN_UNDO |
| Constructor and Description |
|---|
SyntaxDocument(Lexer lexer) |
| Modifier and Type | Method and Description |
|---|---|
void |
addPropertyChangeListener(java.lang.String property,
java.beans.PropertyChangeListener listener) |
SyntaxDocument |
append(java.lang.String str)
Appends the given string to the text of this document.
|
boolean |
canRedo() |
boolean |
canUndo() |
void |
clearUndos()
Discards all undoable edits
|
void |
doRedo()
Performs a redo action, if possible.
|
void |
doUndo()
Performs an undo action, if possible
|
protected void |
fireChangedUpdate(javax.swing.event.DocumentEvent e) |
protected void |
fireInsertUpdate(javax.swing.event.DocumentEvent e) |
protected void |
fireRemoveUpdate(javax.swing.event.DocumentEvent e) |
java.lang.String |
getLineAt(int pos)
Gets the line at given position.
|
int |
getLineCount()
Returns the number of lines in this document
|
int |
getLineEndOffset(int pos)
Returns the end position of the line at pos.
|
int |
getLineNumberAt(int pos)
Returns the line number at given position.
|
int |
getLineStartOffset(int pos)
Returns the starting position of the line at pos
|
java.util.regex.Matcher |
getMatcher(java.util.regex.Pattern pattern)
Returns a matcher that matches the given pattern on the entire document
|
java.util.regex.Matcher |
getMatcher(java.util.regex.Pattern pattern,
int start)
Returns a matcher that matches the given pattern in the part of the
document starting at offset start.
|
java.util.regex.Matcher |
getMatcher(java.util.regex.Pattern pattern,
int start,
int length)
Returns a matcher that matches the given pattern in the part of the
document starting at offset start and ending at start + length.
|
Token |
getNextToken(Token tok)
Returns the token following the current token, or null
This is an expensive operation, so do not use it to update the gui
|
Token |
getPairFor(Token t)
This is used to return the other part of a paired token in the document.
|
Token |
getPrevToken(Token tok)
Returns the token prior to the given token, or null
This is an expensive operation, so do not use it to update the gui
|
Token |
getTokenAt(int pos)
Finds the token at a given position.
|
java.util.Iterator<Token> |
getTokens(int start,
int end)
Returns an iterator of tokens between p0 and p1.
|
java.lang.String |
getUncommentedText(int aStart,
int anEnd)
Gets the text without the comments.
|
Token |
getWordAt(int offs,
java.util.regex.Pattern p) |
void |
removeLineAt(int pos)
Deletes the line at given position
|
void |
removePropertyChangeListener(java.lang.String property,
java.beans.PropertyChangeListener listener) |
void |
replace(int offset,
int length,
java.lang.String text,
javax.swing.text.AttributeSet attrs)
We override this here so that the replace is treated as one operation
by the undo manager
|
void |
replaceLineAt(int pos,
java.lang.String newLines)
Replaces the line at given position with the given string, which can span
multiple lines
|
void |
replaceToken(Token token,
java.lang.String replacement)
Replaces the token with the replacement string
|
void |
setCanRedo(boolean value) |
void |
setCanUndo(boolean value) |
java.lang.String |
toString() |
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertString, insertUpdate, removeUpdateaddDocumentListener, addUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, removeDocumentListener, removeUndoableEditListener, render, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlockpublic static final java.lang.String CAN_UNDO
public static final java.lang.String CAN_REDO
public SyntaxDocument(Lexer lexer)
protected void fireChangedUpdate(javax.swing.event.DocumentEvent e)
fireChangedUpdate in class javax.swing.text.AbstractDocumentprotected void fireInsertUpdate(javax.swing.event.DocumentEvent e)
fireInsertUpdate in class javax.swing.text.AbstractDocumentprotected void fireRemoveUpdate(javax.swing.event.DocumentEvent e)
fireRemoveUpdate in class javax.swing.text.AbstractDocumentpublic void replaceToken(Token token, java.lang.String replacement)
public java.util.Iterator<Token> getTokens(int start, int end)
start - start position for getting tokensend - position for last tokenpublic Token getTokenAt(int pos)
public Token getWordAt(int offs, java.util.regex.Pattern p)
public Token getNextToken(Token tok)
public Token getPrevToken(Token tok)
public Token getPairFor(Token t)
public void setCanUndo(boolean value)
public void setCanRedo(boolean value)
public void addPropertyChangeListener(java.lang.String property,
java.beans.PropertyChangeListener listener)
public void removePropertyChangeListener(java.lang.String property,
java.beans.PropertyChangeListener listener)
public void doUndo()
public boolean canUndo()
public void doRedo()
public boolean canRedo()
public void clearUndos()
public java.util.regex.Matcher getMatcher(java.util.regex.Pattern pattern)
public java.util.regex.Matcher getMatcher(java.util.regex.Pattern pattern,
int start)
startpublic java.util.regex.Matcher getMatcher(java.util.regex.Pattern pattern,
int start,
int length)
startpublic java.lang.String getLineAt(int pos)
throws javax.swing.text.BadLocationException
pos - Position (usually from text.getCaretPosition()javax.swing.text.BadLocationExceptionpublic void removeLineAt(int pos)
throws javax.swing.text.BadLocationException
javax.swing.text.BadLocationExceptionpublic void replaceLineAt(int pos,
java.lang.String newLines)
throws javax.swing.text.BadLocationException
javax.swing.text.BadLocationExceptionpublic java.lang.String getUncommentedText(int aStart,
int anEnd)
{ // it's a comment this method will return "{ ".aStart - start of the text.anEnd - end of the text.public int getLineStartOffset(int pos)
public int getLineEndOffset(int pos)
public int getLineCount()
public int getLineNumberAt(int pos)
public java.lang.String toString()
toString in class java.lang.Objectpublic void replace(int offset,
int length,
java.lang.String text,
javax.swing.text.AttributeSet attrs)
throws javax.swing.text.BadLocationException
replace in class javax.swing.text.AbstractDocumentjavax.swing.text.BadLocationExceptionpublic SyntaxDocument append(java.lang.String str)