com.bbn.swede.core.dom
Class DisplaceableRegion

java.lang.Object
  extended bycom.bbn.swede.core.dom.DisplaceableRegion

public class DisplaceableRegion
extends Object

A region that can adjust its offset or length to accomodate a character displacement. Otherwise, this class behaves exactly like the standard implementation of org.eclipse.jface.text.Region.

Author:
jlerner

Constructor Summary
DisplaceableRegion(int offset, int length)
          Creates a DisplaceableRegion with an initial offset and length.
DisplaceableRegion(int offset, int length, boolean bMoveIfEqual)
          Creates a DisplaceableRegion with an initial offset and length.
 
Method Summary
 void displace(int offset, int length)
          Adjusts the region's offset or length to reflect a character displacement.
 int getLength()
          Returns the region's length in characters.
 int getOffset()
          Returns the starting character offset of the region.
 boolean moveIfEqual()
          Indicates whether displacements at the region's starting offset are handled by moving the offset or increasing the length.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DisplaceableRegion

public DisplaceableRegion(int offset,
                          int length)

Creates a DisplaceableRegion with an initial offset and length.

This is a convenience method, fully equivalent to:

DisplaceableRegion(offset, length, false)

Parameters:
offset - Initial offset
length - Initial length

DisplaceableRegion

public DisplaceableRegion(int offset,
                          int length,
                          boolean bMoveIfEqual)
Creates a DisplaceableRegion with an initial offset and length. The boolean flags indicate how the region's offset should behave during a displacement. bMoveIfIqual controls whether displacements at the region's starting offset are handled by moving the offset or increasing the length.

Parameters:
offset - Initial offset
length - Initial length
bMoveIfEqual - true to move the starting offset when a displacement starts at the beginning of the region, false to lengthen the node in this case.
Method Detail

getLength

public int getLength()
Returns the region's length in characters.

Returns:
Region length

getOffset

public int getOffset()
Returns the starting character offset of the region.

Returns:
Region offset

moveIfEqual

public boolean moveIfEqual()
Indicates whether displacements at the region's starting offset are handled by moving the offset or increasing the length.

Returns:
true if displacements at the start of the region change its offset, false if they change its length.

displace

public void displace(int offset,
                     int length)
Adjusts the region's offset or length to reflect a character displacement. If the region begins after the displacement offset, or if it begins on the displacement offset and moveIfEqual() is true, its offset will be adjusted. If the displacement offset occurs within the region, or if it matches the region's offset and moveIfEqual() is false, its length will be adjusted. If the displacement offset is beyond the end of the region, it is unaffected.

Parameters:
offset - Origin of the displacement
length - Magnitude of the displacement. May be negative.


Copyright © 2004-2005 BBN Technologies. All Rights Reserved.