jwo.landserf.script
Class ScriptDocument

java.lang.Object
  extended by javax.swing.text.AbstractDocument
      extended by javax.swing.text.DefaultStyledDocument
          extended by jwo.landserf.script.ScriptDocument
All Implemented Interfaces:
Serializable, Document, StyledDocument

public class ScriptDocument
extends DefaultStyledDocument

Creates a styled document for syntax highlighting of LandScript files. Based on the code originally described by Crafton, 1999. java.sys-con.com/read/36509.htm

Version:
2.3, 8th December, 2005.
Author:
Jim Crafton with modifications by Jo Wood.
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.text.DefaultStyledDocument
DefaultStyledDocument.AttributeUndoableEdit, DefaultStyledDocument.ElementBuffer, DefaultStyledDocument.ElementSpec, DefaultStyledDocument.SectionElement
 
Nested 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
static int COMMENT_MODE
          Indicates the display of a comment in the script.
static int NUMBER_MODE
          Indicates display of a number in script.
static int STRING_MODE
          Indicates display of string text in script.
static int TEXT_MODE
          Indicates display of normal text in script.
 
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
ScriptDocument(JTextPane textPane)
          Creates the styled document for displaying syntax highlighted landScript.
 
Method Summary
 HashSet getKeywords()
          Reports a list of reserved keywords that will be highlighted.
 void insertString(int offset, String str, AttributeSet attSet)
          Inserts text at the given offset with the given attributes into the document.
 void remove(int offset, int length)
          Removes text at the given offset and length from the document.
 void setKeywords(HashSet keywords)
          Sets the list of reserved keywords that will be highlighted.
 
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

STRING_MODE

public static final int STRING_MODE
Indicates display of string text in script.

See Also:
Constant Field Values

TEXT_MODE

public static final int TEXT_MODE
Indicates display of normal text in script.

See Also:
Constant Field Values

NUMBER_MODE

public static final int NUMBER_MODE
Indicates display of a number in script.

See Also:
Constant Field Values

COMMENT_MODE

public static final int COMMENT_MODE
Indicates the display of a comment in the script.

See Also:
Constant Field Values
Constructor Detail

ScriptDocument

public ScriptDocument(JTextPane textPane)
Creates the styled document for displaying syntax highlighted landScript.

Parameters:
textPane - Panel in which to display text.
Method Detail

insertString

public void insertString(int offset,
                         String str,
                         AttributeSet attSet)
                  throws BadLocationException
Inserts text at the given offset with the given attributes into the document.

Specified by:
insertString in interface Document
Overrides:
insertString in class AbstractDocument
Parameters:
offset - Offset from start of document at which to insert text.
str - Text to insert.
attSet - Attribute set to attach to string. Ignored.
Throws:
BadLocationException

remove

public void remove(int offset,
                   int length)
            throws BadLocationException
Removes text at the given offset and length from the document.

Specified by:
remove in interface Document
Overrides:
remove in class AbstractDocument
Parameters:
offset - Offset from start of document at which to remove text.
length - Length of text to remove.
Throws:
BadLocationException

getKeywords

public HashSet getKeywords()
Reports a list of reserved keywords that will be highlighted.

Returns:
List of keywords that can be highlighted in document.

setKeywords

public void setKeywords(HashSet keywords)
Sets the list of reserved keywords that will be highlighted.

Parameters:
keywords - List of keywords that can be highlighted in document.


Copyright Jo Wood, 1996-2009, last modified, 17th April, 2009