net.pandoragames.far.ui.swing.component
Class StreamedDocumentContent

java.lang.Object
  extended by net.pandoragames.far.ui.swing.component.StreamedDocumentContent
All Implemented Interfaces:
javax.swing.text.AbstractDocument.Content

public class StreamedDocumentContent
extends java.lang.Object
implements javax.swing.text.AbstractDocument.Content

Implementation of javax.swing.text.AbstractDocument.Content backed by a file. This implementation is specifically designed for large contents. It currently is implemented read only, but write support may be added in the future.

Author:
Olivier Wehner at 12/07/2009

Constructor Summary
StreamedDocumentContent(java.io.File file)
          Instantiates this document with a File object, using the default character encoding.
StreamedDocumentContent(FileBuffer fileBuffer)
          Instantiates this document with a FileBuffer object.
 
Method Summary
 javax.swing.text.Position createPosition(int offset)
          Creates a position within the content that will track change as the content is mutated.
 void getChars(int where, int len, javax.swing.text.Segment txt)
          Gets a sequence of characters and copies them into a Segment.
 java.lang.String getString(int where, int len)
          Fetches a string of characters contained in the sequence.
 javax.swing.undo.UndoableEdit insertString(int where, java.lang.String str)
          Throws a BadLocationException as this component is READ ONLY.
 int length()
          Current length of the sequence of character content.
 javax.swing.undo.UndoableEdit remove(int where, int nitems)
          Throws a BadLocationException as this component is READ ONLY.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StreamedDocumentContent

public StreamedDocumentContent(java.io.File file)
                        throws java.io.IOException
Instantiates this document with a File object, using the default character encoding.

Parameters:
file - to back the content
Throws:
java.io.IOException

StreamedDocumentContent

public StreamedDocumentContent(FileBuffer fileBuffer)
Instantiates this document with a FileBuffer object.

Parameters:
fileBuffer - to back the content
Method Detail

createPosition

public javax.swing.text.Position createPosition(int offset)
                                         throws javax.swing.text.BadLocationException
Creates a position within the content that will track change as the content is mutated.

Specified by:
createPosition in interface javax.swing.text.AbstractDocument.Content
Parameters:
offset - the offset in the content >= 0
Returns:
a Position initialised with the specified offset
Throws:
javax.swing.text.BadLocationException - for an invalid offset

getChars

public void getChars(int where,
                     int len,
                     javax.swing.text.Segment txt)
              throws javax.swing.text.BadLocationException
Gets a sequence of characters and copies them into a Segment.

Specified by:
getChars in interface javax.swing.text.AbstractDocument.Content
Parameters:
where - the starting offset >= 0
len - the number of characters >= 0
txt - the target location to copy into
Throws:
javax.swing.text.BadLocationException - Thrown if the area covered by the arguments is not contained in the character sequence.

getString

public java.lang.String getString(int where,
                                  int len)
                           throws javax.swing.text.BadLocationException
Fetches a string of characters contained in the sequence.

Specified by:
getString in interface javax.swing.text.AbstractDocument.Content
Parameters:
where - the starting offset >= 0
len - the number of characters >= 0
Returns:
the String
Throws:
javax.swing.text.BadLocationException - Thrown if the area covered by the arguments is not contained in the character sequence.

insertString

public javax.swing.undo.UndoableEdit insertString(int where,
                                                  java.lang.String str)
                                           throws javax.swing.text.BadLocationException
Throws a BadLocationException as this component is READ ONLY.

Specified by:
insertString in interface javax.swing.text.AbstractDocument.Content
Throws:
javax.swing.text.BadLocationException

length

public int length()
Current length of the sequence of character content.

Specified by:
length in interface javax.swing.text.AbstractDocument.Content
Returns:
length >= 0

remove

public javax.swing.undo.UndoableEdit remove(int where,
                                            int nitems)
                                     throws javax.swing.text.BadLocationException
Throws a BadLocationException as this component is READ ONLY.

Specified by:
remove in interface javax.swing.text.AbstractDocument.Content
Throws:
javax.swing.text.BadLocationException