Method from javax.swing.text.TextLayoutStrategy$AttributedSegment Detail: |
public Set<Attribute> getAllAttributeKeys() {
return keys;
}
Returns the keys of all attributes defined on the
iterator's text range. The set is empty if no
attributes are defined. |
public Object getAttribute(Attribute attribute) {
int pos = toModelPosition(getIndex());
int childIndex = v.getViewIndex(pos, Position.Bias.Forward);
if (attribute == TextAttribute.FONT) {
return getFont(childIndex);
} else if( attribute == TextAttribute.RUN_DIRECTION ) {
return
v.getDocument().getProperty(TextAttribute.RUN_DIRECTION);
} else if (attribute == TextAttribute.NUMERIC_SHAPING) {
return shaper;
}
return null;
}
Returns the value of the named attribute for the current character.
Returns null if the attribute is not defined. |
public Map<Attribute, Object> getAttributes() {
Object[] ka = keys.toArray();
Hashtable< Attribute, Object > h = new Hashtable< Attribute, Object >();
for (int i = 0; i < ka.length; i++) {
TextAttribute a = (TextAttribute) ka[i];
Object value = getAttribute(a);
if (value != null) {
h.put(a, value);
}
}
return h;
}
Returns a map with the attributes defined on the current
character. |
Font getFont(int childIndex) {
View child = v.getView(childIndex);
if (child instanceof GlyphView) {
return ((GlyphView)child).getFont();
}
return null;
}
Get the font at the given child index. |
int getFontBoundary(int childIndex,
int dir) {
View child = v.getView(childIndex);
Font f = getFont(childIndex);
for (childIndex += dir; (childIndex >= 0) && (childIndex < v.getViewCount());
childIndex += dir) {
Font next = getFont(childIndex);
if (next != f) {
// this run is different
break;
}
child = v.getView(childIndex);
}
return (dir < 0) ? child.getStartOffset() : child.getEndOffset();
}
Get a boundary position for the font.
This is implemented to assume that two fonts are
equal if their references are equal (i.e. that the
font came from a cache). |
public int getRunLimit() {
int pos = toModelPosition(getIndex());
int i = v.getViewIndex(pos, Position.Bias.Forward);
View child = v.getView(i);
return toIteratorIndex(child.getEndOffset());
}
Returns the index of the first character following the run
with respect to all attributes containing the current character. |
public int getRunLimit(Attribute attribute) {
if (attribute instanceof TextAttribute) {
int pos = toModelPosition(getIndex());
int i = v.getViewIndex(pos, Position.Bias.Forward);
if (attribute == TextAttribute.FONT) {
return toIteratorIndex(getFontBoundary(i, 1));
}
}
return getEndIndex();
}
Returns the index of the first character following the run
with respect to the given attribute containing the current character. |
public int getRunLimit(Set<? extends Attribute> attributes) {
int index = getEndIndex();
Object[] a = attributes.toArray();
for (int i = 0; i < a.length; i++) {
TextAttribute attr = (TextAttribute) a[i];
index = Math.min(getRunLimit(attr), index);
}
return Math.max(getIndex(), index);
}
Returns the index of the first character following the run
with respect to the given attributes containing the current character. |
public int getRunStart() {
int pos = toModelPosition(getIndex());
int i = v.getViewIndex(pos, Position.Bias.Forward);
View child = v.getView(i);
return toIteratorIndex(child.getStartOffset());
}
Returns the index of the first character of the run
with respect to all attributes containing the current character. |
public int getRunStart(Attribute attribute) {
if (attribute instanceof TextAttribute) {
int pos = toModelPosition(getIndex());
int i = v.getViewIndex(pos, Position.Bias.Forward);
if (attribute == TextAttribute.FONT) {
return toIteratorIndex(getFontBoundary(i, -1));
}
}
return getBeginIndex();
}
Returns the index of the first character of the run
with respect to the given attribute containing the current character. |
public int getRunStart(Set<? extends Attribute> attributes) {
int index = getBeginIndex();
Object[] a = attributes.toArray();
for (int i = 0; i < a.length; i++) {
TextAttribute attr = (TextAttribute) a[i];
index = Math.max(getRunStart(attr), index);
}
return Math.min(getIndex(), index);
}
Returns the index of the first character of the run
with respect to the given attributes containing the current character. |
View getView() {
return v;
}
|
void setView(View v) {
this.v = v;
Document doc = v.getDocument();
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
try {
doc.getText(p0, p1 - p0, this);
} catch (BadLocationException bl) {
throw new IllegalArgumentException("Invalid view");
}
first();
}
|
int toIteratorIndex(int pos) {
return pos - v.getStartOffset() + getBeginIndex();
}
|
int toModelPosition(int index) {
return v.getStartOffset() + (index - getBeginIndex());
}
|