oscript.swing.text
Class ODEEditorKit

java.lang.Object
  extended byjavax.swing.text.EditorKit
      extended byjavax.swing.text.DefaultEditorKit
          extended byoscript.swing.text.ODEEditorKit
All Implemented Interfaces:
java.lang.Cloneable, java.io.Serializable

public class ODEEditorKit
extends javax.swing.text.DefaultEditorKit

An editor-kit for an ODE src code editor. The document used is just a plain-old PlainDocument. Rather than trying to integrate the parser with the ODEEditorKit.ODEDocument's Element structure, the parsed representation of the document is stored seperately as an array of tokens. We create a View for rendering the document that takes into account the token that overlays a section of text, and the AttributeSet which that token maps to, as it renders the text.

For performance reasons, parsing happens asynchronously, which means that whenever the document is mutated. So, when there is an insert, we update the (now out of date) tokens by increasing the end-offset of the current token, and the begin-offset and end-offset of all subsequent tokens by the number of characters inserted. When there is a remove, the process is essentially the reverse.

The script side of things handles creating the parsing thread, and it uses DocumentListeners to determine when reparsing is needed.

Version:
1.10
Author:
Rob Clark (rob@ti.com)
See Also:
createDefaultDocument(), Serialized Form

Nested Class Summary
 class ODEEditorKit.ODEDocument
           
 
Nested classes inherited from class javax.swing.text.DefaultEditorKit
javax.swing.text.DefaultEditorKit.BeepAction, javax.swing.text.DefaultEditorKit.CopyAction, javax.swing.text.DefaultEditorKit.CutAction, javax.swing.text.DefaultEditorKit.DefaultKeyTypedAction, javax.swing.text.DefaultEditorKit.InsertBreakAction, javax.swing.text.DefaultEditorKit.InsertContentAction, javax.swing.text.DefaultEditorKit.InsertTabAction, javax.swing.text.DefaultEditorKit.PasteAction
 
Field Summary
 
Fields inherited from class javax.swing.text.DefaultEditorKit
backwardAction, beepAction, beginAction, beginLineAction, beginParagraphAction, beginWordAction, copyAction, cutAction, defaultKeyTypedAction, deleteNextCharAction, deletePrevCharAction, downAction, endAction, endLineAction, EndOfLineStringProperty, endParagraphAction, endWordAction, forwardAction, insertBreakAction, insertContentAction, insertTabAction, nextWordAction, pageDownAction, pageUpAction, pasteAction, previousWordAction, readOnlyAction, selectAllAction, selectionBackwardAction, selectionBeginAction, selectionBeginLineAction, selectionBeginParagraphAction, selectionBeginWordAction, selectionDownAction, selectionEndAction, selectionEndLineAction, selectionEndParagraphAction, selectionEndWordAction, selectionForwardAction, selectionNextWordAction, selectionPreviousWordAction, selectionUpAction, selectLineAction, selectParagraphAction, selectWordAction, upAction, writableAction
 
Constructor Summary
ODEEditorKit()
          Class Constructor.
 
Method Summary
 javax.swing.text.Document createDefaultDocument()
          Create a uninitialized document.
 oscript.syntaxtree.NodeToken getToken(int off)
          Given an offset into the document, find the corresponding token.
 javax.swing.text.ViewFactory getViewFactory()
          Get a factory for producing Views for rendering ODEEditorKit.ODEDocuments created by this editor-kit.
 java.lang.String offsetToNodeToken(int off)
           
 void setAttributeSetTable(oscript.util.SymbolMap attrSetTable)
          Set the attribute set table.
static void setDefaultFgColor(java.awt.Color c)
           
 void setNodeTokens(java.util.Vector v)
          Called from script code after parsing is completed.
 
Methods inherited from class javax.swing.text.DefaultEditorKit
createCaret, getActions, getContentType, read, read, write, write
 
Methods inherited from class javax.swing.text.EditorKit
clone, deinstall, install
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ODEEditorKit

public ODEEditorKit()
Class Constructor.

Method Detail

setAttributeSetTable

public void setAttributeSetTable(oscript.util.SymbolMap attrSetTable)
Set the attribute set table.

Parameters:
attrSetTable - the table that maps NodeToken.kind to an attribute set. This table is created and maintained from script code, but used here while rendering the text.

setNodeTokens

public void setNodeTokens(java.util.Vector v)
Called from script code after parsing is completed. For performance reasons the tokens are stored here, after they are generated by script.


getViewFactory

public javax.swing.text.ViewFactory getViewFactory()
Get a factory for producing Views for rendering ODEEditorKit.ODEDocuments created by this editor-kit.

Returns:
the view-factory

createDefaultDocument

public javax.swing.text.Document createDefaultDocument()
Create a uninitialized document. The ODEEditorKit.ODEDocument used by this editor kit is basically just a PlainDocument that has been extended to synchronously update the offsets of the tokens in response to document mutations (insert/remove). This is important to ensure that the token's offset maps to sensible positions in the document during the period between when the document is edited, and when the parser has finished re-parsing it

Returns:
an unitialized document

setDefaultFgColor

public static void setDefaultFgColor(java.awt.Color c)

getToken

public oscript.syntaxtree.NodeToken getToken(int off)
Given an offset into the document, find the corresponding token. This is the API used by everything else for accessing the tokens. The remaining methods are just used to implement this method.

Parameters:
off - the offset into the document

offsetToNodeToken

public java.lang.String offsetToNodeToken(int off)