/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation. Oracle designates this
* particular file as subject to the "Classpath" exception as provided
* by Oracle in the LICENSE file that accompanied this code.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/
/**
* {@code GroupLayout} is a {@code LayoutManager} that hierarchically
* groups components in order to position them in a {@code Container}.
* {@code GroupLayout} is intended for use by builders, but may be
* hand-coded as well.
* Grouping is done by instances of the {@link Group Group} class. {@code
* GroupLayout} supports two types of groups. A sequential group
* positions its child elements sequentially, one after another. A
* parallel group aligns its child elements in one of four ways.
* <p>
* Each group may contain any number of elements, where an element is
* a {@code Group}, {@code Component}, or gap. A gap can be thought
* of as an invisible component with a minimum, preferred and maximum
* size. In addition {@code GroupLayout} supports a preferred gap,
* whose value comes from {@code LayoutStyle}.
* <p>
* Elements are similar to a spring. Each element has a range as
* specified by a minimum, preferred and maximum. Gaps have either a
* developer-specified range, or a range determined by {@code
* LayoutStyle}. The range for {@code Component}s is determined from
* the {@code Component}'s {@code getMinimumSize}, {@code
* getPreferredSize} and {@code getMaximumSize} methods. In addition,
* when adding {@code Component}s you may specify a particular range
* to use instead of that from the component. The range for a {@code
* Group} is determined by the type of group. A {@code ParallelGroup}'s
* range is the maximum of the ranges of its elements. A {@code
* SequentialGroup}'s range is the sum of the ranges of its elements.
* <p>
* {@code GroupLayout} treats each axis independently. That is, there
* is a group representing the horizontal axis, and a group
* representing the vertical axis. The horizontal group is
* responsible for determining the minimum, preferred and maximum size
* along the horizontal axis as well as setting the x and width of the
* components contained in it. The vertical group is responsible for
* determining the minimum, preferred and maximum size along the
* vertical axis as well as setting the y and height of the
* components contained in it. Each {@code Component} must exist in both
* a horizontal and vertical group, otherwise an {@code IllegalStateException}
* is thrown during layout, or when the minimum, preferred or
* maximum size is requested.
* <p>
* The following diagram shows a sequential group along the horizontal
* axis. The sequential group contains three components. A parallel group
* was used along the vertical axis.
* <p align="center">
* <img src="doc-files/groupLayout.1.gif">
* <p>
* To reinforce that each axis is treated independently the diagram shows
* the range of each group and element along each axis. The
* range of each component has been projected onto the axes,
* and the groups are rendered in blue (horizontal) and red (vertical).
* For readability there is a gap between each of the elements in the
* sequential group.
* <p>
* The sequential group along the horizontal axis is rendered as a solid
* blue line. Notice the sequential group is the sum of the children elements
* it contains.
* <p>
* Along the vertical axis the parallel group is the maximum of the height
* of each of the components. As all three components have the same height,
* the parallel group has the same height.
* <p>
* The following diagram shows the same three components, but with the
* parallel group along the horizontal axis and the sequential group along
* the vertical axis.
* <p>
* <p align="center">
* <img src="doc-files/groupLayout.2.gif">
* <p>
* As {@code c1} is the largest of the three components, the parallel
* group is sized to {@code c1}. As {@code c2} and {@code c3} are smaller
* than {@code c1} they are aligned based on the alignment specified
* for the component (if specified) or the default alignment of the
* parallel group. In the diagram {@code c2} and {@code c3} were created
* with an alignment of {@code LEADING}. If the component orientation were
* right-to-left then {@code c2} and {@code c3} would be positioned on
* the opposite side.
* <p>
* The following diagram shows a sequential group along both the horizontal
* and vertical axis.
* <p align="center">
* <img src="doc-files/groupLayout.3.gif">
* <p>
* {@code GroupLayout} provides the ability to insert gaps between
* {@code Component}s. The size of the gap is determined by an
* instance of {@code LayoutStyle}. This may be turned on using the
* {@code setAutoCreateGaps} method. Similarly, you may use
* the {@code setAutoCreateContainerGaps} method to insert gaps
* between components that touch the edge of the parent container and the
* container.
* <p>
* The following builds a panel consisting of two labels in
* one column, followed by two textfields in the next column:
* <pre>
* JComponent panel = ...;
* GroupLayout layout = new GroupLayout(panel);
* panel.setLayout(layout);
*
* // Turn on automatically adding gaps between components
* layout.setAutoCreateGaps(true);
*
* // Turn on automatically creating gaps between components that touch
* // the edge of the container and the container.
* layout.setAutoCreateContainerGaps(true);
*
* // Create a sequential group for the horizontal axis.
*
* GroupLayout.SequentialGroup hGroup = layout.createSequentialGroup();
*
* // The sequential group in turn contains two parallel groups.
* // One parallel group contains the labels, the other the text fields.
* // Putting the labels in a parallel group along the horizontal axis
* // positions them at the same x location.
* //
* // Variable indentation is used to reinforce the level of grouping.
* hGroup.addGroup(layout.createParallelGroup().
* addComponent(label1).addComponent(label2));
* hGroup.addGroup(layout.createParallelGroup().
* addComponent(tf1).addComponent(tf2));
* layout.setHorizontalGroup(hGroup);
*
* // Create a sequential group for the vertical axis.
* GroupLayout.SequentialGroup vGroup = layout.createSequentialGroup();
*
* // The sequential group contains two parallel groups that align
* // the contents along the baseline. The first parallel group contains
* // the first label and text field, and the second parallel group contains
* // the second label and text field. By using a sequential group
* // the labels and text fields are positioned vertically after one another.
* vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
* addComponent(label1).addComponent(tf1));
* vGroup.addGroup(layout.createParallelGroup(Alignment.BASELINE).
* addComponent(label2).addComponent(tf2));
* layout.setVerticalGroup(vGroup);
* </pre>
* <p>
* When run the following is produced.
* <p align="center">
* <img src="doc-files/groupLayout.example.png">
* <p>
* This layout consists of the following.
* <ul><li>The horizontal axis consists of a sequential group containing two
* parallel groups. The first parallel group contains the labels,
* and the second parallel group contains the text fields.
* <li>The vertical axis consists of a sequential group
* containing two parallel groups. The parallel groups are configured
* to align their components along the baseline. The first parallel
* group contains the first label and first text field, and
* the second group consists of the second label and second
* text field.
* </ul>
* There are a couple of things to notice in this code:
* <ul>
* <li>You need not explicitly add the components to the container; this
* is indirectly done by using one of the {@code add} methods of
* {@code Group}.
* <li>The various {@code add} methods return
* the caller. This allows for easy chaining of invocations. For
* example, {@code group.addComponent(label1).addComponent(label2);} is
* equivalent to
* {@code group.addComponent(label1); group.addComponent(label2);}.
* <li>There are no public constructors for {@code Group}s; instead
* use the create methods of {@code GroupLayout}.
* </ul>
*
* @author Tomas Pavek
* @author Jan Stola
* @author Scott Violet
* @since 1.6
*/
// Used in size calculations
// Used by prepare, indicates min, pref or max isn't going to be used.
/**
* Indicates the size from the component or gap should be used for a
* particular range value.
*
* @see Group
*/
/**
* Indicates the preferred size from the component or gap should
* be used for a particular range value.
*
* @see Group
*/
// Whether or not we automatically try and create the preferred
// padding between components.
private boolean autocreatePadding;
// Whether or not we automatically try and create the preferred
// padding between components the touch the edge of the container and
// the container.
private boolean autocreateContainerPadding;
/**
* Group responsible for layout along the horizontal axis. This is NOT
* the user specified group, use getHorizontalGroup to dig that out.
*/
/**
* Group responsible for layout along the vertical axis. This is NOT
* the user specified group, use getVerticalGroup to dig that out.
*/
// Maps from Component to ComponentInfo. This is used for tracking
// information specific to a Component.
// Container we're doing layout for.
// Used by areParallelSiblings, cached to avoid excessive garbage.
// Indicates Springs have changed in some way since last change.
private boolean springsChanged;
// Indicates invalidateLayout has been invoked.
private boolean isValid;
// Whether or not any preferred padding (or container padding) springs
// exist
private boolean hasPreferredPaddingSprings;
/**
* The LayoutStyle instance to use, if null the sharedInstance is used.
*/
/**
* If true, components that are not visible are treated as though they
* aren't there.
*/
private boolean honorsVisibility;
/**
* Enumeration of the possible ways {@code ParallelGroup} can align
* its children.
*
* @see #createParallelGroup(Alignment)
* @since 1.6
*/
public enum Alignment {
/**
* Indicates the elements should be
* aligned to the origin. For the horizontal axis with a left to
* right orientation this means aligned to the left edge. For the
* vertical axis leading means aligned to the top edge.
*
* @see #createParallelGroup(Alignment)
*/
/**
* Indicates the elements should be aligned to the end of the
* region. For the horizontal axis with a left to right
* orientation this means aligned to the right edge. For the
* vertical axis trailing means aligned to the bottom edge.
*
* @see #createParallelGroup(Alignment)
*/
/**
* Indicates the elements should be centered in
* the region.
*
* @see #createParallelGroup(Alignment)
*/
/**
* Indicates the elements should be aligned along
* their baseline.
*
* @see #createParallelGroup(Alignment)
* @see #createBaselineGroup(boolean,boolean)
*/
}
boolean isComponentSpring) {
throw new IllegalArgumentException("Pref must be >= 0");
} else if (isComponentSpring) {
checkResizeType(pref, true);
}
}
type != PREFERRED_SIZE) ||
throw new IllegalArgumentException("Invalid size");
}
}
throw new IllegalArgumentException(
"Following is not met: min<=pref<=max");
}
}
/**
* Creates a {@code GroupLayout} for the specified {@code Container}.
*
* @param host the {@code Container} the {@code GroupLayout} is
* the {@code LayoutManager} for
* @throws IllegalArgumentException if host is {@code null}
*/
throw new IllegalArgumentException("Container must be non-null");
}
honorsVisibility = true;
}
/**
* Sets whether component visiblity is considered when sizing and
* positioning components. A value of {@code true} indicates that
* non-visible components should not be treated as part of the
* layout. A value of {@code false} indicates that components should be
* positioned and sized regardless of visibility.
* <p>
* A value of {@code false} is useful when the visibility of components
* is dynamically adjusted and you don't want surrounding components and
* the sizing to change.
* <p>
* The specified value is used for components that do not have an
* explicit visibility specified.
* <p>
* The default is {@code true}.
*
* @param honorsVisibility whether component visiblity is considered when
* sizing and positioning components
* @see #setHonorsVisibility(Component,Boolean)
*/
if (this.honorsVisibility != honorsVisibility) {
this.honorsVisibility = honorsVisibility;
springsChanged = true;
isValid = false;
}
}
/**
* Returns whether component visiblity is considered when sizing and
* positioning components.
*
* @return whether component visiblity is considered when sizing and
* positioning components
*/
public boolean getHonorsVisibility() {
return honorsVisibility;
}
/**
* Sets whether the component's visiblity is considered for
* sizing and positioning. A value of {@code Boolean.TRUE}
* indicates that if {@code component} is not visible it should
* not be treated as part of the layout. A value of {@code false}
* indicates that {@code component} is positioned and sized
* regardless of it's visibility. A value of {@code null}
* indicates the value specified by the single argument method {@code
* setHonorsVisibility} should be used.
* <p>
* If {@code component} is not a child of the {@code Container} this
* {@code GroupLayout} is managine, it will be added to the
* {@code Container}.
*
* @param component the component
* @param honorsVisibility whether {@code component}'s visiblity should be
* considered for sizing and positioning
* @throws IllegalArgumentException if {@code component} is {@code null}
* @see #setHonorsVisibility(Component,Boolean)
*/
throw new IllegalArgumentException("Component must be non-null");
}
springsChanged = true;
isValid = false;
}
/**
* Sets whether a gap between components should automatically be
* created. For example, if this is {@code true} and you add two
* components to a {@code SequentialGroup} a gap between the
* two components is automatically be created. The default is
* {@code false}.
*
* @param autoCreatePadding whether a gap between components is
* automatically created
*/
if (this.autocreatePadding != autoCreatePadding) {
this.autocreatePadding = autoCreatePadding;
}
}
/**
* Returns {@code true} if gaps between components are automatically
* created.
*
* @return {@code true} if gaps between components are automatically
* created
*/
public boolean getAutoCreateGaps() {
return autocreatePadding;
}
/**
* Sets whether a gap between the container and components that
* touch the border of the container should automatically be
* created. The default is {@code false}.
*
* @param autoCreateContainerPadding whether a gap between the container and
* components that touch the border of the container should
* automatically be created
*/
if (this.autocreateContainerPadding != autoCreateContainerPadding) {
}
}
/**
* Returns {@code true} if gaps between the container and components that
* border the container are automatically created.
*
* @return {@code true} if gaps between the container and components that
* border the container are automatically created
*/
public boolean getAutoCreateContainerGaps() {
return autocreateContainerPadding;
}
/**
* Sets the {@code Group} that positions and sizes
* components along the horizontal axis.
*
* @param group the {@code Group} that positions and sizes
* components along the horizontal axis
* @throws IllegalArgumentException if group is {@code null}
*/
throw new IllegalArgumentException("Group must be non-null");
}
}
/**
* Returns the {@code Group} that positions and sizes components
* along the horizontal axis.
*
* @return the {@code Group} responsible for positioning and
* sizing component along the horizontal axis
*/
int index = 0;
index = 1;
}
}
/**
* Sets the {@code Group} that positions and sizes
* components along the vertical axis.
*
* @param group the {@code Group} that positions and sizes
* components along the vertical axis
* @throws IllegalArgumentException if group is {@code null}
*/
throw new IllegalArgumentException("Group must be non-null");
}
}
/**
* Returns the {@code Group} that positions and sizes components
* along the vertical axis.
*
* @return the {@code Group} responsible for positioning and
* sizing component along the vertical axis
*/
int index = 0;
index = 1;
}
}
/**
* Wraps the user specified group in a sequential group. If
* container gaps should be generated the necessary springs are
* added.
*/
if (getAutoCreateContainerGaps()) {
} else {
}
return group;
}
/**
* Creates and returns a {@code SequentialGroup}.
*
* @return a new {@code SequentialGroup}
*/
return new SequentialGroup();
}
/**
* Creates and returns a {@code ParallelGroup} with an alignment of
* {@code Alignment.LEADING}. This is a cover method for the more
* general {@code createParallelGroup(Alignment)} method.
*
* @return a new {@code ParallelGroup}
* @see #createParallelGroup(Alignment)
*/
}
/**
* Creates and returns a {@code ParallelGroup} with the specified
* alignment. This is a cover method for the more general {@code
* createParallelGroup(Alignment,boolean)} method with {@code true}
* supplied for the second argument.
*
* @param alignment the alignment for the elements of the group
* @throws IllegalArgumentException if {@code alignment} is {@code null}
* @return a new {@code ParallelGroup}
* @see #createBaselineGroup
* @see ParallelGroup
*/
return createParallelGroup(alignment, true);
}
/**
* Creates and returns a {@code ParallelGroup} with the specified
* alignment and resize behavior. The {@code
* alignment} argument specifies how children elements are
* positioned that do not fill the group. For example, if a {@code
* ParallelGroup} with an alignment of {@code TRAILING} is given
* 100 and a child only needs 50, the child is
* positioned at the position 50 (with a component orientation of
* left-to-right).
* <p>
* Baseline alignment is only useful when used along the vertical
* axis. A {@code ParallelGroup} created with a baseline alignment
* along the horizontal axis is treated as {@code LEADING}.
* <p>
* Refer to {@link GroupLayout.ParallelGroup ParallelGroup} for details on
* the behavior of baseline groups.
*
* @param alignment the alignment for the elements of the group
* @param resizable {@code true} if the group is resizable; if the group
* is not resizable the preferred size is used for the
* minimum and maximum size of the group
* @throws IllegalArgumentException if {@code alignment} is {@code null}
* @return a new {@code ParallelGroup}
* @see #createBaselineGroup
* @see GroupLayout.ParallelGroup
*/
boolean resizable){
throw new IllegalArgumentException("alignment must be non null");
}
return new BaselineGroup(resizable);
}
}
/**
* Creates and returns a {@code ParallelGroup} that aligns it's
* elements along the baseline.
*
* @param resizable whether the group is resizable
* @param anchorBaselineToTop whether the baseline is anchored to
* the top or bottom of the group
* @see #createBaselineGroup
* @see ParallelGroup
*/
boolean anchorBaselineToTop) {
}
/**
* Forces the specified components to have the same size
* regardless of their preferred, minimum or maximum sizes. Components that
* are linked are given the maximum of the preferred size of each of
* the linked components. For example, if you link two components with
* a preferred width of 10 and 20, both components are given a width of 20.
* <p>
* This can be used multiple times to force any number of
* components to share the same size.
* <p>
* Linked Components are not be resizable.
*
* @param components the {@code Component}s that are to have the same size
* @throws IllegalArgumentException if {@code components} is
* {@code null}, or contains {@code null}
* @see #linkSize(int,Component[])
*/
}
/**
* Forces the specified components to have the same size along the
* specified axis regardless of their preferred, minimum or
* maximum sizes. Components that are linked are given the maximum
* of the preferred size of each of the linked components. For
* example, if you link two components along the horizontal axis
* and the preferred width is 10 and 20, both components are given
* a width of 20.
* <p>
* This can be used multiple times to force any number of
* components to share the same size.
* <p>
* Linked {@code Component}s are not be resizable.
*
* @param components the {@code Component}s that are to have the same size
* @param axis the axis to link the size along; one of
* {@code SwingConstants.HORIZONTAL} or
* {@code SwingConstans.VERTICAL}
* @throws IllegalArgumentException if {@code components} is
* {@code null}, or contains {@code null}; or {@code axis}
* is not {@code SwingConstants.HORIZONTAL} or
* {@code SwingConstants.VERTICAL}
*/
if (components == null) {
throw new IllegalArgumentException("Components must be non-null");
}
throw new IllegalArgumentException(
"Components must be non-null");
}
// Force the component to be added
getComponentInfo(c);
}
int glAxis;
glAxis = HORIZONTAL;
} else {
throw new IllegalArgumentException("Axis must be one of " +
"SwingConstants.HORIZONTAL or SwingConstants.VERTICAL");
}
}
}
/**
* Replaces an existing component with a new one.
*
* @param existingComponent the component that should be removed
* and replaced with {@code newComponent}
* @param newComponent the component to put in
* {@code existingComponent}'s place
* @throws IllegalArgumentException if either of the components are
* {@code null} or {@code existingComponent} is not being managed
* by this layout manager
*/
throw new IllegalArgumentException("Components must be non-null");
}
// Make sure all the components have been registered, otherwise we may
// not update the correct Springs.
if (springsChanged) {
}
throw new IllegalArgumentException("Component must already exist");
}
}
}
/**
* Sets the {@code LayoutStyle} used to calculate the preferred
* gaps between components. A value of {@code null} indicates the
* shared instance of {@code LayoutStyle} should be used.
*
* @param layoutStyle the {@code LayoutStyle} to use
* @see LayoutStyle
*/
this.layoutStyle = layoutStyle;
}
/**
* Returns the {@code LayoutStyle} used for calculating the preferred
* gap between components. This returns the value specified to
* {@code setLayoutStyle}, which may be {@code null}.
*
* @return the {@code LayoutStyle} used for calculating the preferred
* gap between components
*/
return layoutStyle;
}
if (layoutStyle == null) {
}
return layoutStyle;
}
private void invalidateHost() {
if (host instanceof JComponent) {
} else {
host.invalidate();
}
}
//
// LayoutManager
//
/**
* Notification that a {@code Component} has been added to
* the parent container. You should not invoke this method
* directly, instead you should use one of the {@code Group}
* methods to add a {@code Component}.
*
* @param name the string to be associated with the component
* @param component the {@code Component} to be added
*/
}
/**
* Notification that a {@code Component} has been removed from
* the parent container. You should not invoke this method
* directly, instead invoke {@code remove} on the parent
* {@code Container}.
*
* @param component the component to be removed
* @see java.awt.Component#remove
*/
springsChanged = true;
isValid = false;
}
}
/**
* Returns the preferred size for the specified container.
*
* @param parent the container to return the preferred size for
* @return the preferred size for {@code parent}
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} this was created with
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
* @see java.awt.Container#getPreferredSize
*/
}
/**
* Returns the minimum size for the specified container.
*
* @param parent the container to return the size for
* @return the minimum size for {@code parent}
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} that this was created with
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
* @see java.awt.Container#getMinimumSize
*/
}
/**
* Lays out the specified container.
*
* @param parent the container to be laid out
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
*/
// Step 1: Prepare for layout.
boolean ltr = isLeftToRight();
if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
// Step 2: Calculate autopadding springs
width);
height);
}
// Step 3: set the size of the groups.
// Step 4: apply the size to the components.
}
}
//
// LayoutManager2
//
/**
* Notification that a {@code Component} has been added to
* the parent container. You should not invoke this method
* directly, instead you should use one of the {@code Group}
* methods to add a {@code Component}.
*
* @param component the component added
* @param constraints description of where to place the component
*/
}
/**
* Returns the maximum size for the specified container.
*
* @param parent the container to return the size for
* @return the maximum size for {@code parent}
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} that this was created with
* @throws IllegalStateException if any of the components added to
* this layout are not in both a horizontal and vertical group
* @see java.awt.Container#getMaximumSize
*/
}
/**
* Returns the alignment along the x axis. This specifies how
* the component would like to be aligned relative to other
* components. The value should be a number between 0 and 1
* where 0 represents alignment along the origin, 1 is aligned
* the furthest away from the origin, 0.5 is centered, etc.
*
* @param parent the {@code Container} hosting this {@code LayoutManager}
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} that this was created with
* @return the alignment; this implementation returns {@code .5}
*/
return .5f;
}
/**
* Returns the alignment along the y axis. This specifies how
* the component would like to be aligned relative to other
* components. The value should be a number between 0 and 1
* where 0 represents alignment along the origin, 1 is aligned
* the furthest away from the origin, 0.5 is centered, etc.
*
* @param parent the {@code Container} hosting this {@code LayoutManager}
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} that this was created with
* @return alignment; this implementation returns {@code .5}
*/
return .5f;
}
/**
* Invalidates the layout, indicating that if the layout manager
* has cached information it should be discarded.
*
* @param parent the {@code Container} hosting this LayoutManager
* @throws IllegalArgumentException if {@code parent} is not
* the same {@code Container} that this was created with
*/
// invalidateLayout is called from Container.invalidate, which
// does NOT grab the treelock. All other methods do. To make sure
// there aren't any possible threading problems we grab the tree lock
// here.
synchronized(parent.getTreeLock()) {
isValid = false;
}
}
boolean visChanged = false;
// Step 1: If not-valid, clear springs and update visibility.
if (!isValid) {
isValid = true;
if (ci.updateVisibility()) {
visChanged = true;
}
}
}
// Step 2: Make sure components are bound to ComponentInfos
if (springsChanged) {
}
// Step 3: Adjust the autopadding. This removes existing
// autopadding, then recalculates where it should go.
if (springsChanged || visChanged) {
if (getAutoCreateGaps()) {
insertAutopadding(true);
} else if (hasPreferredPaddingSprings ||
insertAutopadding(false);
}
springsChanged = false;
}
// autopadding. This invokes for unsetting the calculated values, then
// recalculating them.
// If sizeType == SPECIFIC_SIZE, it indicates we're doing layout, this
// step will be done later on.
}
}
switch(sizeType) {
case MIN_SIZE:
break;
case PREF_SIZE:
break;
case MAX_SIZE:
break;
default:
break;
}
}
private void checkComponents() {
" is not attached to a horizontal group");
}
" is not attached to a vertical group");
}
}
}
if (spring instanceof ComponentSpring) {
}
}
}
}
throw new IllegalArgumentException(
"GroupLayout can only be used with one Container at a time");
}
}
/**
* Returns the {@code ComponentInfo} for the specified Component,
* creating one if necessary.
*/
}
}
return info;
}
/**
* Adjusts the autopadding springs for the horizontal and vertical
* groups. If {@code insert} is {@code true} this will insert auto padding
* springs, otherwise this will only adjust the springs that
* comprise auto preferred padding springs.
*/
}
/**
* Returns {@code true} if the two Components have a common ParallelGroup
* ancestor along the particular axis.
*/
int axis) {
if (axis == HORIZONTAL) {
} else {
}
sourcePath.clear();
}
sourcePath.clear();
if (spring instanceof ParallelGroup) {
return true;
}
}
return false;
}
}
sourcePath.clear();
return false;
}
private boolean isLeftToRight() {
}
/**
* Returns a string representation of this {@code GroupLayout}.
* This method is intended to be used for debugging purposes,
* and the content and format of the returned string may vary
* between implementations.
*
* @return a string representation of this {@code GroupLayout}
**/
if (springsChanged) {
}
}
if (spring instanceof ComponentSpring) {
}
}
if (spring instanceof AutoPreferredGapSpring) {
}
origin +
padding + "]\n");
indent += " ";
axis);
}
}
}
/**
* Spring consists of a range: min, pref and max, a value some where in
* the middle of that, and a location. Spring caches the
* to be updated you must invoke clear.
*/
private abstract class Spring {
private int size;
private int min;
private int max;
private int pref;
Spring() {
}
/**
* Calculates and returns the minimum size.
*
* @param axis the axis of layout; one of HORIZONTAL or VERTICAL
* @return the minimum size
*/
/**
* Calculates and returns the preferred size.
*
* @param axis the axis of layout; one of HORIZONTAL or VERTICAL
* @return the preferred size
*/
/**
* Calculates and returns the minimum size.
*
* @param axis the axis of layout; one of HORIZONTAL or VERTICAL
* @return the minimum size
*/
/**
* Sets the parent of this Spring.
*/
}
/**
* Returns the parent of this spring.
*/
return parent;
}
// This is here purely as a conveniance for ParallelGroup to avoid
// having to track alignment separately.
}
/**
* Alignment for this Spring, this may be null.
*/
return alignment;
}
/**
* Returns the minimum size.
*/
}
return min;
}
/**
* Returns the preferred size.
*/
}
return pref;
}
/**
* Returns the maximum size.
*/
}
return max;
}
/**
* Sets the value and location of the spring. Subclasses
* will want to invoke super, then do any additional sizing.
*
* @param axis HORIZONTAL or VERTICAL
* @param origin of this Spring
* @param size of the Spring. If size is UNSET, this invokes
* clear.
*/
unset();
}
}
/**
*/
void unset() {
}
/**
* Returns the current size.
*/
int getSize() {
return size;
}
}
int getBaseline() {
return -1;
}
return BaselineResizeBehavior.OTHER;
}
}
/**
* Returns {@code true} if this spring will ALWAYS have a zero
* size. This should NOT check the current size, rather it's
* meant to quickly test if this Spring will always have a
* zero size.
*
* @param treatAutopaddingAsZeroSized if {@code true}, auto padding
* springs should be treated as having a size of {@code 0}
* @return {@code true} if this spring will have a zero size,
* {@code false} otherwise
*/
}
/**
* {@code Group} provides the basis for the two types of
* operations supported by {@code GroupLayout}: laying out
* components one after another ({@link SequentialGroup SequentialGroup})
* or aligned ({@link ParallelGroup ParallelGroup}). {@code Group} and
* its subclasses have no public constructor; to create one use
* one of {@code createSequentialGroup} or
* {@code createParallelGroup}. Additionally, taking a {@code Group}
* created from one {@code GroupLayout} and using it with another
* will produce undefined results.
* <p>
* Various methods in {@code Group} and its subclasses allow you
* to explicitly specify the range. The arguments to these methods
* can take two forms, either a value greater than or equal to 0,
* or one of {@code DEFAULT_SIZE} or {@code PREFERRED_SIZE}. A
* value greater than or equal to {@code 0} indicates a specific
* size. {@code DEFAULT_SIZE} indicates the corresponding size
* from the component should be used. For example, if {@code
* DEFAULT_SIZE} is passed as the minimum size argument, the
* minimum size is obtained from invoking {@code getMinimumSize}
* on the component. Likewise, {@code PREFERRED_SIZE} indicates
* the value from {@code getPreferredSize} should be used.
* The following example adds {@code myComponent} to {@code group}
* with specific values for the range. That is, the minimum is
* explicitly specified as 100, preferred as 200, and maximum as
* 300.
* <pre>
* group.addComponent(myComponent, 100, 200, 300);
* </pre>
* The following example adds {@code myComponent} to {@code group} using
* a combination of the forms. The minimum size is forced to be the
* same as the preferred size, the preferred size is determined by
* using {@code myComponent.getPreferredSize} and the maximum is
* determined by invoking {@code getMaximumSize} on the component.
* <pre>
* group.addComponent(myComponent, GroupLayout.PREFERRED_SIZE,
* GroupLayout.PREFERRED_SIZE, GroupLayout.DEFAULT_SIZE);
* </pre>
* <p>
* Unless otherwise specified all the methods of {@code Group} and
* its subclasses that allow you to specify a range throw an
* {@code IllegalArgumentException} if passed an invalid range. An
* invalid range is one in which any of the values are < 0 and
* not one of {@code PREFERRED_SIZE} or {@code DEFAULT_SIZE}, or
* the following is not met (for specific values): {@code min}
* <= {@code pref} <= {@code max}.
* <p>
* Similarly any methods that take a {@code Component} throw a
* {@code IllegalArgumentException} if passed {@code null} and any methods
* that take a {@code Group} throw an {@code NullPointerException} if
* passed {@code null}.
*
* @see #createSequentialGroup
* @see #createParallelGroup
* @since 1.6
*/
// private int origin;
// private int size;
Group() {
}
/**
* Adds a {@code Group} to this {@code Group}.
*
* @param group the {@code Group} to add
* @return this {@code Group}
*/
}
/**
* Adds a {@code Component} to this {@code Group}.
*
* @param component the {@code Component} to add
* @return this {@code Group}
*/
}
/**
* 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}
*/
int 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}
*/
}
/**
* 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}
*/
}
}
}
/**
* Adds the Spring to the list of {@code Spring}s and returns
* the receiver.
*/
if (!(spring instanceof AutoPreferredGapSpring) ||
springsChanged = true;
}
return this;
}
//
// Spring methods
//
counter--) {
}
} else {
}
}
/**
* This is invoked from {@code setSize} if passed a value
* other than UNSET.
*/
}
}
}
/**
* 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.
*/
if (count == 0) {
return 0;
}
if (count == 1) {
}
}
return size;
}
switch(type) {
case MIN_SIZE:
case PREF_SIZE:
case MAX_SIZE:
}
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.
*/
boolean insert);
/**
* Removes any AutopaddingSprings for this Group and its children.
*/
void removeAutopadding() {
unset();
if (spring instanceof AutoPreferredGapSpring) {
} else {
}
}
}
}
void unsetAutopadding() {
unset();
if (spring instanceof AutoPreferredGapSpring) {
}
}
}
if (spring instanceof AutoPreferredGapSpring) {
// Force size to be reset.
}
}
unset();
}
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
*/
SequentialGroup() {
}
/**
* {@inheritDoc}
*/
}
/**
* 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}
*/
if (useAsBaseline) {
}
return this;
}
/**
* {@inheritDoc}
*/
}
/**
* 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}
*/
super.addComponent(component);
if (useAsBaseline) {
}
return this;
}
/**
* {@inheritDoc}
*/
return (SequentialGroup)super.addComponent(
}
/**
* 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}
*/
if (useAsBaseline) {
}
return this;
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
}
/**
* 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
*/
}
/**
* 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
*/
int max) {
throw new IllegalArgumentException("Type must be non-null");
}
throw new IllegalArgumentException(
"Components must be non-null");
}
}
/**
* 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}
*/
}
/**
* 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
*/
throw new IllegalArgumentException(
"Type must be one of " +
"LayoutStyle.ComponentPlacement.RELATED or " +
"LayoutStyle.ComponentPlacement.UNRELATED");
}
hasPreferredPaddingSprings = true;
}
/**
* 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}
*/
}
/**
* 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}
*/
throw new IllegalArgumentException(
"Pref and max must be either DEFAULT_VALUE " +
"or >= 0 and pref <= max");
}
hasPreferredPaddingSprings = true;
return (SequentialGroup)addSpring(
}
int operator(int a, int b) {
}
// Layout at preferred size
origin += springPref;
}
}
}
assert delta != 0;
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 accomodate 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 the List resizable
if (resizableCount > 0) {
// How much we would like to give each Spring.
// Remaining space.
int[] sizes = new int[springCount];
// Second pass, accumulate the resulting deltas (relative to
// preferred) into sizes.
}
// Spring didn't take all the space, reset how much
// each spring will get.
}
}
// And finally set the size of each spring
}
} else {
// Nothing resizable, use the min or max of each of the
// springs.
int sSize;
if (useMin) {
} else {
}
}
}
}
/**
* Returns the sorted list of SpringDelta's for the current set of
* Springs. The list is ordered based on the amount of flexibility of
* the springs.
*/
boolean useMin) {
// First pass, figure out what is resizable
int sDelta;
if (useMin) {
} else {
}
if (sDelta > 0) {
}
}
return sorted;
}
private int indexOfNextNonZeroSpring(
int index, boolean treatAutopaddingAsZeroSized) {
return index;
}
index++;
}
return index;
}
boolean insert) {
int counter = 0;
// Warning, this must use springs.size, as it may change during the
// loop.
if (spring instanceof AutoPreferredGapSpring) {
// Autopadding spring. Set the sources of the
// autopadding spring based on newLeading.
newLeading.clear();
// Last spring in the list, add it to
// trailingPadding.
if (!(padding instanceof
}
} else {
}
} else {
}
} else {
// Not a padding spring
// There's leading ComponentSprings, create an
// autopadding spring.
new AutoPreferredGapSpring();
// Force the newly created spring to be considered
// by NOT incrementing counter
continue;
}
if (spring instanceof ComponentSpring) {
// Spring is a Component, make it the target of any
// leading AutopaddingSpring.
counter++;
continue;
}
}
newLeading.clear();
// Last Spring, add it to trailing
} else {
// Not that last Spring, add it to leading
}
// Forward call to child Group
if (newTrailing == null) {
} else {
newTrailing.clear();
}
newLeading.clear();
} else {
}
} else {
// Gap
newLeading.clear();
counter++;
}
}
}
}
int getBaseline() {
if (baselineSpring != null) {
if (baseline >= 0) {
int size = 0;
if (spring == baselineSpring) {
} else {
}
}
}
}
return -1;
}
if (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;
if (spring == baselineSpring) {
break;
leadingResizable = true;
break;
}
}
boolean trailingResizable = false;
if (spring == baselineSpring) {
break;
}
trailingResizable = true;
break;
}
}
if (leadingResizable && !trailingResizable) {
} else if (!leadingResizable && trailingResizable) {
}
// If we get here, both leading and trailing springs are
// resizable. Fall through to OTHER.
} else {
if (spring == baselineSpring) {
}
return BaselineResizeBehavior.OTHER;
}
}
if (spring == baselineSpring) {
}
return BaselineResizeBehavior.OTHER;
}
}
}
}
return BaselineResizeBehavior.OTHER;
}
// Not resizable, treat as constant_ascent
}
throw new IllegalArgumentException(
"Pref and max must be either DEFAULT_SIZE, " +
"PREFERRED_SIZE, or >= 0 and pref <= max");
}
}
}
/**
* Used by SequentialGroup in calculating resizability of springs.
*/
// Original index.
public final int index;
// Delta, one of pref - min or max - pref.
public int delta;
}
}
delta + "]";
}
}
/**
* A {@code Group} that aligns and sizes it's children.
* {@code ParallelGroup} aligns it's children in
* four possible ways: along the baseline, centered, anchored to the
* leading edge, or anchored to the trailing edge.
* <h3>Baseline</h3>
* A {@code ParallelGroup} that aligns it's children along the
* baseline must first decide where the baseline is
* anchored. The baseline can either be anchored to the top, or
* anchored to the bottom of the group. That is, the distance between the
* baseline and the beginning of the group can be a constant
* distance, or the distance between the end of the group and the
* baseline can be a constant distance. The possible choices
* correspond to the {@code BaselineResizeBehavior} constants
* {@link
* java.awt.Component.BaselineResizeBehavior#CONSTANT_ASCENT CONSTANT_ASCENT} and
* {@link
* java.awt.Component.BaselineResizeBehavior#CONSTANT_DESCENT CONSTANT_DESCENT}.
* <p>
* The baseline anchor may be explicitly specified by the
* {@code createBaselineGroup} method, or determined based on the elements.
* If not explicitly specified, the baseline will be anchored to
* the bottom if all the elements with a baseline, and that are
* aligned to the baseline, have a baseline resize behavior of
* {@code CONSTANT_DESCENT}; otherwise the baseline is anchored to the top
* of the group.
* <p>
* Elements aligned to the baseline are resizable if they have have
* a baseline resize behavior of {@code CONSTANT_ASCENT} or
* {@code CONSTANT_DESCENT}. Elements with a baseline resize
* behavior of {@code OTHER} or {@code CENTER_OFFSET} are not resizable.
* <p>
* The baseline is calculated based on the preferred height of each
* of the elements that have a baseline. The baseline is
* calculated using the following algorithm:
* {@code max(maxNonBaselineHeight, maxAscent + maxDescent)}, where the
* {@code maxNonBaselineHeight} is the maximum height of all elements
* that do not have a baseline, or are not aligned along the baseline.
* {@code maxAscent} is the maximum ascent (baseline) of all elements that
* have a baseline and are aligned along the baseline.
* {@code maxDescent} is the maximum descent (preferred height - baseline)
* of all elements that have a baseline and are aligned along the baseline.
* <p>
* A {@code ParallelGroup} that aligns it's elements along the baseline
* is only useful along the vertical axis. If you create a
* baseline group and use it along the horizontal axis an
* {@code IllegalStateException} is thrown when you ask
* {@code GroupLayout} for the minimum, preferred or maximum size or
* attempt to layout the components.
* <p>
* Elements that are not aligned to the baseline and smaller than the size
* of the {@code ParallelGroup} are positioned in one of three
* ways: centered, anchored to the leading edge, or anchored to the
* trailing edge.
*
* <h3>Non-baseline {@code ParallelGroup}</h3>
* {@code ParallelGroup}s created with an alignment other than
* {@code BASELINE} align elements that are smaller than the size
* of the group in one of three ways: centered, anchored to the
* leading edge, or anchored to the trailing edge.
* <p>
* The leading edge is based on the axis and {@code
* ComponentOrientation}. For the vertical axis the top edge is
* always the leading edge, and the bottom edge is always the
* trailing edge. When the {@code ComponentOrientation} is {@code
* LEFT_TO_RIGHT}, the leading edge is the left edge and the
* trailing edge the right edge. A {@code ComponentOrientation} of
* {@code RIGHT_TO_LEFT} flips the left and right edges. Child
* elements are aligned based on the specified alignment the
* element was added with. If you do not specify an alignment, the
* alignment specified for the {@code ParallelGroup} is used.
* <p>
* To align elements along the baseline you {@code createBaselineGroup},
* or {@code createParallelGroup} with an alignment of {@code BASELINE}.
* If the group was not created with a baseline alignment, and you attempt
* to add an element specifying a baseline alignment, an
* {@code IllegalArgumentException} is thrown.
*
* @see #createParallelGroup()
* @see #createBaselineGroup(boolean,boolean)
* @since 1.6
*/
// How children are layed out.
// Whether or not we're resizable.
private final boolean resizable;
this.childAlignment = childAlignment;
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
int max) {
}
/**
* {@inheritDoc}
*/
}
/**
* {@inheritDoc}
*/
}
/**
* Adds a {@code Group} to this {@code ParallelGroup} with the
* specified alignment. If the child is smaller than the
* {@code Group} it is aligned based on the specified
* alignment.
*
* @param alignment the alignment
* @param group the {@code Group} to add
* @return this {@code ParallelGroup}
* @throws IllegalArgumentException if {@code alignment} is
* {@code null}
*/
}
/**
* Adds a {@code Component} to this {@code ParallelGroup} with
* the specified alignment.
*
* @param alignment the alignment
* @param component the {@code Component} to add
* @return this {@code Group}
* @throws IllegalArgumentException if {@code alignment} is
* {@code null}
*/
}
/**
* Adds a {@code Component} to this {@code ParallelGroup} with the
* specified alignment and size.
*
* @param alignment the alignment
* @param component the {@code Component} to add
* @param min the minimum size
* @param pref the preferred size
* @param max the maximum size
* @throws IllegalArgumentException if {@code alignment} is
* {@code null}
* @return this {@code Group}
*/
}
boolean isResizable() {
return resizable;
}
int operator(int a, int b) {
}
if (!isResizable()) {
return getPreferredSize(axis);
}
return super.calculateMinimumSize(axis);
}
if (!isResizable()) {
return getPreferredSize(axis);
}
return super.calculateMaximumSize(axis);
}
}
}
}
switch (alignment) {
case TRAILING:
break;
case CENTER:
break;
default: // LEADING, or BASELINE
break;
}
}
boolean insert) {
if (spring instanceof ComponentSpring) {
for (AutoPreferredGapSpring gapSpring :
}
}
} else if (spring instanceof AutoPreferredGapSpring) {
}
}
}
}
boolean allowsBaseline) {
throw new IllegalArgumentException("Alignment must be non-null");
}
throw new IllegalArgumentException("Alignment must be one of:" +
"LEADING, TRAILING or CENTER");
}
}
}
/**
* An extension of {@code ParallelGroup} that aligns its
* constituent {@code Spring}s along the baseline.
*/
// 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;
calcedBaseline = false;
}
this(resizable);
baselineAnchorSet = true;
}
void unset() {
super.unset();
calcedBaseline = false;
}
if (prefAscent == -1) {
} else {
// do baseline layout
}
}
if (!calcedBaseline) {
}
return calculateMinSize();
}
return calculateMaxSize();
}
if (allSpringsHaveBaseline) {
return prefAscent + prefDescent;
}
}
private void calculateBaselineAndResizeBehavior() {
// calculate baseline
prefAscent = 0;
prefDescent = 0;
int baselineSpringCount = 0;
if (baseline >= 0) {
if (resizeBehavior == null) {
} else if (brb != resizeBehavior) {
}
}
}
}
}
if (!baselineAnchorSet) {
this.baselineAnchoredToTop = false;
} else {
this.baselineAnchoredToTop = true;
}
}
calcedBaseline = true;
}
private int calculateMaxSize() {
int maxAscent = prefAscent;
int maxDescent = prefDescent;
int nonBaselineMax = 0;
int baseline;
if (springPref != springMax) {
switch (spring.getBaselineResizeBehavior()) {
case CONSTANT_ASCENT:
if (baselineAnchoredToTop) {
}
break;
case CONSTANT_DESCENT:
if (!baselineAnchoredToTop) {
}
break;
default: // CENTER_OFFSET and OTHER, not resizable
break;
}
}
} else {
// Not aligned along the baseline, or no baseline.
}
}
}
private int calculateMinSize() {
int minAscent = 0;
int minDescent = 0;
int nonBaselineMin = 0;
if (baselineAnchoredToTop) {
} else {
}
int baseline;
switch (brb) {
case CONSTANT_ASCENT:
if (baselineAnchoredToTop) {
} else {
}
break;
case CONSTANT_DESCENT:
if (!baselineAnchoredToTop) {
} else {
}
break;
default:
// CENTER_OFFSET and OTHER are !resizable, use
// the preferred size.
break;
}
} else {
// Not aligned along the baseline, or no baseline.
}
}
}
/**
* Lays out springs that have a baseline along the baseline. All
* others are centered.
*/
int ascent;
int descent;
if (baselineAnchoredToTop) {
ascent = prefAscent;
} else {
}
if (baseline >= 0) {
int height = springPref;
int y;
switch(spring.getBaselineResizeBehavior()) {
case CONSTANT_ASCENT:
break;
case CONSTANT_DESCENT:
springPref + baseline) +
(springPref - baseline);
break;
default: // CENTER_OFFSET & OTHER, not resizable
break;
}
} else {
}
} else {
}
}
}
int getBaseline() {
// Force the baseline to be calculated
return prefAscent;
}
return -1;
}
}
if (baselineAnchoredToTop) {
}
}
// If the axis is VERTICAL, throws an IllegalStateException
if (axis == HORIZONTAL) {
throw new IllegalStateException(
"Baseline must be used along vertical axis");
}
}
}
private int origin;
// DEFAULT_SIZE or PREFERRED_SIZE
private final int min;
private final int pref;
private final int max;
// Baseline for the component, computed as necessary.
// Whether or not the size has been requested yet.
private boolean installed;
int max) {
throw new IllegalArgumentException(
"Component must be non-null");
}
// getComponentInfo makes sure component is a child of the
// Container GroupLayout is the LayoutManager for.
}
}
return calculateNonlinkedMinimumSize(axis);
}
}
}
}
}
boolean isVisible() {
}
if (!isVisible()) {
return 0;
}
if (min >= 0) {
return min;
}
if (min == PREFERRED_SIZE) {
return calculateNonlinkedPreferredSize(axis);
}
assert (min == DEFAULT_SIZE);
}
if (!isVisible()) {
return 0;
}
if (pref >= 0) {
return pref;
}
}
if (!isVisible()) {
return 0;
}
if (max >= 0) {
return max;
}
if (max == PREFERRED_SIZE) {
return calculateNonlinkedPreferredSize(axis);
}
assert (max == DEFAULT_SIZE);
}
}
if (!isVisible()) {
return 0;
}
}
baseline = -1;
}
}
int getOrigin() {
return origin;
}
}
return component;
}
int getBaseline() {
if (baseline == -1) {
}
}
return baseline;
}
return getComponent().getBaselineResizeBehavior();
}
}
if (!installed) {
installed = true;
if (axis == HORIZONTAL) {
} else {
}
}
}
return !isVisible();
}
}
/**
* Spring representing the preferred distance between two components.
*/
private final int pref;
private final int max;
}
return getPadding(axis);
}
return getMinimumSize(axis);
}
}
return getPadding(axis);
}
}
int position;
if (axis == HORIZONTAL) {
} else {
}
}
return false;
}
}
/**
* Spring represented a certain amount of space.
*/
private final int min;
private final int pref;
private final int max;
}
if (min == PREFERRED_SIZE) {
return getPreferredSize(axis);
}
return min;
}
return pref;
}
if (max == PREFERRED_SIZE) {
return getPreferredSize(axis);
}
return max;
}
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.
*/
int size;
int lastSize;
private final int pref;
private final int max;
// Type of gap
private boolean userCreated;
private AutoPreferredGapSpring() {
this.pref = PREFERRED_SIZE;
this.max = PREFERRED_SIZE;
}
}
this.userCreated = true;
}
}
}
this.userCreated = userCreated;
}
public boolean getUserCreated() {
return userCreated;
}
void unset() {
super.unset();
size = 0;
}
public void reset() {
size = 0;
}
int maxPadding = UNSET;
LayoutStyle p = getLayoutStyle0();
int position;
if (axis == HORIZONTAL) {
if (isLeftToRight()) {
} else {
}
} else {
}
}
}
size = 0;
}
if (maxPadding == UNSET) {
maxPadding = 0;
}
}
}
if (delta >= 0) {
int padding;
padding = p.getPreferredGap(
host);
} else {
padding = 10;
}
}
return padding;
}
return 0;
}
}
} else {
counter--){
}
}
}
}
}
}
return size;
}
return size;
}
}
if (max >= 0) {
}
return size;
}
}
return super.toString() + getMatchDescription();
}
return treatAutopaddingAsZeroSized;
}
}
/**
* Represents two springs that should have autopadding inserted between
* them.
*/
private final static class AutoPreferredGapMatch {
}
}
}
}
/**
* An extension of AutopaddingSpring used for container level padding.
*/
private class ContainerAutoPreferredGapSpring extends
super();
setUserCreated(true);
}
setUserCreated(true);
}
}
}
LayoutStyle p = getLayoutStyle0();
int maxPadding = 0;
int position;
size = 0;
// Leading
if (axis == HORIZONTAL) {
if (isLeftToRight()) {
} else {
}
} else {
}
int padding = 10;
padding = p.getContainerGap(
} else {
}
}
} else {
// Trailing
if (axis == HORIZONTAL) {
if (isLeftToRight()) {
} else {
}
} else {
}
}
}
}
}
}
int position) {
int padding = 10;
padding = p.getContainerGap(
host);
}
return padding;
}
}
}
return "--";
}
}
// LinkInfo contains the set of ComponentInfosthat are linked along a
// particular axis.
private static class LinkInfo {
private final int axis;
private int size;
}
if (childMaster == null) {
} else if (childMaster != this) {
}
}
}
}
}
public void clearCachedSize() {
}
}
return size;
}
int size = 0;
if (axis == HORIZONTAL) {
} else {
}
}
return size;
}
}
/**
* Tracks the horizontal/vertical Springs for a Component.
* This class is also used to handle Springs that have their sizes
* linked.
*/
private class ComponentInfo {
// Component being layed out
// If the component's size is linked to other components, the
// linked components.
private boolean visible;
}
public void dispose() {
// Remove horizontal/vertical springs
// Clean up links
if (horizontalMaster != null) {
horizontalMaster.remove(this);
}
if (verticalMaster != null) {
verticalMaster.remove(this);
}
}
this.honorsVisibility = honorsVisibility;
}
}
}
public boolean isVisible() {
return visible;
}
/**
* Updates the cached visibility.
*
* @return true if the visibility changed
*/
boolean updateVisibility() {
boolean honorsVisibility;
if (this.honorsVisibility == null) {
} else {
honorsVisibility = this.honorsVisibility;
}
boolean newVisible = (honorsVisibility) ?
if (visible != newVisible) {
return true;
}
return false;
}
int x = horizontalSpring.getOrigin();
int w = horizontalSpring.getSize();
int y = verticalSpring.getOrigin();
int h = verticalSpring.getSize();
if (!ltr) {
x = parentWidth - x - w;
}
}
if (horizontalSpring != null) {
}
if (verticalSpring != null) {
}
}
return component;
}
/**
* Returns true if this component has its size linked to
* other components.
*/
if (axis == HORIZONTAL) {
return horizontalMaster != null;
}
return (verticalMaster != null);
}
if (axis == HORIZONTAL) {
} else {
}
}
return getLinkInfo(axis, true);
}
if (axis == HORIZONTAL) {
// horizontalMaster field is directly set by adding
// us to the LinkInfo.
}
return horizontalMaster;
} else {
// verticalMaster field is directly set by adding
// us to the LinkInfo.
}
return verticalMaster;
}
}
public void clearCachedSize() {
if (horizontalMaster != null) {
}
if (verticalMaster != null) {
}
}
if (axis == HORIZONTAL) {
} else {
}
}
}
}