* @param component the {@code Component} to add * @return this {@code Group} */ public Group addComponent(Component component) { return addComponent(component, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE); } /** * Adds a {@code Component} to this {@code Group} * with the specified size. * * @param component the {@code Component} to add * @param min the minimum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param pref the preferred size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param max the maximum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @return this {@code Group} */ public Group addComponent(Component component, int min, int pref, int max) { return addSpring(new ComponentSpring(component, min, pref, max)); } /** * Adds a rigid gap to this {@code Group}. * * @param size the size of the gap * @return this {@code Group} * @throws IllegalArgumentException if {@code size} is less than * {@code 0} */ public Group addGap(int size) { return addGap(size, size, size); } /** * Adds a gap to this {@code Group} 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 any of the values are * less than {@code 0} * @return this {@code Group} */ public Group addGap(int min, int pref, int max) { return addSpring(new GapSpring(min, pref, max)); } Spring getSpring(int index) { return springs.get(index); } int indexOf(Spring spring) { return springs.indexOf(spring); } /** * Adds the Spring to the list of {@code Spring}s and returns * the receiver. */ Group addSpring(Spring spring) { springs.add(spring); spring.setParent(this); if (!(spring instanceof AutoPreferredGapSpring) || !((AutoPreferredGapSpring)spring).getUserCreated()) { springsChanged = true; } return this; } // // Spring methods // void setSize(int axis, int origin, int size) { super.setSize(axis, origin, size); if (size == UNSET) { for (int counter = springs.size() - 1; counter >= 0; counter--) { getSpring(counter).setSize(axis, origin, size); } } else { setValidSize(axis, origin, size); } } /** * This is invoked from {@code setSize} if passed a value * other than UNSET. */ abstract void setValidSize(int axis, int origin, int size); int calculateMinimumSize(int axis) { return calculateSize(axis, MIN_SIZE); } int calculatePreferredSize(int axis) { return calculateSize(axis, PREF_SIZE); } int calculateMaximumSize(int axis) { return calculateSize(axis, MAX_SIZE); } /** * Calculates the specified size. This is called from * one of the {@code getMinimumSize0}, * {@code getPreferredSize0} or * {@code getMaximumSize0} methods. This will invoke * to {@code operator} to combine the values. */ int calculateSize(int axis, int type) { int count = springs.size(); if (count == 0) { return 0; } if (count == 1) { return getSpringSize(getSpring(0), axis, type); } int size = constrain(operator(getSpringSize(getSpring(0), axis, type), getSpringSize(getSpring(1), axis, type))); for (int counter = 2; counter < count; counter++) { size = constrain(operator(size, getSpringSize( getSpring(counter), axis, type))); } return size; } int getSpringSize(Spring spring, int axis, int type) { switch(type) { case MIN_SIZE: return spring.getMinimumSize(axis); case PREF_SIZE: return spring.getPreferredSize(axis); case MAX_SIZE: return spring.getMaximumSize(axis); } assert false; return 0; } /** * Used to compute how the two values representing two springs * will be combined. For example, a group that layed things out * one after the next would return {@code a + b}. */ abstract int operator(int a, int b); // // Padding // /** * Adjusts the autopadding springs in this group and its children. * If {@code insert} is true this will insert auto padding * springs, otherwise this will only adjust the springs that * comprise auto preferred padding springs. * * @param axis the axis of the springs; HORIZONTAL or VERTICAL * @param leadingPadding List of AutopaddingSprings that occur before * this Group * @param trailingPadding any trailing autopadding springs are added * to this on exit * @param leading List of ComponentSprings that occur before this Group * @param trailing any trailing ComponentSpring are added to this * List * @param insert Whether or not to insert AutopaddingSprings or just * adjust any existing AutopaddingSprings. */ abstract void insertAutopadding(int axis, List<AutoPreferredGapSpring> leadingPadding, List<AutoPreferredGapSpring> trailingPadding, List<ComponentSpring> leading, List<ComponentSpring> trailing, boolean insert); /** * Removes any AutopaddingSprings for this Group and its children. */ void removeAutopadding() { unset(); for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { if (((AutoPreferredGapSpring)spring).getUserCreated()) { ((AutoPreferredGapSpring)spring).reset(); } else { springs.remove(counter); } } else if (spring instanceof Group) { ((Group)spring).removeAutopadding(); } } } void unsetAutopadding() { // Clear cached pref/min/max. unset(); for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { spring.unset(); } else if (spring instanceof Group) { ((Group)spring).unsetAutopadding(); } } } void calculateAutopadding(int axis) { for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { // Force size to be reset. spring.unset(); ((AutoPreferredGapSpring)spring).calculatePadding(axis); } else if (spring instanceof Group) { ((Group)spring).calculateAutopadding(axis); } } // Clear cached pref/min/max. unset(); } @Override boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) { for (int i = springs.size() - 1; i >= 0; i--) { Spring spring = springs.get(i); if (!spring.willHaveZeroSize(treatAutopaddingAsZeroSized)) { return false; } } return true; } } /** * A {@code Group} that positions and sizes its elements * sequentially, one after another. This class has no public * constructor, use the {@code createSequentialGroup} method * to create one. * <p> * In order to align a {@code SequentialGroup} along the baseline * of a baseline aligned {@code ParallelGroup} you need to specify * which of the elements of the {@code SequentialGroup} is used to * determine the baseline. The element used to calculate the * baseline is specified using one of the {@code add} methods that * take a {@code boolean}. The last element added with a value of * {@code true} for {@code useAsBaseline} is used to calculate the * baseline. * * @see #createSequentialGroup * @since 1.6 */ public class SequentialGroup extends Group { private Spring baselineSpring; SequentialGroup() { } /** * {@inheritDoc} */ public SequentialGroup addGroup(Group group) { return (SequentialGroup)super.addGroup(group); } /** * Adds a {@code Group} to this {@code Group}. * * @param group the {@code Group} to add * @param useAsBaseline whether the specified {@code Group} should * be used to calculate the baseline for this {@code Group} * @return this {@code Group} */ public SequentialGroup addGroup(boolean useAsBaseline, Group group) { super.addGroup(group); if (useAsBaseline) { baselineSpring = group; } return this; } /** * {@inheritDoc} */ public SequentialGroup addComponent(Component component) { return (SequentialGroup)super.addComponent(component); } /** * Adds a {@code Component} to this {@code Group}. * * @param useAsBaseline whether the specified {@code Component} should * be used to calculate the baseline for this {@code Group} * @param component the {@code Component} to add * @return this {@code Group} */ public SequentialGroup addComponent(boolean useAsBaseline, Component component) { super.addComponent(component); if (useAsBaseline) { baselineSpring = springs.get(springs.size() - 1); } return this; } /** * {@inheritDoc} */ public SequentialGroup addComponent(Component component, int min, int pref, int max) { return (SequentialGroup)super.addComponent( component, min, pref, max); } /** * Adds a {@code Component} to this {@code Group} * with the specified size. * * @param useAsBaseline whether the specified {@code Component} should * be used to calculate the baseline for this {@code Group} * @param component the {@code Component} to add * @param min the minimum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param pref the preferred size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param max the maximum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @return this {@code Group} */ public SequentialGroup addComponent(boolean useAsBaseline, Component component, int min, int pref, int max) { super.addComponent(component, min, pref, max); if (useAsBaseline) { baselineSpring = springs.get(springs.size() - 1); } return this; } /** * {@inheritDoc} */ public SequentialGroup addGap(int size) { return (SequentialGroup)super.addGap(size); } /** * {@inheritDoc} */ public SequentialGroup addGap(int min, int pref, int max) { return (SequentialGroup)super.addGap(min, pref, max); } /** * Adds an element representing the preferred gap between two * components. The element created to represent the gap is not * resizable. * * @param comp1 the first component * @param comp2 the second component * @param type the type of gap; one of the constants defined by * {@code LayoutStyle} * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type}, {@code comp1} or * {@code comp2} is {@code null} * @see LayoutStyle */ public SequentialGroup addPreferredGap(JComponent comp1, JComponent comp2, ComponentPlacement type) { return addPreferredGap(comp1, comp2, type, DEFAULT_SIZE, PREFERRED_SIZE); } /** * Adds an element representing the preferred gap between two * components. * * @param comp1 the first component * @param comp2 the second component * @param type the type of gap * @param pref the preferred size of the grap; one of * {@code DEFAULT_SIZE} or a value >= 0 * @param max the maximum size of the gap; one of * {@code DEFAULT_SIZE}, {@code PREFERRED_SIZE} * or a value >= 0 * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type}, {@code comp1} or * {@code comp2} is {@code null} * @see LayoutStyle */ public SequentialGroup addPreferredGap(JComponent comp1, JComponent comp2, ComponentPlacement type, int pref, int max) { if (type == null) { throw new IllegalArgumentException("Type must be non-null"); } if (comp1 == null || comp2 == null) { throw new IllegalArgumentException( "Components must be non-null"); } checkPreferredGapValues(pref, max); return (SequentialGroup)addSpring(new PreferredGapSpring( comp1, comp2, type, pref, max)); } /** * Adds an element representing the preferred gap between the * nearest components. During layout, neighboring * components are found, and the size of the added gap is set * based on the preferred gap between the components. If no * neighboring components are found the gap has a size of {@code 0}. * <p> * The element created to represent the gap is not * resizable. * * @param type the type of gap; one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @return this {@code SequentialGroup} * @see LayoutStyle * @throws IllegalArgumentException if {@code type} is not one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} */ public SequentialGroup addPreferredGap(ComponentPlacement type) { return addPreferredGap(type, DEFAULT_SIZE, DEFAULT_SIZE); } /** * Adds an element representing the preferred gap between the * nearest components. During layout, neighboring * components are found, and the minimum of this * gap is set based on the size of the preferred gap between the * neighboring components. If no neighboring components are found the * minimum size is set to 0. * * @param type the type of gap; one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @param pref the preferred size of the grap; one of * {@code DEFAULT_SIZE} or a value >= 0 * @param max the maximum size of the gap; one of * {@code DEFAULT_SIZE}, {@code PREFERRED_SIZE} * or a value >= 0 * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type} is not one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @see LayoutStyle */ public SequentialGroup addPreferredGap(ComponentPlacement type, int pref, int max) { if (type != ComponentPlacement.RELATED && type != ComponentPlacement.UNRELATED) { throw new IllegalArgumentException( "Type must be one of " + "LayoutStyle.ComponentPlacement.RELATED or " + "LayoutStyle.ComponentPlacement.UNRELATED"); } checkPreferredGapValues(pref, max); hasPreferredPaddingSprings = true; return (SequentialGroup)addSpring(new AutoPreferredGapSpring( type, pref, max)); } /** * Adds an element representing the preferred gap between an edge * the container and components that touch the border of the * container. This has no effect if the added gap does not * touch an edge of the parent container. * <p> * The element created to represent the gap is not * resizable. * * @return this {@code SequentialGroup} */ 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 or previous {@code * Component} with the specified size. This has no * effect if the next or previous element is not a {@code * Component} and does not touch one edge of the parent * container. * * @param pref the preferred size; one of {@code DEFAULT_SIZE} or a * value >= 0 * @param max the maximum size; one of {@code DEFAULT_SIZE}, * {@code PREFERRED_SIZE} or a value >= 0 * @return this {@code SequentialGroup} */ public SequentialGroup addContainerGap(int pref, int max) { if ((pref < 0 && pref != DEFAULT_SIZE) ||Lines 1501–2000 of 3745. Previous lines Load more
* @param component the {@code Component} to add * @return this {@code Group} */ public Group addComponent(Component component) { return addComponent(component, DEFAULT_SIZE, DEFAULT_SIZE, DEFAULT_SIZE); } /** * Adds a {@code Component} to this {@code Group} * with the specified size. * * @param component the {@code Component} to add * @param min the minimum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param pref the preferred size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param max the maximum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @return this {@code Group} */ public Group addComponent(Component component, int min, int pref, int max) { return addSpring(new ComponentSpring(component, min, pref, max)); } /** * Adds a rigid gap to this {@code Group}. * * @param size the size of the gap * @return this {@code Group} * @throws IllegalArgumentException if {@code size} is less than * {@code 0} */ public Group addGap(int size) { return addGap(size, size, size); } /** * Adds a gap to this {@code Group} 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 any of the values are * less than {@code 0} * @return this {@code Group} */ public Group addGap(int min, int pref, int max) { return addSpring(new GapSpring(min, pref, max)); } Spring getSpring(int index) { return springs.get(index); } int indexOf(Spring spring) { return springs.indexOf(spring); } /** * Adds the Spring to the list of {@code Spring}s and returns * the receiver. */ Group addSpring(Spring spring) { springs.add(spring); spring.setParent(this); if (!(spring instanceof AutoPreferredGapSpring) || !((AutoPreferredGapSpring)spring).getUserCreated()) { springsChanged = true; } return this; } // // Spring methods // void setSize(int axis, int origin, int size) { super.setSize(axis, origin, size); if (size == UNSET) { for (int counter = springs.size() - 1; counter >= 0; counter--) { getSpring(counter).setSize(axis, origin, size); } } else { setValidSize(axis, origin, size); } } /** * This is invoked from {@code setSize} if passed a value * other than UNSET. */ abstract void setValidSize(int axis, int origin, int size); int calculateMinimumSize(int axis) { return calculateSize(axis, MIN_SIZE); } int calculatePreferredSize(int axis) { return calculateSize(axis, PREF_SIZE); } int calculateMaximumSize(int axis) { return calculateSize(axis, MAX_SIZE); } /** * Calculates the specified size. This is called from * one of the {@code getMinimumSize0}, * {@code getPreferredSize0} or * {@code getMaximumSize0} methods. This will invoke * to {@code operator} to combine the values. */ int calculateSize(int axis, int type) { int count = springs.size(); if (count == 0) { return 0; } if (count == 1) { return getSpringSize(getSpring(0), axis, type); } int size = constrain(operator(getSpringSize(getSpring(0), axis, type), getSpringSize(getSpring(1), axis, type))); for (int counter = 2; counter < count; counter++) { size = constrain(operator(size, getSpringSize( getSpring(counter), axis, type))); } return size; } int getSpringSize(Spring spring, int axis, int type) { switch(type) { case MIN_SIZE: return spring.getMinimumSize(axis); case PREF_SIZE: return spring.getPreferredSize(axis); case MAX_SIZE: return spring.getMaximumSize(axis); } assert false; return 0; } /** * Used to compute how the two values representing two springs * will be combined. For example, a group that layed things out * one after the next would return {@code a + b}. */ abstract int operator(int a, int b); // // Padding // /** * Adjusts the autopadding springs in this group and its children. * If {@code insert} is true this will insert auto padding * springs, otherwise this will only adjust the springs that * comprise auto preferred padding springs. * * @param axis the axis of the springs; HORIZONTAL or VERTICAL * @param leadingPadding List of AutopaddingSprings that occur before * this Group * @param trailingPadding any trailing autopadding springs are added * to this on exit * @param leading List of ComponentSprings that occur before this Group * @param trailing any trailing ComponentSpring are added to this * List * @param insert Whether or not to insert AutopaddingSprings or just * adjust any existing AutopaddingSprings. */ abstract void insertAutopadding(int axis, List<AutoPreferredGapSpring> leadingPadding, List<AutoPreferredGapSpring> trailingPadding, List<ComponentSpring> leading, List<ComponentSpring> trailing, boolean insert); /** * Removes any AutopaddingSprings for this Group and its children. */ void removeAutopadding() { unset(); for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { if (((AutoPreferredGapSpring)spring).getUserCreated()) { ((AutoPreferredGapSpring)spring).reset(); } else { springs.remove(counter); } } else if (spring instanceof Group) { ((Group)spring).removeAutopadding(); } } } void unsetAutopadding() { // Clear cached pref/min/max. unset(); for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { spring.unset(); } else if (spring instanceof Group) { ((Group)spring).unsetAutopadding(); } } } void calculateAutopadding(int axis) { for (int counter = springs.size() - 1; counter >= 0; counter--) { Spring spring = springs.get(counter); if (spring instanceof AutoPreferredGapSpring) { // Force size to be reset. spring.unset(); ((AutoPreferredGapSpring)spring).calculatePadding(axis); } else if (spring instanceof Group) { ((Group)spring).calculateAutopadding(axis); } } // Clear cached pref/min/max. unset(); } @Override boolean willHaveZeroSize(boolean treatAutopaddingAsZeroSized) { for (int i = springs.size() - 1; i >= 0; i--) { Spring spring = springs.get(i); if (!spring.willHaveZeroSize(treatAutopaddingAsZeroSized)) { return false; } } return true; } } /** * A {@code Group} that positions and sizes its elements * sequentially, one after another. This class has no public * constructor, use the {@code createSequentialGroup} method * to create one. * <p> * In order to align a {@code SequentialGroup} along the baseline * of a baseline aligned {@code ParallelGroup} you need to specify * which of the elements of the {@code SequentialGroup} is used to * determine the baseline. The element used to calculate the * baseline is specified using one of the {@code add} methods that * take a {@code boolean}. The last element added with a value of * {@code true} for {@code useAsBaseline} is used to calculate the * baseline. * * @see #createSequentialGroup * @since 1.6 */ public class SequentialGroup extends Group { private Spring baselineSpring; SequentialGroup() { } /** * {@inheritDoc} */ public SequentialGroup addGroup(Group group) { return (SequentialGroup)super.addGroup(group); } /** * Adds a {@code Group} to this {@code Group}. * * @param group the {@code Group} to add * @param useAsBaseline whether the specified {@code Group} should * be used to calculate the baseline for this {@code Group} * @return this {@code Group} */ public SequentialGroup addGroup(boolean useAsBaseline, Group group) { super.addGroup(group); if (useAsBaseline) { baselineSpring = group; } return this; } /** * {@inheritDoc} */ public SequentialGroup addComponent(Component component) { return (SequentialGroup)super.addComponent(component); } /** * Adds a {@code Component} to this {@code Group}. * * @param useAsBaseline whether the specified {@code Component} should * be used to calculate the baseline for this {@code Group} * @param component the {@code Component} to add * @return this {@code Group} */ public SequentialGroup addComponent(boolean useAsBaseline, Component component) { super.addComponent(component); if (useAsBaseline) { baselineSpring = springs.get(springs.size() - 1); } return this; } /** * {@inheritDoc} */ public SequentialGroup addComponent(Component component, int min, int pref, int max) { return (SequentialGroup)super.addComponent( component, min, pref, max); } /** * Adds a {@code Component} to this {@code Group} * with the specified size. * * @param useAsBaseline whether the specified {@code Component} should * be used to calculate the baseline for this {@code Group} * @param component the {@code Component} to add * @param min the minimum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param pref the preferred size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @param max the maximum size or one of {@code DEFAULT_SIZE} or * {@code PREFERRED_SIZE} * @return this {@code Group} */ public SequentialGroup addComponent(boolean useAsBaseline, Component component, int min, int pref, int max) { super.addComponent(component, min, pref, max); if (useAsBaseline) { baselineSpring = springs.get(springs.size() - 1); } return this; } /** * {@inheritDoc} */ public SequentialGroup addGap(int size) { return (SequentialGroup)super.addGap(size); } /** * {@inheritDoc} */ public SequentialGroup addGap(int min, int pref, int max) { return (SequentialGroup)super.addGap(min, pref, max); } /** * Adds an element representing the preferred gap between two * components. The element created to represent the gap is not * resizable. * * @param comp1 the first component * @param comp2 the second component * @param type the type of gap; one of the constants defined by * {@code LayoutStyle} * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type}, {@code comp1} or * {@code comp2} is {@code null} * @see LayoutStyle */ public SequentialGroup addPreferredGap(JComponent comp1, JComponent comp2, ComponentPlacement type) { return addPreferredGap(comp1, comp2, type, DEFAULT_SIZE, PREFERRED_SIZE); } /** * Adds an element representing the preferred gap between two * components. * * @param comp1 the first component * @param comp2 the second component * @param type the type of gap * @param pref the preferred size of the grap; one of * {@code DEFAULT_SIZE} or a value >= 0 * @param max the maximum size of the gap; one of * {@code DEFAULT_SIZE}, {@code PREFERRED_SIZE} * or a value >= 0 * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type}, {@code comp1} or * {@code comp2} is {@code null} * @see LayoutStyle */ public SequentialGroup addPreferredGap(JComponent comp1, JComponent comp2, ComponentPlacement type, int pref, int max) { if (type == null) { throw new IllegalArgumentException("Type must be non-null"); } if (comp1 == null || comp2 == null) { throw new IllegalArgumentException( "Components must be non-null"); } checkPreferredGapValues(pref, max); return (SequentialGroup)addSpring(new PreferredGapSpring( comp1, comp2, type, pref, max)); } /** * Adds an element representing the preferred gap between the * nearest components. During layout, neighboring * components are found, and the size of the added gap is set * based on the preferred gap between the components. If no * neighboring components are found the gap has a size of {@code 0}. * <p> * The element created to represent the gap is not * resizable. * * @param type the type of gap; one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @return this {@code SequentialGroup} * @see LayoutStyle * @throws IllegalArgumentException if {@code type} is not one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} */ public SequentialGroup addPreferredGap(ComponentPlacement type) { return addPreferredGap(type, DEFAULT_SIZE, DEFAULT_SIZE); } /** * Adds an element representing the preferred gap between the * nearest components. During layout, neighboring * components are found, and the minimum of this * gap is set based on the size of the preferred gap between the * neighboring components. If no neighboring components are found the * minimum size is set to 0. * * @param type the type of gap; one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @param pref the preferred size of the grap; one of * {@code DEFAULT_SIZE} or a value >= 0 * @param max the maximum size of the gap; one of * {@code DEFAULT_SIZE}, {@code PREFERRED_SIZE} * or a value >= 0 * @return this {@code SequentialGroup} * @throws IllegalArgumentException if {@code type} is not one of * {@code LayoutStyle.ComponentPlacement.RELATED} or * {@code LayoutStyle.ComponentPlacement.UNRELATED} * @see LayoutStyle */ public SequentialGroup addPreferredGap(ComponentPlacement type, int pref, int max) { if (type != ComponentPlacement.RELATED && type != ComponentPlacement.UNRELATED) { throw new IllegalArgumentException( "Type must be one of " + "LayoutStyle.ComponentPlacement.RELATED or " + "LayoutStyle.ComponentPlacement.UNRELATED"); } checkPreferredGapValues(pref, max); hasPreferredPaddingSprings = true; return (SequentialGroup)addSpring(new AutoPreferredGapSpring( type, pref, max)); } /** * Adds an element representing the preferred gap between an edge * the container and components that touch the border of the * container. This has no effect if the added gap does not * touch an edge of the parent container. * <p> * The element created to represent the gap is not * resizable. * * @return this {@code SequentialGroup} */ 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 or previous {@code * Component} with the specified size. This has no * effect if the next or previous element is not a {@code * Component} and does not touch one edge of the parent * container. * * @param pref the preferred size; one of {@code DEFAULT_SIZE} or a * value >= 0 * @param max the maximum size; one of {@code DEFAULT_SIZE}, * {@code PREFERRED_SIZE} or a value >= 0 * @return this {@code SequentialGroup} */ public SequentialGroup addContainerGap(int pref, int max) { if ((pref < 0 && pref != DEFAULT_SIZE) ||