edu.rice.cs.drjava.model
Interface RegionManager<R extends IDocumentRegion>

All Known Implementing Classes:
ConcreteRegionManager

public interface RegionManager<R extends IDocumentRegion>

Interface for a region manager. Region ordering (as in DocumentRegion) is not required, but it facilitates efficient implementation.

Version:
$Id: RegionManager.java 5236 2010-04-27 01:43:36Z mgricken $

Method Summary
 void addListener(RegionManagerListener<R> listener)
          Adds a listener to the notifier.
 void addRegion(R region)
          Add the supplied DocumentRegion to the manager.
 void changeRegion(R region, Lambda<R,Object> cmd)
          Apply the given command to the specified region to change it.
 void clearRegions()
          Tells the manager to remove all regions.
 boolean contains(R r)
          Tests if specified region r is contained in this manager.
 Set<OpenDefinitionsDocument> getDocuments()
           
 SortedSet<R> getHeadSet(R r)
          Gets the sorted set of regions less than r.
 R getRegionAt(OpenDefinitionsDocument odd, int offset)
          Returns the unique region [start,end), if any, containing the specified offset.
 int getRegionCount()
           
 Pair<R,R> getRegionInterval(OpenDefinitionsDocument odd, int offset)
          Returns the first and last region r where r.getLineStart() <= offset < r.getLineEnd().
 ArrayList<R> getRegions()
           
 SortedSet<R> getRegions(OpenDefinitionsDocument odd)
           
 Collection<R> getRegionsOverlapping(OpenDefinitionsDocument odd, int startOffset, int endOffset)
          Returns the rightmost region starting on the same line containing the specified selection
 SortedSet<R> getTailSet(R r)
          Gets the sorted set of regions greater than or equal to r.
 void removeAllListeners()
          Removes all listeners from this notifier.
 void removeListener(RegionManagerListener<R> listener)
          Removes a listener from the notifier.
 void removeRegion(R region)
          Remove the given DocumentRegion from the manager.
 void removeRegions(Iterable<? extends R> regions)
          Remove the given DocumentRegions from the manager.
 void removeRegions(OpenDefinitionsDocument odd)
          Remove the given OpenDefinitionsDocument and all of its regions from the manager.
 void updateLines(R firstRegion, R lastRegion)
          Updates _lineStartPos, _lineEndPos of regions in the interval [firstRegion, lastRegion] using total ordering on regions.
 

Method Detail

getRegionAt

R getRegionAt(OpenDefinitionsDocument odd,
              int offset)
Returns the unique region [start,end), if any, containing the specified offset. Assumes that document regions are disjoint.

Parameters:
odd - the document
offset - the offset in the document
Returns:
the unique DocumentRegion containing the given offset, or null if it does not exist.

getRegionInterval

Pair<R,R> getRegionInterval(OpenDefinitionsDocument odd,
                            int offset)
Returns the first and last region r where r.getLineStart() <= offset < r.getLineEnd(). Assumes that document regions are disjoint and that lineStart precedes the start offset by at most 119 characters.

Parameters:
odd - the document
offset - the offset in the document
Returns:
the unique DocumentRegion containing the given offset, or null if it does not exist.

getRegionsOverlapping

Collection<R> getRegionsOverlapping(OpenDefinitionsDocument odd,
                                    int startOffset,
                                    int endOffset)
Returns the rightmost region starting on the same line containing the specified selection

Returns:
the rightmost DocumentRegion containing the given selection, or null if it does not exist.

contains

boolean contains(R r)
Tests if specified region r is contained in this manager.

Parameters:
r - The region
Returns:
whether the manager contains region r

addRegion

void addRegion(R region)
Add the supplied DocumentRegion to the manager.

Parameters:
region - the DocumentRegion to be inserted into the manager

removeRegion

void removeRegion(R region)
Remove the given DocumentRegion from the manager.

Parameters:
region - the DocumentRegion to be removed.

removeRegions

void removeRegions(Iterable<? extends R> regions)
Remove the given DocumentRegions from the manager.

Parameters:
regions - the DocumentRegions to be removed.

removeRegions

void removeRegions(OpenDefinitionsDocument odd)
Remove the given OpenDefinitionsDocument and all of its regions from the manager.


changeRegion

void changeRegion(R region,
                  Lambda<R,Object> cmd)
Apply the given command to the specified region to change it.

Parameters:
region - the region to find and change
cmd - command that mutates the region.

getRegions

SortedSet<R> getRegions(OpenDefinitionsDocument odd)
Returns:
a Vector containing the DocumentRegion objects for document odd in this manager.

getRegions

ArrayList<R> getRegions()
Returns:
a Vector containing all the DocumentRegion objects in this mangager.

getRegionCount

int getRegionCount()
Returns:
the number if regions contained in this manager.

getHeadSet

SortedSet<R> getHeadSet(R r)
Gets the sorted set of regions less than r.


getTailSet

SortedSet<R> getTailSet(R r)
Gets the sorted set of regions greater than or equal to r.


clearRegions

void clearRegions()
Tells the manager to remove all regions.


getDocuments

Set<OpenDefinitionsDocument> getDocuments()
Returns:
the set of documents containing regions.

updateLines

void updateLines(R firstRegion,
                 R lastRegion)
Updates _lineStartPos, _lineEndPos of regions in the interval [firstRegion, lastRegion] using total ordering on regions. Removes empty regions. firstRegion and lastRegion are not necessarily regions in this manager.


addListener

void addListener(RegionManagerListener<R> listener)
Adds a listener to the notifier.

Parameters:
listener - a listener that reacts on events

removeListener

void removeListener(RegionManagerListener<R> listener)
Removes a listener from the notifier.

Parameters:
listener - a listener that reacts on events

removeAllListeners

void removeAllListeners()
Removes all listeners from this notifier.