org.annotation.wordfreak
Interface AnnotationView

All Superinterfaces:
javax.swing.tree.TreeModel

public interface AnnotationView
extends javax.swing.tree.TreeModel

Provides a tree inteface and a list interface to a group of annotations. Which annotations are visible with the view depends on view filters. The order in which annotation are accessed depends on the sort criteria set for the view. Any modifications to annotations in the view should be done via the view or the view should be notified of these changes with the update method.

Author:
Jeremy Lacivita, Tom Morton

Method Summary
 int binarySearchAnnotation(Annotation a)
          Returns the index of the specified annotation in the list of annotations available for display.
 int binarySearchBase(Annotation a)
          Returns the index of the specified annotation in the list of annotations on which other annotaitons are based.
 void chainAnnotations(Annotation a, Annotation b)
          Creates a chain between the two specified annotations.
 void close()
          Does any clean up that needs to happen before the view goes away
 boolean containsAll(java.util.List list, java.lang.Object node)
          Checks whether each child of the specified node is contained in the specified list.
 Relation createRelation(java.lang.String type, java.lang.Object key, java.lang.String[] frame, Annotation[] annotations)
          Returns a new releation with the specified type, anchor key, frame, and annotations.
 void deepInsert(Annotation a)
          Inserts the specified annotation as deep as possible.
 Annotation deepInsert(java.lang.String type, int start, int end)
          Creates and inserts a new annotation specified type and span given by the specified start and end indices.
 void filter(AnnotationFilter f)
          Applies the specified filter to this view.
 Annotation getAnnotation(int i)
          Returns sorted annotation at index i.
 java.util.Iterator getAnnotationIterator()
          Returns Iterator for filtered/sorted annotations.
 int getAnnotationSize()
          Returns size of filtered/sorted annotations.
 Annotation getBase(int index)
          Returns the annotation at the specified index from the list of annotations which new annotation are based on.
 java.util.Iterator getBaseIterator()
          Returns an iterator over the list of annotations which new annotation are based on.
 int getBaseSize()
          Returns the number of annotation in the list of annotations which new annotation are based on.
 Annotation[] getChain(Annotation a)
          Returns the chains associated with the specified annotation.
 java.lang.Object getContainingLeaf(int offset)
          Returns the leaf node which contains the specified offset.
 java.lang.Object getFirstLeaf(java.lang.Object startNode)
          Returns the left-most leaf child of the specified start node.
 java.lang.Object getLastLeaf(java.lang.Object startNode)
          Returns the right-most leaf child of the specified start node.
 java.lang.Object getNextLeaf(java.lang.Object node)
          Returns the susequent leaf node to the right of the specified node.
 java.lang.Object getParent(java.lang.Object node)
          Returns the parent of the specified node.
 javax.swing.tree.TreeNode[] getPath(java.lang.Object node)
          Returns an array of nodes between the specified node and the root.
 java.lang.Object getPreviousLeaf(java.lang.Object node)
          Returns the previous leaf node to the left of the specified node.
 Relation getRelation(java.lang.String type, Annotation a)
          Returns a relation which is of the specified type and has as its anchor the specified annotation.
 Relation[] getRelations(Annotation a)
          Returns all relations which contain the specified annotation.
 Relation[] getRelations(java.lang.String type)
          Returns all relations of the specified type.
 Relation[] getRelations(java.lang.String type, Annotation a)
          Returns all relation which are of the specified type and which contain the specified annotation.
 SelectionMode getSelectionMode()
          Returns the types of selection which are valid.
 SortedAnnotations getSortedAnnotations()
          Returns the object which manages sorted annotations.
 AnnotationSource getSource()
          Returns the source data associated with the file for this view.
 Annotation getUnsortedAnnotation(int i)
          Returns filtered annotation at index i.
 AnnotationSelection getValidSelection(AnnotationSelection annotations)
          Returns appropiate selection based on selection mode and attempted selection, null is returned if no selection is appropiate.
 Span getValidSelection(int s, int e)
          Returns appropiate selection based on selection mode and attempted selection, null is returned if no selection is appropiate.
 int indexOfAnnotation(Annotation a)
          Returns index of Annotation a in sorted annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).
 int indexOfAnnotationOffset(int o)
          Returns index of sorted annotation which contains the offset o or the offset of the annotation which is closest.
 int indexOfBase(Annotation a)
          Returns index of Annotation a in base annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).
 int indexOfBaseOffset(int offset)
          Returns the index of an annotation in the list of annotations which new annotation are based on which contains the specified offset.
 int indexOfUnsortedAnnotation(Annotation a)
          Returns index of the annotation in the filtered annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).
 void insert(Annotation a)
          Inserts the specified annotation into the view.
 Annotation insert(int s, int e)
          Creates and inserts a new annotation with the span specified by s and e.
 Annotation insert(int start, int end, Annotation parent)
          Returns an annotation with the specified start, end, and parent that has been inserted into the view.
 Annotation insert(java.lang.String type, Annotation start, Annotation end)
          Returns an annotation with the specified type, start, and end that has been inserted into the view.
 Annotation insert(java.lang.String type, int start, int end)
          Returns an annotation with the specified type, start, and end that has been inserted into the view.
 Annotation insert(java.lang.String type, int start, int end, Annotation parent)
          Returns an annotation with the specified type, start, end, and parent that has been inserted into the view.
 Annotation insertParent(Annotation child)
          Returns a new annotation which has the same span as the specified child annotation and is the parent of the specified child.
 Annotation insertParent(java.lang.String type, Annotation child)
          Returns a new annotation with the specified type which has the same span as the specified child annotation and is the parent of the specified child.
 Annotation insertZeroLengthAnnotationAfter(Annotation after)
          Returns a zero length annotation which is inserted after the specified annotation.
 Annotation insertZeroLengthAnnotationAfter(java.lang.String type, Annotation after)
          Returns a zero length annotation with the specified type which is inserted after the specified annotation.
 Annotation insertZeroLengthAnnotationBefore(Annotation before)
          Returns a zero length annotation which is inserted before the specified annotation.
 Annotation insertZeroLengthAnnotationBefore(java.lang.String type, Annotation before)
          Returns a zero length annotation of the specified type which is inserted before the specified annotation.
 boolean isTerminalSpan(int start, int end)
          Returns true if the span given by the specified start and end values can be inserted into this view as a leaf.
 void move(Annotation node, Annotation parent)
          Makes annotation parent the parent of annotaiton node.
 void put(int roleIndex, Annotation ann, Relation relation)
          Puts the specified annotation at the specified role index in the specified relation.
 void put(java.lang.String role, Annotation ann, Relation relation)
          Puts the specified annotation the specified relation with the specified role name.
 void remove(Annotation node)
          Removes an annotation from the view.
 void remove(Annotation node, boolean shrink)
          Removes an annotation from the view and shinks annotations which contained it based on teh specified shrink value.
 void remove(Annotation annotation, Relation relation)
          Removes the specified annotation from the specified relation or if the specified annotation is the anchor of the relation, removes the relation from this view.
 void remove(Relation relation)
          Removes the specified relation from this view.
 Annotation removeFromChain(Annotation a)
          Removes the specified annotation from a chain and returns another annotation from the modified chain if such an annotation exists.
 void resetSelection()
          Resets the selection.
 void setSelectionMode(SelectionMode sm)
          Specified what types of selection are valid.
 void sort(java.util.Comparator c)
          Sorts the annotations in this view based on the specified comparison criteria.
 Annotation terminalInsert(java.lang.String type, int start, int end)
          Inserts a newly created annotation with the specified type and span in this tree and returns the newly created annotation.
 void update()
          Rebuilds the view based on the AnnotationTree.
 void update(Annotation a)
          Indicates that the specified annotation has been changed.
 
Methods inherited from interface javax.swing.tree.TreeModel
addTreeModelListener, getChild, getChildCount, getIndexOfChild, getRoot, isLeaf, removeTreeModelListener, valueForPathChanged
 

Method Detail

close

public void close()
Does any clean up that needs to happen before the view goes away


update

public void update()
Rebuilds the view based on the AnnotationTree. This is called when major changes to the tree occur; such as after automatic annotation.


getParent

public java.lang.Object getParent(java.lang.Object node)
Returns the parent of the specified node.

Parameters:
node - The node whose parent is being requested.
Returns:
The parent of the specified node or null is no such parent exists..

getFirstLeaf

public java.lang.Object getFirstLeaf(java.lang.Object startNode)
Returns the left-most leaf child of the specified start node.

Parameters:
startNode - The node at which to begin the search.
Returns:
The left-most leaf child of the specified start node.

getLastLeaf

public java.lang.Object getLastLeaf(java.lang.Object startNode)
Returns the right-most leaf child of the specified start node.

Parameters:
startNode - The node at which to begin the search.
Returns:
The right-most leaf child of the specified start node.

getContainingLeaf

public java.lang.Object getContainingLeaf(int offset)
Returns the leaf node which contains the specified offset.

Parameters:
offset - The offset that the returned leaf should contain.
Returns:
The leaf node which contains the specified offset or null if no such leaf exists.

getPath

public javax.swing.tree.TreeNode[] getPath(java.lang.Object node)
Returns an array of nodes between the specified node and the root.

Parameters:
node - The node in the tree from which to start the part.
Returns:
An array of nodes between the specified node and the root.

getNextLeaf

public java.lang.Object getNextLeaf(java.lang.Object node)
Returns the susequent leaf node to the right of the specified node.

Parameters:
node - An existing leaft node.
Returns:
The susequent leaf node to the right of the specified node or null if no such node exists.

getPreviousLeaf

public java.lang.Object getPreviousLeaf(java.lang.Object node)
Returns the previous leaf node to the left of the specified node.

Parameters:
node - An existing leaft node.
Returns:
The previous leaf node to the left of the specified node or null if no such node exists.

move

public void move(Annotation node,
                 Annotation parent)
Makes annotation parent the parent of annotaiton node.

Parameters:
node - The annotation being moved.
parent - The parent annotation.

getSource

public AnnotationSource getSource()
Returns the source data associated with the file for this view.

Returns:
The source data associated with the file for this view.

sort

public void sort(java.util.Comparator c)
Sorts the annotations in this view based on the specified comparison criteria.

Parameters:
c - The criteria on which the sort is based.

filter

public void filter(AnnotationFilter f)
Applies the specified filter to this view.

Parameters:
f - The filter to be applied to this view.

getBase

public Annotation getBase(int index)
Returns the annotation at the specified index from the list of annotations which new annotation are based on.

Parameters:
index - The index of the annotation to be returned.
Returns:
The annotation at the specified index from the list of annotations which new annotation are based on.

getBaseSize

public int getBaseSize()
Returns the number of annotation in the list of annotations which new annotation are based on.

Returns:
The number of annotation in the list of annotations which new annotation are based on.

getBaseIterator

public java.util.Iterator getBaseIterator()
Returns an iterator over the list of annotations which new annotation are based on.

Returns:
An iterator over the list of annotations which new annotation are based on.

getSortedAnnotations

public SortedAnnotations getSortedAnnotations()
Returns the object which manages sorted annotations.


getAnnotation

public Annotation getAnnotation(int i)
Returns sorted annotation at index i.

Parameters:
i - index
Returns:
sorted annotation at index i.

getUnsortedAnnotation

public Annotation getUnsortedAnnotation(int i)
Returns filtered annotation at index i.

Parameters:
i - index
Returns:
filtered annotation at index i.

getAnnotationSize

public int getAnnotationSize()
Returns size of filtered/sorted annotations.

Returns:
returns size of filtered/sorted annotations.

getAnnotationIterator

public java.util.Iterator getAnnotationIterator()
Returns Iterator for filtered/sorted annotations.

Returns:
Iterator for filtered annotations.

indexOfAnnotation

public int indexOfAnnotation(Annotation a)
Returns index of Annotation a in sorted annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).

Parameters:
a - Annotation.
Returns:
index of the Annotation a in sorted annotaitons list if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the filtered annotations list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified Annotation.

containsAll

public boolean containsAll(java.util.List list,
                           java.lang.Object node)
Checks whether each child of the specified node is contained in the specified list.

Parameters:
list - A list of children.
node - The node of a tree.
Returns:
true if each child of node is contained in the list, false otherwise.

indexOfUnsortedAnnotation

public int indexOfUnsortedAnnotation(Annotation a)
Returns index of the annotation in the filtered annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).

Parameters:
a - Annotation.
Returns:
index of the Annotation a in the filtered annotaitons list if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the filtered annotations list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified Annotation.

indexOfAnnotationOffset

public int indexOfAnnotationOffset(int o)
Returns index of sorted annotation which contains the offset o or the offset of the annotation which is closest.

Parameters:
o - offset.
Returns:
index of sorted annotation which contains the offset o or the offset of the annotation which is closest.

indexOfBase

public int indexOfBase(Annotation a)
Returns index of Annotation a in base annotations list if it is contained in the list; otherwise, (-(insertion point) - 1).

Parameters:
a - The annotation whose index is being searched for.
Returns:
index of the Annotation a in base annotaitons list if it is contained in the list; otherwise, (-(insertion point) - 1). The insertion point is defined as the point at which the key would be inserted into the base annotations list: the index of the first element greater than the key, or list.size(), if all elements in the list are less than the specified Annotation.

indexOfBaseOffset

public int indexOfBaseOffset(int offset)
Returns the index of an annotation in the list of annotations which new annotation are based on which contains the specified offset.

Parameters:
offset - The offset the base annotation at the returned index will contain.
Returns:
The index of an annotation in the list of annotations which new annotation are based on which contains the specified offset or (-(insertion point) - 1) of such an annotation if no such annotation exist.

binarySearchAnnotation

public int binarySearchAnnotation(Annotation a)
Returns the index of the specified annotation in the list of annotations available for display.

Parameters:
a - The annotation being searched for.
Returns:
the index of the specified annotation in the list of annotations available for display or (-(insertion point) - 1) of such an annotation if no such annotation exist..

binarySearchBase

public int binarySearchBase(Annotation a)
Returns the index of the specified annotation in the list of annotations on which other annotaitons are based.

Parameters:
a - The annotation being searched for.
Returns:
the index of the specified annotation in the list of annotations on which other annotations are based or (-(insertion point) - 1) of such an annotation if no such annotation exist..

remove

public void remove(Annotation node)
Removes an annotation from the view.

Parameters:
node - The annotation to be removed.

remove

public void remove(Annotation node,
                   boolean shrink)
Removes an annotation from the view and shinks annotations which contained it based on teh specified shrink value.

Parameters:
node - The node to be removed.
shrink - Whether nodes which contains the specifed annotation should be shunk.

insert

public Annotation insert(int s,
                         int e)
Creates and inserts a new annotation with the span specified by s and e.

Parameters:
s - the start of the span for the annotation.
e - the end of the span for the annotation.

deepInsert

public Annotation deepInsert(java.lang.String type,
                             int start,
                             int end)
Creates and inserts a new annotation specified type and span given by the specified start and end indices.

Parameters:
type - The type of the annotation to be inserted.
start - the start of the span for the annotation.
end - the end of the span for the annotation.

isTerminalSpan

public boolean isTerminalSpan(int start,
                              int end)
Returns true if the span given by the specified start and end values can be inserted into this view as a leaf.

Parameters:
start - The start value of the span.
end - The end value of the span.
Returns:
true if the span given by the specified start and end values does not intersect any existing nodes, false otherwise.

insert

public void insert(Annotation a)
Inserts the specified annotation into the view.

Parameters:
a - The annotation to insert.

terminalInsert

public Annotation terminalInsert(java.lang.String type,
                                 int start,
                                 int end)
Inserts a newly created annotation with the specified type and span in this tree and returns the newly created annotation.

Parameters:
type - The type of annotation to create.
start - The start of the span of the new annotation.
end - The end of the span of the new annotation.
Returns:
the newly ceated annotation or null if the annotation would intersect with an exiting annotation.

deepInsert

public void deepInsert(Annotation a)
Inserts the specified annotation as deep as possible.

Parameters:
a - The annotation to insert.

insert

public Annotation insert(int start,
                         int end,
                         Annotation parent)
Returns an annotation with the specified start, end, and parent that has been inserted into the view.

Parameters:
start - The start value of the annotation's span.
end - The end value of the annotation's span.
parent - The parent of the annotation.
Returns:
An annotation with the specified start, end, and parent that has been inserted into the view.

insertZeroLengthAnnotationBefore

public Annotation insertZeroLengthAnnotationBefore(Annotation before)
Returns a zero length annotation which is inserted before the specified annotation.

Parameters:
before - The annotation which the the new annotaiton is before.
Returns:
A zero length annotation which is inserted before the specified annotation.

insertZeroLengthAnnotationAfter

public Annotation insertZeroLengthAnnotationAfter(Annotation after)
Returns a zero length annotation which is inserted after the specified annotation.

Parameters:
after - The annotation which the the new annotaiton is after.
Returns:
A zero length annotation which is inserted after the specified annotation.

insertParent

public Annotation insertParent(Annotation child)
Returns a new annotation which has the same span as the specified child annotation and is the parent of the specified child.

Parameters:
child - The annotation on which the new annotation is based.
Returns:
A new annotation which has the same span as the specified child annotation and is the parent of the specified child.

insert

public Annotation insert(java.lang.String type,
                         int start,
                         int end)
Returns an annotation with the specified type, start, and end that has been inserted into the view.

Parameters:
type - The type of the new annotation.
start - The start of the new annotation's span.
end - The end of the new annotation's span.
Returns:
An annotation with the specified type, start, end, and parent that has been inserted into the view.

insert

public Annotation insert(java.lang.String type,
                         int start,
                         int end,
                         Annotation parent)
Returns an annotation with the specified type, start, end, and parent that has been inserted into the view.

Parameters:
type - The type of the new annotation.
start - The start of the new annotation's span.
end - The end of the new annotation's span.
parent - The parent of the new annotation.
Returns:
An annotation with the specified type, start, end, and parent that has been inserted into the view.

insert

public Annotation insert(java.lang.String type,
                         Annotation start,
                         Annotation end)
Returns an annotation with the specified type, start, and end that has been inserted into the view.

Parameters:
type - The type of the new annotation.
start - The start annotation of the new annotation's span.
end - The end annotation of the new annotation's span.
Returns:
An annotation with the specified type, start, end, and parent that has been inserted into the view.

insertZeroLengthAnnotationBefore

public Annotation insertZeroLengthAnnotationBefore(java.lang.String type,
                                                   Annotation before)
Returns a zero length annotation of the specified type which is inserted before the specified annotation.

Parameters:
type - The type of the new annotation.
before - The annotation which the the new annotaiton is before.
Returns:
A zero length annotation which is inserted before the specified annotation.

insertZeroLengthAnnotationAfter

public Annotation insertZeroLengthAnnotationAfter(java.lang.String type,
                                                  Annotation after)
Returns a zero length annotation with the specified type which is inserted after the specified annotation.

Parameters:
type - The type of the new annotation.
after - The annotation which the the new annotaiton is after.
Returns:
A zero length annotation which is inserted after the specified annotation.

insertParent

public Annotation insertParent(java.lang.String type,
                               Annotation child)
Returns a new annotation with the specified type which has the same span as the specified child annotation and is the parent of the specified child.

Parameters:
type - The type of the new annotation.
child - The annotation on which the new annotation is based.
Returns:
A new annotation which has the same span as the specified child annotation and is the parent of the specified child.

update

public void update(Annotation a)
Indicates that the specified annotation has been changed.

Parameters:
a - The annotation which needs to be updated.

chainAnnotations

public void chainAnnotations(Annotation a,
                             Annotation b)
Creates a chain between the two specified annotations.

Parameters:
a - The first annotation in the chain.
b - The second annotation in the chain.

getChain

public Annotation[] getChain(Annotation a)
Returns the chains associated with the specified annotation. Annotations can only be in one chain.

Parameters:
a - An annotation in a chain.
Returns:
The chains associated with the specified annotation. The returned array can be empty.

removeFromChain

public Annotation removeFromChain(Annotation a)
Removes the specified annotation from a chain and returns another annotation from the modified chain if such an annotation exists.

Parameters:
a - The annotation to be removed.
Returns:
A annotation from the modified chain or null if no such an annotation exists.

createRelation

public Relation createRelation(java.lang.String type,
                               java.lang.Object key,
                               java.lang.String[] frame,
                               Annotation[] annotations)
Returns a new releation with the specified type, anchor key, frame, and annotations.

Parameters:
type - The type of the relations.
key - The anchor annotation of this relation.
frame - The names of the frame elements of the relation.
annotations - The annotation which occupy the frame elements.
Returns:
A new releation with the specified type, anchor key, frame, and annotations.

put

public void put(int roleIndex,
                Annotation ann,
                Relation relation)
Puts the specified annotation at the specified role index in the specified relation.

Parameters:
roleIndex - The position in the frame of the specified relation when the specified annotaiton will be placed.
ann - The annotation to be placed at the specified role Index in the specified relation.
relation - The annotation to be modified.

put

public void put(java.lang.String role,
                Annotation ann,
                Relation relation)
Puts the specified annotation the specified relation with the specified role name. Role names can be duplicated and this will always add anothor element to the relations frame.

Parameters:
role - The name of the role slot in the relation when the annotation will be placed.
ann - The annotation to put in the relation.
relation - The relation to be modified.

remove

public void remove(Relation relation)
Removes the specified relation from this view.

Parameters:
relation - The relation to be removed.

remove

public void remove(Annotation annotation,
                   Relation relation)
Removes the specified annotation from the specified relation or if the specified annotation is the anchor of the relation, removes the relation from this view.

Parameters:
annotation - The annotation to remove.
relation - The relation from which the spevified annotation is removed.

getRelations

public Relation[] getRelations(java.lang.String type)
Returns all relations of the specified type.

Parameters:
type - The type of relations to be returned.
Returns:
An array of all relations of the specified type.

getRelations

public Relation[] getRelations(Annotation a)
Returns all relations which contain the specified annotation.

Parameters:
a - The annotation which the returned relations contain.
Returns:
An array of all relations which contain the specified annotation.

getRelations

public Relation[] getRelations(java.lang.String type,
                               Annotation a)
Returns all relation which are of the specified type and which contain the specified annotation.

Parameters:
type - The type of relations to be returned.
a - The annotation which the returned relations contain.
Returns:
An array of all relation which are of the specified type and which contain the specified relation.

getRelation

public Relation getRelation(java.lang.String type,
                            Annotation a)
Returns a relation which is of the specified type and has as its anchor the specified annotation.

Parameters:
type - The type of relation to be returned.
a - The anchor of the relations to be returned.
Returns:
A relation which is of the specified type and has as its anchor the specified annotation or null if not such relation exists.

getValidSelection

public Span getValidSelection(int s,
                              int e)
Returns appropiate selection based on selection mode and attempted selection, null is returned if no selection is appropiate.

Returns:
span indicating appropiate selection.

getValidSelection

public AnnotationSelection getValidSelection(AnnotationSelection annotations)
Returns appropiate selection based on selection mode and attempted selection, null is returned if no selection is appropiate.

Returns:
span indicating appropiate selection.

resetSelection

public void resetSelection()
Resets the selection. This should be called before #getValidSelection when a new selection is made.


setSelectionMode

public void setSelectionMode(SelectionMode sm)
Specified what types of selection are valid.

Parameters:
sm - The types of selection which are valid.

getSelectionMode

public SelectionMode getSelectionMode()
Returns the types of selection which are valid.

Returns:
The types of selection which are valid.


Copyright © 2004 Thomas Morton and Jeremy LaCivita. All Rights Reserved.