public class HighlightFragmentsList
extends java.lang.Object
HighlightFragmentsList
is a list of HighlightFragment
instances that we can re-use without constantly having to reallocate
arrays and fragment objects. This class is similar to the
StyledFragmentsList
class except that it applies to
HighlightFragment
objects. This fragments list is used primarily for rendering highlights, so it will take care of resolving priority levels of highlights as they are added to the list. This means highlights can be added to the list out of order (both in terms of offsets as well as priority levels), relieving the view and renderers from the responsibility of having to pre-sort through the highlights.
Note that unlike the StyledFragmentsList
, fragments added
to this list are not required, or expected, to be adjacent regions
of text.
For more information about how the different attributes (background,
foreground, font, underline) of a highlight are applied, refer to
HighlightLayer
.
HighlightFragment
,
HighlightLayer
Modifier and Type | Field and Description |
---|---|
static int |
ATTRIBUTE_ALL
Constant indicating that all attributes should be included.
|
static int |
ATTRIBUTE_BACKGROUND
Constant indicating that background should be included.
|
static int |
ATTRIBUTE_FONT
Constant indicating that fonts should be included.
|
static int |
ATTRIBUTE_FOREGROUND
Constant indicating that foreground should be included.
|
static int |
ATTRIBUTE_UNDERLINE
Constant indicating that underlines should be included.
|
static int |
TYPE_ALL
Constant indicating that all underline types should be included.
|
static int |
TYPE_SEPARATOR
Constant indicating that seprator type should be included.
|
static int |
TYPE_STRIKETHRU
Constant indicating that strikethru type should be included.
|
static int |
TYPE_UNDERLINE
Constant indicating that underline type should be included.
|
Constructor and Description |
---|
HighlightFragmentsList()
Constructs a new
HighlightFragmentsList with an initial
size of the default. |
Modifier and Type | Method and Description |
---|---|
void |
add(HighlightStyle highlightStyle,
int startOffset,
int endOffset)
Adds the given fragment to the list, accounting for priority and
offsets so that the list is always sorted in increasing offsets
with higher priority highlights displacing lower priority ones.
|
void |
addSentinel(HighlightStyle highlightStyle)
Adds a final sentinel fragment for background attribute.
|
void |
clear()
Discards all fragments from the list.
|
void |
clearAllFilters()
Utility routine to clear attribute filters.
|
void |
clearAttributeFilter()
Utility routine to clear attribute filters.
|
void |
clearUnderlineTypeFilter()
Utility routine to clear underline type filters.
|
void |
compact()
Utility routine to compact the list if possible, if there are adjacent
fragments that are continuous, and have the same styles set.
|
HighlightFragment |
get(int index)
Get the fragment at the specified index.
|
HighlightStyle |
getSentinelBackground()
Fetch the final sentinel background style if any.
|
HighlightStyle |
getSentinelUnderline()
Fetch the final sentinel underline style if any.
|
void |
setAttributeFilter(int attributeFilter)
Sets the filtering on attributes (when adding highlights to the
list) of what to include in the list.
|
void |
setAttributeFontOnly()
Convenience routine to set filtering to include only highlights with
a font attribute defined.
|
void |
setAttributeTextOnly()
Convenience routine to set filtering to include only highlights with
any text attribute (background, foreground, fonts).
|
void |
setAttributeUnderlineOnly()
Convenience routine to set filtering to include only highlights
with an underline attribute defined.
|
void |
setHighlightRegistry(HighlightRegistry registry)
Set the
HighlightRegistry used by this list when
building up its list of highlight fragments. |
void |
setUnderlineTypeFilter(int underlineTypeFilter)
Sets the filtering on attributes (when adding highlights to the
list) of what to include in the list.
|
int |
size()
Returns the size of the list (number of fragments.)
|
java.lang.String |
toString() |
java.lang.String |
toString(int from,
int to) |
public static final int ATTRIBUTE_BACKGROUND
public static final int ATTRIBUTE_FOREGROUND
public static final int ATTRIBUTE_FONT
public static final int ATTRIBUTE_UNDERLINE
public static final int ATTRIBUTE_ALL
public static final int TYPE_STRIKETHRU
public static final int TYPE_UNDERLINE
public static final int TYPE_SEPARATOR
public static final int TYPE_ALL
public HighlightFragmentsList()
HighlightFragmentsList
with an initial
size of the default.public void setHighlightRegistry(HighlightRegistry registry)
HighlightRegistry
used by this list when
building up its list of highlight fragments.public void addSentinel(HighlightStyle highlightStyle)
highlightStyle
- the highlight stylepublic HighlightStyle getSentinelBackground()
public HighlightStyle getSentinelUnderline()
public void compact()
public void add(HighlightStyle highlightStyle, int startOffset, int endOffset)
highlightStyle
- the highlight stylestartOffset
- the starting offset of the highlightendOffset
- the ending offset of the highlightpublic java.lang.String toString()
toString
in class java.lang.Object
public java.lang.String toString(int from, int to)
public void clear()
public int size()
public HighlightFragment get(int index)
index
- the index of the fragment to retrievepublic void clearAllFilters()
public void clearAttributeFilter()
public void setAttributeFilter(int attributeFilter)
public void setAttributeTextOnly()
public void setAttributeFontOnly()
public void setAttributeUnderlineOnly()
public void clearUnderlineTypeFilter()
public void setUnderlineTypeFilter(int underlineTypeFilter)