org.netbeans.modules.editor.util/1 1.26

org.netbeans.lib.editor.util.swing
Class PositionRegion

java.lang.Object
  extended by org.netbeans.lib.editor.util.swing.PositionRegion
Direct Known Subclasses:
MutablePositionRegion

public class PositionRegion
extends Object

A pair of positions delimiting a text region in a swing document.
At all times it should be satisfied that getStartOffset() <= getEndOffset().

Since:
1.6

Constructor Summary
PositionRegion(Document doc, int startOffset, int endOffset)
          Construct new position region based on the knowledge of the document and starting and ending offset.
PositionRegion(Position startPosition, Position endPosition)
          Construct new position region.
 
Method Summary
static Position createFixedPosition(int offset)
          Create a fixed position instance that just wraps a given integer offset.
static Comparator<PositionRegion> getComparator()
          Get comparator for position regions comparing start offsets of the two given regions.
 int getEndOffset()
          Get ending offset of this region.
 Position getEndPosition()
          Get ending position of this region.
 int getLength()
          Get length of this region.
 int getStartOffset()
          Get starting offset of this region.
 Position getStartPosition()
          Get starting position of this region.
 String getString(Document doc)
          Get text enclosed by this position region as a String.
 CharSequence getText(Document doc)
          Get text enclosed by this position region as a character sequence.
static boolean isRegionsSorted(List<? extends PositionRegion> positionRegionList)
          Check whether a list of position regions is sorted according the start offsets of the regions.
 String toString()
          Debug info about this region.
 String toString(Document doc)
          Debug info about this region that includes line and column info.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

PositionRegion

public PositionRegion(Position startPosition,
                      Position endPosition)
Construct new position region.

Parameters:
startPosition - non-null start position of the region <= end position.
endPosition - non-null end position of the region >= start position.

PositionRegion

public PositionRegion(Document doc,
                      int startOffset,
                      int endOffset)
               throws BadLocationException
Construct new position region based on the knowledge of the document and starting and ending offset.

Throws:
BadLocationException
Method Detail

getComparator

public static final Comparator<PositionRegion> getComparator()
Get comparator for position regions comparing start offsets of the two given regions.

Returns:
non-null comparator comparing the start offsets of the two given regions.

createFixedPosition

public static Position createFixedPosition(int offset)
Create a fixed position instance that just wraps a given integer offset.
This may be useful for situations where a position needs to be used but the document is not available yet. Once the document becomes available the regular position instance (over an existing document) may be used instead.

Parameters:
offset - >=0 offset at which the position should be created.
Since:
1.10

isRegionsSorted

public static boolean isRegionsSorted(List<? extends PositionRegion> positionRegionList)
Check whether a list of position regions is sorted according the start offsets of the regions.

Parameters:
positionRegionList - list of the regions to be compared.
Returns:
true if the regions are sorted according to the starting offset of the given regions or false otherwise.

getStartOffset

public final int getStartOffset()
Get starting offset of this region.

Returns:
>=0 starting offset of this region.

getStartPosition

public final Position getStartPosition()
Get starting position of this region.

Returns:
non-null starting position of this region.

getEndOffset

public final int getEndOffset()
Get ending offset of this region.

Returns:
>=0 ending offset of this region.

getEndPosition

public final Position getEndPosition()
Get ending position of this region.

Returns:
non-null ending position of this region.

getLength

public final int getLength()
Get length of this region.

Returns:
>=0 length of this region computed as getEndOffset() - getStartOffset().

getText

public CharSequence getText(Document doc)
Get text enclosed by this position region as a character sequence.

Parameters:
doc - non-null document to which this position region belongs.
Returns:
non-null character sequence representing the enclosed text.
Throws:
IndexOutOfBoundsException - if the bounds are wrong (likely positions were created for another document).

getString

public String getString(Document doc)
                 throws BadLocationException
Get text enclosed by this position region as a String.

Parameters:
doc - non-null document to which this position region belongs.
Returns:
non-null java.lang.String instance representing the enclosed text.
Throws:
BadLocationException - if the bounds are wrong (likely positions were created for another document).

toString

public String toString(Document doc)
Debug info about this region that includes line and column info.

Parameters:
doc - non-null document to which this position region belongs.
Returns:
debugging info describing this region (inlcuding line and column info).

toString

public String toString()
Debug info about this region.

Overrides:
toString in class Object
Returns:
debugging info describing this region.

org.netbeans.modules.editor.util/1 1.26

Built on December 3 2008.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.