com.bluemarsh.jswat.view
Class SourceContent

java.lang.Object
  |
  +--com.bluemarsh.jswat.view.SourceContent

public class SourceContent
extends java.lang.Object

Class SourceContent holds the content for a source view.

Author:
Nathan Fiedler

Field Summary
protected  int lineCount
          Number of lines in content.
protected  int[] lineEndOffset
          Array of end-of-line offsets.
protected  int[] lineEndSize
          Array of end-of-line sizes.
protected  int[] lineStartOffset
          Array of start-of-line offsets.
protected  int longestLineLength
          Length in characters of the longest line.
protected  char[] textBuffer
          The text buffer, sized to fit.
 
Constructor Summary
SourceContent(char[] buf)
          Constructs a SourceContent.
 
Method Summary
protected  void addLineOffset(int start, int eolsize)
          Add another entry into the offset array.
 void dump(java.io.PrintStream out)
          Prints diagnostic information to the given output stream.
protected  void findLines(char[] text)
          Determines the line information.
 char[] getBuffer()
          Returns the actual character buffer.
 int getLength()
          Returns the length of this content, in characters.
 int getLineCount()
          Returns the number of lines in this content.
 int getLineEndOffset(int line)
          Get the offset of the end of the given line.
 int getLineOfOffset(int offset)
          Find the line containing the given offset.
 int getLineRealEndOffset(int line)
          Get the offset of the end of the given line, not counting the end-of-line characters themselves.
 int getLineStartOffset(int line)
          Get the offset of the start of the given line.
 int getLongestLineLength()
          Returns the length in characters of the longest line in this content object.
static void main(java.lang.String[] args)
          Test-wrapper for this class.
static char[] replaceTabs(char[] str, int tabWidth)
          Find and replace tabs with spaces.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

lineStartOffset

protected int[] lineStartOffset
Array of start-of-line offsets.

lineEndOffset

protected int[] lineEndOffset
Array of end-of-line offsets.

lineEndSize

protected int[] lineEndSize
Array of end-of-line sizes.

lineCount

protected int lineCount
Number of lines in content.

textBuffer

protected char[] textBuffer
The text buffer, sized to fit.

longestLineLength

protected int longestLineLength
Length in characters of the longest line.
Constructor Detail

SourceContent

public SourceContent(char[] buf)
Constructs a SourceContent.
Parameters:
buf - array of text, sized to fit (may be null).
Method Detail

addLineOffset

protected void addLineOffset(int start,
                             int eolsize)
Add another entry into the offset array.
Parameters:
start - start-of-line offset to add.
eolsize - number of end-of-line characters (1 or 2).

dump

public void dump(java.io.PrintStream out)
Prints diagnostic information to the given output stream.
Parameters:
out - stream to dump to.

findLines

protected void findLines(char[] text)
Determines the line information.
Parameters:
text - the text to analyze.

getLength

public int getLength()
Returns the length of this content, in characters.
Returns:
number of characters in this content.

getLineCount

public int getLineCount()
Returns the number of lines in this content. Lines are sequences of text separated by carriage return, line feed, or the pair of carriage return and line feed.
Returns:
line count.

getLineEndOffset

public int getLineEndOffset(int line)
                     throws javax.swing.text.BadLocationException
Get the offset of the end of the given line.
Parameters:
line - zero-based line for which to find the end.
Returns:
offset of end of line.
Throws:
javax.swing.text.BadLocationException - Thrown if line is invalid.

getLineRealEndOffset

public int getLineRealEndOffset(int line)
                         throws javax.swing.text.BadLocationException
Get the offset of the end of the given line, not counting the end-of-line characters themselves.
Parameters:
line - zero-based line for which to find the end.
Returns:
offset of end of line.
Throws:
javax.swing.text.BadLocationException - Thrown if line is invalid.

getLineOfOffset

public int getLineOfOffset(int offset)
                    throws javax.swing.text.BadLocationException
Find the line containing the given offset.
Parameters:
offset - offset within content >= 0.
Returns:
zero-based line containing that offset.
Throws:
javax.swing.text.BadLocationException - Thrown if offset is invalid.

getLineStartOffset

public int getLineStartOffset(int line)
                       throws javax.swing.text.BadLocationException
Get the offset of the start of the given line.
Parameters:
line - zero-based line for which to find the start.
Returns:
offset of start of line.
Throws:
javax.swing.text.BadLocationException - Thrown if line is invalid.

getLongestLineLength

public int getLongestLineLength()
Returns the length in characters of the longest line in this content object.
Returns:
longest line lenght.

getBuffer

public char[] getBuffer()
Returns the actual character buffer. Changes should not be made directly to this buffer. It is provided for efficiency only.

replaceTabs

public static char[] replaceTabs(char[] str,
                                 int tabWidth)
Find and replace tabs with spaces.
Parameters:
str - string on which to operate.
tabWidth - width of tabs.
Returns:
result of replacement.

main

public static void main(java.lang.String[] args)
Test-wrapper for this class.
Parameters:
args - command-line arguments.