Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

com.memoire.jedit
Class JEditTokenMarker  view JEditTokenMarker download JEditTokenMarker.java

java.lang.Object
  extended bycom.memoire.jedit.JEditTokenMarker
Direct Known Subclasses:
JEditBatchFileTokenMarker, JEditCTokenMarker, JEditEiffelTokenMarker, JEditHTMLTokenMarker, JEditMakefileTokenMarker, JEditPatchTokenMarker, JEditPerlTokenMarker, JEditPropsTokenMarker, JEditPythonTokenMarker, JEditShellScriptTokenMarker, JEditSQLTokenMarker, JEditTeXTokenMarker

public abstract class JEditTokenMarker
extends java.lang.Object

A token marker that splits lines of text into tokens. Each token carries a length field and an indentification tag that can be mapped to a color for painting that token.

For performance reasons, the linked list of tokens is reused after each line is tokenized. Therefore, the return value of markTokens should only be used for immediate painting. Notably, it cannot be cached.

Version:
$Id: JEditTokenMarker.java,v 1.4 2002/05/22 16:44:39 deniger Exp $

Nested Class Summary
 class JEditTokenMarker.LineInfo
          Inner class for storing information about tokenized lines.
 
Field Summary
protected  JEditToken firstJEditToken
          The first token in the list.
protected  JEditToken lastJEditToken
          The last token in the list.
protected  int lastLine
          The last tokenized line.
protected  int length
          The length of the lineInfo array.
protected  JEditTokenMarker.LineInfo[] lineInfo
          An array for storing information about lines.
protected  boolean nextLineRequested
          True if the next line should be painted.
 
Constructor Summary
protected JEditTokenMarker()
          Creates a new TokenMarker.
 
Method Summary
protected  void addToken(int length, byte id)
          Adds a token to the token list.
 void deleteLines(int index, int lines)
          Informs the token marker that line have been deleted from the document.
protected  void ensureCapacity(int index)
          Ensures that the lineInfo array can contain the specified index.
 void insertLines(int index, int lines)
          Informs the token marker that lines have been inserted into the document.
 boolean isNextLineRequested()
          Returns true if the next line should be repainted.
 JEditToken markTokens(javax.swing.text.Segment line, int lineIndex)
          A wrapper for the lower-level markTokensImpl method that is called to split a line up into tokens.
protected abstract  byte markTokensImpl(byte token, javax.swing.text.Segment line, int lineIndex)
          An abstract method that splits a line up into tokens.
 boolean supportsMultilineTokens()
          Returns if the token marker supports tokens that span multiple lines.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

firstJEditToken

protected JEditToken firstJEditToken
The first token in the list. This should be used as the return value from markTokens().


lastJEditToken

protected JEditToken lastJEditToken
The last token in the list. New tokens are added here. This should be set to null before a new line is to be tokenized.


lineInfo

protected JEditTokenMarker.LineInfo[] lineInfo
An array for storing information about lines. It is enlarged and shrunk automatically by the insertLines() and deleteLines() methods.


length

protected int length
The length of the lineInfo array.


lastLine

protected int lastLine
The last tokenized line.


nextLineRequested

protected boolean nextLineRequested
True if the next line should be painted.

Constructor Detail

JEditTokenMarker

protected JEditTokenMarker()
Creates a new TokenMarker. This DOES NOT create a lineInfo array; an initial call to insertLines() does that.

Method Detail

markTokens

public JEditToken markTokens(javax.swing.text.Segment line,
                             int lineIndex)
A wrapper for the lower-level markTokensImpl method that is called to split a line up into tokens.


markTokensImpl

protected abstract byte markTokensImpl(byte token,
                                       javax.swing.text.Segment line,
                                       int lineIndex)
An abstract method that splits a line up into tokens. It should parse the line, and call addToken() to add syntax tokens to the token list. Then, it should return the initial token type for the next line.

For example if the current line contains the start of a multiline comment that doesn't end on that line, this method should return the comment token type so that it continues on the next line.


supportsMultilineTokens

public boolean supportsMultilineTokens()
Returns if the token marker supports tokens that span multiple lines. If this is true, the object using this token marker is required to pass all lines in the document to the markTokens() method (in turn).

The default implementation returns true; it should be overridden to return false on simpler token markers for increased speed.


insertLines

public void insertLines(int index,
                        int lines)
Informs the token marker that lines have been inserted into the document. This inserts a gap in the lineInfo array.


deleteLines

public void deleteLines(int index,
                        int lines)
Informs the token marker that line have been deleted from the document. This removes the lines in question from the lineInfo array.


isNextLineRequested

public boolean isNextLineRequested()
Returns true if the next line should be repainted. This will return true after a line has been tokenized that starts a multiline token that continues onto the next line.


ensureCapacity

protected void ensureCapacity(int index)
Ensures that the lineInfo array can contain the specified index. This enlarges it if necessary. No action is taken if the array is large enough already.

It should be unnecessary to call this under normal circumstances; insertLine() should take care of enlarging the line info array automatically.


addToken

protected void addToken(int length,
                        byte id)
Adds a token to the token list.