📄 grouplayout.java.svn-base
字号:
* <code>GroupLayout</code> is managing, it will be added to the * <code>Container</code>. * * @param component the component * @param honorsVisibility whether <code>component</code>'s visiblity should be * considered for sizing and positioning * @throws IllegalArgumentException if <code>component</code> is <code>null</code> * @see #setHonorsVisibility(boolean) */ public void setHonorsVisibility(Component component, Boolean honorsVisibility) { if (component == null) { throw new IllegalArgumentException("Component must be non-null"); } getComponentInfo(component).setHonorsVisibility(honorsVisibility); springsChanged = true; isValid = false; invalidateHost(); } /** * Returns a textual description of this GroupLayout. The return value * is intended for debugging purposes only. * * @return textual description of this GroupLayout **/ public String toString() { if (springsChanged) { registerComponents(horizontalGroup, HORIZONTAL); registerComponents(verticalGroup, VERTICAL); } StringBuffer buffer = new StringBuffer(); buffer.append("HORIZONTAL\n"); dump(buffer, horizontalGroup, " ", HORIZONTAL); buffer.append("\nVERTICAL\n"); dump(buffer, verticalGroup, " ", VERTICAL); return buffer.toString(); } private void dump(StringBuffer buffer, Spring spring, String indent, int axis) { String origin = ""; String padding = ""; if (spring instanceof ComponentSpring) { ComponentSpring cSpring = (ComponentSpring)spring; origin = Integer.toString(cSpring.getOrigin()) + " "; String name = cSpring.getComponent().toString(); if (name != null) { origin = "name=" + name + ", "; } } if (spring instanceof AutopaddingSpring) { AutopaddingSpring paddingSpring = (AutopaddingSpring)spring; padding = ", userCreated=" + paddingSpring.getUserCreated() + ", matches=" + paddingSpring.getMatchDescription(); } buffer.append(indent + spring.getClass().getName() + " " + Integer.toHexString(spring.hashCode()) + " " + origin + ", size=" + spring.getSize() + ", alignment=" + spring.getAlignment() + " prefs=[" + spring.getMinimumSize(axis) + " " + spring.getPreferredSize(axis) + " " + spring.getMaximumSize(axis) + padding + "]\n"); if (spring instanceof Group) { Vector springs = ((Group)spring).springs; indent += " "; for (int counter = 0; counter < springs.size(); counter++) { dump(buffer, (Spring)springs.elementAt(counter), indent, axis); } } } /** * Sets whether or not a gap between components * should automatically be created. For example, if this is true * and you add two components to a <code>SequentialGroup</code> a * gap between the two will automatically be created. The default * is false. * * @param autocreatePadding whether or not to automatically created a gap * between components and the container */ public void setAutocreateGaps(boolean autocreatePadding) { if (this.autocreatePadding != autocreatePadding) { this.autocreatePadding = autocreatePadding; invalidateHost(); } } /** * Returns true if gaps between components are automatically be created. * * @return true if gaps between components should automatically be created */ public boolean getAutocreateGaps() { return autocreatePadding; } /** * Sets whether or not gaps between the container and the first/last * components should automatically be created. The default * is false. * * @param autocreatePadding whether or not to automatically create * gaps between the container and first/last components. */ public void setAutocreateContainerGaps(boolean autocreatePadding) { if (autocreatePadding != autocreateContainerPadding) { autocreateContainerPadding = autocreatePadding; horizontalGroup = createTopLevelGroup(getHorizontalGroup()); verticalGroup = createTopLevelGroup(getVerticalGroup()); invalidateHost(); } } /** * Returns whether or not gaps between the container and the * first/last components should automatically be created. The default * is false. * * @return whether or not the gaps between the container and the * first/last components should automatically be created */ public boolean getAutocreateContainerGaps() { return autocreateContainerPadding; } /** * Sets the <code>Group</code> that is responsible for * layout along the horizontal axis. * * @param group <code>Group</code> responsible for layout along * the horizontal axis * @throws IllegalArgumentException if group is null */ public void setHorizontalGroup(Group group) { if (group == null) { throw new IllegalArgumentException("Group must be non-null"); } horizontalGroup = createTopLevelGroup(group); invalidateHost(); } /** * Returns the <code>Group</code> that is responsible for * layout along the horizontal axis. * * @return <code>ParallelGroup</code> responsible for layout along * the horizontal axis. */ public Group getHorizontalGroup() { int index = 0; if (horizontalGroup.springs.size() > 1) { index = 1; } return (Group)horizontalGroup.springs.elementAt(index); } /** * Sets the <code>Group</code> that is responsible for * layout along the vertical axis. * * @param group <code>Group</code> responsible for layout along * the vertical axis. * @throws IllegalArgumentException if group is null. */ public void setVerticalGroup(Group group) { if (group == null) { throw new IllegalArgumentException("Group must be non-null"); } verticalGroup = createTopLevelGroup(group); invalidateHost(); } /** * Returns the <code>ParallelGroup</code> that is responsible for * layout along the vertical axis. * * @return <code>ParallelGroup</code> responsible for layout along * the vertical axis. */ public Group getVerticalGroup() { int index = 0; if (verticalGroup.springs.size() > 1) { index = 1; } return (Group)verticalGroup.springs.elementAt(index); } /** * Wraps the user specified group in a sequential group. If * container gaps should be generate the necessary springs are * added. */ private Group createTopLevelGroup(Group specifiedGroup) { SequentialGroup group = createSequentialGroup(); if (getAutocreateContainerGaps()) { group.addSpring(new ContainerAutopaddingSpring()); group.add(specifiedGroup); group.addSpring(new ContainerAutopaddingSpring()); } else { group.add(specifiedGroup); } return group; } /** * Creates and returns a <code>SequentialGroup</code>. * * @return a new <code>SequentialGroup</code> */ public SequentialGroup createSequentialGroup() { return new SequentialGroup(); } /** * Creates and returns a <code>ParallelGroup</code> with a * <code>LEADING</code> alignment. This is a cover method for the more * general <code>createParallelGroup(int)</code> method. * * @return a new ParallelGroup * @see #createParallelGroup(int) */ public ParallelGroup createParallelGroup() { return createParallelGroup(LEADING); } /** * Creates and returns an <code>ParallelGroup</code>. The alignment * specifies how children elements should be positioned when the * the parallel group is given more space than necessary. For example, * if a ParallelGroup with an alignment of TRAILING is given 100 pixels * and a child only needs 50 pixels, the child will be positioned at the * position 50. * * @param alignment alignment for the elements of the Group, one * of <code>LEADING</code>, <code>TRAILING</code>, * <code>CENTER</code> or <code>BASELINE</code>. * @throws IllegalArgumentException if alignment is not one of * <code>LEADING</code>, <code>TRAILING</code>, * <code>CENTER</code> or <code>BASELINE</code> * @return a new <code>ParallelGroup</code> */ public ParallelGroup createParallelGroup(int alignment) { return createParallelGroup(alignment, true); } /** * Creates and returns an <code>ParallelGroup</code>. The alignment * specifies how children elements should be positioned when the * the parallel group is given more space than necessary. For example, * if a ParallelGroup with an alignment of TRAILING is given 100 pixels * and a child only needs 50 pixels, the child will be positioned at the * position 50. * * @param alignment alignment for the elements of the Group, one * of <code>LEADING</code>, <code>TRAILING</code>, * <code>CENTER</code> or <code>BASELINE</code>. * @param resizable whether or not the group is resizable. If the group * is not resizable the min/max size will be the same as the * preferred. * @throws IllegalArgumentException if alignment is not one of * <code>LEADING</code>, <code>TRAILING</code>, * <code>CENTER</code> or <code>BASELINE</code> * @return a new <code>ParallelGroup</code> */ public ParallelGroup createParallelGroup(int alignment, boolean resizable) { if (alignment == BASELINE) { return new BaselineGroup(resizable); } return new ParallelGroup(alignment, resizable); } /** * Creates and returns a <code>ParallelGroup</code> 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 */ public ParallelGroup createBaselineGroup(boolean resizable, boolean anchorBaselineToTop) { return new BaselineGroup(resizable, anchorBaselineToTop); } /** * Forces the set of components to have the same size. * 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 Components to force to have same size. * @throws IllegalArgumentException if <code>components</code> is * null, or contains null. */ public void linkSize(Component[] components) { linkSize(components, HORIZONTAL | VERTICAL); } /** * Forces the set of components to have the same size. * 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 Components to force to have same size. * @param axis Axis to bind size, one of HORIZONTAL, VERTICAL or * HORIZONTAL | VERTICAL * @throws IllegalArgumentException if <code>components</code> is * null, or contains null. * @throws IllegalArgumentException if <code>axis</code> does not * contain <code>HORIZONTAL</code> or <code>VERTICAL</code> */ public void linkSize(Component[] components, int axis) { if (components == null) { throw new IllegalArgumentException("Components must be non-null"); } boolean horizontal = ((axis & HORIZONTAL) == HORIZONTAL); boolean vertical = ((axis & VERTICAL) == VERTICAL); if (!vertical && !horizontal) { throw new IllegalArgumentException( "Axis must contain HORIZONTAL or VERTICAL"); } for (int counter = components.length - 1; counter >= 0; counter--) { Component c = components[counter]; if (components[counter] == null) { throw new IllegalArgumentException( "Components must be non-null"); } // Force the component to be added getComponentInfo(c); } if (horizontal) { linkSize0(components, HORIZONTAL); } if (vertical) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -