Methods Summary |
---|
protected javax.swing.SizeRequirements | calculateMinorAxisRequirements(int axis, javax.swing.SizeRequirements r)Calculate the needs for the paragraph along the minor axis.
This implemented to use the requirements of the superclass,
modified slightly to set a minimum span allowed. Typical
html rendering doesn't let the view size shrink smaller than
the length of the longest word.
r = super.calculateMinorAxisRequirements(axis, r);
if (!BlockView.spanSetFromAttributes(axis, r, cssWidth, cssHeight)) {
// PENDING(prinz) Need to make this better so it doesn't require
// InlineView and works with font changes within the word.
// find the longest minimum span.
float min = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
if (v instanceof InlineView) {
float wordSpan = ((InlineView) v).getLongestWordSpan();
min = Math.max(wordSpan, min);
} else {
min = Math.max(v.getMinimumSpan(axis), min);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
}
else {
// Offset by the margins so that pref/min/max return the
// right value.
int margin = (axis == X_AXIS) ? getLeftInset() + getRightInset() :
getTopInset() + getBottomInset();
r.minimum -= margin;
r.preferred -= margin;
r.maximum -= margin;
}
return r;
|
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.
if (attr == null) {
StyleSheet sheet = getStyleSheet();
attr = sheet.getViewAttributes(this);
}
return attr;
|
public float | getMaximumSpan(int axis)Determines the maximum span for this view along an
axis. Returns 0 if the view is not visible, otherwise
it calls the superclass method ot get the maximum span.
if (!isVisible()) {
return 0;
}
return super.getMaximumSpan(axis);
|
public float | getMinimumSpan(int axis)Determines the minimum span for this view along an
axis. Returns 0 if the view is not visible, otherwise
it calls the superclass method to get the minimum span.
if (!isVisible()) {
return 0;
}
return super.getMinimumSpan(axis);
|
public float | getPreferredSpan(int axis)Determines the preferred span for this view. Returns
0 if the view is not visible, otherwise it calls the
superclass method to get the preferred span.
axis.
if (!isVisible()) {
return 0;
}
return super.getPreferredSpan(axis);
|
protected javax.swing.text.html.StyleSheet | getStyleSheet()
HTMLDocument doc = (HTMLDocument) getDocument();
return doc.getStyleSheet();
|
public boolean | isVisible()Indicates whether or not this view should be
displayed. If none of the children wish to be
displayed and the only visible child is the
break that ends the paragraph, the paragraph
will not be considered visible. Otherwise,
it will be considered visible and return true.
int n = getLayoutViewCount() - 1;
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
if (v.isVisible()) {
return true;
}
}
if (n > 0) {
View v = getLayoutView(n);
if ((v.getEndOffset() - v.getStartOffset()) == 1) {
return false;
}
}
// If it's the last paragraph and not editable, it shouldn't
// be visible.
if (getStartOffset() == getDocument().getLength()) {
boolean editable = false;
Component c = getContainer();
if (c instanceof JTextComponent) {
editable = ((JTextComponent)c).isEditable();
}
if (!editable) {
return false;
}
}
return true;
|
public void | paint(java.awt.Graphics g, java.awt.Shape a)Renders using the given rendering surface and area on that
surface. This is implemented to delgate to the superclass
after stashing the base coordinate for tab calculations.
if (a == null) {
return;
}
Rectangle r;
if (a instanceof Rectangle) {
r = (Rectangle) a;
} else {
r = a.getBounds();
}
painter.paint(g, r.x, r.y, r.width, r.height, this);
super.paint(g, a);
|
public void | setParent(javax.swing.text.View parent)Establishes the parent view for this view. This is
guaranteed to be called before any other methods if the
parent view is functioning properly.
This is implemented
to forward to the superclass as well as call the
setPropertiesFromAttributes
method to set the paragraph properties from the css
attributes. The call is made at this time to ensure
the ability to resolve upward through the parents
view attributes.
super.setParent(parent);
if (parent != null) {
setPropertiesFromAttributes();
}
|
protected void | setPropertiesFromAttributes()Sets up the paragraph from css attributes instead of
the values found in StyleConstants (i.e. which are used
by the superclass). Since
StyleSheet sheet = getStyleSheet();
attr = sheet.getViewAttributes(this);
painter = sheet.getBoxPainter(attr);
if (attr != null) {
super.setPropertiesFromAttributes();
setInsets((short) painter.getInset(TOP, this),
(short) painter.getInset(LEFT, this),
(short) painter.getInset(BOTTOM, this),
(short) painter.getInset(RIGHT, this));
Object o = attr.getAttribute(CSS.Attribute.TEXT_ALIGN);
if (o != null) {
// set horizontal alignment
String ta = o.toString();
if (ta.equals("left")) {
setJustification(StyleConstants.ALIGN_LEFT);
} else if (ta.equals("center")) {
setJustification(StyleConstants.ALIGN_CENTER);
} else if (ta.equals("right")) {
setJustification(StyleConstants.ALIGN_RIGHT);
} else if (ta.equals("justify")) {
setJustification(StyleConstants.ALIGN_JUSTIFIED);
}
}
// Get the width/height
cssWidth = (CSS.LengthValue)attr.getAttribute(
CSS.Attribute.WIDTH);
cssHeight = (CSS.LengthValue)attr.getAttribute(
CSS.Attribute.HEIGHT);
}
|