下面列出了怎么用javax.swing.SizeRequirements的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Adjust the given requirements to the CSS width or height if
* it is specified along the applicable axis. Return true if the
* size is exactly specified, false if the span is not specified
* in an attribute or the size specified is a percentage.
*/
static boolean spanSetFromAttributes(int axis, SizeRequirements r,
CSS.LengthValue cssWidth,
CSS.LengthValue cssHeight) {
if (axis == X_AXIS) {
if ((cssWidth != null) && (! cssWidth.isPercentage())) {
r.minimum = r.preferred = r.maximum = (int) cssWidth.getValue();
return true;
}
} else {
if ((cssHeight != null) && (! cssHeight.isPercentage())) {
r.minimum = r.preferred = r.maximum = (int) cssHeight.getValue();
return true;
}
}
return false;
}
/**
* Calculate the needs for the paragraph along the minor axis.
*
* <p>This uses size requirements of the superclass, modified to take into
* account the non-breakable areas at the adjacent views edges. The minimal
* size requirements for such views should be no less than the sum of all
* adjacent fragments.</p>
*
* <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
* {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown. If the
* {@code r} parameter is {@code null,} a new {@code SizeRequirements}
* object is created, otherwise the supplied {@code SizeRequirements}
* object is returned.</p>
*
* @param axis the minor axis
* @param r the input {@code SizeRequirements} object
* @return the new or adjusted {@code SizeRequirements} object
* @throws IllegalArgumentException if the {@code axis} parameter is invalid
*/
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min = 0;
float glue = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
float span = v.getMinimumSpan(axis);
if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis)) > View.BadBreakWeight) {
// find the longest non-breakable fragments at the view edges
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
float start = findEdgeSpan(v, axis, p0, p0, p1);
float end = findEdgeSpan(v, axis, p1, p0, p1);
glue += start;
min = Math.max(min, Math.max(span, glue));
glue = end;
} else {
// non-breakable view
glue += span;
min = Math.max(min, glue);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
return r;
}
@Override
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements r) {
int oldJustficationData[] = justificationData;
justificationData = null;
SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
if (isJustifyEnabled()) {
justificationData = oldJustficationData;
}
return ret;
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}
/**
* Constrains <code>want</code> to fit in the minimum size specified
* by <code>min</code>.
*/
private void constrainSize(int axis, SizeRequirements want,
SizeRequirements min) {
if (min.minimum > want.minimum) {
want.minimum = want.preferred = min.minimum;
want.maximum = Math.max(want.maximum, min.maximum);
}
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements req = new SizeRequirements();
req.minimum = totalColumnRequirements.minimum;
req.maximum = totalColumnRequirements.maximum;
req.preferred = totalColumnRequirements.preferred;
req.alignment = 0f;
return req;
}
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements rv = super.calculateMinorAxisRequirements(axis, r);
//for the cell the minimum should be derived from the child views
//the parent behaviour is to use CSS for that
int n = getViewCount();
int min = 0;
for (int i = 0; i < n; i++) {
View v = getView(i);
min = Math.max((int) v.getMinimumSpan(axis), min);
}
rv.minimum = Math.min(rv.minimum, min);
return rv;
}
/**
* Calculate the needs for the paragraph along the minor axis.
*
* <p>This uses size requirements of the superclass, modified to take into
* account the non-breakable areas at the adjacent views edges. The minimal
* size requirements for such views should be no less than the sum of all
* adjacent fragments.</p>
*
* <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
* {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown. If the
* {@code r} parameter is {@code null,} a new {@code SizeRequirements}
* object is created, otherwise the supplied {@code SizeRequirements}
* object is returned.</p>
*
* @param axis the minor axis
* @param r the input {@code SizeRequirements} object
* @return the new or adjusted {@code SizeRequirements} object
* @throws IllegalArgumentException if the {@code axis} parameter is invalid
*/
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min = 0;
float glue = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
float span = v.getMinimumSpan(axis);
if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis)) > View.BadBreakWeight) {
// find the longest non-breakable fragments at the view edges
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
float start = findEdgeSpan(v, axis, p0, p0, p1);
float end = findEdgeSpan(v, axis, p1, p0, p1);
glue += start;
min = Math.max(min, Math.max(span, glue));
glue = end;
} else {
// non-breakable view
glue += span;
min = Math.max(min, glue);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
return r;
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements req = new SizeRequirements();
req.minimum = totalColumnRequirements.minimum;
req.maximum = totalColumnRequirements.maximum;
req.preferred = totalColumnRequirements.preferred;
req.alignment = 0f;
return req;
}
/**
* Constrains <code>want</code> to fit in the minimum size specified
* by <code>min</code>.
*/
private void constrainSize(int axis, SizeRequirements want,
SizeRequirements min) {
if (min.minimum > want.minimum) {
want.minimum = want.preferred = min.minimum;
want.maximum = Math.max(want.maximum, min.maximum);
}
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}
/**
* Calculate the needs for the paragraph along the minor axis.
*
* <p>This uses size requirements of the superclass, modified to take into
* account the non-breakable areas at the adjacent views edges. The minimal
* size requirements for such views should be no less than the sum of all
* adjacent fragments.</p>
*
* <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
* {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown. If the
* {@code r} parameter is {@code null,} a new {@code SizeRequirements}
* object is created, otherwise the supplied {@code SizeRequirements}
* object is returned.</p>
*
* @param axis the minor axis
* @param r the input {@code SizeRequirements} object
* @return the new or adjusted {@code SizeRequirements} object
* @throws IllegalArgumentException if the {@code axis} parameter is invalid
*/
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min = 0;
float glue = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
float span = v.getMinimumSpan(axis);
if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis)) > View.BadBreakWeight) {
// find the longest non-breakable fragments at the view edges
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
float start = findEdgeSpan(v, axis, p0, p0, p1);
float end = findEdgeSpan(v, axis, p1, p0, p1);
glue += start;
min = Math.max(min, Math.max(span, glue));
glue = end;
} else {
// non-breakable view
glue += span;
min = Math.max(min, glue);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
return r;
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements req = new SizeRequirements();
req.minimum = totalColumnRequirements.minimum;
req.maximum = totalColumnRequirements.maximum;
req.preferred = totalColumnRequirements.preferred;
req.alignment = 0f;
return req;
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
@Override
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements req = new SizeRequirements();
req.minimum = totalColumnRequirements.minimum;
req.maximum = totalColumnRequirements.maximum;
req.preferred = totalColumnRequirements.preferred;
req.alignment = 0f;
return req;
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}
/**
* Constrains <code>want</code> to fit in the minimum size specified
* by <code>min</code>.
*/
private void constrainSize(int axis, SizeRequirements want,
SizeRequirements min) {
if (min.minimum > want.minimum) {
want.minimum = want.preferred = min.minimum;
want.maximum = Math.max(want.maximum, min.maximum);
}
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
SizeRequirements req = new SizeRequirements();
req.minimum = totalColumnRequirements.minimum;
req.maximum = totalColumnRequirements.maximum;
req.preferred = totalColumnRequirements.preferred;
req.alignment = 0f;
return req;
}
/**
* Calculate the needs for the paragraph along the minor axis.
*
* <p>This uses size requirements of the superclass, modified to take into
* account the non-breakable areas at the adjacent views edges. The minimal
* size requirements for such views should be no less than the sum of all
* adjacent fragments.</p>
*
* <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
* {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown. If the
* {@code r} parameter is {@code null,} a new {@code SizeRequirements}
* object is created, otherwise the supplied {@code SizeRequirements}
* object is returned.</p>
*
* @param axis the minor axis
* @param r the input {@code SizeRequirements} object
* @return the new or adjusted {@code SizeRequirements} object
* @throws IllegalArgumentException if the {@code axis} parameter is invalid
*/
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min = 0;
float glue = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
float span = v.getMinimumSpan(axis);
if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis)) > View.BadBreakWeight) {
// find the longest non-breakable fragments at the view edges
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
float start = findEdgeSpan(v, axis, p0, p0, p1);
float end = findEdgeSpan(v, axis, p1, p0, p1);
glue += start;
min = Math.max(min, Math.max(span, glue));
glue = end;
} else {
// non-breakable view
glue += span;
min = Math.max(min, glue);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
return r;
}
@Override
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements r) {
int oldJustficationData[] = justificationData;
justificationData = null;
SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
if (isJustifyEnabled()) {
justificationData = oldJustficationData;
}
return ret;
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}
@Override
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements r) {
int oldJustficationData[] = justificationData;
justificationData = null;
SizeRequirements ret = super.calculateMajorAxisRequirements(axis, r);
if (isJustifyEnabled()) {
justificationData = oldJustficationData;
}
return ret;
}
/**
* Constructs a TableView for the given element.
*
* @param elem the element that this view is responsible for
*/
public TableView(Element elem) {
super(elem, View.Y_AXIS);
rows = new Vector<RowView>();
gridValid = false;
captionIndex = -1;
totalColumnRequirements = new SizeRequirements();
}
/**
* Calculate the needs for the paragraph along the minor axis.
*
* <p>This uses size requirements of the superclass, modified to take into
* account the non-breakable areas at the adjacent views edges. The minimal
* size requirements for such views should be no less than the sum of all
* adjacent fragments.</p>
*
* <p>If the {@code axis} parameter is neither {@code View.X_AXIS} nor
* {@code View.Y_AXIS}, {@link IllegalArgumentException} is thrown. If the
* {@code r} parameter is {@code null,} a new {@code SizeRequirements}
* object is created, otherwise the supplied {@code SizeRequirements}
* object is returned.</p>
*
* @param axis the minor axis
* @param r the input {@code SizeRequirements} object
* @return the new or adjusted {@code SizeRequirements} object
* @throws IllegalArgumentException if the {@code axis} parameter is invalid
*/
@Override
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements r) {
r = super.calculateMinorAxisRequirements(axis, r);
float min = 0;
float glue = 0;
int n = getLayoutViewCount();
for (int i = 0; i < n; i++) {
View v = getLayoutView(i);
float span = v.getMinimumSpan(axis);
if (v.getBreakWeight(axis, 0, v.getMaximumSpan(axis)) > View.BadBreakWeight) {
// find the longest non-breakable fragments at the view edges
int p0 = v.getStartOffset();
int p1 = v.getEndOffset();
float start = findEdgeSpan(v, axis, p0, p0, p1);
float end = findEdgeSpan(v, axis, p1, p0, p1);
glue += start;
min = Math.max(min, Math.max(span, glue));
glue = end;
} else {
// non-breakable view
glue += span;
min = Math.max(min, glue);
}
}
r.minimum = Math.max(r.minimum, (int) min);
r.preferred = Math.max(r.minimum, r.preferred);
r.maximum = Math.max(r.preferred, r.maximum);
return r;
}
/**
* check the requirements of a table cell that spans a single column.
*/
void checkSingleColumnCell(int axis, int col, View v) {
SizeRequirements req = columnRequirements[col];
req.minimum = Math.max((int) v.getMinimumSpan(axis), req.minimum);
req.preferred = Math.max((int) v.getPreferredSpan(axis), req.preferred);
req.maximum = Math.max((int) v.getMaximumSpan(axis), req.maximum);
}