BioLegato 0.7.0 Core API

org.biolegato.core.data.seqdoc
Class SeqDoc

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

public class SeqDoc
extends java.lang.Object
implements SequenceListener, java.awt.datatransfer.Transferable

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
static java.awt.datatransfer.DataFlavor seqDocFlavour
          A data flavour representing the SeqDoc data type.
 
Constructor Summary
SeqDoc()
          Creates a new instance of SeqDoc
SeqDoc(Sequence[] sequenceList)
          Creates a new instance of SeqDoc using the existing sequence list
 
Method Summary
 void addListener(SeqDocListener listener)
          Adds a listener object to the data container.
 boolean addSequence(int y, Sequence seq)
          Adds a sequence to the data container.
 boolean delete(int x, int y, int w)
          Removes text from the document.
 boolean delete(int x, int y, int w, int h)
          Removes text from the document.
protected  void finalize()
          Finalizes the object - removes all references to itself
 Sequence getLine(int y)
          Retrieves a sequence object from the SeqDoc specified by its line number.
 int getLineCount()
          Returns the number of lines in the document.
 int getLineLength(int y)
          Retrieves the length of a line in the document.
 int getLongestLine()
          Returns the length of the longest line in the data container
 java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavour)
          Translates the SeqDoc to the given format
 java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
          Dictates what formats the SeqDoc can be converted to.
 int indexOf(Sequence seq)
          Retrieves the line number for a sequence object in the SeqDoc.
 boolean insert(int x, int y, Sequence[] sequences)
          Inserts sequences at a specific offset in the document.
 boolean insert(int x, int y, java.lang.String string)
          Inserts a string into the document on a given line.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavour)
          Dictates whether a given format is supported for conversion
 boolean 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.
 Sequence[] toArray()
          Converts the SeqDoc into a sequence array representation
 java.lang.String toString()
          Converts the SeqDoc into a string representation
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

seqDocFlavour

public static final java.awt.datatransfer.DataFlavor seqDocFlavour
A data flavour representing the SeqDoc data type.

Constructor Detail

SeqDoc

public SeqDoc()
Creates a new instance of SeqDoc


SeqDoc

public SeqDoc(Sequence[] sequenceList)
Creates a new instance of SeqDoc using the existing sequence list

Parameters:
sequenceList - the list of sequences to initialize the SeqDoc with.
Method Detail

insert

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

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

insert

public boolean insert(int x,
                      int y,
                      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:
insertion X offset: 4
insertion Y offset: 0

Document: ggggtttt

Sequence[0]: aaaa
....
Sequence[last]: cccc

Result: ggggaaaa
....
cccctttt

Parameters:
x - the X co-ordinate offset in the document to insert the sequences.
y - the Y co-ordinate offset in the document to insert the sequences.
sequences - the array of sequences to insert.
Returns:
true if the insertion was successful, otherwise false.

delete

public boolean delete(int x,
                      int y,
                      int w)
Removes text from the document.

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

NOTE: ALL DELETIONS ARE PERFORMED AS FOLLOWS:
Sequence[0]: ggggaaaa
....
Sequence[3]: cccctttt
delete(4, 0, 4, 3);
Result: gggg .... cccc

Parameters:
x - the X-offset/column number to start the deletion from.
y - the Y-offset/line number to delete characters from.
w - the width of the deletion (measured in characters along the X-axis).
Returns:
true if the deletion was successful, otherwise false.

delete

public boolean delete(int x,
                      int y,
                      int w,
                      int h)
Removes text from the document.

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

NOTE: ALL DELETIONS ARE PERFORMED AS FOLLOWS:
Sequence[0]: ggggaaaa
....
Sequence[3]: cccctttt
delete(4, 0, 4, 3);
Result: gggg .... cccc

Parameters:
x - the X-offset/column number to start the deletion from.
y - the Y-offset/line number to delete characters from.
w - the width of the deletion (measured in characters along the X-axis).
h - the height of the deletion (measured in sequences along the Y-axis).
Returns:
true if the deletion was successful, otherwise false.

addSequence

public boolean addSequence(int y,
                           Sequence seq)
Adds a sequence to the data container. This function calls all listeners.

Parameters:
y - is the line number to insert the sequence.
seq - is the sequence to insert.
Returns:
true if the insertion was successful, otherwise false.

removeSequence

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

Parameters:
lineNumber - the line number of the sequence to remove.
Returns:
true if the deletion was successful, otherwise false.

removeSequences

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

Parameters:
lineNumbers - the line numbers to remove.

getLine

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

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

getLineLength

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

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

getLineCount

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

Returns:
the number of lines in the document.

getLongestLine

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

Returns:
the length of the longest line

indexOf

public int indexOf(Sequence seq)
Retrieves the line number for a sequence object in the SeqDoc.

Parameters:
seq - the sequence to search for.
Returns:
the line number of the sequence.

addListener

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

Parameters:
listener - the listener to add.

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.

getTransferDataFlavors

public java.awt.datatransfer.DataFlavor[] getTransferDataFlavors()
Dictates what formats the SeqDoc can be converted to.

Specified by:
getTransferDataFlavors in interface java.awt.datatransfer.Transferable
Returns:
an array of supported formats

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavour)
Dictates whether a given format is supported for conversion

Specified by:
isDataFlavorSupported in interface java.awt.datatransfer.Transferable
Parameters:
flavour - the flavour to test for compatability
Returns:
true if the format is supported

getTransferData

public java.lang.Object getTransferData(java.awt.datatransfer.DataFlavor flavour)
                                 throws java.awt.datatransfer.UnsupportedFlavorException,
                                        java.io.IOException
Translates the SeqDoc to the given format

Specified by:
getTransferData in interface java.awt.datatransfer.Transferable
Parameters:
flavour - the data flavour to use for translation
Returns:
the translated object
Throws:
java.awt.datatransfer.UnsupportedFlavorException - if the SeqDoc cannot be translated into the requested data flavour
java.io.IOException - if there is a problem with I/O during the translation

toString

public java.lang.String toString()
Converts the SeqDoc into a string representation

Overrides:
toString in class java.lang.Object
Returns:
the string representation of the sequence document

toArray

public Sequence[] toArray()
Converts the SeqDoc into a sequence array representation

Returns:
the sequence array representation of the sequence document

finalize

protected void finalize()
Finalizes the object - removes all references to itself

Overrides:
finalize in class java.lang.Object

BioLegato 0.7.0 Core API

Copyright © 2008-2010 University of Manitoba.