| Method from javax.swing.SizeRequirements Detail: |
public static int[] adjustSizes(int delta,
SizeRequirements[] children) {
return new int[0];
}
Adjust a specified array of sizes by a given amount. |
public static void calculateAlignedPositions(int allocated,
SizeRequirements total,
SizeRequirements[] children,
int[] offsets,
int[] spans) {
calculateAlignedPositions( allocated, total, children, offsets, spans, true );
}
Creates a bunch of offset/span pairs specifying how to
lay out a set of components with the specified alignments.
The resulting span allocations will overlap, with each one
fitting as well as possible into the given total allocation.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirements of the set of components
(only the alignment field of which is actually used).
You can get the total size requirement by invoking
getAlignedSizeRequirements.
Normal alignment will be done with an alignment value of 0.0f
representing the left/top edge of a component. |
public static void calculateAlignedPositions(int allocated,
SizeRequirements total,
SizeRequirements[] children,
int[] offsets,
int[] spans,
boolean normal) {
float totalAlignment = normal ? total.alignment : 1.0f - total.alignment;
int totalAscent = (int)(allocated * totalAlignment);
int totalDescent = allocated - totalAscent;
for (int i = 0; i < children.length; i++) {
SizeRequirements req = children[i];
float alignment = normal ? req.alignment : 1.0f - req.alignment;
int maxAscent = (int)(req.maximum * alignment);
int maxDescent = req.maximum - maxAscent;
int ascent = Math.min(totalAscent, maxAscent);
int descent = Math.min(totalDescent, maxDescent);
offsets[i] = totalAscent - ascent;
spans[i] = (int) Math.min((long) ascent + (long) descent, Integer.MAX_VALUE);
}
}
Creates a set of offset/span pairs specifying how to
lay out a set of components with the specified alignments.
The resulting span allocations will overlap, with each one
fitting as well as possible into the given total allocation.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirements of the set of components
(only the alignment field of which is actually used)
You can get the total size requirement by invoking
getAlignedSizeRequirements.
This method also requires a flag indicating whether normal or
reverse alignment should be performed. With normal alignment
the value 0.0f represents the left/top edge of the component
to be aligned. With reverse alignment, 0.0f represents the
right/bottom edge. |
public static void calculateTiledPositions(int allocated,
SizeRequirements total,
SizeRequirements[] children,
int[] offsets,
int[] spans) {
calculateTiledPositions(allocated, total, children, offsets, spans, true);
}
Creates a set of offset/span pairs representing how to
lay out a set of components end-to-end.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirement of the set of components.
You can get the total size requirement
by invoking the getTiledSizeRequirements method. The components
will be tiled in the forward direction with offsets increasing from 0. |
public static void calculateTiledPositions(int allocated,
SizeRequirements total,
SizeRequirements[] children,
int[] offsets,
int[] spans,
boolean forward) {
// The total argument turns out to be a bad idea since the
// total of all the children can overflow the integer used to
// hold the total. The total must therefore be calculated and
// stored in long variables.
long min = 0;
long pref = 0;
long max = 0;
for (int i = 0; i < children.length; i++) {
min += children[i].minimum;
pref += children[i].preferred;
max += children[i].maximum;
}
if (allocated >= pref) {
expandedTile(allocated, min, pref, max, children, offsets, spans, forward);
} else {
compressedTile(allocated, min, pref, max, children, offsets, spans, forward);
}
}
Creates a set of offset/span pairs representing how to
lay out a set of components end-to-end.
This method requires that you specify
the total amount of space to be allocated,
the size requirements for each component to be placed
(specified as an array of SizeRequirements), and
the total size requirement of the set of components.
You can get the total size requirement
by invoking the getTiledSizeRequirements method.
This method also requires a flag indicating whether components
should be tiled in the forward direction (offsets increasing
from 0) or reverse direction (offsets decreasing from the end
of the allocated space). The forward direction represents
components tiled from left to right or top to bottom. The
reverse direction represents components tiled from right to left
or bottom to top. |
public static SizeRequirements getAlignedSizeRequirements(SizeRequirements[] children) {
SizeRequirements totalAscent = new SizeRequirements();
SizeRequirements totalDescent = new SizeRequirements();
for (int i = 0; i < children.length; i++) {
SizeRequirements req = children[i];
int ascent = (int) (req.alignment * req.minimum);
int descent = req.minimum - ascent;
totalAscent.minimum = Math.max(ascent, totalAscent.minimum);
totalDescent.minimum = Math.max(descent, totalDescent.minimum);
ascent = (int) (req.alignment * req.preferred);
descent = req.preferred - ascent;
totalAscent.preferred = Math.max(ascent, totalAscent.preferred);
totalDescent.preferred = Math.max(descent, totalDescent.preferred);
ascent = (int) (req.alignment * req.maximum);
descent = req.maximum - ascent;
totalAscent.maximum = Math.max(ascent, totalAscent.maximum);
totalDescent.maximum = Math.max(descent, totalDescent.maximum);
}
int min = (int) Math.min((long) totalAscent.minimum + (long) totalDescent.minimum, Integer.MAX_VALUE);
int pref = (int) Math.min((long) totalAscent.preferred + (long) totalDescent.preferred, Integer.MAX_VALUE);
int max = (int) Math.min((long) totalAscent.maximum + (long) totalDescent.maximum, Integer.MAX_VALUE);
float alignment = 0.0f;
if (min > 0) {
alignment = (float) totalAscent.minimum / min;
alignment = alignment > 1.0f ? 1.0f : alignment < 0.0f ? 0.0f : alignment;
}
return new SizeRequirements(min, pref, max, alignment);
}
Determines the total space necessary to
align a set of components. The needs
of each component in the set are represented by an entry in the
passed-in SizeRequirements array. The total space required will
never be more than Integer.MAX_VALUE. |
public static SizeRequirements getTiledSizeRequirements(SizeRequirements[] children) {
SizeRequirements total = new SizeRequirements();
for (int i = 0; i < children.length; i++) {
SizeRequirements req = children[i];
total.minimum = (int) Math.min((long) total.minimum + (long) req.minimum, Integer.MAX_VALUE);
total.preferred = (int) Math.min((long) total.preferred + (long) req.preferred, Integer.MAX_VALUE);
total.maximum = (int) Math.min((long) total.maximum + (long) req.maximum, Integer.MAX_VALUE);
}
return total;
}
Determines the total space necessary to
place a set of components end-to-end. The needs
of each component in the set are represented by an entry in the
passed-in SizeRequirements array.
The returned SizeRequirements object has an alignment of 0.5
(centered). The space requirement is never more than
Integer.MAX_VALUE. |
public String toString() {
return "[" + minimum + "," + preferred + "," + maximum + "]@" + alignment;
}
Returns a string describing the minimum, preferred, and maximum
size requirements, along with the alignment. |