Class HighlightingStyledDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.DefaultStyledDocument
          extended by HighlightingStyledDocument
All Implemented Interfaces:
java.io.Serializable, javax.swing.text.Document, javax.swing.text.StyledDocument

public class HighlightingStyledDocument
extends javax.swing.text.DefaultStyledDocument

Highlights jython syntax in a Document Created for the Jython Environment for Students (JES) Hilghights keywords and environment words that are defined for it. It will also highlight single-line comments that start with '#', and single-line strings that start with "'" or '"'.

See Also:
Serialized Form

Nested Class Summary
 
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 java.lang.String newline
          The system specific line separator 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
HighlightingStyledDocument()
           
 
Method Summary
protected  void fireRemoveUpdate(javax.swing.event.DocumentEvent e)
          Overrides the default method from DefaultStyledDocument.
 void insertString(int offs, java.lang.String str, javax.swing.text.AttributeSet a)
          Overrides the default method from DefaultStyledDocument.
 void setCommentStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for comments
 void setDefaultStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the default style of text to use
 void setEnvironmentWords(java.lang.String[] words)
          Sets a collection of environment words to highlight.
 void setEnvironmentWordStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for environment words
 void setKeywords(java.lang.String[] words)
          Sets a collection of keywords to highlight.
 void setKeywordStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for keywords
 void setLParenStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for invalid Left Parens
 void setRParenStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for invalid Right Parens
 void setStringStyle(javax.swing.text.SimpleAttributeSet style)
          Sets the style of text to use for strings
 void updateHighlightingInRange(int offset, int length)
          Looks at a given range of text in a document and highlights it according to keywords, environment, strings, and comments.
 
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, fireUndoableEditUpdate, getAsynchronousLoadPriority, getAttributeContext, getBidiRootElement, getContent, getCurrentWriter, getDocumentFilter, getDocumentListeners, getDocumentProperties, getEndPosition, getLength, getListeners, getProperty, getRootElements, getStartPosition, getText, getText, getUndoableEditListeners, postRemoveUpdate, putProperty, readLock, readUnlock, remove, 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, remove, removeUndoableEditListener, render
 

Field Detail

newline

public static java.lang.String newline
The system specific line separator String.

Constructor Detail

HighlightingStyledDocument

public HighlightingStyledDocument()
Method Detail

insertString

public void insertString(int offs,
                         java.lang.String str,
                         javax.swing.text.AttributeSet a)
                  throws javax.swing.text.BadLocationException
Overrides the default method from DefaultStyledDocument. Calls appropriate syntax highlighting code and then class super.

Specified by:
insertString in interface javax.swing.text.Document
Overrides:
insertString in class javax.swing.text.AbstractDocument
Parameters:
offs - the starting offset >= 0
str - the string to insert; does nothing with null/empty strings
a - the attributes for the inserted content
Throws:
javax.swing.text.BadLocationException

fireRemoveUpdate

protected void fireRemoveUpdate(javax.swing.event.DocumentEvent e)
Overrides the default method from DefaultStyledDocument. Calls appropriate syntax highlighting code and then class super.

Overrides:
fireRemoveUpdate in class javax.swing.text.AbstractDocument
Parameters:
e - the DocumentEvent

updateHighlightingInRange

public void updateHighlightingInRange(int offset,
                                      int length)
Looks at a given range of text in a document and highlights it according to keywords, environment, strings, and comments.

Parameters:
offset - where in the document the change started
length - the length of change measured from the offset

setKeywords

public void setKeywords(java.lang.String[] words)
Sets a collection of keywords to highlight.

Parameters:
words - an array of all the words

setEnvironmentWords

public void setEnvironmentWords(java.lang.String[] words)
Sets a collection of environment words to highlight.

Parameters:
words - an array of all the words

setKeywordStyle

public void setKeywordStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for keywords

Parameters:
style - the new text style

setEnvironmentWordStyle

public void setEnvironmentWordStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for environment words

Parameters:
style - the new text style

setCommentStyle

public void setCommentStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for comments

Parameters:
style - the new text style

setStringStyle

public void setStringStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for strings

Parameters:
style - the new text style

setLParenStyle

public void setLParenStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for invalid Left Parens

Parameters:
style - the new text style

setRParenStyle

public void setRParenStyle(javax.swing.text.SimpleAttributeSet style)
Sets the style of text to use for invalid Right Parens

Parameters:
style - the new text style

setDefaultStyle

public void setDefaultStyle(javax.swing.text.SimpleAttributeSet style)
Sets the default style of text to use

Parameters:
style - the new text style