| Method from javax.swing.text.ParagraphView$Row Detail: |
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements r) {
int oldJustficationData[] = justificationData;
justificationData = null;
SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
if (isJustifyEnabled()) {
justificationData = oldJustficationData;
}
return ret;
}
|
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
return baselineRequirements(axis, r);
}
|
public float getAlignment(int axis) {
if (axis == View.X_AXIS) {
switch (justification) {
case StyleConstants.ALIGN_LEFT:
return 0;
case StyleConstants.ALIGN_RIGHT:
return 1;
case StyleConstants.ALIGN_CENTER:
return 0.5f;
case StyleConstants.ALIGN_JUSTIFIED:
float rv = 0.5f;
//if we can justifiy the content always align to
//the left.
if (isJustifiableDocument()) {
rv = 0f;
}
return rv;
}
}
return super.getAlignment(axis);
}
|
public AttributeSet getAttributes() {
View p = getParent();
return (p != null) ? p.getAttributes() : null;
}
Fetches the attributes to use when rendering. This view
isn't directly responsible for an element so it returns
the outer classes attributes. |
protected short getBottomInset() {
return (short)(super.getBottomInset() +
((minorRequest != null) ? minorRequest.preferred : 0) *
lineSpacing);
}
|
public int getEndOffset() {
int offs = 0;
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
offs = Math.max(offs, v.getEndOffset());
}
return offs;
}
|
protected short getLeftInset() {
View parentView;
int adjustment = 0;
if ((parentView = getParent()) != null) { //use firstLineIdent for the first row
if (this == parentView.getView(0)) {
adjustment = firstLineIndent;
}
}
return (short)(super.getLeftInset() + adjustment);
}
|
public float getMaximumSpan(int axis) {
float ret;
if (View.X_AXIS == axis
&& isJustifyEnabled()) {
ret = Float.MAX_VALUE;
} else {
ret = super.getMaximumSpan(axis);
}
return ret;
}
|
public int getStartOffset() {
int offs = Integer.MAX_VALUE;
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
offs = Math.min(offs, v.getStartOffset());
}
return offs;
}
Range represented by a row in the paragraph is only
a subset of the total range of the paragraph element. |
protected int getViewIndexAtPosition(int pos) {
// This is expensive, but are views are not necessarily layed
// out in model order.
if(pos < getStartOffset() || pos >= getEndOffset())
return -1;
for(int counter = getViewCount() - 1; counter >= 0; counter--) {
View v = getView(counter);
if(pos >= v.getStartOffset() &&
pos < v.getEndOffset()) {
return counter;
}
}
return -1;
}
Fetches the child view index representing the given position in
the model. |
protected void layoutMajorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans) {
int oldJustficationData[] = justificationData;
justificationData = null;
super.layoutMajorAxis(targetSpan, axis, offsets, spans);
if (! isJustifyEnabled()) {
return;
}
int currentSpan = 0;
for (int span : spans) {
currentSpan += span;
}
if (currentSpan == targetSpan) {
//no need to justify
return;
}
// we justify text by enlarging spaces by the {@code spaceAddon}.
// justification is started to the right of the rightmost TAB.
// leading and trailing spaces are not extendable.
//
// GlyphPainter1 uses
// justificationData
// for all painting and measurement.
int extendableSpaces = 0;
int startJustifiableContent = -1;
int endJustifiableContent = -1;
int lastLeadingSpaces = 0;
int rowStartOffset = getStartOffset();
int rowEndOffset = getEndOffset();
int spaceMap[] = new int[rowEndOffset - rowStartOffset];
Arrays.fill(spaceMap, 0);
for (int i = getViewCount() - 1; i >= 0 ; i--) {
View view = getView(i);
if (view instanceof GlyphView) {
GlyphView.JustificationInfo justificationInfo =
((GlyphView) view).getJustificationInfo(rowStartOffset);
final int viewStartOffset = view.getStartOffset();
final int offset = viewStartOffset - rowStartOffset;
for (int j = 0; j < justificationInfo.spaceMap.length(); j++) {
if (justificationInfo.spaceMap.get(j)) {
spaceMap[j + offset] = 1;
}
}
if (startJustifiableContent > 0) {
if (justificationInfo.end >= 0) {
extendableSpaces += justificationInfo.trailingSpaces;
} else {
lastLeadingSpaces += justificationInfo.trailingSpaces;
}
}
if (justificationInfo.start >= 0) {
startJustifiableContent =
justificationInfo.start + viewStartOffset;
extendableSpaces += lastLeadingSpaces;
}
if (justificationInfo.end >= 0
&& endJustifiableContent < 0) {
endJustifiableContent =
justificationInfo.end + viewStartOffset;
}
extendableSpaces += justificationInfo.contentSpaces;
lastLeadingSpaces = justificationInfo.leadingSpaces;
if (justificationInfo.hasTab) {
break;
}
}
}
if (extendableSpaces < = 0) {
//there is nothing we can do to justify
return;
}
int adjustment = (targetSpan - currentSpan);
int spaceAddon = (extendableSpaces > 0)
? adjustment / extendableSpaces
: 0;
int spaceAddonLeftoverEnd = -1;
for (int i = startJustifiableContent - rowStartOffset,
leftover = adjustment - spaceAddon * extendableSpaces;
leftover > 0;
leftover -= spaceMap[i],
i++) {
spaceAddonLeftoverEnd = i;
}
if (spaceAddon > 0 || spaceAddonLeftoverEnd >= 0) {
justificationData = (oldJustficationData != null)
? oldJustficationData
: new int[END_JUSTIFIABLE + 1];
justificationData[SPACE_ADDON] = spaceAddon;
justificationData[SPACE_ADDON_LEFTOVER_END] =
spaceAddonLeftoverEnd;
justificationData[START_JUSTIFIABLE] =
startJustifiableContent - rowStartOffset;
justificationData[END_JUSTIFIABLE] =
endJustifiableContent - rowStartOffset;
super.layoutMajorAxis(targetSpan, axis, offsets, spans);
}
}
|
protected void layoutMinorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans) {
baselineLayout(targetSpan, axis, offsets, spans);
}
|
protected void loadChildren(ViewFactory f) {
}
This is reimplemented to do nothing since the
paragraph fills in the row with its needed
children. |
public Shape modelToView(int pos,
Shape a,
Position.Bias b) throws BadLocationException {
Rectangle r = a.getBounds();
View v = getViewAtPosition(pos, r);
if ((v != null) && (!v.getElement().isLeaf())) {
// Don't adjust the height if the view represents a branch.
return super.modelToView(pos, a, b);
}
r = a.getBounds();
int height = r.height;
int y = r.y;
Shape loc = super.modelToView(pos, a, b);
r = loc.getBounds();
r.height = height;
r.y = y;
return r;
}
Provides a mapping from the document model coordinate space
to the coordinate space of the view mapped to it. This is
implemented to let the superclass find the position along
the major axis and the allocation of the row is used
along the minor axis, so that even though the children
are different heights they all get the same caret height. |