Methods Summary |
---|
public javax.swing.text.View | breakView(int axis, int offset, float pos, float len)Tries to break this view on the given axis. Refer to
{@link javax.swing.text.View#breakView} for a complete
description of this method.
Behavior of this method is unspecified in case axis
is neither View.X_AXIS nor View.Y_AXIS , and
in case offset , pos , or len
is null.
InlineView view = (InlineView)super.breakView(axis, offset, pos, len);
if (view != this) {
view.longestWordSpan = -1;
}
return view;
|
float | calculateLongestWordSpan()
float rv = 0f;
Document doc = getDocument();
//AbstractDocument.MultiByteProperty
final Object MultiByteProperty = "multiByte";
if (doc != null &&
Boolean.TRUE.equals(doc.getProperty(MultiByteProperty))) {
rv = calculateLongestWordSpanUseBreakIterator();
} else {
rv = calculateLongestWordSpanUseWhitespace();
}
return rv;
|
float | calculateLongestWordSpanUseBreakIterator()
float span = 0;
Document doc = getDocument();
int p0 = getStartOffset();
int p1 = getEndOffset();
if (p1 > p0) {
try {
FontMetrics metrics = getFontMetrics();
Segment segment = new Segment();
doc.getText(p0, p1 - p0, segment);
Container c = getContainer();
BreakIterator line;
if (c != null) {
line = BreakIterator.getLineInstance(c.getLocale());
} else {
line = BreakIterator.getLineInstance();
}
line.setText(segment);
int start = line.first();
for (int end = line.next();
end != BreakIterator.DONE;
start = end, end = line.next()) {
if (end > start) {
span = Math.max(span,
metrics.charsWidth(segment.array, start,
end - start));
}
}
} catch (BadLocationException ble) {
// If the text can't be retrieved, it can't influence the size.
}
}
return span;
|
float | calculateLongestWordSpanUseWhitespace()
float span = 0;
Document doc = getDocument();
int p0 = getStartOffset();
int p1 = getEndOffset();
if (p1 > p0) {
try {
Segment segment = new Segment();
doc.getText(p0, p1 - p0, segment);
final int CONTENT = 0;
final int SPACES = 1;
int state = CONTENT;
int start = segment.offset;
int end = start;
FontMetrics metrics = getFontMetrics();
final int lastIndex = segment.offset + segment.count - 1;
for (int i = segment.offset; i <= lastIndex; i++) {
boolean updateSpan = false;
if (Character.isWhitespace(segment.array[i])) {
if (state == CONTENT) {
//we got a word
updateSpan = true;
state = SPACES;
}
} else {
if (state == SPACES) {
//first non space
start = i;
end = start;
state = CONTENT;
} else {
end = i;
}
//handle last word
if (i == lastIndex) {
updateSpan = true;
}
}
if (updateSpan) {
if (end > start) {
span = Math.max(span,
metrics.charsWidth(segment.array, start,
end - start + 1));
}
}
}
} catch (BadLocationException ble) {
// If the text can't be retrieved, it can't influence the size.
}
}
return span;
|
public void | changedUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)Gives notification from the document that attributes were changed
in a location that this view is responsible for.
super.changedUpdate(e, a, f);
StyleSheet sheet = getStyleSheet();
attr = sheet.getViewAttributes(this);
longestWordSpan = -1.0f;
preferenceChanged(null, true, true);
|
public javax.swing.text.AttributeSet | getAttributes()Fetches the attributes to use when rendering. This is
implemented to multiplex the attributes specified in the
model with a StyleSheet.
return attr;
|
public int | getBreakWeight(int axis, float pos, float len)Determines how attractive a break opportunity in
this view is. This can be used for determining which
view is the most attractive to call breakView
on in the process of formatting. A view that represents
text that has whitespace in it might be more attractive
than a view that has no whitespace, for example. The
higher the weight, the more attractive the break. A
value equal to or lower than BadBreakWeight
should not be considered for a break. A value greater
than or equal to ForcedBreakWeight should
be broken.
This is implemented to provide the default behavior
of returning BadBreakWeight unless the length
is greater than the length of the view in which case the
entire view represents the fragment. Unless a view has
been written to support breaking behavior, it is not
attractive to try and break the view. An example of
a view that does support breaking is LabelView .
An example of a view that uses break weight is
ParagraphView .
if (nowrap) {
return BadBreakWeight;
}
return super.getBreakWeight(axis, pos, len);
|
float | getLongestWordSpan()Fetch the span of the longest word in the view.
if (longestWordSpan < 0.0f) {
longestWordSpan = calculateLongestWordSpan();
}
return longestWordSpan;
|
protected javax.swing.text.html.StyleSheet | getStyleSheet()
HTMLDocument doc = (HTMLDocument) getDocument();
return doc.getStyleSheet();
|
public void | insertUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)Gives notification that something was inserted into
the document in a location that this view is responsible for.
If either parameter is null , behavior of this method is
implementation dependent.
super.insertUpdate(e, a, f);
longestWordSpan = -1.0f;
|
public void | removeUpdate(javax.swing.event.DocumentEvent e, java.awt.Shape a, javax.swing.text.ViewFactory f)Gives notification that something was removed from the document
in a location that this view is responsible for.
If either parameter is null , behavior of this method is
implementation dependent.
super.removeUpdate(e, a, f);
longestWordSpan = -1.0f;
|
protected void | setPropertiesFromAttributes()Set the cached properties from the attributes.
super.setPropertiesFromAttributes();
AttributeSet a = getAttributes();
Object decor = a.getAttribute(CSS.Attribute.TEXT_DECORATION);
boolean u = (decor != null) ?
(decor.toString().indexOf("underline") >= 0) : false;
setUnderline(u);
boolean s = (decor != null) ?
(decor.toString().indexOf("line-through") >= 0) : false;
setStrikeThrough(s);
Object vAlign = a.getAttribute(CSS.Attribute.VERTICAL_ALIGN);
s = (vAlign != null) ? (vAlign.toString().indexOf("sup") >= 0) : false;
setSuperscript(s);
s = (vAlign != null) ? (vAlign.toString().indexOf("sub") >= 0) : false;
setSubscript(s);
Object whitespace = a.getAttribute(CSS.Attribute.WHITE_SPACE);
if ((whitespace != null) && whitespace.equals("nowrap")) {
nowrap = true;
} else {
nowrap = false;
}
HTMLDocument doc = (HTMLDocument)getDocument();
// fetches background color from stylesheet if specified
Color bg = doc.getBackground(a);
if (bg != null) {
setBackground(bg);
}
|