public class SyntaxDocument
extends javax.swing.text.DefaultStyledDocument
| Modifier and Type | Class and Description |
|---|---|
static class |
SyntaxDocument.ATTR_TYPE
The attribute type.
|
javax.swing.text.DefaultStyledDocument.AttributeUndoableEdit, javax.swing.text.DefaultStyledDocument.ElementBuffer, javax.swing.text.DefaultStyledDocument.ElementSpec, javax.swing.text.DefaultStyledDocument.SectionElementjavax.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 javax.swing.text.SimpleAttributeSet |
DEFAULT_COMMENT
the attribute set for comments.
|
static java.lang.String |
DEFAULT_FONT_FAMILY
the font family.
|
static int |
DEFAULT_FONT_SIZE
the font size.
|
static javax.swing.text.SimpleAttributeSet |
DEFAULT_KEYWORD
the attribute set for keywords.
|
static javax.swing.text.SimpleAttributeSet |
DEFAULT_NORMAL
the attribute set for normal code.
|
static javax.swing.text.SimpleAttributeSet |
DEFAULT_STRING
the attribute set for strings.
|
protected boolean |
m_AddMatchingEndBlocks
whether to add matching brackets.
|
protected java.awt.Color |
m_BackgroundColor
the background color.
|
protected java.lang.String |
m_BlockEnd
the end of a block.
|
protected java.lang.String |
m_BlockStart
the start of a block.
|
protected boolean |
m_CaseSensitive
whether keywords are case-sensitive.
|
protected java.lang.String |
m_Delimiters
the delimiters.
|
protected java.lang.String |
m_FontName
the font name.
|
protected int |
m_FontSize
the font size.
|
protected java.lang.String |
m_Indentation
the number of spaces used for indentation.
|
protected boolean |
m_InsideMultiLineComment
whether we're currently in a multi-line comment.
|
protected java.util.HashMap<java.lang.String,javax.swing.text.MutableAttributeSet> |
m_Keywords
the keywords.
|
protected boolean |
m_MultiLineComment
whether multi-line comments are enabled.
|
protected java.lang.String |
m_MultiLineCommentEnd
the multi-line comment end.
|
protected java.lang.String |
m_MultiLineCommentStart
the multi-line comment start.
|
protected java.lang.String |
m_QuoteDelimiters
the quote delimiter.
|
protected java.lang.String |
m_QuoteEscape
the quote escape.
|
protected javax.swing.text.Element |
m_RootElement
the root element.
|
protected javax.swing.text.DefaultStyledDocument |
m_Self
the document.
|
protected java.lang.String |
m_SingleLineCommentStart
the single-line comment start.
|
protected boolean |
m_UseBlanks
whether to use blanks instead of tabs.
|
static int |
MAX_TABS
the maximum number of tabs.
|
protected static long |
serialVersionUID
for serialization.
|
| Constructor and Description |
|---|
SyntaxDocument(java.util.Properties props)
Initializes the document.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addKeyword(java.lang.String keyword,
javax.swing.text.MutableAttributeSet attr)
Associates a keyword with a particular formatting style.
|
void |
addKeywords(java.lang.String[] keywords,
javax.swing.text.MutableAttributeSet attr)
Associates the keywords with a particular formatting style.
|
protected java.lang.String |
addMatchingBlockEnd(int offset)
Adds the matching block end.
|
protected void |
applyHighlighting(java.lang.String content,
int line)
Parse the line to determine the appropriate highlighting.
|
protected void |
checkForTokens(java.lang.String content,
int startOffset,
int endOffset)
Parse the line for tokens to highlight.
|
protected void |
commentLinesAfter(java.lang.String content,
int line)
Highlight comment lines to matching end delimiter.
|
protected boolean |
commentLinesBefore(java.lang.String content,
int line)
Highlight lines when a multi line comment is still 'open' (ie. matching end
delimiter has not yet been encountered).
|
protected boolean |
endingMultiLineComment(java.lang.String content,
int startOffset,
int endOffset)
Does this line contain the end delimiter of a multi-line comment.
|
java.lang.String |
escapeQuote(java.lang.String quoteDelimiter)
Escapes the quote delimiter.
|
boolean |
getAddMatchingEndBlocks()
Returns whether matching block ends are inserted or not.
|
java.awt.Color |
getBackgroundColor()
Returns the background color.
|
java.lang.String |
getBlockEnd()
Returns the end of a block.
|
java.lang.String |
getBlockStart()
Returns the start of a block.
|
boolean |
getCaseSensitive()
Returns whether blanks are used instead of tabs.
|
java.lang.String |
getDelimiters()
Returns the delimiter characters to use.
|
java.lang.String |
getFontName()
gets the current font family.
|
int |
getFontSize()
gets the current font size.
|
int |
getIndentationSize()
Returns the number of blanks used for indentation.
|
javax.swing.text.MutableAttributeSet |
getKeywordFormatting(java.lang.String keyword)
Gets the formatting for a keyword.
|
protected java.lang.String |
getLine(java.lang.String content,
int offset)
Returns the line.
|
boolean |
getMultiLineComment()
Returns whether multi-line comments are enabled.
|
java.lang.String |
getMultiLineCommentEnd()
Returns the end of a multi-line comment.
|
java.lang.String |
getMultiLineCommentStart()
Returns the string that is the start of a multi-line comment.
|
protected int |
getOtherToken(java.lang.String content,
int startOffset,
int endOffset)
Searches for a keyword token.
|
java.lang.String |
getQuoteDelimiters()
Returns the quote delimiter characters to use.
|
java.lang.String |
getQuoteEscape()
Returns the character for escaping a quote delimiter.
|
protected int |
getQuoteToken(java.lang.String content,
int startOffset,
int endOffset)
Searches for a quote token.
|
java.lang.String |
getSingleLineCommentStart()
Retrusn the single line comment start string.
|
boolean |
getUseBlanks()
Returns whether blanks are used instead of tabs.
|
protected void |
highlightLinesAfter(java.lang.String content,
int line)
Highlight lines to start or end delimiter.
|
protected int |
indexOf(java.lang.String content,
java.lang.String needle,
int offset)
Assume the needle will the found at the start/end of the line.
|
void |
insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet a)
Override to apply syntax highlighting after the document has been updated.
|
boolean |
isDelimiter(java.lang.String character)
Checks whether the character is a delimiter.
|
protected boolean |
isMultiLineComment()
We have found a start delimiter and are still searching for the end
delimiter.
|
boolean |
isQuoteDelimiter(java.lang.String character)
Checks whether the character is quote delimiter.
|
protected int |
lastIndexOf(java.lang.String content,
java.lang.String needle,
int offset)
Assume the needle will the found at the start/end of the line.
|
void |
processChangedLines(int offset,
int length)
Determine how many lines have been changed, then apply highlighting to each
line.
|
void |
remove(int offset,
int length)
Applies syntax highlighting after the document has been updated.
|
void |
removeKeyword(java.lang.String keyword)
Removes an association between a keyword with a particular formatting
style.
|
void |
setAddMatchingEndBlocks(boolean value)
Sets whether matching block ends are inserted or not.
|
static void |
setAttributeColor(javax.swing.text.MutableAttributeSet attr,
java.awt.Color c)
Sets the foreground (font) color of the specified attribute.
|
void |
setAttributeColor(SyntaxDocument.ATTR_TYPE attr,
java.awt.Color c)
Sets the foreground (font) color of the specified attribute.
|
static void |
setAttributeFont(javax.swing.text.MutableAttributeSet attr,
java.awt.Font f)
Sets the font of the specified attribute.
|
void |
setAttributeFont(SyntaxDocument.ATTR_TYPE attr,
int style)
Sets the font of the specified attribute.
|
void |
setBackgroundColor(java.awt.Color value)
Sets the background color.
|
void |
setBlockEnd(java.lang.String value)
Sets the string that is the end of a block.
|
void |
setBlockStart(java.lang.String value)
Sets the string that is the start of a block.
|
void |
setCaseSensitive(boolean value)
Sets whether the keywords are case-sensitive or not.
|
void |
setDelimiters(java.lang.String value)
Sets the delimiter characters to use.
|
void |
setFontName(java.lang.String fontName)
sets the current font family (affects all built-in styles).
|
void |
setFontSize(int fontSize)
sets the current font size (affects all built-in styles).
|
void |
setIndentationSize(int value)
Sets the number of blanks to use for indentation.
|
protected void |
setInsideMultiLineComment(boolean value)
Sets whether we're currently within a multi-line comment or not.
|
void |
setMultiLineComment(boolean value)
Sets whether to enable multi-line comments.
|
void |
setMultiLineCommentEnd(java.lang.String value)
Sets the string that is the end of a multi-line comment.
|
void |
setMultiLineCommentStart(java.lang.String value)
Sets the string that is the start of a multi-line comment.
|
void |
setQuoteDelimiters(java.lang.String value)
Sets the quote delimiter characters to use.
|
void |
setQuoteEscape(java.lang.String value)
Sets the character to use for escaping a quote character.
|
void |
setSingleLineCommentStart(java.lang.String value)
Sets the string that is the start of a single-line comment.
|
void |
setTabs(int charactersPerTab)
sets the number of characters per tab.
|
protected void |
setup(java.util.Properties props)
Sets up the document according to the properties.
|
void |
setUseBlanks(boolean value)
Sets whether to use blanks instead of tabs.
|
protected boolean |
startingMultiLineComment(java.lang.String content,
int startOffset,
int endOffset)
Does this line contain the start of a multi-line comment.
|
addDocumentListener, addStyle, create, createDefaultRoot, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, insert, insertUpdate, removeDocumentListener, removeElement, removeStyle, removeUpdate, setCharacterAttributes, setLogicalStyle, setParagraphAttributes, styleChangedaddUndoableEditListener, createBranchElement, createLeafElement, createPosition, dump, fireChangedUpdate, fireInsertUpdate, fireRemoveUpdate, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties, writeLock, writeUnlockprotected static final long serialVersionUID
public static final int MAX_TABS
public static final java.lang.String DEFAULT_FONT_FAMILY
public static final int DEFAULT_FONT_SIZE
public static final javax.swing.text.SimpleAttributeSet DEFAULT_NORMAL
public static final javax.swing.text.SimpleAttributeSet DEFAULT_COMMENT
public static final javax.swing.text.SimpleAttributeSet DEFAULT_STRING
public static final javax.swing.text.SimpleAttributeSet DEFAULT_KEYWORD
protected javax.swing.text.DefaultStyledDocument m_Self
protected javax.swing.text.Element m_RootElement
protected boolean m_InsideMultiLineComment
protected java.util.HashMap<java.lang.String,javax.swing.text.MutableAttributeSet> m_Keywords
protected java.lang.String m_Delimiters
protected java.lang.String m_QuoteDelimiters
protected java.lang.String m_QuoteEscape
protected java.lang.String m_MultiLineCommentStart
protected java.lang.String m_MultiLineCommentEnd
protected java.lang.String m_SingleLineCommentStart
protected java.lang.String m_BlockStart
protected java.lang.String m_BlockEnd
protected int m_FontSize
protected java.lang.String m_FontName
protected java.awt.Color m_BackgroundColor
protected java.lang.String m_Indentation
protected boolean m_AddMatchingEndBlocks
protected boolean m_UseBlanks
protected boolean m_MultiLineComment
protected boolean m_CaseSensitive
public SyntaxDocument(java.util.Properties props)
props - the properties to obtain the setup fromprotected void setup(java.util.Properties props)
props - the properties to usepublic void setAttributeFont(SyntaxDocument.ATTR_TYPE attr, int style)
attr - the attribute to apply this font to (normal, comment, string)style - font style (Font.BOLD, Font.ITALIC, Font.PLAIN)public static void setAttributeFont(javax.swing.text.MutableAttributeSet attr,
java.awt.Font f)
attr - attribute to apply this font tof - the font to usepublic void setAttributeColor(SyntaxDocument.ATTR_TYPE attr, java.awt.Color c)
attr - the attribute to apply this font to (normal, comment, string)c - the color to usepublic static void setAttributeColor(javax.swing.text.MutableAttributeSet attr,
java.awt.Color c)
attr - attribute to apply this color toc - the color to usepublic void addKeywords(java.lang.String[] keywords,
javax.swing.text.MutableAttributeSet attr)
keywords - the tokens or words to formatattr - how to format the keywordspublic void addKeyword(java.lang.String keyword,
javax.swing.text.MutableAttributeSet attr)
keyword - the token or word to formatattr - how to format keywordpublic javax.swing.text.MutableAttributeSet getKeywordFormatting(java.lang.String keyword)
keyword - the token or word to stop formattingpublic void removeKeyword(java.lang.String keyword)
keyword - the token or word to stop formattingpublic void setTabs(int charactersPerTab)
charactersPerTab - the characters per tabpublic void insertString(int offset,
java.lang.String str,
javax.swing.text.AttributeSet a)
throws javax.swing.text.BadLocationException
insertString in interface javax.swing.text.DocumentinsertString in class javax.swing.text.AbstractDocumentoffset - the offsetstr - the string to inserta - the attribute set, can be nulljavax.swing.text.BadLocationException - if offset is invalidpublic void remove(int offset,
int length)
throws javax.swing.text.BadLocationException
remove in interface javax.swing.text.Documentremove in class javax.swing.text.AbstractDocumentoffset - the offset of the deletionlength - the length of the deletionjavax.swing.text.BadLocationException - if offsets are invalidpublic void processChangedLines(int offset,
int length)
throws javax.swing.text.BadLocationException
offset - the offset of the changed lineslength - the length of the changejavax.swing.text.BadLocationException - if offset is invalidprotected boolean commentLinesBefore(java.lang.String content,
int line)
content - the content to checkline - the line numberprotected void commentLinesAfter(java.lang.String content,
int line)
content - the content to parseline - the line numberprotected void highlightLinesAfter(java.lang.String content,
int line)
throws javax.swing.text.BadLocationException
content - the content to parseline - the line numberjavax.swing.text.BadLocationException - if offsets are wrongprotected void applyHighlighting(java.lang.String content,
int line)
throws javax.swing.text.BadLocationException
content - the content to parseline - the line numberjavax.swing.text.BadLocationException - if offsets are invalidprotected boolean startingMultiLineComment(java.lang.String content,
int startOffset,
int endOffset)
throws javax.swing.text.BadLocationException
content - the content to searchstartOffset - the start of the searchendOffset - the end of the searchjavax.swing.text.BadLocationException - if offsets are invalidprotected boolean endingMultiLineComment(java.lang.String content,
int startOffset,
int endOffset)
throws javax.swing.text.BadLocationException
content - the content to searchstartOffset - the start of the searchendOffset - the end of the searchjavax.swing.text.BadLocationException - if offsets are invalidprotected boolean isMultiLineComment()
protected void setInsideMultiLineComment(boolean value)
value - true if currently within a multi-line commentprotected void checkForTokens(java.lang.String content,
int startOffset,
int endOffset)
content - the content to parsestartOffset - the start positionendOffset - the end positionprotected int getQuoteToken(java.lang.String content,
int startOffset,
int endOffset)
content - the content to searchstartOffset - the start of the searchendOffset - the end of the searchprotected int getOtherToken(java.lang.String content,
int startOffset,
int endOffset)
content - the content to search instartOffset - the position to start the search frommendOffset - the position to end the searchprotected int indexOf(java.lang.String content,
java.lang.String needle,
int offset)
content - the content to searchneedle - the string to look foroffset - the offset to start atprotected int lastIndexOf(java.lang.String content,
java.lang.String needle,
int offset)
content - the content searchneedle - what to look foroffset - the offset to startprotected java.lang.String getLine(java.lang.String content,
int offset)
content - the contentoffset - the offset to start atpublic boolean isDelimiter(java.lang.String character)
character - the character to checkpublic boolean isQuoteDelimiter(java.lang.String character)
character - the character to checkpublic java.lang.String escapeQuote(java.lang.String quoteDelimiter)
quoteDelimiter - the string to escapeprotected java.lang.String addMatchingBlockEnd(int offset)
throws javax.swing.text.BadLocationException
offset - the offsetjavax.swing.text.BadLocationException - if the offset is invalidpublic int getFontSize()
public void setFontSize(int fontSize)
fontSize - the sizepublic java.lang.String getFontName()
public void setFontName(java.lang.String fontName)
fontName - the font namepublic void setIndentationSize(int value)
value - the number of blankspublic int getIndentationSize()
public void setDelimiters(java.lang.String value)
value - the characterspublic java.lang.String getDelimiters()
public void setQuoteDelimiters(java.lang.String value)
value - the characterspublic java.lang.String getQuoteDelimiters()
public void setQuoteEscape(java.lang.String value)
value - the characterpublic java.lang.String getQuoteEscape()
public void setSingleLineCommentStart(java.lang.String value)
value - the stringpublic java.lang.String getSingleLineCommentStart()
public void setMultiLineCommentStart(java.lang.String value)
value - the stringpublic java.lang.String getMultiLineCommentStart()
public void setMultiLineCommentEnd(java.lang.String value)
value - the stringpublic java.lang.String getMultiLineCommentEnd()
public void setBlockStart(java.lang.String value)
value - the stringpublic java.lang.String getBlockStart()
public void setBlockEnd(java.lang.String value)
value - the stringpublic java.lang.String getBlockEnd()
public void setAddMatchingEndBlocks(boolean value)
value - if true then matching block ends are insertedpublic boolean getAddMatchingEndBlocks()
public void setUseBlanks(boolean value)
value - if true then blanks are used instead of tabspublic boolean getUseBlanks()
public void setBackgroundColor(java.awt.Color value)
value - the background colorpublic java.awt.Color getBackgroundColor()
public void setMultiLineComment(boolean value)
value - if true then multi-line comments are enabledpublic boolean getMultiLineComment()
public void setCaseSensitive(boolean value)
value - if true then keywords are treated case-sensitivepublic boolean getCaseSensitive()