/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*
*/
/*
* (C) Copyright IBM Corp. 1999, All rights reserved.
*/
/**
* This class stores Font, GraphicAttribute, and Decoration intervals
* on a paragraph of styled text.
* <p>
* Currently, this class is optimized for a small number of intervals
* (preferrably 1).
*/
final class StyledParagraph {
// the length of the paragraph
private int length;
// If there is a single Decoration for the whole paragraph, it
// is stored here. Otherwise this field is ignored.
// If there is a single Font or GraphicAttribute for the whole
// paragraph, it is stored here. Otherwise this field is ignored.
// If there are multiple Decorations in the paragraph, they are
// stored in this Vector, in order. Otherwise this vector and
// the decorationStarts array are null.
// If there are multiple Decorations in the paragraph,
// decorationStarts[i] contains the index where decoration i
// starts. For convenience, there is an extra entry at the
// end of this array with the length of the paragraph.
int[] decorationStarts;
// If there are multiple Fonts/GraphicAttributes in the paragraph,
// they are
// stored in this Vector, in order. Otherwise this vector and
// the fontStarts array are null.
// If there are multiple Fonts/GraphicAttributes in the paragraph,
// fontStarts[i] contains the index where decoration i
// starts. For convenience, there is an extra entry at the
// end of this array with the length of the paragraph.
int[] fontStarts;
/**
* Create a new StyledParagraph over the given styled text.
* @param aci an iterator over the text
* @param chars the characters extracted from aci
*/
char[] chars) {
do {
addDecoration(d, localIndex);
if (f == null) {
}
else {
addFont(f, localIndex);
}
// Add extra entries to starts arrays with the length
// of the paragraph. 'this' is used as a dummy value
// in the Vector.
if (decorations != null) {
}
}
}
/**
* Adjust indices in starts to reflect an insertion after pos.
* Any index in starts greater than pos will be increased by 1.
*/
}
}
/**
* 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.
* @param 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.
* @param chars the characters in aci
* @param insertPos the index of the new character in aci
* @param oldParagraph a StyledParagraph for the text in aci before the
* insertion
*/
char[] chars,
int insertPos,
// If the styles at insertPos match those at insertPos-1,
// oldParagraph will be reused. Otherwise we create a new
// paragraph.
}
if (f == null) {
}
}
// insert into existing paragraph
}
}
return oldParagraph;
}
/**
* 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.
*/
}
}
/**
* 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.
* @param 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.
* @param chars the characters in aci
* @param deletePos the index where a character was removed
* @param oldParagraph a StyledParagraph for the text in aci before the
* insertion
*/
char[] chars,
int deletePos,
// We will reuse oldParagraph unless there was a length-1 run
// at deletePos. We could do more work and check the individual
// Font and Decoration runs, but we don't right now...
return oldParagraph;
}
}
}
}
}
return oldParagraph;
}
/**
* Return the index at which there is a different Font, GraphicAttribute, or
* Dcoration than at the given index.
* @param index a valid index in the paragraph
* @return the first index where there is a change in attributes from
* those at index
*/
throw new IllegalArgumentException("index out of range");
}
if (decorations != null) {
}
}
}
/**
* Return the Decoration in effect at the given index.
* @param index a valid index in the paragraph
* @return the Decoration at index.
*/
throw new IllegalArgumentException("index out of range");
}
if (decorations == null) {
return decoration;
}
}
/**
* 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.
* @param index a valid index in the paragraph
* @return the Font or GraphicAttribute at index.
*/
throw new IllegalArgumentException("index out of range");
}
return font;
}
}
/**
* Return i such that starts[i] <= index < starts[i+1]. starts
* must be in increasing order, with at least one element greater
* than index.
*/
for (int i=1; true; i++) {
return i-1;
}
}
}
/**
* 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.
*/
int index,
Vector v,
int[] starts) {
v.addElement(obj);
}
}
return starts;
}
/**
* Add a new Decoration run with the given Decoration at the
* given index.
*/
if (decorations != null) {
}
else if (decoration == null) {
decoration = d;
}
else {
if (!decoration.equals(d)) {
decorationStarts = new int[INITIAL_SIZE];
}
}
}
/**
* Add a new Font/GraphicAttribute run with the given object at the
* given index.
*/
}
font = f;
}
else {
fonts.addElement(f);
fontStarts = new int[INITIAL_SIZE];
}
}
}
/**
* Resolve the given chars into Fonts using FontResolver, then add
* font runs for each.
*/
}
}
/**
* Return a Map with entries from oldStyles, as well as input
* method entries, if any.
*/
try {
if (value instanceof Annotation) {
}
try {
} catch (NoSuchMethodError e) {
}
}
return newStyles;
}
}
}
catch(ClassCastException e) {
}
return oldStyles;
}
/**
* 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.
*/
return value;
}
return value;
}
}
else {
return null;
}
}
}