use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class BoxView method calculateMinorAxisRequirements.
/**
* Calculates the size requirements for the minor axis
* <code>axis</code>.
*
* @param axis the axis being studied
* @param r the <code>SizeRequirements</code> object;
* if <code>null</code> one will be created
* @return the newly initialized <code>SizeRequirements</code> object
* @see javax.swing.SizeRequirements
*/
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
int min = 0;
long pref = 0;
int max = Integer.MAX_VALUE;
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
min = Math.max((int) v.getMinimumSpan(axis), min);
pref = Math.max((int) v.getPreferredSpan(axis), pref);
max = Math.max((int) v.getMaximumSpan(axis), max);
}
if (r == null) {
r = new SizeRequirements();
r.alignment = 0.5f;
}
r.preferred = (int) pref;
r.minimum = min;
r.maximum = max;
return r;
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class BoxView method calculateMajorAxisRequirements.
/**
* Calculates the size requirements for the major axis
* <code>axis</code>.
*
* @param axis the axis being studied
* @param r the <code>SizeRequirements</code> object;
* if <code>null</code> one will be created
* @return the newly initialized <code>SizeRequirements</code> object
* @see javax.swing.SizeRequirements
*/
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r) {
// calculate tiled request
float min = 0;
float pref = 0;
float max = 0;
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
min += v.getMinimumSpan(axis);
pref += v.getPreferredSpan(axis);
max += v.getMaximumSpan(axis);
}
if (r == null) {
r = new SizeRequirements();
}
r.alignment = 0.5f;
r.minimum = (int) min;
r.preferred = (int) pref;
r.maximum = (int) max;
return r;
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class BoxView method baselineRequirements.
/**
* Calculates the size requirements for this <code>BoxView</code>
* by examining the size of each child view.
*
* @param axis the axis being studied
* @param r the <code>SizeRequirements</code> object;
* if <code>null</code> one will be created
* @return the newly initialized <code>SizeRequirements</code> object
*/
protected SizeRequirements baselineRequirements(int axis, SizeRequirements r) {
SizeRequirements totalAscent = new SizeRequirements();
SizeRequirements totalDescent = new SizeRequirements();
if (r == null) {
r = new SizeRequirements();
}
r.alignment = 0.5f;
int n = getViewCount();
// descents at minimum, preferred, and maximum sizes
for (int i = 0; i < n; i++) {
View v = getView(i);
float align = v.getAlignment(axis);
float span;
int ascent;
int descent;
// find the maximum of the preferred ascents and descents
span = v.getPreferredSpan(axis);
ascent = (int) (align * span);
descent = (int) (span - ascent);
totalAscent.preferred = Math.max(ascent, totalAscent.preferred);
totalDescent.preferred = Math.max(descent, totalDescent.preferred);
if (v.getResizeWeight(axis) > 0) {
// if the view is resizable then do the same for the minimum and
// maximum ascents and descents
span = v.getMinimumSpan(axis);
ascent = (int) (align * span);
descent = (int) (span - ascent);
totalAscent.minimum = Math.max(ascent, totalAscent.minimum);
totalDescent.minimum = Math.max(descent, totalDescent.minimum);
span = v.getMaximumSpan(axis);
ascent = (int) (align * span);
descent = (int) (span - ascent);
totalAscent.maximum = Math.max(ascent, totalAscent.maximum);
totalDescent.maximum = Math.max(descent, totalDescent.maximum);
} else {
// otherwise use the preferred
totalAscent.minimum = Math.max(ascent, totalAscent.minimum);
totalDescent.minimum = Math.max(descent, totalDescent.minimum);
totalAscent.maximum = Math.max(ascent, totalAscent.maximum);
totalDescent.maximum = Math.max(descent, totalDescent.maximum);
}
}
// we now have an overall preferred, minimum, and maximum ascent and descent
// calculate the preferred span as the sum of the preferred ascent and preferred descent
r.preferred = (int) Math.min((long) totalAscent.preferred + (long) totalDescent.preferred, Integer.MAX_VALUE);
// calculate the preferred alignment as the preferred ascent divided by the preferred span
if (r.preferred > 0) {
r.alignment = (float) totalAscent.preferred / r.preferred;
}
if (r.alignment == 0.0f) {
// if the preferred alignment is 0 then the minimum and maximum spans are simply
// the minimum and maximum descents since there's nothing above the baseline
r.minimum = totalDescent.minimum;
r.maximum = totalDescent.maximum;
} else if (r.alignment == 1.0f) {
// if the preferred alignment is 1 then the minimum and maximum spans are simply
// the minimum and maximum ascents since there's nothing below the baseline
r.minimum = totalAscent.minimum;
r.maximum = totalAscent.maximum;
} else {
// we want to honor the preferred alignment so we calculate two possible minimum
// span values using 1) the minimum ascent and the alignment, and 2) the minimum
// descent and the alignment. We'll choose the larger of these two numbers.
r.minimum = Math.round(Math.max(totalAscent.minimum / r.alignment, totalDescent.minimum / (1.0f - r.alignment)));
// a similar calculation is made for the maximum but we choose the smaller number.
r.maximum = Math.round(Math.min(totalAscent.maximum / r.alignment, totalDescent.maximum / (1.0f - r.alignment)));
}
return r;
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class TableView method updateGrid.
/**
* Fill in the grid locations that are placeholders
* for multi-column, multi-row, and missing grid
* locations.
*/
void updateGrid() {
if (!gridValid) {
// determine which views are table rows and clear out
// grid points marked filled.
rows.removeAllElements();
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
if (v instanceof TableRow) {
rows.addElement((TableRow) v);
TableRow rv = (TableRow) v;
rv.clearFilledColumns();
rv.setRow(i);
}
}
int maxColumns = 0;
int nrows = rows.size();
for (int row = 0; row < nrows; row++) {
TableRow rv = getRow(row);
int col = 0;
for (int cell = 0; cell < rv.getViewCount(); cell++, col++) {
View cv = rv.getView(cell);
// advance to a free column
for (; rv.isFilled(col); col++) ;
int rowSpan = getRowsOccupied(cv);
int colSpan = getColumnsOccupied(cv);
if ((colSpan > 1) || (rowSpan > 1)) {
// fill in the overflow entries for this cell
int rowLimit = row + rowSpan;
int colLimit = col + colSpan;
for (int i = row; i < rowLimit; i++) {
for (int j = col; j < colLimit; j++) {
if (i != row || j != col) {
addFill(i, j);
}
}
}
if (colSpan > 1) {
col += colSpan - 1;
}
}
}
maxColumns = Math.max(maxColumns, col);
}
// setup the column layout/requirements
columnSpans = new int[maxColumns];
columnOffsets = new int[maxColumns];
columnRequirements = new SizeRequirements[maxColumns];
for (int i = 0; i < maxColumns; i++) {
columnRequirements[i] = new SizeRequirements();
}
gridValid = true;
}
}
use of javax.swing.SizeRequirements in project jdk8u_jdk by JetBrains.
the class BlockView method calculateMinorAxisRequirements.
/**
* Calculate the requirements of the block along the minor
* axis (i.e. the axis orthogonal to the axis along with it tiles).
* This is implemented
* to provide the superclass behavior and then adjust it if the
* CSS width or height attribute is specified and applicable to
* the axis.
*/
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) {
if (r == null) {
r = new SizeRequirements();
}
if (!spanSetFromAttributes(axis, r, cssWidth, cssHeight)) {
/*
* The requirements were not directly specified by attributes, so
* compute the aggregate of the requirements of the children. The
* children that have a percentage value specified will be treated
* as completely stretchable since that child is not limited in any
* way.
*/
/*
int min = 0;
long pref = 0;
int max = 0;
int n = getViewCount();
for (int i = 0; i < n; i++) {
View v = getView(i);
min = Math.max((int) v.getMinimumSpan(axis), min);
pref = Math.max((int) v.getPreferredSpan(axis), pref);
if (
max = Math.max((int) v.getMaximumSpan(axis), max);
}
r.preferred = (int) pref;
r.minimum = min;
r.maximum = max;
*/
r = super.calculateMinorAxisRequirements(axis, r);
} else {
// Offset by the margins so that pref/min/max return the
// right value.
SizeRequirements parentR = super.calculateMinorAxisRequirements(axis, null);
int margin = (axis == X_AXIS) ? getLeftInset() + getRightInset() : getTopInset() + getBottomInset();
r.minimum -= margin;
r.preferred -= margin;
r.maximum -= margin;
constrainSize(axis, r, parentR);
}
/*
* Set the alignment based upon the CSS properties if it is
* specified. For X_AXIS this would be text-align, for
* Y_AXIS this would be vertical-align.
*/
if (axis == X_AXIS) {
Object o = getAttributes().getAttribute(CSS.Attribute.TEXT_ALIGN);
if (o != null) {
String align = o.toString();
if (align.equals("center")) {
r.alignment = 0.5f;
} else if (align.equals("right")) {
r.alignment = 1.0f;
} else {
r.alignment = 0.0f;
}
}
}
// Y_AXIS TBD
return r;
}
Aggregations