cdx.scorebot.util.swing
Class MultiSyntaxDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.DefaultStyledDocument
          extended by cdx.scorebot.util.swing.MultiSyntaxDocument
All Implemented Interfaces:
java.io.Serializable, javax.swing.text.Document, javax.swing.text.StyledDocument
Direct Known Subclasses:
LogSyntaxDocument

public class MultiSyntaxDocument
extends javax.swing.text.DefaultStyledDocument

Highlights syntax in a DefaultStyledDocument. Allows any number of keywords to be formatted in any number of user-defined styles.

Author:
camickr (java sun forums user), David Underhill
See Also:
Serialized Form

Nested Class Summary
static class MultiSyntaxDocument.ATTR_TYPE
           
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultStyledDocument
javax.swing.text.DefaultStyledDocument.AttributeUndoableEdit, javax.swing.text.DefaultStyledDocument.ElementBuffer, javax.swing.text.DefaultStyledDocument.ElementSpec, javax.swing.text.DefaultStyledDocument.SectionElement
 
Nested classes/interfaces inherited from class javax.swing.text.AbstractDocument
javax.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
 
Field Summary
static javax.swing.text.SimpleAttributeSet DEFAULT_COMMENT
           
static java.lang.String DEFAULT_FONT_FAMILY
           
static int DEFAULT_FONT_SIZE
           
static javax.swing.text.SimpleAttributeSet DEFAULT_KEYWORD
           
static javax.swing.text.SimpleAttributeSet DEFAULT_NORMAL
           
static javax.swing.text.SimpleAttributeSet DEFAULT_STRING
           
 
Fields inherited from class javax.swing.text.DefaultStyledDocument
buffer, BUFFER_SIZE_DEFAULT
 
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
MultiSyntaxDocument(java.util.HashMap<java.lang.String,javax.swing.text.MutableAttributeSet> keywords)
           
 
Method Summary
 void addKeyword(java.lang.String keyword, javax.swing.text.MutableAttributeSet attr)
          Associates a keyword with a particular formatting style
protected  java.lang.String addMatchingBrace(int offset)
           
 void clearKeywords()
          Removes all associations between a keyword with a particular formatting style
protected  java.lang.String getEndDelimiter()
           
protected  java.lang.String getEscapeString(java.lang.String quoteDelimiter)
           
 java.lang.String getFontName()
          gets the current font family
 int getFontSize()
          gets the current font size
 javax.swing.text.MutableAttributeSet getKeywordFormatting(java.lang.String keyword)
          Gets the formatting for a keyword
protected  java.lang.String getSingleLineDelimiter()
           
protected  java.lang.String getStartDelimiter()
           
 void insertString(int offset, java.lang.String str, javax.swing.text.AttributeSet a)
           
protected  boolean isDelimiter(java.lang.String character)
           
protected  boolean isQuoteDelimiter(java.lang.String character)
           
 void processChangedLines(int offset, int length)
           
 void remove(int offset, int length)
           
 void removeKeyword(java.lang.String keyword)
          Removes an association between a keyword with a particular formatting style
 void setAttributeColor(MultiSyntaxDocument.ATTR_TYPE attr, java.awt.Color c)
          Sets the foreground (font) color of the specified attribute
static void setAttributeColor(javax.swing.text.MutableAttributeSet attr, java.awt.Color c)
          Sets the foreground (font) color of the specified attribute
 void setAttributeFont(MultiSyntaxDocument.ATTR_TYPE attr, int style)
          Sets the font of the specified attribute
static void setAttributeFont(javax.swing.text.MutableAttributeSet attr, java.awt.Font f)
          Sets the font of the specified attribute
protected  void setAttributeStyle(MultiSyntaxDocument.ATTR_TYPE attr, javax.swing.text.MutableAttributeSet style)
          Sets the style of the specified attribute
 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 setTabs(int charactersPerTab)
          sets the number of characters per tab
 
Methods inherited from class javax.swing.text.DefaultStyledDocument
addDocumentListener, addStyle, create, createDefaultRoot, getBackground, getCharacterElement, getDefaultRootElement, getFont, getForeground, getLogicalStyle, getParagraphElement, getStyle, getStyleNames, insert, insertUpdate, removeDocumentListener, removeStyle, removeUpdate, setCharacterAttributes, setLogicalStyle, setParagraphAttributes, styleChanged
 
Methods inherited from class javax.swing.text.AbstractDocument
addUndoableEditListener, 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, writeUnlock
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface javax.swing.text.Document
addUndoableEditListener, createPosition, getEndPosition, getLength, getProperty, getRootElements, getStartPosition, getText, getText, putProperty, removeUndoableEditListener, render
 

Field Detail

DEFAULT_FONT_FAMILY

public static final java.lang.String DEFAULT_FONT_FAMILY
See Also:
Constant Field Values

DEFAULT_FONT_SIZE

public static final int DEFAULT_FONT_SIZE
See Also:
Constant Field Values

DEFAULT_NORMAL

public static final javax.swing.text.SimpleAttributeSet DEFAULT_NORMAL

DEFAULT_COMMENT

public static final javax.swing.text.SimpleAttributeSet DEFAULT_COMMENT

DEFAULT_STRING

public static final javax.swing.text.SimpleAttributeSet DEFAULT_STRING

DEFAULT_KEYWORD

public static final javax.swing.text.SimpleAttributeSet DEFAULT_KEYWORD
Constructor Detail

MultiSyntaxDocument

public MultiSyntaxDocument(java.util.HashMap<java.lang.String,javax.swing.text.MutableAttributeSet> keywords)
Method Detail

setAttributeFont

public void setAttributeFont(MultiSyntaxDocument.ATTR_TYPE attr,
                             int style)
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

public static void setAttributeFont(javax.swing.text.MutableAttributeSet attr,
                                    java.awt.Font f)
Sets the font of the specified attribute

Parameters:
attr - attribute to apply this font to
f - the font to use

setAttributeColor

public void setAttributeColor(MultiSyntaxDocument.ATTR_TYPE attr,
                              java.awt.Color c)
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

public static void setAttributeColor(javax.swing.text.MutableAttributeSet attr,
                                     java.awt.Color c)
Sets the foreground (font) color of the specified attribute

Parameters:
attr - attribute to apply this color to
c - the color to use

setAttributeStyle

protected void setAttributeStyle(MultiSyntaxDocument.ATTR_TYPE attr,
                                 javax.swing.text.MutableAttributeSet style)
Sets the style of the specified attribute

Parameters:
attr - the attribute to apply this font to (normal, comment, string)
style - the style to use

addKeyword

public void addKeyword(java.lang.String keyword,
                       javax.swing.text.MutableAttributeSet attr)
Associates a keyword with a particular formatting style

Parameters:
keyword - the token or word to format
attr - how to format keyword

clearKeywords

public void clearKeywords()
Removes all associations between a keyword with a particular formatting style


getKeywordFormatting

public javax.swing.text.MutableAttributeSet getKeywordFormatting(java.lang.String keyword)
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

public void removeKeyword(java.lang.String keyword)
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


insertString

public void insertString(int offset,
                         java.lang.String str,
                         javax.swing.text.AttributeSet a)
                  throws javax.swing.text.BadLocationException
Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.AbstractDocument
Throws:
javax.swing.text.BadLocationException

remove

public void remove(int offset,
                   int length)
            throws javax.swing.text.BadLocationException
Specified by:
remove in interface javax.swing.text.Document
Overrides:
remove in class javax.swing.text.AbstractDocument
Throws:
javax.swing.text.BadLocationException

processChangedLines

public void processChangedLines(int offset,
                                int length)
                         throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

isDelimiter

protected boolean isDelimiter(java.lang.String character)

isQuoteDelimiter

protected boolean isQuoteDelimiter(java.lang.String character)

getStartDelimiter

protected java.lang.String getStartDelimiter()

getEndDelimiter

protected java.lang.String getEndDelimiter()

getSingleLineDelimiter

protected java.lang.String getSingleLineDelimiter()

getEscapeString

protected java.lang.String getEscapeString(java.lang.String quoteDelimiter)

addMatchingBrace

protected java.lang.String addMatchingBrace(int offset)
                                     throws javax.swing.text.BadLocationException
Throws:
javax.swing.text.BadLocationException

getFontSize

public int getFontSize()
gets the current font size


setFontSize

public void setFontSize(int fontSize)
sets the current font size (affects all built-in styles)


getFontName

public java.lang.String getFontName()
gets the current font family


setFontName

public void setFontName(java.lang.String fontName)
sets the current font family (affects all built-in styles)