GroupLayout.java
上传用户:haobig99
上传日期:2022-06-15
资源大小:369k
文件大小:130k
- throw new IllegalArgumentException(
- "Pref and max must be either DEFAULT_SIZE, " +
- "PREFERRED_SIZE, or >= 0 and pref <= max");
- }
- hasPreferredPaddingSprings = true;
- return (SequentialGroup)addSpring(new AutopaddingSpring(
- type, pref, max));
- }
-
- /**
- * Adds an element representing the preferred gap between one edge
- * of the container and the next/previous Component. This will have
- * no effect if the next/previous element is not a Component and does
- * not touch one edge of the parent container.
- *
- * @return this <code>SequentialGroup</code>.
- */
- public SequentialGroup addContainerGap() {
- return addContainerGap(DEFAULT_SIZE, DEFAULT_SIZE);
- }
-
- /**
- * Adds an element representing the preferred gap between one edge
- * of the container and the next/previous Component. This will have
- * no effect if the next/previous element is not a Component and does
- * not touch one edge of the parent container.
- *
- * @param pref the preferred size; one of DEFAULT_SIZE or a value > 0
- * @param max the maximum size; one of DEFAULT_SIZE, PREFERRED_SIZE
- * or a value > 0.
- * @throws IllegalArgumentException if pref/max is
- * != DEFAULT_SIZE and < 0, or pref > max
- * @return this <code>SequentialGroup</code>
- */
- public SequentialGroup addContainerGap(int pref, int max) {
- if ((pref < 0 && pref != DEFAULT_SIZE) ||
- (max < 0 && max != DEFAULT_SIZE && max != PREFERRED_SIZE) ||
- (pref >= 0 && max >= 0 && pref > max)) {
- throw new IllegalArgumentException(
- "Pref and max must be either DEFAULT_VALUE or >= 0 and pref <= max");
- }
- hasPreferredPaddingSprings = true;
- return (SequentialGroup)addSpring(
- new ContainerAutopaddingSpring(pref, max));
- }
-
- int operator(int a, int b) {
- return constrain(a) + constrain(b);
- }
-
- void setValidSize(int axis, int origin, int size) {
- int pref = getPreferredSize(axis);
- if (size == pref) {
- for (int counter = 0, max = springs.size(); counter < max;
- counter++) {
- Spring spring = getSpring(counter);
- int springPref = spring.getPreferredSize(axis);
- spring.setSize(axis, origin, springPref);
- origin += springPref;
- }
- } else if (springs.size() == 1) {
- Spring spring = getSpring(0);
- spring.setSize(axis, origin, Math.min(
- Math.max(size, spring.getMinimumSize(axis)),
- spring.getMaximumSize(axis)));
- } else if (springs.size() > 1) {
- // Adjust between min/pref
- setValidSizeNotPreferred(axis, origin, size);
- }
- }
-
- private void setValidSizeNotPreferred(int axis, int origin, int size) {
- int delta = size - getPreferredSize(axis);
- //assert delta != 0;
- boolean useMin = (delta < 0);
- int springCount = springs.size();
- if (useMin) {
- delta *= -1;
- }
-
- // The following algorithm if used for resizing springs:
- // 1. Calculate the resizability of each spring (pref - min or
- // max - pref) into a list.
- // 2. Sort the list in ascending order
- // 3. Iterate through each of the resizable Springs, attempting
- // to give them (pref - size) / resizeCount
- // 4. For any Springs that can not accommodate that much space
- // add the remainder back to the amount to distribute and
- // recalculate how must space the remaining springs will get.
- // 5. Set the size of the springs.
- // First pass, sort the resizable springs into resizable
- Vector resizable = buildResizableList(axis, useMin);
- int resizableCount = resizable.size();
-
- if (resizableCount > 0) {
- // How much we would like to give each Spring.
- int sDelta = delta / resizableCount;
- // Remaining space.
- int slop = delta - sDelta * resizableCount;
- int[] sizes = new int[springCount];
- int sign = useMin ? -1 : 1;
- // Second pass, accumulate the resulting deltas (relative to
- // preferred) into sizes.
- for (int counter = 0; counter < resizableCount; counter++) {
- SpringDelta springDelta = (SpringDelta)resizable.
- elementAt(counter);
- if ((counter + 1) == resizableCount) {
- sDelta += slop;
- }
- springDelta.delta = Math.min(sDelta, springDelta.delta);
- delta -= springDelta.delta;
- if (springDelta.delta != sDelta && counter + 1 <
- resizableCount) {
- // Spring didn't take all the space, reset how much
- // each spring will get.
- sDelta = delta / (resizableCount - counter - 1);
- slop = delta - sDelta * (resizableCount - counter - 1);
- }
- sizes[springDelta.index] = sign * springDelta.delta;
- }
-
- // And finally set the size of each spring
- for (int counter = 0; counter < springCount; counter++) {
- Spring spring = getSpring(counter);
- int sSize = spring.getPreferredSize(axis) + sizes[counter];
- spring.setSize(axis, origin, sSize);
- origin += sSize;
- }
- } else {
- // Nothing resizable, use the min or max of each of the
- // springs.
- for (int counter = 0; counter < springCount; counter++) {
- Spring spring = getSpring(counter);
- int sSize;
- if (useMin) {
- sSize = spring.getMinimumSize(axis);
- } else {
- sSize = spring.getMaximumSize(axis);
- }
- spring.setSize(axis, origin, sSize);
- origin += sSize;
- }
- }
- }
-
- /**
- * Returns the sorted list of SpringDelta's for the current set of
- * Springs.
- */
- private Vector buildResizableList(int axis, boolean useMin) {
- // First pass, figure out what is resizable
- int size = springs.size();
- Vector sorted = new Vector(size);
- for (int counter = 0; counter < size; counter++) {
- Spring spring = getSpring(counter);
- int sDelta;
- if (useMin) {
- sDelta = spring.getPreferredSize(axis) -
- spring.getMinimumSize(axis);
- } else {
- sDelta = spring.getMaximumSize(axis) -
- spring.getPreferredSize(axis);
- }
- if (sDelta > 0) {
- sorted.addElement(new SpringDelta(counter, sDelta));
- }
- }
- //size = sorted.size();
-
- // insertion sort for a relatively small vector
- for (int i = 0 ; i < 0 ; i++) {
- for (int j = i; j > 0 && ((SpringDelta)sorted.elementAt(j-1)).compareTo(sorted.elementAt(j)) > 0 ; j--) {
- Object a = sorted.elementAt(j-1);
- Object b = sorted.elementAt(j);
- sorted.setElementAt(b, j - 1);
- sorted.setElementAt(a, j);
- }
- }
- return sorted;
- }
-
- private int indexOfNextNonZeroSpring(int index, boolean treatAutopaddingAsZeroSized) {
- while (index < springs.size()) {
- Spring spring = (Spring)springs.elementAt(index);
- if (!((Spring)spring).willHaveZeroSize(treatAutopaddingAsZeroSized)) {
- return index;
- }
- index++;
- }
- return index;
- }
- void insertAutopadding(int axis, Vector leadingPadding,
- Vector trailingPadding, Vector leading, Vector trailing,
- boolean insert) {
- Vector newLeadingPadding = create(leadingPadding);
- Vector newTrailingPadding = new Vector(1);
- Vector newLeading = create(leading);
- Vector newTrailing = null;
- int counter = 0;
- // Warning, this must use springs.size, as it may change during the
- // loop.
- while (counter < springs.size()) {
- Spring spring = getSpring(counter);
- if (spring instanceof AutopaddingSpring) {
- if (newLeadingPadding.size() == 0) {
- AutopaddingSpring padding = (AutopaddingSpring)spring;
- padding.setSources(newLeading);
- newLeading.removeAllElements();
- int nextCounter = indexOfNextNonZeroSpring(counter + 1, true);
- if (nextCounter == springs.size()) {
- // Last spring in the list, add it to trailingPadding.
- if (!(padding instanceof ContainerAutopaddingSpring)) {
- trailingPadding.addElement(padding);
- }
- } else {
- newLeadingPadding.removeAllElements();
- newLeadingPadding.addElement(padding);
- }
- counter = nextCounter;
- } else {
- counter = indexOfNextNonZeroSpring(counter + 1, true);
- }
- } else {
- // Not a padding spring
- if (newLeading.size() > 0 && insert) {
- // There's leading ComponentSprings, create an
- // autopadding spring.
- AutopaddingSpring padding = new AutopaddingSpring();
- // Force the newly created spring to be considered
- // by NOT incrementing counter
- springs.insertElementAt(padding, counter);
- continue;
- }
- if (spring instanceof ComponentSpring) {
- // Spring is a Component, make it the target of any
- // leading AutopaddingSpring.
- ComponentSpring cSpring = (ComponentSpring)spring;
- if (!cSpring.isVisible()) {
- counter++;
- continue;
- }
- for (int i = 0; i < newLeadingPadding.size(); i++) {
- ((AutopaddingSpring)newLeadingPadding.elementAt(i)).
- addTarget(cSpring, axis);
- }
- newLeading.removeAllElements();
- newLeadingPadding.removeAllElements();
- int nextCounter = indexOfNextNonZeroSpring(counter + 1, false);
- if (nextCounter == springs.size()) {
- // Last Spring, add it to trailing
- trailing.addElement(cSpring);
- } else {
- // Not that last Spring, add it to leading
- newLeading.addElement(cSpring);
- }
- counter = nextCounter;
- } else if (spring instanceof Group) {
- // Forward call to child Group
- if (newTrailing == null) {
- newTrailing = new Vector(1);
- } else {
- newTrailing.removeAllElements();
- }
- newTrailingPadding.removeAllElements();
- ((Group)spring).insertAutopadding(axis, newLeadingPadding,
- newTrailingPadding, newLeading, newTrailing,
- insert);
- newLeading.removeAllElements();
- newLeadingPadding.removeAllElements();
- int nextCounter = indexOfNextNonZeroSpring(counter + 1,
- newTrailing.size() == 0);
- if (nextCounter == springs.size()) {
- addAll(trailing, newTrailing);
- addAll(trailingPadding, newTrailingPadding);
- } else {
- addAll(newLeading, newTrailing);
- addAll(newLeadingPadding, newTrailingPadding);
- }
- counter = nextCounter;
- } else {
- // Gap
- newLeadingPadding.removeAllElements();
- newLeading.removeAllElements();
- counter++;
- }
- }
- }
- }
-
- int getBaseline() {
- if (baselineSpring != null) {
- int baseline = baselineSpring.getBaseline();
- if (baseline >= 0) {
- int size = 0;
- for (int i = 0, max = springs.size(); i < max; i++) {
- Spring spring = getSpring(i);
- if (spring == baselineSpring) {
- return size + baseline;
- } else {
- size += spring.getPreferredSize(VERTICAL);
- }
- }
- }
- }
- return -1;
- }
-
- int getBaselineResizeBehavior() {
- if (isResizable(VERTICAL)) {
- if (!baselineSpring.isResizable(VERTICAL)) {
- // Spring to use for baseline isn't resizable. In this case
- // baseline resize behavior can be determined based on how
- // preceeding springs resize.
- boolean leadingResizable = false;
- for (int i = 0, max = springs.size(); i < max; i++) {
- Spring spring = getSpring(i);
- if (spring == baselineSpring) {
- break;
- } else if (spring.isResizable(VERTICAL)) {
- leadingResizable = true;
- break;
- }
- }
- boolean trailingResizable = false;
- for (int i = springs.size() - 1; i >= 0; i--) {
- Spring spring = getSpring(i);
- if (spring == baselineSpring) {
- break;
- }
- if (spring.isResizable(VERTICAL)) {
- trailingResizable = true;
- break;
- }
- }
- if (leadingResizable && !trailingResizable) {
- return Component.BRB_CONSTANT_DESCENT;
- } else if (!leadingResizable && trailingResizable) {
- return Component.BRB_CONSTANT_ASCENT;
- }
- // If we get here, both leading and trailing springs are
- // resizable. Fall through to OTHER.
- } else {
- int brb = baselineSpring.getBaselineResizeBehavior();
- if (brb == Component.BRB_CONSTANT_ASCENT) {
- for (int i = 0, max = springs.size(); i < max; i++) {
- Spring spring = getSpring(i);
- if (spring == baselineSpring) {
- return Component.BRB_CONSTANT_ASCENT;
- }
- if (spring.isResizable(VERTICAL)) {
- return Component.BRB_OTHER;
- }
- }
- } else if (brb == Component.BRB_CONSTANT_DESCENT) {
- for (int i = springs.size() - 1; i >= 0; i--) {
- Spring spring = getSpring(i);
- if (spring == baselineSpring) {
- return Component.BRB_CONSTANT_DESCENT;
- }
- if (spring.isResizable(VERTICAL)) {
- return Component.BRB_OTHER;
- }
- }
- }
- }
- return Component.BRB_OTHER;
- }
- // Not resizable, treat as constant_ascent
- return Component.BRB_CONSTANT_ASCENT;
- }
- }
-
-
- /**
- * Used in figuring out how much space to give resizable springs.
- */
- private static final class SpringDelta {
- // Original index.
- public final int index;
- // Delta, one of pref - min or max - pref.
- public int delta;
-
- public SpringDelta(int index, int delta) {
- this.index = index;
- this.delta = delta;
- }
-
- public int compareTo(Object o) {
- return delta - ((SpringDelta)o).delta;
- }
-
- public String toString() {
- return super.toString() + "[index=" + index + ", delta=" +
- delta + "]";
- }
- }
-
-
- /**
- * A <code>Group</code> that lays out its elements on top of each
- * other. If a child element is smaller than the provided space it
- * is aligned based on the alignment of the child (if specified) or
- * on the alignment of the ParallelGroup.
- *
- * @see #createParallelGroup()
- */
- public class ParallelGroup extends Group {
- // How children are layed out.
- private final int childAlignment;
- // Whether or not we're resizable.
- private final boolean resizable;
-
- ParallelGroup(int childAlignment, boolean resizable) {
- this.childAlignment = childAlignment;
- this.resizable = resizable;
- }
-
- /**
- * Adds the specified <code>Group</code>.
- *
- * @param group the Group to add
- * @return this Group
- */
- public ParallelGroup add(Group group) {
- return (ParallelGroup)addSpring(group);
- }
-
- /**
- * Adds the specified Component. If the Component's min/max
- * are different from its pref than the component will be resizable.
- *
- * @param component the Component to add
- * @return this <code>ParallelGroup</code>
- */
- public ParallelGroup add(Component component) {
- return add(component, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE);
- }
-
- /**
- * Adds the specified <code>Component</code>. Min, pref and max
- * can be absolute values, or they can be one of
- * <code>DEFAULT_SIZE</code> or <code>PREFERRED_SIZE</code>. For
- * example, the following:
- * <pre>
- * add(component, PREFERRED_SIZE, PREFERRED_SIZE, 1000);
- * </pre>
- * Forces a max of 1000, with the min and preferred equalling that
- * of the preferred size of <code>component</code>.
- *
- * @param component the Component to add
- * @param min the minimum size
- * @param pref the preferred size
- * @param max the maximum size
- * @throws IllegalArgumentException if min, pref or max are
- * not positive and not one of PREFERRED_SIZE or DEFAULT_SIZE.
- * @return this <code>SequentialGroup</code>
- */
- public ParallelGroup add(Component component, int min, int pref,
- int max) {
- return (ParallelGroup)addSpring(new ComponentSpring(
- component, min, pref, max));
- }
-
- /**
- * Adds a rigid gap.
- *
- * @param pref the size of the gap
- * @throws IllegalArgumentException if min < 0 or pref < 0 or max < 0
- * or the following is not meant min <= pref <= max.
- * @return this <code>ParallelGroup</code>
- */
- public ParallelGroup add(int pref) {
- return add(pref, pref, pref);
- }
-
- /**
- * Adds a gap with the specified size.
- *
- * @param min the minimum size of the gap
- * @param pref the preferred size of the gap
- * @param max the maximum size of the gap
- * @throws IllegalArgumentException if min < 0 or pref < 0 or max < 0
- * or the following is not meant min <= pref <= max.
- * @return this <code>ParallelGroup</code>
- */
- public ParallelGroup add(int min, int pref, int max) {
- return (ParallelGroup)addSpring(new GapSpring(min, pref, max));
- }
-
- /**
- * Adds the specified <code>Group</code> as a child of this group.
- *
- * @param alignment the alignment of the Group.
- * @param group the Group to add
- * @return this <code>ParallelGroup</code>
- * @throws IllegalArgumentException if alignment is not one of
- * <code>LEADING</code>, <code>TRAILING</code> or
- * <code>CENTER</code>
- */
- public ParallelGroup add(int alignment, Group group) {
- checkChildAlignment(alignment);
- group.setAlignment(alignment);
- return (ParallelGroup)addSpring(group);
- }
-
- /**
- * Adds the specified Component. If the Component's min/max
- * are different from its pref than the component will be resizable.
- *
- * @param alignment the alignment for the component
- * @param component the Component to add
- * @return this <code>Group</code>
- * @throws IllegalArgumentException if alignment is not one of
- * <code>LEADING</code>, <code>TRAILING</code> or
- * <code>CENTER</code>
- */
- public ParallelGroup add(int alignment, Component component) {
- return add(alignment, component, DEFAULT_SIZE, DEFAULT_SIZE,
- DEFAULT_SIZE);
- }
-
- /**
- * Adds the specified <code>Component</code>. Min, pref and max
- * can be absolute values, or they can be one of
- * <code>DEFAULT_SIZE</code> or <code>PREFERRED_SIZE</code>. For
- * example, the following:
- * <pre>
- * add(component, PREFERRED_SIZE, PREFERRED_SIZE, 1000);
- * </pre>
- * Forces a max of 1000, with the min and preferred equalling that
- * of the preferred size of <code>component</code>.
- *
- * @param alignment the alignment for the component.
- * @param component the Component to add
- * @param min the minimum size
- * @param pref the preferred size
- * @param max the maximum size
- * @throws IllegalArgumentException if min, pref or max are
- * not positive and not one of PREFERRED_SIZE or DEFAULT_SIZE.
- * @return this <code>Group</code>
- */
- public ParallelGroup add(int alignment, Component component, int min,
- int pref, int max) {
- checkChildAlignment(alignment);
- ComponentSpring spring = new ComponentSpring(component,
- min, pref, max);
- spring.setAlignment(alignment);
- return (ParallelGroup)addSpring(spring);
- }
-
- boolean isResizable() {
- return resizable;
- }
-
- int operator(int a, int b) {
- return Math.max(a, b);
- }
-
- int calculateMinimumSize(int axis) {
- if (!isResizable()) {
- return getPreferredSize(axis);
- }
- return super.calculateMinimumSize(axis);
- }
-
- int calculateMaximumSize(int axis) {
- if (!isResizable()) {
- return getPreferredSize(axis);
- }
- return super.calculateMaximumSize(axis);
- }
-
- void setValidSize(int axis, int origin, int size) {
- for (int i = 0, max = springs.size(); i < max; i++) {
- setChildSize(getSpring(i), axis, origin, size);
- }
- }
-
- void setChildSize(Spring spring, int axis, int origin, int size) {
- int alignment = spring.getAlignment();
- int springSize = Math.min(
- Math.max(spring.getMinimumSize(axis), size),
- spring.getMaximumSize(axis));
- if (alignment == NO_ALIGNMENT) {
- alignment = childAlignment;
- }
- switch (alignment) {
- case TRAILING:
- spring.setSize(axis, origin + size - springSize,
- springSize);
- break;
- case CENTER:
- spring.setSize(axis, origin +
- (size - springSize) / 2,springSize);
- break;
- default: // LEADING, or BASELINE
- spring.setSize(axis, origin, springSize);
- break;
- }
- }
-
- void insertAutopadding(int axis, Vector leadingPadding,
- Vector trailingPadding, Vector leading, Vector trailing,
- boolean insert) {
- for (int counter = 0, max = springs.size(); counter < max; counter++) {
- Spring spring = getSpring(counter);
- if (spring instanceof ComponentSpring) {
- if (((ComponentSpring)spring).isVisible()) {
- for (int i = 0; i < leadingPadding.size(); i++) {
- ((AutopaddingSpring)leadingPadding.elementAt(i)).addTarget(
- (ComponentSpring)spring, axis);
- }
- trailing.addElement(spring);
- }
- } else if (spring instanceof Group) {
- ((Group)spring).insertAutopadding(axis, leadingPadding,
- trailingPadding, leading, trailing, insert);
- } else if (spring instanceof AutopaddingSpring) {
- ((AutopaddingSpring)spring).setSources(leading);
- trailingPadding.addElement(spring);
- }
- }
- }
- private void checkChildAlignment(int alignment) {
- boolean allowsBaseline = (this instanceof BaselineGroup);
- if (!allowsBaseline && alignment == BASELINE) {
- throw new IllegalArgumentException("Alignment must be one of:" +
- "LEADING, TRAILING or CENTER");
- }
- if (alignment != CENTER && alignment != BASELINE &&
- alignment != LEADING && alignment != TRAILING) {
- throw new IllegalArgumentException("Alignment must be one of:" +
- "LEADING, TRAILING or CENTER");
- }
- }
- }
-
-
- /**
- * An extension of <code>ParallelGroup</code> that aligns its
- * constituent <code>Spring</code>s along the baseline.
- */
- private class BaselineGroup extends ParallelGroup {
- // Whether or not all child springs have a baseline
- private boolean allSpringsHaveBaseline;
- // max(spring.getBaseline()) of all springs aligned along the baseline
- // that have a baseline
- private int prefAscent;
- // max(spring.getPreferredSize().height - spring.getBaseline()) of all
- // springs aligned along the baseline that have a baseline
- private int prefDescent;
- // Whether baselineAnchoredToTop was explicitly set
- private boolean baselineAnchorSet;
- // Whether the baseline is anchored to the top or the bottom.
- // If anchored to the top the baseline is always at prefAscent,
- // otherwise the baseline is at (height - prefDescent)
- private boolean baselineAnchoredToTop;
-
- // Whether or not the baseline has been calculated.
- private boolean calcedBaseline;
-
- BaselineGroup(boolean resizable) {
- super(LEADING, resizable);
- prefAscent = prefDescent = -1;
- calcedBaseline = false;
- }
-
- BaselineGroup(boolean resizable, boolean baselineAnchoredToTop) {
- this(resizable);
- this.baselineAnchoredToTop = baselineAnchoredToTop;
- baselineAnchorSet = true;
- }
-
- void unset() {
- super.unset();
- prefAscent = prefDescent = -1;
- calcedBaseline = false;
- }
-
- void setValidSize(int axis, int origin, int size) {
- checkAxis(axis);
- if (prefAscent == -1) {
- super.setValidSize(axis, origin, size);
- } else {
- // do baseline layout
- baselineLayout(origin, size);
- }
- }
-
- int calculateSize(int axis, int type) {
- checkAxis(axis);
- if (!calcedBaseline) {
- calculateBaselineAndResizeBehavior();
- }
- if (type == MIN_SIZE) {
- return calculateMinSize();
- }
- if (type == MAX_SIZE) {
- return calculateMaxSize();
- }
- if (allSpringsHaveBaseline) {
- return prefAscent + prefDescent;
- }
- return Math.max(prefAscent + prefDescent,
- super.calculateSize(axis, type));
- }
-
- private void calculateBaselineAndResizeBehavior() {
- // calculate baseline
- prefAscent = 0;
- prefDescent = 0;
- int baselineSpringCount = 0;
- int resizeBehavior = 0;
- for (int counter = springs.size() - 1; counter >= 0; counter--) {
- Spring spring = getSpring(counter);
- if (spring.getAlignment() == NO_ALIGNMENT ||
- spring.getAlignment() == BASELINE) {
- int baseline = spring.getBaseline();
- if (baseline >= 0) {
- if (spring.isResizable(VERTICAL)) {
- int brb = spring.
- getBaselineResizeBehavior();
- if (resizeBehavior == 0) {
- resizeBehavior = brb;
- } else if (brb != resizeBehavior) {
- resizeBehavior = Component.BRB_CONSTANT_ASCENT;
- }
- }
- prefAscent = Math.max(prefAscent, baseline);
- prefDescent = Math.max(prefDescent, spring.
- getPreferredSize(VERTICAL) - baseline);
- baselineSpringCount++;
- }
- }
- }
- if (!baselineAnchorSet) {
- if (resizeBehavior == Component.BRB_CONSTANT_DESCENT){
- this.baselineAnchoredToTop = false;
- } else {
- this.baselineAnchoredToTop = true;
- }
- }
- allSpringsHaveBaseline = (baselineSpringCount == springs.size());
- calcedBaseline = true;
- }
-
- private int calculateMaxSize() {
- int maxAscent = prefAscent;
- int maxDescent = prefDescent;
- int nonBaselineMax = 0;
- for (int counter = springs.size() - 1; counter >= 0; counter--) {
- Spring spring = getSpring(counter);
- int baseline;
- int springMax = spring.getMaximumSize(VERTICAL);
- if ((spring.getAlignment() == NO_ALIGNMENT ||
- spring.getAlignment() == BASELINE) &&
- (baseline = spring.getBaseline()) >= 0) {
- int springPref = spring.getPreferredSize(VERTICAL);
- if (springPref != springMax) {
- switch (spring.getBaselineResizeBehavior()) {
- case Component.BRB_CONSTANT_ASCENT:
- if (baselineAnchoredToTop) {
- maxDescent = Math.max(maxDescent,
- springMax - baseline);
- }
- break;
- case Component.BRB_CONSTANT_DESCENT:
- if (!baselineAnchoredToTop) {
- maxAscent = Math.max(maxAscent,
- springMax - springPref + baseline);
- }
- break;
- default: // CENTER_OFFSET and OTHER, not resizable
- break;
- }
- }
- } else {
- // Not aligned along the baseline, or no baseline.
- nonBaselineMax = Math.max(nonBaselineMax, springMax);
- }
- }
- return Math.max(nonBaselineMax, maxAscent + maxDescent);
- }
-
- private int calculateMinSize() {
- int minAscent = 0;
- int minDescent = 0;
- int nonBaselineMin = 0;
- if (baselineAnchoredToTop) {
- minAscent = prefAscent;
- } else {
- minDescent = prefDescent;
- }
- for (int counter = springs.size() - 1; counter >= 0; counter--) {
- Spring spring = getSpring(counter);
- int springMin = spring.getMinimumSize(VERTICAL);
- int baseline;
- if ((spring.getAlignment() == NO_ALIGNMENT ||
- spring.getAlignment() == BASELINE) &&
- (baseline = spring.getBaseline()) >= 0) {
- int springPref = spring.getPreferredSize(VERTICAL);
- switch (spring.getBaselineResizeBehavior()) {
- case Component.BRB_CONSTANT_ASCENT:
- if (baselineAnchoredToTop) {
- minDescent = Math.max(springMin - baseline,
- minDescent);
- } else {
- minAscent = Math.max(baseline, minAscent);
- }
- break;
- case Component.BRB_CONSTANT_DESCENT:
- if (!baselineAnchoredToTop) {
- minAscent = Math.max(
- baseline - (springPref - springMin),
- minAscent);
- } else {
- minDescent = Math.max(springPref - baseline,
- minDescent);
- }
- break;
- default:
- // CENTER_OFFSET and OTHER are !resizable, use
- // the preferred size.
- minAscent = Math.max(baseline, minAscent);
- minDescent = Math.max(springPref - baseline,
- minDescent);
- break;
- }
- } else {
- // Not aligned along the baseline, or no baseline.
- nonBaselineMin = Math.max(nonBaselineMin, springMin);
- }
- }
- return Math.max(nonBaselineMin, minAscent + minDescent);
- }
- /**
- * Lays out springs that have a baseline along the baseline. All
- * others are centered.
- */
- private void baselineLayout(int origin, int size) {
- int ascent;
- int descent;
- if (baselineAnchoredToTop) {
- ascent = prefAscent;
- descent = size - ascent;
- } else {
- ascent = size - prefDescent;
- descent = prefDescent;
- }
- for (int counter = springs.size() - 1; counter >= 0; counter--) {
- Spring spring = getSpring(counter);
- int alignment = spring.getAlignment();
- if (alignment == NO_ALIGNMENT || alignment == BASELINE) {
- int baseline = spring.getBaseline();
- if (baseline >= 0) {
- int springMax = spring.getMaximumSize(VERTICAL);
- int springPref = spring.getPreferredSize(VERTICAL);
- int height = springPref;
- int y;
- switch(spring.getBaselineResizeBehavior()) {
- case Component.BRB_CONSTANT_ASCENT:
- y = origin + ascent - baseline;
- height = Math.min(descent, springMax -
- baseline) + baseline;
- break;
- case Component.BRB_CONSTANT_DESCENT:
- height = Math.min(ascent, springMax -
- springPref + baseline) +
- (springPref - baseline);
- y = origin + ascent +
- (springPref - baseline) - height;
- break;
- default: // CENTER_OFFSET & OTHER, not resizable
- y = origin + ascent - baseline;
- break;
- }
- spring.setSize(VERTICAL, y, height);
- } else {
- setChildSize(spring, VERTICAL, origin, size);
- }
- } else {
- setChildSize(spring, VERTICAL, origin, size);
- }
- }
- }
-
- int getBaseline() {
- if (springs.size() > 1) {
- // Force the baseline to be calculated
- getPreferredSize(VERTICAL);
- return prefAscent;
- } else if (springs.size() == 1) {
- return getSpring(0).getBaseline();
- }
- return -1;
- }
-
- int getBaselineResizeBehavior() {
- if (springs.size() == 1) {
- return getSpring(0).getBaselineResizeBehavior();
- }
- if (baselineAnchoredToTop) {
- return Component.BRB_CONSTANT_ASCENT;
- }
- return Component.BRB_CONSTANT_DESCENT;
- }
-
- // If the axis is VERTICAL, throws an IllegalStateException
- private void checkAxis(int axis) {
- if (axis == HORIZONTAL) {
- throw new IllegalStateException(
- "Baseline must be used along vertical axis");
- }
- }
- }
-
-
- /**
- * A Spring representing one axis of a Component.
- * There are three ways to configure this:
- * <ul>
- * <li>Use the pref/min/max from the component
- * <li>Use the pref from the component and fix the min to 0 or max
- * to a big number.
- * <li>Force the min/max/pref to be a certain value.
- * If the Component's size is to be linked to another components than
- * the min/max/pref all come from the ComponentInfo.
- */
- private final class ComponentSpring extends Spring {
- private Component component;
- private int origin;
-
- // min/pref/max are either a value >= 0 or one of
- // DEFAULT_SIZE or PREFERRED_SIZE
- private final int min;
- private final int pref;
- private final int max;
-
- // Baseline for the component.
- private int baseline = -1;
-
- // Whether or not the size has been requested yet.
- private boolean installed;
-
- private ComponentSpring(Component component, int min, int pref,
- int max) {
- this.component = component;
- if (component == null) {
- throw new IllegalArgumentException(
- "Component must be non-null");
- }
- checkSize(min, pref, max, true);
-
- this.min = min;
- this.max = max;
- this.pref = pref;
-
- // getComponentInfo makes sure component is a child of the
- // Container GroupLayout is the LayoutManager for.
- getComponentInfo(component);
- }
-
- int calculateMinimumSize(int axis) {
- if (isLinked(axis)) {
- return getLinkSize(axis, MIN_SIZE);
- }
- return calculateNonlinkedMinimumSize(axis);
- }
-
- int calculatePreferredSize(int axis) {
- if (isLinked(axis)) {
- return getLinkSize(axis, PREF_SIZE);
- }
- int min = getMinimumSize(axis);
- int pref = calculateNonlinkedPreferredSize(axis);
- int max = getMaximumSize(axis);
- return Math.min(max, Math.max(min, pref));
- }
-
- int calculateMaximumSize(int axis) {
- if (isLinked(axis)) {
- return getLinkSize(axis, MAX_SIZE);
- }
- return Math.max(getMinimumSize(axis),
- calculateNonlinkedMaximumSize(axis));
- }
-
- boolean isVisible() {
- return getComponentInfo(getComponent()).isVisible();
- }
-
- int calculateNonlinkedMinimumSize(int axis) {
- if (!isVisible()) {
- return 0;
- }
- if (min >= 0) {
- return min;
- }
- if (min == PREFERRED_SIZE) {
- return calculateNonlinkedPreferredSize(axis);
- }
- //assert (min == DEFAULT_SIZE);
- //return getSizeAlongAxis(axis, component.getMinimumSize());
- // Do we need this if we don't support minimum size?
- return getSizeAlongAxis(axis, component.getPreferredSize());
- }
-
- int calculateNonlinkedPreferredSize(int axis) {
- if (!isVisible()) {
- return 0;
- }
- if (pref >= 0) {
- return pref;
- }
- //assert (pref == DEFAULT_SIZE || pref == PREFERRED_SIZE);
- return getSizeAlongAxis(axis, component.getPreferredSize());
- }
-
- int calculateNonlinkedMaximumSize(int axis) {
- if (!isVisible()) {
- return 0;
- }
- if (max >= 0) {
- return max;
- }
- if (max == PREFERRED_SIZE) {
- return calculateNonlinkedPreferredSize(axis);
- }
- //assert (max == DEFAULT_SIZE);
- //return getSizeAlongAxis(axis, component.getMaximumSize());
- return getSizeAlongAxis(axis, component.getPreferredSize());
- }
-
- private int getSizeAlongAxis(int axis, Dimension size) {
- return (axis == HORIZONTAL) ? size.getWidth() : size.getHeight();
- }
-
- private int getLinkSize(int axis, int type) {
- if (!isVisible()) {
- return 0;
- }
- ComponentInfo ci = getComponentInfo(component);
- return ci.getLinkSize(axis, type);
- }
-
- void setSize(int axis, int origin, int size) {
- super.setSize(axis, origin, size);
- this.origin = origin;
- if (size == UNSET) {
- baseline = -1;
- }
- }
-
- int getOrigin() {
- return origin;
- }
-
- void setComponent(Component component) {
- this.component = component;
- }
-
- Component getComponent() {
- return component;
- }
-
- int getBaseline() {
- if (baseline == -1) {
- Spring horizontalSpring = getComponentInfo(component).
- horizontalSpring;
- int width = horizontalSpring.getPreferredSize(HORIZONTAL);
- int height = getPreferredSize(VERTICAL);
- if (width > 0 && height > 0) {
- baseline = component.getBaseline(width, height);
- }
- }
- return baseline;
- }
-
- int getBaselineResizeBehavior() {
- return getComponent().getBaselineResizeBehavior();
- }
- private boolean isLinked(int axis) {
- return getComponentInfo(component).isLinked(axis);
- }
-
- void installIfNecessary(int axis) {
- if (!installed) {
- installed = true;
- if (axis == HORIZONTAL) {
- getComponentInfo(component).horizontalSpring = this;
- } else {
- getComponentInfo(component).verticalSpring = this;
- }
- }
- }
- boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) {
- return !isVisible();
- }
- }
-
- /**
- * Spring representing the preferred distance between two components.
- */
- private final class PaddingSpring extends Spring {
- private final Component source;
- private final Component target;
- private final int type;
- private final boolean canGrow;
-
- PaddingSpring(Component source, Component target, int type,
- boolean canGrow) {
- this.source = source;
- this.target = target;
- this.type = type;
- this.canGrow = canGrow;
- }
-
- int calculateMinimumSize(int axis) {
- return getPadding(axis);
- }
-
- int calculatePreferredSize(int axis) {
- return getPadding(axis);
- }
-
- int calculateMaximumSize(int axis) {
- if (canGrow) {
- return Short.MAX_VALUE;
- }
- return getPadding(axis);
- }
-
- private int getPadding(int axis) {
- int position;
- if (axis == HORIZONTAL) {
- position = EAST;
- } else {
- position = SOUTH;
- }
- return getLayoutStyle0().getPreferredGap(source,
- target, type, position, host);
- }
- boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) {
- return false;
- }
- }
-
-
- /**
- * Spring represented a certain amount of space.
- */
- private final class GapSpring extends Spring {
- private final int min;
- private final int pref;
- private final int max;
-
- GapSpring(int min, int pref, int max) {
- checkSize(min, pref, max, false);
- this.min = min;
- this.pref = pref;
- this.max = max;
- }
- int calculateMinimumSize(int axis) {
- if (min == PREFERRED_SIZE) {
- return getPreferredSize(axis);
- }
- return min;
- }
-
- int calculatePreferredSize(int axis) {
- return pref;
- }
-
- int calculateMaximumSize(int axis) {
- if (max == PREFERRED_SIZE) {
- return getPreferredSize(axis);
- }
- return max;
- }
- boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) {
- return false;
- }
- }
-
-
- /**
- * Spring reprensenting the distance between any number of sources and
- * targets. The targets and sources are computed during layout. An
- * instance of this can either be dynamically created when
- * autocreatePadding is true, or explicitly created by the developer.
- */
- private class AutopaddingSpring extends Spring {
- Vector sources;
- ComponentSpring source;
- private Vector matches;
- int size;
- int lastSize;
- private final int pref;
- private final int max;
- private int type;
- private boolean userCreated;
-
- private AutopaddingSpring() {
- this.pref = PREFERRED_SIZE;
- this.max = PREFERRED_SIZE;
- this.type = LayoutStyle.RELATED;
- }
- AutopaddingSpring(int pref, int max) {
- this.pref = pref;
- this.max = max;
- }
-
- AutopaddingSpring(int type, int pref, int max) {
- this.type = type;
- this.pref = pref;
- this.max = max;
- this.userCreated = true;
- }
-
- public void setSource(ComponentSpring source) {
- this.source = source;
- }
-
- public void setSources(Vector sources) {
- this.sources = create(sources);
- }
-
- public void setUserCreated(boolean userCreated) {
- this.userCreated = userCreated;
- }
-
- public boolean getUserCreated() {
- return userCreated;
- }
-
- void unset() {
- lastSize = getSize();
- super.unset();
- size = 0;
- }
-
- public void reset() {
- size = 0;
- sources = null;
- source = null;
- matches = null;
- }
-
- public void calculatePadding(int axis) {
- size = UNSET;
- int maxPadding = UNSET;
- if (matches != null) {
- LayoutStyle p = getLayoutStyle0();
- int position;
- if (axis == HORIZONTAL) {
- if (isLeftToRight()) {
- position = EAST;
- } else {
- position = WEST;
- }
- } else {
- position = SOUTH;
- }
- for (int i = matches.size() - 1; i >= 0; i--) {
- AutopaddingMatch match = (AutopaddingMatch)matches.elementAt(i);
- maxPadding = Math.max(maxPadding,
- calculatePadding(p, position, match.source,
- match.target));
- }
- }
- if (size == UNSET) {
- size = 0;
- }
- if (maxPadding == UNSET) {
- maxPadding = 0;
- }
- if (lastSize != UNSET) {
- size += Math.min(maxPadding, lastSize);
- }
- }
-
- private int calculatePadding(LayoutStyle p, int position,
- ComponentSpring source,
- ComponentSpring target) {
- int delta = target.getOrigin() - (source.getOrigin() +
- source.getSize());
- if (delta >= 0) {
- int padding = p.getPreferredGap(source.getComponent(),
- target.getComponent(), type, position, host);
- if (padding > delta) {
- size = Math.max(size, padding - delta);
- }
- return padding;
- }
- return 0;
- }
-
- public void addTarget(ComponentSpring spring, int axis) {
- int oAxis = (axis == HORIZONTAL) ? VERTICAL : HORIZONTAL;
- if (source != null) {
- if (areParallelSiblings(source.getComponent(),
- spring.getComponent(), oAxis)) {
- addValidTarget(source, spring);
- }
- } else {
- Component component = spring.getComponent();
- for (int counter = sources.size() - 1; counter >= 0; counter--){
- ComponentSpring source = (ComponentSpring)sources.
- elementAt(counter);
- if (areParallelSiblings(source.getComponent(),
- component, oAxis)) {
- addValidTarget(source, spring);
- }
- }
- }
- }
-
- private void addValidTarget(ComponentSpring source,
- ComponentSpring target) {
- if (matches == null) {
- matches = new Vector(1);
- }
- matches.addElement(new AutopaddingMatch(source, target));
- }
-
- int calculateMinimumSize(int axis) {
- return size;
- }
-
- int calculatePreferredSize(int axis) {
- if (pref == PREFERRED_SIZE || pref == DEFAULT_SIZE) {
- return size;
- }
- return Math.max(size, pref);
- }
-
- int calculateMaximumSize(int axis) {
- if (max >= 0) {
- return Math.max(getPreferredSize(axis), max);
- }
- return size;
- }
-
- String getMatchDescription() {
- return (matches == null) ? "" : matches.toString();
- }
-
- public String toString() {
- return super.toString() + getMatchDescription();
- }
- boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) {
- return treatAutopaddingAsZeroSized;
- }
- }
-
-
- /**
- * Represents two springs that should have autopadding inserted between
- * them.
- */
- private final static class AutopaddingMatch {
- public final ComponentSpring source;
- public final ComponentSpring target;
- AutopaddingMatch(ComponentSpring source, ComponentSpring target) {
- this.source = source;
- this.target = target;
- }
-
- private String toString(ComponentSpring spring) {
- return spring.getComponent().toString();
- }
- public String toString() {
- return "[" + toString(source) + "-" + toString(target) + "]";
- }
- }
-
-
- /**
- * An extension of AutopaddingSpring used for container level padding.
- */
- private class ContainerAutopaddingSpring extends AutopaddingSpring {
- private Vector targets;
-
- ContainerAutopaddingSpring() {
- super();
- setUserCreated(true);
- }
- ContainerAutopaddingSpring(int pref, int max) {
- super(pref, max);
- setUserCreated(true);
- }
- public void addTarget(ComponentSpring spring, int axis) {
- if (targets == null) {
- targets = new Vector(1);
- }
- targets.addElement(spring);
- }
- public void calculatePadding(int axis) {
- LayoutStyle p = getLayoutStyle0();
- int maxPadding = 0;
- int position;
- size = 0;
- if (targets != null) {
- // Leading
- if (axis == HORIZONTAL) {
- if (isLeftToRight()) {
- position = WEST;
- } else {
- position = EAST;
- }
- } else {
- position = SOUTH;
- }
- for (int i = targets.size() - 1; i >= 0; i--) {
- ComponentSpring targetSpring = (ComponentSpring)targets.
- elementAt(i);
- int padding = p.getContainerGap(
- targetSpring.getComponent(),
- position, host);
- maxPadding = Math.max(padding, maxPadding);
- padding -= targetSpring.getOrigin();
- size = Math.max(size, padding);
- }
- }
- else {
- // Trailing
- if (axis == HORIZONTAL) {
- if (isLeftToRight()) {
- position = EAST;
- } else {
- position = WEST;
- }
- } else {
- position = SOUTH;
- }
- if (sources != null) {
- for (int i = sources.size() - 1; i >= 0; i--) {
- ComponentSpring sourceSpring = (ComponentSpring)sources.
- elementAt(i);
- maxPadding = Math.max(maxPadding,
- updateSize(p, sourceSpring, position));
- }
- }
- else if (source != null) {
- maxPadding = updateSize(p, source, position);
- }
- }
- if (lastSize != UNSET) {
- size += Math.min(maxPadding, lastSize);
- }
- }
- private int updateSize(LayoutStyle p, ComponentSpring sourceSpring,
- int position) {
- int padding = p.getContainerGap(
- sourceSpring.getComponent(), position,
- host);
- int delta = Math.max(0, getParent().getSize() -
- sourceSpring.getSize() - sourceSpring.getOrigin());
- size = Math.max(size, padding - delta);
- return padding;
- }
-
- String getMatchDescription() {
- if (targets != null) {
- return "leading: " + targets.toString();
- }
- if (sources != null) {
- return "trailing: " + sources.toString();
- }
- return "--";
- }
- }
-
- // LinkInfo contains the set of ComponentInfosthat are linked along a
- // particular axis.
- private static final class LinkInfo {
- private final int axis;
- private final Vector linked;
- private int size;
-
- LinkInfo(int axis) {
- linked = new Vector();
- size = UNSET;
- this.axis = axis;
- }
-
- public void add(ComponentInfo child) {
- LinkInfo childMaster = child.getLinkInfo(axis, false);
- if (childMaster == null) {
- linked.addElement(child);
- child.setLinkInfo(axis, this);
- } else if (childMaster != this) {
- addAll(linked, childMaster.linked);
- for (int i = 0; i < childMaster.linked.size(); i++) {
- ComponentInfo childInfo = (ComponentInfo)childMaster.linked.elementAt(i);
- childInfo.setLinkInfo(axis, this);
- }
- }
- clearCachedSize();
- }
-
- public void remove(ComponentInfo info) {
- linked.removeElement(info);
- info.setLinkInfo(axis, null);
- if (linked.size() == 1) {
- ((ComponentInfo)linked.elementAt(0)).setLinkInfo(axis, null);
- }
- clearCachedSize();
- }
-
- public void clearCachedSize() {
- size = UNSET;
- }
-
- public int getSize(int axis) {
- if (size == UNSET) {
- size = calculateLinkedSize(axis);
- }
- return size;
- }
-
- private int calculateLinkedSize(int axis) {
- int size = 0;
- for (int i = 0; i < linked.size(); i++) {
- ComponentInfo info = (ComponentInfo)linked.elementAt(i);
- ComponentSpring spring;
- if (axis == HORIZONTAL) {
- spring = info.horizontalSpring;
- } else {
- //assert (axis == VERTICAL);
- spring = info.verticalSpring;
- }
- size = Math.max(size,
- spring.calculateNonlinkedPreferredSize(axis));
- }
- return size;
- }
- }
-
- /**
- * Tracks the horizontal/vertical Springs for a Component.
- * This class is also used to handle Springs that have their sizes
- * linked.
- */
- private final class ComponentInfo {
- // Component being layed out
- private Component component;
-
- ComponentSpring horizontalSpring;
- ComponentSpring verticalSpring;
-
- // If the component's size is linked to other components, the
- // horizontalMaster and/or verticalMaster reference the group of
- // linked components.
- private LinkInfo horizontalMaster;
- private LinkInfo verticalMaster;
- private boolean visible;
- private Boolean honorsVisibility;
-
- ComponentInfo(Component component) {
- this.component = component;
- updateVisibility();
- }
-
- public void dispose() {
- // Remove horizontal/vertical springs
- removeSpring(horizontalSpring);
- horizontalSpring = null;
- removeSpring(verticalSpring);
- verticalSpring = null;
- // Clean up links
- if (horizontalMaster != null) {
- horizontalMaster.remove(this);
- }
- if (verticalMaster != null) {
- verticalMaster.remove(this);
- }
- }
-
- void setHonorsVisibility(Boolean honorsVisibility) {
- this.honorsVisibility = honorsVisibility;
- }
- private void removeSpring(Spring spring) {
- if (spring != null) {
- ((Group)spring.getParent()).springs.removeElement(spring);
- }
- }
-
- public boolean isVisible() {
- return visible;
- }
-
- /**
- * Updates the cached visibility.
- *
- * @return true if the visibility changed
- */
- boolean updateVisibility() {
- boolean honorsVisibility;
- if (this.honorsVisibility == null) {
- honorsVisibility = GroupLayout.this.getHonorsVisibility();
- } else {
- honorsVisibility = this.honorsVisibility.booleanValue();
- }
- boolean newVisible = (honorsVisibility) ?
- component.isVisible() : true;
- if (visible != newVisible) {
- visible = newVisible;
- return true;
- }
- return false;
- }
-
- public void setBounds(int insetX, int insetY, int parentWidth, boolean ltr) {
- int x = horizontalSpring.getOrigin();
- int w = horizontalSpring.getSize();
- int y = verticalSpring.getOrigin();
- int h = verticalSpring.getSize();
-
- if (!ltr) {
- x = parentWidth - x - w;
- }
- component.setX(x + insetX);
- component.setY(y + insetY);
- component.setWidth(w);
- component.setHeight(h);
- }
-
- public void setComponent(Component component) {
- this.component = component;
- if (horizontalSpring != null) {
- horizontalSpring.setComponent(component);
- }
- if (verticalSpring != null) {
- verticalSpring.setComponent(component);
- }
- }
-
- public Component getComponent() {
- return component;
- }
-
- /**
- * Returns true if this component has its size linked to
- * other components.
- */
- public boolean isLinked(int axis) {
- if (axis == HORIZONTAL) {
- return horizontalMaster != null;
- }
- //assert (axis == VERTICAL);
- return (verticalMaster != null);
- }
-
- private void setLinkInfo(int axis, LinkInfo linkInfo) {
- if (axis == HORIZONTAL) {
- horizontalMaster = linkInfo;
- } else {
- //assert (axis == VERTICAL);
- verticalMaster = linkInfo;
- }
- }
-
- public LinkInfo getLinkInfo(int axis) {
- return getLinkInfo(axis, true);
- }
-
- private LinkInfo getLinkInfo(int axis, boolean create) {
- if (axis == HORIZONTAL) {
- if (horizontalMaster == null && create) {
- // horizontalMaster field is directly set by adding
- // us to the LinkInfo.
- new LinkInfo(HORIZONTAL).add(this);
- }
- return horizontalMaster;
- } else {
- //assert (axis == VERTICAL);
- if (verticalMaster == null && create) {
- // verticalMaster field is directly set by adding
- // us to the LinkInfo.
- new LinkInfo(VERTICAL).add(this);
- }
- return verticalMaster;
- }
- }
- public void clearCachedSize() {
- if (horizontalMaster != null) {
- horizontalMaster.clearCachedSize();
- }
- if (verticalMaster != null) {
- verticalMaster.clearCachedSize();
- }
- }
-
- int getLinkSize(int axis, int type) {
- if (axis == HORIZONTAL) {
- return horizontalMaster.getSize(axis);
- } else {
- //assert (axis == VERTICAL);
- return verticalMaster.getSize(axis);
- }
- }
- }
- }