org.apache.pivot.wtk
Class RangeSelection

java.lang.Object
  extended by org.apache.pivot.wtk.RangeSelection

public class RangeSelection
extends Object

Class for managing a set of indexed range selections.


Constructor Summary
RangeSelection()
           
 
Method Summary
 Sequence<Span> addRange(int start, int end)
          Adds a range to the selection, merging and removing intersecting ranges as needed.
 void clear()
          Clears the selection.
 boolean containsIndex(int index)
          Tests for the presence of an index in the selection.
 Span get(int index)
          Returns the range at a given index.
 int getLength()
          Returns the number of ranges in the selection.
 ImmutableList<Span> getSelectedRanges()
          Returns an immutable wrapper around the selected ranges.
 int indexOf(Span range)
          Determines the index of a range in the selection.
 int insertIndex(int index)
          Inserts an index into the span sequence (e.g. when items are inserted into the model data).
static Span normalize(int start, int end)
          Ensures that the start value is less than or equal to the end value.
 int removeIndexes(int index, int count)
          Removes a range of indexes from the span sequence (e.g. when items are removed from the model data).
 Sequence<Span> removeRange(int start, int end)
          Removes a range from the selection, truncating and removing intersecting ranges as needed.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RangeSelection

public RangeSelection()
Method Detail

addRange

public Sequence<Span> addRange(int start,
                               int end)
Adds a range to the selection, merging and removing intersecting ranges as needed.

Parameters:
start -
end -
Returns:
A sequence containing the ranges that were added.

removeRange

public Sequence<Span> removeRange(int start,
                                  int end)
Removes a range from the selection, truncating and removing intersecting ranges as needed.

Parameters:
start -
end -
Returns:
A sequence containing the ranges that were removed.

clear

public void clear()
Clears the selection.


get

public Span get(int index)
Returns the range at a given index.

Parameters:
index -

getLength

public int getLength()
Returns the number of ranges in the selection.


getSelectedRanges

public ImmutableList<Span> getSelectedRanges()
Returns an immutable wrapper around the selected ranges.


indexOf

public int indexOf(Span range)
Determines the index of a range in the selection.

Parameters:
range -
Returns:
The index of the range, if it exists in the selection; -1, otherwise.

containsIndex

public boolean containsIndex(int index)
Tests for the presence of an index in the selection.

Parameters:
index -
Returns:
true if the index is selected; false, otherwise.

insertIndex

public int insertIndex(int index)
Inserts an index into the span sequence (e.g. when items are inserted into the model data).

Parameters:
index -
Returns:
The number of ranges that were updated.

removeIndexes

public int removeIndexes(int index,
                         int count)
Removes a range of indexes from the span sequence (e.g. when items are removed from the model data).

Parameters:
index -
count -
Returns:
The number of ranges that were updated.

normalize

public static Span normalize(int start,
                             int end)
Ensures that the start value is less than or equal to the end value.

Parameters:
start -
end -
Returns:
A span containing the normalized range.