public class SyntaxDocument extends DefaultStyledDocument
Modifier and Type | Class and Description |
---|---|
static class |
SyntaxDocument.ATTR_TYPE
The attribute type.
|
DefaultStyledDocument.AttributeUndoableEdit, DefaultStyledDocument.ElementBuffer, DefaultStyledDocument.ElementSpec
AbstractDocument.AbstractElement, AbstractDocument.AttributeContext, AbstractDocument.BranchElement, AbstractDocument.Content, AbstractDocument.DefaultDocumentEvent, AbstractDocument.ElementEdit, AbstractDocument.LeafElement
Modifier and Type | Field and Description |
---|---|
static SimpleAttributeSet |
DEFAULT_COMMENT
the attribute set for comments.
|
static String |
DEFAULT_FONT_FAMILY
the font family.
|
static int |
DEFAULT_FONT_SIZE
the font size.
|
static SimpleAttributeSet |
DEFAULT_KEYWORD
the attribute set for keywords.
|
static SimpleAttributeSet |
DEFAULT_NORMAL
the attribute set for normal code.
|
static SimpleAttributeSet |
DEFAULT_STRING
the attribute set for strings.
|
static int |
MAX_TABS
the maximum number of tabs.
|
BUFFER_SIZE_DEFAULT
BidiElementName, ContentElementName, ElementNameAttribute, ParagraphElementName, SectionElementName
StreamDescriptionProperty, TitleProperty
Constructor and Description |
---|
SyntaxDocument(Properties props)
Initializes the document.
|
Modifier and Type | Method and Description |
---|---|
void |
addKeyword(String keyword,
MutableAttributeSet attr)
Associates a keyword with a particular formatting style.
|
void |
addKeywords(String[] keywords,
MutableAttributeSet attr)
Associates the keywords with a particular formatting style.
|
String |
escapeQuote(String quoteDelimiter)
Escapes the quote delimiter.
|
boolean |
getAddMatchingEndBlocks()
Returns whether matching block ends are inserted or not.
|
Color |
getBackgroundColor()
Returns the background color.
|
String |
getBlockEnd()
Returns the end of a block.
|
String |
getBlockStart()
Returns the start of a block.
|
boolean |
getCaseSensitive()
Returns whether blanks are used instead of tabs.
|
String |
getDelimiters()
Returns the delimiter characters to use.
|
String |
getFontName()
gets the current font family.
|
int |
getFontSize()
gets the current font size.
|
int |
getIndentationSize()
Returns the number of blanks used for indentation.
|
MutableAttributeSet |
getKeywordFormatting(String keyword)
Gets the formatting for a keyword.
|
boolean |
getMultiLineComment()
Returns whether multi-line comments are enabled.
|
String |
getMultiLineCommentEnd()
Returns the end of a multi-line comment.
|
String |
getMultiLineCommentStart()
Returns the string that is the start of a multi-line comment.
|
String |
getQuoteDelimiters()
Returns the quote delimiter characters to use.
|
String |
getQuoteEscape()
Returns the character for escaping a quote delimiter.
|
String |
getSingleLineCommentStart()
Retrusn the single line comment start string.
|
boolean |
getUseBlanks()
Returns whether blanks are used instead of tabs.
|
void |
insertString(int offset,
String str,
AttributeSet a)
Override to apply syntax highlighting after the document has been updated.
|
boolean |
isDelimiter(String character)
Checks whether the character is a delimiter.
|
boolean |
isQuoteDelimiter(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(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(MutableAttributeSet attr,
Color c)
Sets the foreground (font) color of the specified attribute.
|
void |
setAttributeColor(SyntaxDocument.ATTR_TYPE attr,
Color c)
Sets the foreground (font) color of the specified attribute.
|
static void |
setAttributeFont(MutableAttributeSet attr,
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(Color value)
Sets the background color.
|
void |
setBlockEnd(String value)
Sets the string that is the end of a block.
|
void |
setBlockStart(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(String value)
Sets the delimiter characters to use.
|
void |
setFontName(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(String value)
Sets the string that is the end of a multi-line comment.
|
void |
setMultiLineCommentStart(String value)
Sets the string that is the start of a multi-line comment.
|
void |
setQuoteDelimiters(String value)
Sets the quote delimiter characters to use.
|
void |
setQuoteEscape(String value)
Sets the character to use for escaping a quote character.
|
void |
setSingleLineCommentStart(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, setParagraphAttributes
addUndoableEditListener, createPosition, dump, getAsynchronousLoadPriority, getBidiRootElement, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, putProperty, readLock, readUnlock, removeUndoableEditListener, render, replace, setAsynchronousLoadPriority, setDocumentFilter, setDocumentProperties
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeUndoableEditListener, render
public static final int MAX_TABS
public static final String DEFAULT_FONT_FAMILY
public static final int DEFAULT_FONT_SIZE
public static final SimpleAttributeSet DEFAULT_NORMAL
public static final SimpleAttributeSet DEFAULT_COMMENT
public static final SimpleAttributeSet DEFAULT_STRING
public static final SimpleAttributeSet DEFAULT_KEYWORD
public SyntaxDocument(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(MutableAttributeSet attr, Font f)
attr
- attribute to apply this font tof
- the font to usepublic void setAttributeColor(SyntaxDocument.ATTR_TYPE attr, Color c)
attr
- the attribute to apply this font to (normal, comment, string)c
- the color to usepublic static void setAttributeColor(MutableAttributeSet attr, Color c)
attr
- attribute to apply this color toc
- the color to usepublic void addKeywords(String[] keywords, MutableAttributeSet attr)
keywords
- the tokens or words to formatattr
- how to format the keywordspublic void addKeyword(String keyword, MutableAttributeSet attr)
keyword
- the token or word to formatattr
- how to format keywordpublic MutableAttributeSet getKeywordFormatting(String keyword)
keyword
- the token or word to stop formattingpublic void removeKeyword(String keyword)
keyword
- the token or word to stop formattingpublic void setTabs(int charactersPerTab)
charactersPerTab
- the characters per tabpublic void insertString(int offset, String str, AttributeSet a) throws BadLocationException
insertString
in interface Document
insertString
in class AbstractDocument
offset
- the offsetstr
- the string to inserta
- the attribute set, can be nullBadLocationException
- if offset is invalidpublic void remove(int offset, int length) throws BadLocationException
remove
in interface Document
remove
in class AbstractDocument
offset
- the offset of the deletionlength
- the length of the deletionBadLocationException
- if offsets are invalidpublic void processChangedLines(int offset, int length) throws BadLocationException
offset
- the offset of the changed lineslength
- the length of the changeBadLocationException
- if offset is invalidpublic boolean isDelimiter(String character)
character
- the character to checkpublic boolean isQuoteDelimiter(String character)
character
- the character to checkpublic String escapeQuote(String quoteDelimiter)
quoteDelimiter
- the string to escapepublic int getFontSize()
public void setFontSize(int fontSize)
fontSize
- the sizepublic String getFontName()
public void setFontName(String fontName)
fontName
- the font namepublic void setIndentationSize(int value)
value
- the number of blankspublic int getIndentationSize()
public void setDelimiters(String value)
value
- the characterspublic String getDelimiters()
public void setQuoteDelimiters(String value)
value
- the characterspublic String getQuoteDelimiters()
public void setQuoteEscape(String value)
value
- the characterpublic String getQuoteEscape()
public void setSingleLineCommentStart(String value)
value
- the stringpublic String getSingleLineCommentStart()
public void setMultiLineCommentStart(String value)
value
- the stringpublic String getMultiLineCommentStart()
public void setMultiLineCommentEnd(String value)
value
- the stringpublic String getMultiLineCommentEnd()
public void setBlockStart(String value)
value
- the stringpublic String getBlockStart()
public void setBlockEnd(String value)
value
- the stringpublic 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(Color value)
value
- the background colorpublic 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()
Copyright © 2012 University of Waikato, Hamilton, NZ. All Rights Reserved.