|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjavax.swing.text.AbstractDocument
javax.swing.text.PlainDocument
org.fife.ui.rtextarea.RDocument
org.fife.ui.rsyntaxtextarea.RSyntaxDocument
public class RSyntaxDocument
The document used by RSyntaxTextArea
.
This document is like javax.swing.text.PlainDocument
except that
it also keeps track of syntax highlighting in the document. It has a "style"
attribute associated with it that determines how syntax highlighting is done
(i.e., what language is being highlighted).
Instances of RSyntaxTextArea
will only accept instances of
RSyntaxDocument
, since it is this document that keeps
track of syntax highlighting. All others will cause an exception to be
thrown.
To change the language being syntax highlighted at any time, you merely have
to call setSyntaxStyle(java.lang.String)
. Other than that, this document can be
treated like any other save one caveat: all DocumentEvent
s of
type CHANGE
use their offset and length values to represent the
first and last lines, respectively, that have had their syntax coloring
change. This is really a hack to increase the speed of the painting code
and should really be corrected, but oh well.
Nested Class Summary |
---|
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument |
---|
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement |
Field Summary | |
---|---|
protected DynamicIntArray |
lastTokensOnLines
Array of values representing the "last token type" on each line. |
Fields inherited from class javax.swing.text.PlainDocument |
---|
lineLimitAttribute, tabSizeAttribute |
Fields inherited from class javax.swing.text.AbstractDocument |
---|
BAD_LOCATION, BidiElementName, ContentElementName, ElementNameAttribute, listenerList, ParagraphElementName, SectionElementName |
Fields inherited from interface javax.swing.text.Document |
---|
StreamDescriptionProperty, TitleProperty |
Constructor Summary | |
---|---|
RSyntaxDocument(String syntaxStyle)
Constructs a plain text document. |
|
RSyntaxDocument(TokenMakerFactory tmf,
String syntaxStyle)
Constructs a plain text document. |
Method Summary | |
---|---|
protected void |
fireInsertUpdate(DocumentEvent e)
Alerts all listeners to this document of an insertion. |
protected void |
fireRemoveUpdate(DocumentEvent chng)
This method is called AFTER the content has been inserted into the document and the element structure has been updated. |
boolean |
getCompleteMarkupCloseTags()
Returns whether closing markup tags should be automatically completed. |
boolean |
getCurlyBracesDenoteCodeBlocks()
Returns whether the current programming language uses curly braces ('{' and '}') to denote code blocks. |
boolean |
getLanguageIsMarkup()
Returns whether the current language is a markup language, such as HTML, XML or PHP. |
int |
getLastTokenTypeOnLine(int line)
Returns the token type of the last token on the given line. |
String[] |
getLineCommentStartAndEnd()
Returns the text to place at the beginning and end of a line to "comment" it in the current programming language. |
boolean |
getShouldIndentNextLine(int line)
This method returns whether auto indentation should be done if Enter is pressed at the end of the specified line. |
Token |
getTokenListForLine(int line)
Returns a token list for the specified segment of text representing the specified line number. |
boolean |
isWhitespaceVisible()
Returns whether whitespace is visible. |
void |
setSyntaxStyle(String styleKey)
Sets the syntax style being used for syntax highlighting in this document. |
void |
setSyntaxStyle(TokenMaker tokenMaker)
Sets the syntax style being used for syntax highlighting in this document. |
void |
setTokenMakerFactory(TokenMakerFactory tmf)
Sets the token maker factory used by this document. |
void |
setWhitespaceVisible(boolean visible)
Sets whether whitespace is visible. |
protected void |
updateSyntaxHighlightingInformation()
Updates internal state information; e.g. |
Methods inherited from class org.fife.ui.rtextarea.RDocument |
---|
charAt |
Methods inherited from class javax.swing.text.PlainDocument |
---|
createDefaultRoot, getDefaultRootElement, getParagraphElement, insertString, insertUpdate, removeUpdate |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected transient DynamicIntArray lastTokensOnLines
Constructor Detail |
---|
public RSyntaxDocument(String syntaxStyle)
syntaxStyle
- The syntax highlighting scheme to use.public RSyntaxDocument(TokenMakerFactory tmf, String syntaxStyle)
tmf
- The TokenMakerFactory
for this document. If
this is null
, a default factory is used.syntaxStyle
- The syntax highlighting scheme to use.Method Detail |
---|
protected void fireInsertUpdate(DocumentEvent e)
The syntax highlighting stuff has to be here instead of in
insertUpdate
because insertUpdate
is not
called by the undo/redo actions, but this method is.
fireInsertUpdate
in class AbstractDocument
e
- The change.protected void fireRemoveUpdate(DocumentEvent chng)
The syntax-highlighting updates need to be done here (as opposed to
an override of postRemoveUpdate
) as this method is called
in response to undo/redo events, whereas postRemoveUpdate
is not.
Now that the text is actually inserted into the content and element structure, we can update our token elements and "last tokens on lines" structure.
fireRemoveUpdate
in class AbstractDocument
chng
- The change that occurred.PlainDocument.removeUpdate(javax.swing.text.AbstractDocument.DefaultDocumentEvent)
public boolean getCompleteMarkupCloseTags()
true
if
getLanguageIsMarkup()
also returns true
.
getLanguageIsMarkup()
public boolean getCurlyBracesDenoteCodeBlocks()
public boolean getLanguageIsMarkup()
public int getLastTokenTypeOnLine(int line)
line
- The line to inspect.
public String[] getLineCommentStartAndEnd()
null
value for either means there
is no string to add for that part. A value of
null
for the array means this language
does not support commenting/uncommenting lines.public boolean getShouldIndentNextLine(int line)
line
- The line to check.
public final Token getTokenListForLine(int line)
tokenMaker.getTokenList
that takes into account the last
token on the previous line to assure token accuracy.
line
- The line number of text
in the document, >= 0.
public boolean isWhitespaceVisible()
setWhitespaceVisible(boolean)
public void setSyntaxStyle(String styleKey)
TokenMakerFactory
. By default, all RSyntaxDocument
s
support all languages built into RSyntaxTextArea
.
styleKey
- The new style to use, such as
SyntaxConstants.SYNTAX_STYLE_JAVA
. If this style is not
known or supported by this document, then
SyntaxConstants.SYNTAX_STYLE_NONE
is used.public void setSyntaxStyle(TokenMaker tokenMaker)
RSyntaxTextArea
.
tokenMaker
- The new token maker to use.public void setTokenMakerFactory(TokenMakerFactory tmf)
tmf
- The TokenMakerFactory
for this document. If
this is null
, a default factory is used.public void setWhitespaceVisible(boolean visible)
visible
- Whether whitespace should be visible.isWhitespaceVisible()
protected void updateSyntaxHighlightingInformation()
This is called internally whenever the syntax style changes.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |