APIdia Launch Partner
Top Description Fields Constructors Methods
java.awt.font

pack-priv final Class StyledParagraph

extends Object
Class Inheritance
Imports
java.awt.Font, .Toolkit, java.awt.im.InputMethodHighlight, java.text.Annotation, .AttributedCharacterIterator, .AttributedCharacterIterator.Attribute, java.util.Vector, .HashMap, .Map, sun.font.CodePointIterator, .Decoration, .FontResolver

This class stores Font, GraphicAttribute, and Decoration intervals on a paragraph of styled text.

Currently, this class is optimized for a small number of intervals (preferably 1).

Field Summary

Modifier and TypeField and Description
private Decoration
private Vector<Decoration>
pack-priv int[]
private Object
private Vector<Object>
pack-priv int[]
private static int
private int

Constructor Summary

AccessConstructor and Description
public
StyledParagraph(AttributedCharacterIterator
an iterator over the text
aci
,
char[]
the characters extracted from aci
chars
)

Create a new StyledParagraph over the given styled text.

Method Summary

Modifier and TypeMethod and Description
private void
addDecoration(Decoration d, int index)

Add a new Decoration run with the given Decoration at the given index.

private void
addFont(Object f, int index)

Add a new Font/GraphicAttribute run with the given object at the given index.

private void
addFonts(char[] chars, Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, int start, int limit)

Resolve the given chars into Fonts using FontResolver, then add font runs for each.

pack-priv static Map<? extends AttributedCharacterIterator.Attribute, ?>
addInputMethodAttrs(Map<? extends AttributedCharacterIterator.Attribute, ?> oldStyles)

Return a Map with entries from oldStyles, as well as input method entries, if any.

private static int[]
addToVector(Object obj, int index, Vector<E> v, int[] starts)

Append the given Object to the given Vector.

public static StyledParagraph
deleteChar(AttributedCharacterIterator
an iterator over the text. The text should be the same as the text used to create (or most recently update) oldParagraph, with the exception of deleting a single character at deletePos.
aci
,
char[]
the characters in aci
chars
,
int
the index where a character was removed
deletePos
,
StyledParagraph
a StyledParagraph for the text in aci before the insertion
oldParagraph
)

Return a StyledParagraph reflecting the insertion of a single character into the text.

private static void
deleteFrom(int deleteAt, int[] starts, int numStarts)

Adjust indices in starts to reflect a deletion after deleteAt.

private static int
findRunContaining(int index, int[] starts)

Return i such that starts[i] <= index < starts[i+1].

public Decoration

Returns:

the Decoration at index.
getDecorationAt
(int
a valid index in the paragraph
index
)

Return the Decoration in effect at the given index.

public Object

Returns:

the Font or GraphicAttribute at index.
getFontOrGraphicAt
(int
a valid index in the paragraph
index
)

Return the Font or GraphicAttribute in effect at the given index.

private static Object
getGraphicOrFont(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)

Extract a GraphicAttribute or Font from the given attributes.

public int

Returns:

the first index where there is a change in attributes from those at index
getRunLimit
(int
a valid index in the paragraph
index
)

Return the index at which there is a different Font, GraphicAttribute, or Decoration than at the given index.

public static StyledParagraph
insertChar(AttributedCharacterIterator
an iterator over the text. The text should be the same as the text used to create (or most recently update) oldParagraph, with the exception of inserting a single character at insertPos.
aci
,
char[]
the characters in aci
chars
,
int
the index of the new character in aci
insertPos
,
StyledParagraph
a StyledParagraph for the text in aci before the insertion
oldParagraph
)

Return a StyledParagraph reflecting the insertion of a single character into the text.

private static void
insertInto(int pos, int[] starts, int numStarts)

Adjust indices in starts to reflect an insertion after pos.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

decorationback to summary
private Decoration decoration
decorationsback to summary
private Vector<Decoration> decorations
decorationStartsback to summary
pack-priv int[] decorationStarts
fontback to summary
private Object font
fontsback to summary
private Vector<Object> fonts
fontStartsback to summary
pack-priv int[] fontStarts
INITIAL_SIZEback to summary
private static int INITIAL_SIZE
lengthback to summary
private int length

Constructor Detail

StyledParagraphback to summary
public StyledParagraph(AttributedCharacterIterator aci, char[] chars)

Create a new StyledParagraph over the given styled text.

Parameters
aci:AttributedCharacterIterator

an iterator over the text

chars:char[]

the characters extracted from aci

Method Detail

addDecorationback to summary
private void addDecoration(Decoration d, int index)

Add a new Decoration run with the given Decoration at the given index.

addFontback to summary
private void addFont(Object f, int index)

Add a new Font/GraphicAttribute run with the given object at the given index.

addFontsback to summary
private void addFonts(char[] chars, Map<? extends AttributedCharacterIterator.Attribute, ?> attributes, int start, int limit)

Resolve the given chars into Fonts using FontResolver, then add font runs for each.

addInputMethodAttrsback to summary
pack-priv static Map<? extends AttributedCharacterIterator.Attribute, ?> addInputMethodAttrs(Map<? extends AttributedCharacterIterator.Attribute, ?> oldStyles)

Return a Map with entries from oldStyles, as well as input method entries, if any.

addToVectorback to summary
private static int[] addToVector(Object obj, int index, Vector<E> v, int[] starts)

Append the given Object to the given Vector. Add the given index to the given starts array. If the starts array does not have room for the index, a new array is created and returned.

Annotations
@SuppressWarnings:rawtypes, unchecked
deleteCharback to summary
public static StyledParagraph deleteChar(AttributedCharacterIterator aci, char[] chars, int deletePos, StyledParagraph oldParagraph)

Return a StyledParagraph reflecting the insertion of a single character into the text. This method will attempt to reuse the given paragraph, but may create a new paragraph.

Parameters
aci:AttributedCharacterIterator

an iterator over the text. The text should be the same as the text used to create (or most recently update) oldParagraph, with the exception of deleting a single character at deletePos.

chars:char[]

the characters in aci

deletePos:int

the index where a character was removed

oldParagraph:StyledParagraph

a StyledParagraph for the text in aci before the insertion

deleteFromback to summary
private static void deleteFrom(int deleteAt, int[] starts, int numStarts)

Adjust indices in starts to reflect a deletion after deleteAt. Any index in starts greater than deleteAt will be increased by 1. It is the caller's responsibility to make sure that no 0-length runs result.

findRunContainingback to summary
private static int findRunContaining(int index, int[] starts)

Return i such that starts[i] <= index < starts[i+1]. starts must be in increasing order, with at least one element greater than index.

getDecorationAtback to summary
public Decoration getDecorationAt(int index)

Return the Decoration in effect at the given index.

Parameters
index:int

a valid index in the paragraph

Returns:Decoration

the Decoration at index.

getFontOrGraphicAtback to summary
public Object getFontOrGraphicAt(int index)

Return the Font or GraphicAttribute in effect at the given index. The client must test the type of the return value to determine what it is.

Parameters
index:int

a valid index in the paragraph

Returns:Object

the Font or GraphicAttribute at index.

getGraphicOrFontback to summary
private static Object getGraphicOrFont(Map<? extends AttributedCharacterIterator.Attribute, ?> attributes)

Extract a GraphicAttribute or Font from the given attributes. If attributes does not contain a GraphicAttribute, Font, or Font family entry this method returns null.

getRunLimitback to summary
public int getRunLimit(int index)

Return the index at which there is a different Font, GraphicAttribute, or Decoration than at the given index.

Parameters
index:int

a valid index in the paragraph

Returns:int

the first index where there is a change in attributes from those at index

insertCharback to summary
public static StyledParagraph insertChar(AttributedCharacterIterator aci, char[] chars, int insertPos, StyledParagraph oldParagraph)

Return a StyledParagraph reflecting the insertion of a single character into the text. This method will attempt to reuse the given paragraph, but may create a new paragraph.

Parameters
aci:AttributedCharacterIterator

an iterator over the text. The text should be the same as the text used to create (or most recently update) oldParagraph, with the exception of inserting a single character at insertPos.

chars:char[]

the characters in aci

insertPos:int

the index of the new character in aci

oldParagraph:StyledParagraph

a StyledParagraph for the text in aci before the insertion

insertIntoback to summary
private static void insertInto(int pos, int[] starts, int numStarts)

Adjust indices in starts to reflect an insertion after pos. Any index in starts greater than pos will be increased by 1.