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.ElementSpecjavax.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.
|
static int |
MAX_TABS
the maximum number of tabs.
|
| 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.
|
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.
|
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.
|
java.lang.String |
getQuoteDelimiters()
Returns the quote delimiter characters to use.
|
java.lang.String |
getQuoteEscape()
Returns the character for escaping a quote delimiter.
|
java.lang.String |
getSingleLineCommentStart()
Retrusn the single line comment start string.
|
boolean |
getUseBlanks()
Returns whether blanks are used instead of tabs.
|
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.
|
boolean |
isQuoteDelimiter(java.lang.String character)
Checks whether the character is quote delimiter.
|
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.
|
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.
|
void |
setUseBlanks(boolean value)
Sets whether to use blanks instead of tabs.
|
addDocumentListener, addStyle, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, removeDocumentListener, removeElement, removeStyle, setCharacterAttributes, setLogicalStyle, setParagraphAttributesaddUndoableEditListener, createPosition, dump, getAsynchronousLoadPriority, getBidiRootElement, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, putProperty, readLock, readUnlock, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentPropertiespublic 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
public SyntaxDocument(java.util.Properties props)
props - the properties to obtain the setup frompublic 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 invalidpublic 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 escapepublic 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()