BioLegato 0.5.6

org.biolegato.core.data.seqdoc
Class SeqDoc

java.lang.Object
  extended by org.biolegato.core.data.seqdoc.SeqDoc
All Implemented Interfaces:
SequenceListener

public class SeqDoc
extends java.lang.Object
implements SequenceListener

The internal document format for BioLegato.

This document is structured as a linked list of sequences. Each character has an offset based on its position within the list and it's position within its containing sequence. Sequences start at 0 (first character in the first sequence in the list, and end with the last character in the last sequence within the list.

Author:
Graham Alvare, Brian Fristensky

Field Summary
protected  java.util.Stack<Undoable> redoStack
          The stack of redoable events
protected  java.util.Stack<Undoable> undoStack
          The stack of undoable events.
 
Constructor Summary
SeqDoc()
          Creates a new instance of SeqDoc
 
Method Summary
 void addListener(SeqDocListener listener)
          Adds a listener object to the data container.
 void addSequence(int lineNumber, Sequence seq)
          Adds a sequence to the document.
 void addSequence(Sequence seq)
          Adds a sequence to the end of the data container.
 void addSequences(int lineNumber, Sequence[] sequenceList)
          Adds an array of sequences to a data container at position "lineNumber".
 void addSequences(Sequence[] sequenceList)
          Adds an array of sequences to the end of the data container.
 boolean delete(int offset, int length)
          Removes text from the document.
 boolean delete(int lineNumber, int offset, int length)
          Removes text from the document.
 int getLength()
          Returns the length of the data container's content.
 java.lang.String getLine(int lineNumber)
          Retrieves a given line of text from the document.
 int getLineCount()
          Returns the number of lines in the document.
 int getLineEndOffset(int lineNumber)
          Retrieves the end offset of the given line.
 int getLineLength(int lineNumber)
          Retrieves the length of a line in the document.
 int getLineNumber(int offset)
          Obtains the line number for a given offset.
 int getLineStartOffset(int lineNumber)
          Retrieves the start offset of a line.
 int getLongestLineLength()
          Returns the length of the longest line in the data container
 Sequence getSequence(int lineNumber)
          Retrieves a sequence object from the SeqDoc specified by its line number.
 Sequence[] getSequences(int[] lineNumbers)
          Calls getSequence multiple times for multiple line numbers.
 java.lang.String getText(int offset, int length)
          Retrieves a body of text from the data container.
 boolean insert(int lineNumber, int offset, java.lang.String string)
          Inserts a string into the document on a given line.
 boolean insert(int offset, Sequence[] sequences)
          Inserts sequences at a specific offset in the document.
 boolean redo()
          Performs an redo operation to the data container.
 void removeSequence(int lineNumber)
          Removes a sequences from the data container.
 void removeSequences(int[] lineNumbers)
          Removes an array of sequences from the data container.
 void sequenceChanged(Sequence sequence, java.lang.String key)
          Called when a field in a sequence is modified.
 boolean undo()
          Performs an undo operation to the data container.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

undoStack

protected java.util.Stack<Undoable> undoStack
The stack of undoable events.

Every time an event occurs within the SeqDoc that is undoable, an undo object is created and added to this stack. This allows one to undo performed SeqDoc actions. To undo an action, pop the top object off of the stack and call its undo method. This will perform the undo and the undo method will return a redo object. The resulting redo object can then be added to the redoStack stack.

See Also:
org.biolegato.core.data.undo.Undoable

redoStack

protected java.util.Stack<Undoable> redoStack
The stack of redoable events

Every time an event is undone, a redo object is created and added to this stack. A redo object is essentially an undo object created to "undo an undo". To perform a redo, pop the top object off the stact and call its undo method. This will perform the redo and the undo method will return an undo object. The resulting undo object can then be added to the undoStack stack.

See Also:
org.biolegato.core.data.undo.Undoable
Constructor Detail

SeqDoc

public SeqDoc()
Creates a new instance of SeqDoc

Method Detail

insert

public boolean insert(int lineNumber,
                      int offset,
                      java.lang.String string)
Inserts a string into the document on a given line.

Parameters:
lineNumber - the line number to insert the string.
offset - the offset in the document to insert the text.
string - the text to insert.
Returns:
true if the operation was successful, otherwise false.

insert

public boolean insert(int offset,
                      Sequence[] sequences)
Inserts sequences at a specific offset in the document.

The first sequence is always merged with the sequence located at offset, unless the offset points to the end of the sequence. The same applies to the last sequence.

Example:
Sequence[0]: aaaa
....
Sequence[last]: cccc
Document: ggggtttt
offset: 4
Result: ggggaaaa
....
cccctttt

Parameters:
offset - the offset in the document to insert the sequences.
sequences - the array of sequences to insert.
Returns:
true if the operation was successful, otherwise false.

delete

public boolean delete(int offset,
                      int length)
Removes text from the document.

This method will delete line endings and sequences as well as individual characters from the document. The offset and length parameters are both character based (not line based).

Parameters:
offset - the offset to start the deletion from.
length - the number of characters to delete.
Returns:
true if the operation was successful, otherwise false.

delete

public boolean delete(int lineNumber,
                      int offset,
                      int length)
Removes text from the document.

This method will delete line endings and sequences as well as individual characters from the document.

Parameters:
lineNumber - the line number to delete characters from.
offset - the offset to start the deletion from.
length - the number of characters to delete.
Returns:
true if the operation was successful, otherwise false.

addSequences

public void addSequences(int lineNumber,
                         Sequence[] sequenceList)
Adds an array of sequences to a data container at position "lineNumber".

Parameters:
lineNumber - the line number to insert the sequence.
sequenceList - the array of sequences to add to the data container.

removeSequences

public void removeSequences(int[] lineNumbers)
Removes an array of sequences from the data container.

Parameters:
lineNumbers - the line numbers to remove.

addSequence

public void addSequence(Sequence seq)
Adds a sequence to the end of the data container.

Parameters:
seq - the sequence to add to the data container.

addSequence

public void addSequence(int lineNumber,
                        Sequence seq)
Adds a sequence to the document.

Parameters:
lineNumber - the line number to insert the sequence.
seq - the sequence to add to the document.

addSequences

public void addSequences(Sequence[] sequenceList)
Adds an array of sequences to the end of the data container.

Parameters:
sequenceList - the array of sequences to add to the data container.

removeSequence

public void removeSequence(int lineNumber)
Removes a sequences from the data container.

Parameters:
lineNumber - the line number of the sequence to remove.

undo

public boolean undo()
Performs an undo operation to the data container.

Returns:
true if the undo was successful.

redo

public boolean redo()
Performs an redo operation to the data container.

Returns:
true if the redo was successful.

getLength

public int getLength()
Returns the length of the data container's content.

Returns:
the length in characters of the data container's sequence content.

getLineNumber

public int getLineNumber(int offset)
Obtains the line number for a given offset.

Parameters:
offset - the offset to get the line number for (in characters).
Returns:
the corresponding line number.

getLineCount

public int getLineCount()
Returns the number of lines in the document.

Returns:
the number of lines in the document.

getLine

public java.lang.String getLine(int lineNumber)
Retrieves a given line of text from the document.

Parameters:
lineNumber - the line number to retrieve.
Returns:
the line of text.

getLineStartOffset

public int getLineStartOffset(int lineNumber)
Retrieves the start offset of a line.

Parameters:
lineNumber - the line number to obtain the start offset for.
Returns:
the start offset for the line (in characters).

getLineEndOffset

public int getLineEndOffset(int lineNumber)
Retrieves the end offset of the given line.

Parameters:
lineNumber - the line number to obtain the end offset for.
Returns:
the end offset for the line (in characters).

getLineLength

public int getLineLength(int lineNumber)
Retrieves the length of a line in the document.

Parameters:
lineNumber - the line number to find the length of.
Returns:
the length of the line (in characters).

getText

public java.lang.String getText(int offset,
                                int length)
Retrieves a body of text from the data container.

Parameters:
offset - the offset to start retrieving from (in characters).
length - the length of text to retrieve (in characters).
Returns:
the corresponding body of text.

getSequence

public Sequence getSequence(int lineNumber)
Retrieves a sequence object from the SeqDoc specified by its line number.

Parameters:
lineNumber - the line number to retreive the sequence.
Returns:
the sequence.

getSequences

public Sequence[] getSequences(int[] lineNumbers)
Calls getSequence multiple times for multiple line numbers.

Parameters:
lineNumbers - the line numbers to send to get sequence.
Returns:
the resulting sequences (in an array).

addListener

public void addListener(SeqDocListener listener)
Adds a listener object to the data container.

Parameters:
listener - the listener to add.

getLongestLineLength

public int getLongestLineLength()
Returns the length of the longest line in the data container

Returns:
the length of the longest line

sequenceChanged

public void sequenceChanged(Sequence sequence,
                            java.lang.String key)
Called when a field in a sequence is modified.

Specified by:
sequenceChanged in interface SequenceListener
Parameters:
sequence - the sequence modified.
key - the key of the modified field in the sequence.

BioLegato 0.5.6

Copyright © 2008-2009 University of Manitoba.