java.awt.font
Class StyledParagraph

java.lang.Object
  extended byjava.awt.font.StyledParagraph

final class StyledParagraph
extends Object

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 (preferrably 1).


Field Summary
private  sun.awt.font.Decoration decoration
           
private  Vector decorations
           
(package private)  int[] decorationStarts
           
private  Object font
           
private  Vector fonts
           
(package private)  int[] fontStarts
           
private static int INITIAL_SIZE
           
private  int length
           
 
Constructor Summary
StyledParagraph(AttributedCharacterIterator aci, char[] chars)
          Create a new StyledParagraph over the given styled text.
 
Method Summary
private  void addDecoration(sun.awt.font.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 attributes, int start, int limit)
          Resolve the given chars into Fonts using FontResolver, then add font runs for each.
(package private) static Map addInputMethodAttrs(Map 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 v, int[] starts)
          Append the given Object to the given Vector.
static StyledParagraph deleteChar(AttributedCharacterIterator aci, char[] chars, int deletePos, StyledParagraph 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].
 sun.awt.font.Decoration getDecorationAt(int index)
          Return the Decoration in effect at the given index.
 Object getFontOrGraphicAt(int index)
          Return the Font or GraphicAttribute in effect at the given index.
private static Object getGraphicOrFont(Map attributes)
          Extract a GraphicAttribute or Font from the given attributes.
 int getRunLimit(int index)
          Return the index at which there is a different Font, GraphicAttribute, or Dcoration than at the given index.
static StyledParagraph insertChar(AttributedCharacterIterator aci, char[] chars, int insertPos, StyledParagraph 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

length

private int length

decoration

private sun.awt.font.Decoration decoration

font

private Object font

decorations

private Vector decorations

decorationStarts

int[] decorationStarts

fonts

private Vector fonts

fontStarts

int[] fontStarts

INITIAL_SIZE

private static int INITIAL_SIZE
Constructor Detail

StyledParagraph

public StyledParagraph(AttributedCharacterIterator aci,
                       char[] chars)
Create a new StyledParagraph over the given styled text.

Parameters:
aci - an iterator over the text
chars - the characters extracted from aci
Method Detail

insertInto

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.


insertChar

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 - 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 - the characters in aci
insertPos - the index of the new character in aci
oldParagraph - a StyledParagraph for the text in aci before the insertion

deleteFrom

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.


deleteChar

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 - 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 - the characters in aci
deletePos - the index where a character was removed
oldParagraph - a StyledParagraph for the text in aci before the insertion

getRunLimit

public int getRunLimit(int index)
Return the index at which there is a different Font, GraphicAttribute, or Dcoration than at the given index.

Parameters:
index - a valid index in the paragraph
Returns:
the first index where there is a change in attributes from those at index

getDecorationAt

public sun.awt.font.Decoration getDecorationAt(int index)
Return the Decoration in effect at the given index.

Parameters:
index - a valid index in the paragraph
Returns:
the Decoration at index.

getFontOrGraphicAt

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 - a valid index in the paragraph
Returns:
the Font or GraphicAttribute at index.

findRunContaining

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.


addToVector

private static int[] addToVector(Object obj,
                                 int index,
                                 Vector 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.


addDecoration

private void addDecoration(sun.awt.font.Decoration d,
                           int index)
Add a new Decoration run with the given Decoration at the given index.


addFont

private void addFont(Object f,
                     int index)
Add a new Font/GraphicAttribute run with the given object at the given index.


addFonts

private void addFonts(char[] chars,
                      Map attributes,
                      int start,
                      int limit)
Resolve the given chars into Fonts using FontResolver, then add font runs for each.


addInputMethodAttrs

static Map addInputMethodAttrs(Map oldStyles)
Return a Map with entries from oldStyles, as well as input method entries, if any.


getGraphicOrFont

private static Object getGraphicOrFont(Map 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.