use of java.awt.font.TextAttribute in project opennars by opennars.
the class StyledString method addAttribute.
/**
* Set the attribute to be applied to a range of characters starting at
* beginIdx and ending with endIdx-1.
*
* @param type attribute type
* @param value attribute value
* @param beginIdx the index of the first character (inclusive)
* @param endIdx the index of the last character (exclusive)
*/
public void addAttribute(Attribute type, Object value, int beginIdx, int endIdx) {
value = validateTextAttributeColor((TextAttribute) type, value);
AttributeRun ar = new AttributeRun(type, value, beginIdx, endIdx);
// runs if possible and removing runs that no longer have a visible effect.
if (atrun.size() > 0) {
ListIterator<AttributeRun> iter = atrun.listIterator(atrun.size());
while (iter.hasPrevious()) {
AttributeRun a = iter.previous();
int action = ar.intersectionWith(a);
int intersect = action & I_MODES;
int combiMode = action & COMBI_MODES;
if (combiMode == MERGE_RUNS) {
switch(intersect) {
case I_TL:
case I_CL:
ar.start = a.start;
iter.remove();
break;
case I_TR:
case I_CR:
ar.end = a.end;
iter.remove();
break;
}
} else if (combiMode == CLIP_RUN) {
switch(intersect) {
case I_CL:
a.end = ar.start;
break;
case I_CR:
a.start = ar.end;
break;
}
}
switch(intersect) {
case I_INSIDE:
iter.remove();
break;
case I_COVERED:
ar = null;
break;
}
}
}
// If the run is still effective then add it
if (ar != null)
atrun.addLast(ar);
applyAttributes();
invalidLayout = true;
}
Aggregations