Package weka.gui.scripting
Class SyntaxDocument
java.lang.Object
javax.swing.text.AbstractDocument
javax.swing.text.DefaultStyledDocument
weka.gui.scripting.SyntaxDocument
- All Implemented Interfaces:
Serializable,Document,StyledDocument
Highlights syntax in a DefaultStyledDocument. Allows any number of keywords
to be formatted in any number of user-defined styles.
- Author:
- camickr (primary author; java sun forums user), David Underhill, FracPete (fracpete at waikato dot ac dot nz) - use of a properties file to setup syntax highlighting instead of hard-coded
- See Also:
-
Nested Class Summary
Nested ClassesNested classes/interfaces inherited from class javax.swing.text.DefaultStyledDocument
DefaultStyledDocument.AttributeUndoableEdit, DefaultStyledDocument.ElementBuffer, DefaultStyledDocument.ElementSpecNested 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
FieldsModifier and TypeFieldDescriptionstatic final SimpleAttributeSetthe attribute set for comments.static final Stringthe font family.static final intthe font size.static final SimpleAttributeSetthe attribute set for keywords.static final SimpleAttributeSetthe attribute set for normal code.static final SimpleAttributeSetthe attribute set for strings.static final intthe maximum number of tabs.Fields inherited from class javax.swing.text.DefaultStyledDocument
BUFFER_SIZE_DEFAULTFields inherited from class javax.swing.text.AbstractDocument
BidiElementName, ContentElementName, ElementNameAttribute, ParagraphElementName, SectionElementNameFields inherited from interface javax.swing.text.Document
StreamDescriptionProperty, TitleProperty -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidaddKeyword(String keyword, MutableAttributeSet attr) Associates a keyword with a particular formatting style.voidaddKeywords(String[] keywords, MutableAttributeSet attr) Associates the keywords with a particular formatting style.escapeQuote(String quoteDelimiter) Escapes the quote delimiter.booleanReturns whether matching block ends are inserted or not.Returns the background color.Returns the end of a block.Returns the start of a block.booleanReturns whether blanks are used instead of tabs.Returns the delimiter characters to use.gets the current font family.intgets the current font size.intReturns the number of blanks used for indentation.getKeywordFormatting(String keyword) Gets the formatting for a keyword.booleanReturns whether multi-line comments are enabled.Returns the end of a multi-line comment.Returns the string that is the start of a multi-line comment.Returns the quote delimiter characters to use.Returns the character for escaping a quote delimiter.Retrusn the single line comment start string.booleanReturns whether blanks are used instead of tabs.voidinsertString(int offset, String str, AttributeSet a) Override to apply syntax highlighting after the document has been updated.booleanisDelimiter(String character) Checks whether the character is a delimiter.booleanisQuoteDelimiter(String character) Checks whether the character is quote delimiter.voidprocessChangedLines(int offset, int length) Determine how many lines have been changed, then apply highlighting to each line.voidremove(int offset, int length) Applies syntax highlighting after the document has been updated.voidremoveKeyword(String keyword) Removes an association between a keyword with a particular formatting style.voidsetAddMatchingEndBlocks(boolean value) Sets whether matching block ends are inserted or not.static voidsetAttributeColor(MutableAttributeSet attr, Color c) Sets the foreground (font) color of the specified attribute.voidSets the foreground (font) color of the specified attribute.static voidsetAttributeFont(MutableAttributeSet attr, Font f) Sets the font of the specified attribute.voidsetAttributeFont(SyntaxDocument.ATTR_TYPE attr, int style) Sets the font of the specified attribute.voidsetBackgroundColor(Color value) Sets the background color.voidsetBlockEnd(String value) Sets the string that is the end of a block.voidsetBlockStart(String value) Sets the string that is the start of a block.voidsetCaseSensitive(boolean value) Sets whether the keywords are case-sensitive or not.voidsetDelimiters(String value) Sets the delimiter characters to use.voidsetFontName(String fontName) sets the current font family (affects all built-in styles).voidsetFontSize(int fontSize) sets the current font size (affects all built-in styles).voidsetIndentationSize(int value) Sets the number of blanks to use for indentation.voidsetMultiLineComment(boolean value) Sets whether to enable multi-line comments.voidsetMultiLineCommentEnd(String value) Sets the string that is the end of a multi-line comment.voidsetMultiLineCommentStart(String value) Sets the string that is the start of a multi-line comment.voidsetQuoteDelimiters(String value) Sets the quote delimiter characters to use.voidsetQuoteEscape(String value) Sets the character to use for escaping a quote character.voidsetSingleLineCommentStart(String value) Sets the string that is the start of a single-line comment.voidsetTabs(int charactersPerTab) sets the number of characters per tab.voidsetUseBlanks(boolean value) Sets whether to use blanks instead of tabs.Methods inherited from class javax.swing.text.DefaultStyledDocument
addDocumentListener, addStyle, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, removeDocumentListener, removeElement, removeStyle, setCharacterAttributes, setLogicalStyle, setParagraphAttributesMethods inherited from class javax.swing.text.AbstractDocument
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, setDocumentPropertiesMethods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface javax.swing.text.Document
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeUndoableEditListener, render
-
Field Details
-
MAX_TABS
public static final int MAX_TABSthe maximum number of tabs.- See Also:
-
DEFAULT_FONT_FAMILY
the font family.- See Also:
-
DEFAULT_FONT_SIZE
public static final int DEFAULT_FONT_SIZEthe font size.- See Also:
-
DEFAULT_NORMAL
the attribute set for normal code. -
DEFAULT_COMMENT
the attribute set for comments. -
DEFAULT_STRING
the attribute set for strings. -
DEFAULT_KEYWORD
the attribute set for keywords.
-
-
Constructor Details
-
SyntaxDocument
Initializes the document.- Parameters:
props- the properties to obtain the setup from
-
-
Method Details
-
setAttributeFont
Sets the font of the specified attribute.- Parameters:
attr- the attribute to apply this font to (normal, comment, string)style- font style (Font.BOLD, Font.ITALIC, Font.PLAIN)
-
setAttributeFont
Sets the font of the specified attribute.- Parameters:
attr- attribute to apply this font tof- the font to use
-
setAttributeColor
Sets the foreground (font) color of the specified attribute.- Parameters:
attr- the attribute to apply this font to (normal, comment, string)c- the color to use
-
setAttributeColor
Sets the foreground (font) color of the specified attribute.- Parameters:
attr- attribute to apply this color toc- the color to use
-
addKeywords
Associates the keywords with a particular formatting style.- Parameters:
keywords- the tokens or words to formatattr- how to format the keywords
-
addKeyword
Associates a keyword with a particular formatting style.- Parameters:
keyword- the token or word to formatattr- how to format keyword
-
getKeywordFormatting
Gets the formatting for a keyword.- Parameters:
keyword- the token or word to stop formatting- Returns:
- how keyword is formatted, or null if no formatting is applied to it
-
removeKeyword
Removes an association between a keyword with a particular formatting style.- Parameters:
keyword- the token or word to stop formatting
-
setTabs
public void setTabs(int charactersPerTab) sets the number of characters per tab.- Parameters:
charactersPerTab- the characters per tab
-
insertString
Override to apply syntax highlighting after the document has been updated.- Specified by:
insertStringin interfaceDocument- Overrides:
insertStringin classAbstractDocument- Parameters:
offset- the offsetstr- the string to inserta- the attribute set, can be null- Throws:
BadLocationException- if offset is invalid
-
remove
Applies syntax highlighting after the document has been updated.- Specified by:
removein interfaceDocument- Overrides:
removein classAbstractDocument- Parameters:
offset- the offset of the deletionlength- the length of the deletion- Throws:
BadLocationException- if offsets are invalid
-
processChangedLines
Determine how many lines have been changed, then apply highlighting to each line.- Parameters:
offset- the offset of the changed lineslength- the length of the change- Throws:
BadLocationException- if offset is invalid
-
isDelimiter
Checks whether the character is a delimiter.- Parameters:
character- the character to check- Returns:
- true if a delimiter
-
isQuoteDelimiter
Checks whether the character is quote delimiter.- Parameters:
character- the character to check- Returns:
- true if a quote delimiter
-
escapeQuote
Escapes the quote delimiter.- Parameters:
quoteDelimiter- the string to escape- Returns:
- the escaped string
-
getFontSize
public int getFontSize()gets the current font size.- Returns:
- the font size
-
setFontSize
public void setFontSize(int fontSize) sets the current font size (affects all built-in styles).- Parameters:
fontSize- the size
-
getFontName
gets the current font family.- Returns:
- the font name
-
setFontName
sets the current font family (affects all built-in styles).- Parameters:
fontName- the font name
-
setIndentationSize
public void setIndentationSize(int value) Sets the number of blanks to use for indentation.- Parameters:
value- the number of blanks
-
getIndentationSize
public int getIndentationSize()Returns the number of blanks used for indentation.- Returns:
- the number of blanks
-
setDelimiters
Sets the delimiter characters to use.- Parameters:
value- the characters
-
getDelimiters
Returns the delimiter characters to use.- Returns:
- the characters
-
setQuoteDelimiters
Sets the quote delimiter characters to use.- Parameters:
value- the characters
-
getQuoteDelimiters
Returns the quote delimiter characters to use.- Returns:
- the characters
-
setQuoteEscape
Sets the character to use for escaping a quote character.- Parameters:
value- the character
-
getQuoteEscape
Returns the character for escaping a quote delimiter.- Returns:
- the character
-
setSingleLineCommentStart
Sets the string that is the start of a single-line comment.- Parameters:
value- the string
-
getSingleLineCommentStart
Retrusn the single line comment start string.- Returns:
- the start string
-
setMultiLineCommentStart
Sets the string that is the start of a multi-line comment.- Parameters:
value- the string
-
getMultiLineCommentStart
Returns the string that is the start of a multi-line comment.- Returns:
- the string
-
setMultiLineCommentEnd
Sets the string that is the end of a multi-line comment.- Parameters:
value- the string
-
getMultiLineCommentEnd
Returns the end of a multi-line comment.- Returns:
- the end string
-
setBlockStart
Sets the string that is the start of a block.- Parameters:
value- the string
-
getBlockStart
Returns the start of a block.- Returns:
- the end string
-
setBlockEnd
Sets the string that is the end of a block.- Parameters:
value- the string
-
getBlockEnd
Returns the end of a block.- Returns:
- the end string
-
setAddMatchingEndBlocks
public void setAddMatchingEndBlocks(boolean value) Sets whether matching block ends are inserted or not.- Parameters:
value- if true then matching block ends are inserted
-
getAddMatchingEndBlocks
public boolean getAddMatchingEndBlocks()Returns whether matching block ends are inserted or not.- Returns:
- true if matching block ends are inserted
-
setUseBlanks
public void setUseBlanks(boolean value) Sets whether to use blanks instead of tabs.- Parameters:
value- if true then blanks are used instead of tabs
-
getUseBlanks
public boolean getUseBlanks()Returns whether blanks are used instead of tabs.- Returns:
- true if blanks are used instead of tabs
-
setBackgroundColor
Sets the background color.- Parameters:
value- the background color
-
getBackgroundColor
Returns the background color.- Returns:
- the background color
-
setMultiLineComment
public void setMultiLineComment(boolean value) Sets whether to enable multi-line comments.- Parameters:
value- if true then multi-line comments are enabled
-
getMultiLineComment
public boolean getMultiLineComment()Returns whether multi-line comments are enabled.- Returns:
- true if multi-line comments are enabled
-
setCaseSensitive
public void setCaseSensitive(boolean value) Sets whether the keywords are case-sensitive or not.- Parameters:
value- if true then keywords are treated case-sensitive
-
getCaseSensitive
public boolean getCaseSensitive()Returns whether blanks are used instead of tabs.- Returns:
- true if keywords are case-sensitive
-