Java Code Examples for java.awt.Container#getInsets()

The following examples show how to use java.awt.Container#getInsets() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: SnapshotsWindowUI.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private Dimension maximumLayoutSize(Container parent) {
    int maxw = 0;
    int maxh = 0;
    for (Component c : parent.getComponents()) {
        Dimension pref = c.getPreferredSize();
        maxw += pref.height * MAX_WIDTH_FACTOR;
        maxh = Math.max(maxh, pref.height);
    }
    maxw += HGAP * (parent.getComponentCount() - 1);
    
    Insets i = parent.getInsets();
    maxw += i.left + i.right;
    maxh += i.top + i.bottom;
    
    return new Dimension(maxw, maxh);
}
 
Example 2
Source File: VerticalFlowLayout.java    From Method_Trace_Tool with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the preferred dimensions given the components in the target
 * container.
 *
 * @param target
 *            the component to lay out
 */
public Dimension preferredLayoutSize(Container target) {
	Dimension tarsiz = new Dimension(0, 0);

	for (int i = 0; i < target.getComponentCount(); i++) {
		Component m = target.getComponent(i);
		if (m.isVisible()) {
			Dimension d = m.getPreferredSize();
			tarsiz.width = Math.max(tarsiz.width, d.width);
			if (i > 0) {
				tarsiz.height += hgap;
			}
			tarsiz.height += d.height;
		}
	}
	Insets insets = target.getInsets();
	tarsiz.width += insets.left + insets.right + hgap * 2;
	tarsiz.height += insets.top + insets.bottom + vgap * 2;
	return tarsiz;
}
 
Example 3
Source File: VerticalFlowLayout.java    From Method_Trace_Tool with Apache License 2.0 6 votes vote down vote up
/**
 * Returns the minimum size needed to layout the target container.
 *
 * @param target
 *            the component to lay out.
 * @return the minimum layout dimension.
 */
public Dimension minimumLayoutSize(Container target) {
	Dimension tarsiz = new Dimension(0, 0);

	for (int i = 0; i < target.getComponentCount(); i++) {
		Component m = target.getComponent(i);
		if (m.isVisible()) {
			Dimension d = m.getMinimumSize();
			tarsiz.width = Math.max(tarsiz.width, d.width);
			if (i > 0) {
				tarsiz.height += vgap;
			}
			tarsiz.height += d.height;
		}
	}
	Insets insets = target.getInsets();
	tarsiz.width += insets.left + insets.right + hgap * 2;
	tarsiz.height += insets.top + insets.bottom + vgap * 2;
	return tarsiz;
}
 
Example 4
Source File: CharacterSheetLayout.java    From gcs with Mozilla Public License 2.0 6 votes vote down vote up
@Override
public void layoutContainer(Container target) {
    Component[] children = target.getComponents();
    if (children.length > 0) {
        Dimension size   = children[0].getPreferredSize();
        Dimension avail  = target.getSize();
        Insets    insets = target.getInsets();
        int       x      = insets.left;
        int       y      = insets.top;
        int       margin = mSheet.getScale().scale(MARGIN);
        for (Component child : children) {
            child.setBounds(x, y, size.width, size.height);
            x += size.width + margin;
            if (x + size.width + insets.right > avail.width) {
                x = insets.left;
                y += size.height + margin;
            }
        }
    }
}
 
Example 5
Source File: MetalworksPrefs.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;
    int width = 0 + insets.left + insets.right;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        height += compSize.height + yGap;
        width = Math.max(width, compSize.width + insets.left + insets.right + xInset
                * 2);
    }
    height += insets.bottom;
    return new Dimension(width, height);
}
 
Example 6
Source File: MetalworksPrefs.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Dimension minimumLayoutSize(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;
    int width = 0 + insets.left + insets.right;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        height += compSize.height + yGap;
        width = Math.max(width, compSize.width + insets.left + insets.right + xInset
                * 2);
    }
    height += insets.bottom;
    return new Dimension(width, height);
}
 
Example 7
Source File: GroupLayout.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * 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
 */
public void layoutContainer(Container parent) {
    // Step 1: Prepare for layout.
    prepare(SPECIFIC_SIZE);
    Insets insets = parent.getInsets();
    int width = parent.getWidth() - insets.left - insets.right;
    int height = parent.getHeight() - insets.top - insets.bottom;
    boolean ltr = isLeftToRight();
    if (getAutoCreateGaps() || getAutoCreateContainerGaps() ||
            hasPreferredPaddingSprings) {
        // Step 2: Calculate autopadding springs
        calculateAutopadding(horizontalGroup, HORIZONTAL, SPECIFIC_SIZE, 0,
                width);
        calculateAutopadding(verticalGroup, VERTICAL, SPECIFIC_SIZE, 0,
                height);
    }
    // Step 3: set the size of the groups.
    horizontalGroup.setSize(HORIZONTAL, 0, width);
    verticalGroup.setSize(VERTICAL, 0, height);
    // Step 4: apply the size to the components.
    for (ComponentInfo info : componentInfos.values()) {
        info.setBounds(insets, width, ltr);
    }
}
 
Example 8
Source File: MetalworksPrefs.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 9
Source File: MetalworksDocumentFrame.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();

    int labelWidth = 0;
    for (Component comp : labels) {
        labelWidth = Math.max(labelWidth, comp.getPreferredSize().width);
    }

    int yPos = insets.top;

    Iterator<Component> fieldIter = fields.listIterator();
    Iterator<Component> labelIter = labels.listIterator();
    while (labelIter.hasNext() && fieldIter.hasNext()) {
        JComponent label = (JComponent) labelIter.next();
        JComponent field = (JComponent) fieldIter.next();
        int height = Math.max(label.getPreferredSize().height, field.
                getPreferredSize().height);
        label.setBounds(insets.left, yPos, labelWidth, height);
        field.setBounds(insets.left + labelWidth + xGap,
                yPos,
                c.getSize().width - (labelWidth + xGap + insets.left
                + insets.right),
                height);
        yPos += (height + yGap);
    }

}
 
Example 10
Source File: CompactLayout.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public Dimension getSize(Container parent, boolean minimum) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension d = new Dimension();
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        if (comp instanceof EnableButton) {
            continue;
        }
        Dimension p = (minimum
                       ? comp.getMinimumSize()
                       : comp.getPreferredSize());
        if (horizontal) {
            d.width += p.width;
            if (d.height < p.height) {
                d.height = p.height;
            }
        } else {
            if (d.width < p.width) {
                d.width = p.width;
            }
            d.height += p.height;
        }
    }
    d.width += (insets.left + insets.right);
    d.height += (insets.top + insets.bottom);
    return d;
}
 
Example 11
Source File: SpringLayout.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container parent) {
    setParent(parent);

    int n = parent.getComponentCount();
    getConstraints(parent).reset();
    for (int i = 0 ; i < n ; i++) {
        getConstraints(parent.getComponent(i)).reset();
    }

    Insets insets = parent.getInsets();
    Constraints pc = getConstraints(parent);
    abandonCycles(pc.getX()).setValue(0);
    abandonCycles(pc.getY()).setValue(0);
    abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
                                          insets.left - insets.right);
    abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
                                           insets.top - insets.bottom);

    for (int i = 0 ; i < n ; i++) {
        Component c = parent.getComponent(i);
        Constraints cc = getConstraints(c);
        int x = abandonCycles(cc.getX()).getValue();
        int y = abandonCycles(cc.getY()).getValue();
        int width = abandonCycles(cc.getWidth()).getValue();
        int height = abandonCycles(cc.getHeight()).getValue();
        c.setBounds(insets.left + x, insets.top + y, width, height);
    }
}
 
Example 12
Source File: SimpleGridLayout.java    From swift-k with Apache License 2.0 5 votes vote down vote up
public Dimension maximumLayoutSize(Container container) {
	Insets insets = container.getInsets();
	int height = insets.top + insets.bottom;
	int width = insets.left + insets.right;

	int[] widths = new int[nCols];
	int[] heights = new int[nRows];

	Arrays.fill(widths, 0);
	Arrays.fill(heights, 0);

	for (int i = 0; i < nRows; i++) {
		for (int j = 0; j < nCols; j++) {
			if (grid[i][j] == null) {
				continue;
			}

			Dimension cSize = grid[i][j].getMaximumSize();

			if (widths[j] < cSize.width) {
				widths[j] = cSize.width;
			}
			if (heights[i] < cSize.height) {
				heights[i] = cSize.height;
			}
		}
	}
	for (int i = 0; i < nRows; i++) {
		height += heights[i];
	}
	height += vGap * (nRows - 1);

	for (int i = 0; i < nCols; i++) {
		width += widths[i];
	}
	width += hGap * (nCols - 1);
	return new Dimension(width, height);
}
 
Example 13
Source File: CompactLayout.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Lays out the specified container.
 * @param parent the container to be laid out
 */
public void layoutContainer(Container parent) {
    int n = parent.getComponentCount();
    Insets insets = parent.getInsets();
    Dimension size = parent.getSize();
    int c = horizontal ? insets.left : insets.top;
    int x, y;
    int ebx = size.width - insets.right;
    size.width -= (insets.left + insets.right);
    size.height -= (insets.top + insets.bottom);
    for (int i = 0; i < n; i++) {
        Component comp = parent.getComponent(i);
        Dimension pref = comp.getPreferredSize();
        if (comp instanceof EnableButton) {
            ebx -= 4;
            ebx -= pref.width;
            x = ebx;
            y = (insets.top - pref.height) / 2;
        } else if (horizontal) {
            x = c;
            c += pref.width;
            y = insets.top;
            pref.height = size.height;
        } else {
            x = insets.left;
            pref.width = size.width;
            y = c;
            c += pref.height;
        }
        comp.setBounds(x, y, pref.width, pref.height);
    }
}
 
Example 14
Source File: SpringLayout.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container parent) {
    setParent(parent);

    int n = parent.getComponentCount();
    getConstraints(parent).reset();
    for (int i = 0 ; i < n ; i++) {
        getConstraints(parent.getComponent(i)).reset();
    }

    Insets insets = parent.getInsets();
    Constraints pc = getConstraints(parent);
    abandonCycles(pc.getX()).setValue(0);
    abandonCycles(pc.getY()).setValue(0);
    abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
                                          insets.left - insets.right);
    abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
                                           insets.top - insets.bottom);

    for (int i = 0 ; i < n ; i++) {
        Component c = parent.getComponent(i);
        Constraints cc = getConstraints(c);
        int x = abandonCycles(cc.getX()).getValue();
        int y = abandonCycles(cc.getY()).getValue();
        int width = abandonCycles(cc.getWidth()).getValue();
        int height = abandonCycles(cc.getHeight()).getValue();
        c.setBounds(insets.left + x, insets.top + y, width, height);
    }
}
 
Example 15
Source File: HorizontalSplitPane.java    From Logisim with GNU General Public License v3.0 5 votes vote down vote up
@Override
public Dimension preferredLayoutSize(Container parent) {
	if (fraction <= 0.0)
		return comp1.getPreferredSize();
	if (fraction >= 1.0)
		return comp0.getPreferredSize();
	Insets in = parent.getInsets();
	Dimension d0 = comp0.getPreferredSize();
	Dimension d1 = comp1.getPreferredSize();
	return new Dimension(in.left + Math.max(d0.width, d1.width) + in.right,
			in.top + d0.height + d1.height + in.bottom);
}
 
Example 16
Source File: LuckTitlePanelLayout.java    From littleluck with Apache License 2.0 5 votes vote down vote up
public Dimension preferredLayoutSize(Container parent)
{
    LuckTitlePanel root = (LuckTitlePanel) parent;

    Insets i = parent.getInsets();

    // 高度由父面板决定
    // Height is determined by the parent panel
    return new Dimension(0 + i.left + i.right, root.getHeight() + i.top + i.bottom);
}
 
Example 17
Source File: SpringLayout.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container parent) {
    setParent(parent);

    int n = parent.getComponentCount();
    getConstraints(parent).reset();
    for (int i = 0 ; i < n ; i++) {
        getConstraints(parent.getComponent(i)).reset();
    }

    Insets insets = parent.getInsets();
    Constraints pc = getConstraints(parent);
    abandonCycles(pc.getX()).setValue(0);
    abandonCycles(pc.getY()).setValue(0);
    abandonCycles(pc.getWidth()).setValue(parent.getWidth() -
                                          insets.left - insets.right);
    abandonCycles(pc.getHeight()).setValue(parent.getHeight() -
                                           insets.top - insets.bottom);

    for (int i = 0 ; i < n ; i++) {
        Component c = parent.getComponent(i);
        Constraints cc = getConstraints(c);
        int x = abandonCycles(cc.getX()).getValue();
        int y = abandonCycles(cc.getY()).getValue();
        int width = abandonCycles(cc.getWidth()).getValue();
        int height = abandonCycles(cc.getHeight()).getValue();
        c.setBounds(insets.left + x, insets.top + y, width, height);
    }
}
 
Example 18
Source File: MetalworksPrefs.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public void layoutContainer(Container c) {
    Insets insets = c.getInsets();
    int height = yInset + insets.top;

    Component[] children = c.getComponents();
    Dimension compSize = null;
    for (Component child : children) {
        compSize = child.getPreferredSize();
        child.setSize(compSize.width, compSize.height);
        child.setLocation(xInset + insets.left, height);
        height += compSize.height + yGap;
    }

}
 
Example 19
Source File: FilterBar.java    From pcgen with GNU Lesser General Public License v2.1 4 votes vote down vote up
@Override
public Dimension minimumLayoutSize(Container target)
{
	synchronized (target.getTreeLock())
	{
		Dimension dim = new Dimension(0, 0);
		int nmembers = target.getComponentCount();

		Insets insets = target.getInsets();
		int maxwidth = target.getWidth() - (insets.left + insets.right + getHgap() * 2);
		int width = 0;
		int height = 0;
		int component = 0;
		for (int i = 0; i < nmembers; i++, component++)
		{
			Component m = target.getComponent(i);
			if (m.isVisible())
			{
				Dimension d = m.getMinimumSize();
				if (component > 0)
				{
					if (width + d.width > maxwidth)
					{
						dim.width = Math.max(dim.width, width);
						dim.height += height + getVgap();
						width = 0;
						height = 0;
						component = 0;
					}
					width += getHgap();
				}
				height = Math.max(height, d.height);
				width += d.width;
			}
		}
		dim.width = Math.max(dim.width, width);
		dim.height += height;

		dim.width += insets.left + insets.right + getHgap() * 2;
		dim.height += insets.top + insets.bottom + getVgap() * 2;
		return dim;
	}
}
 
Example 20
Source File: ToolBarLayout.java    From ramus with GNU General Public License v3.0 4 votes vote down vote up
/**
 * Sets the sizes and locations of the specified container's subcomponents
 * (docked toolbars and content).
 */
public void layoutContainer(final Container target) {
    ourTargetContainer = target;

    synchronized (target.getTreeLock()) {
        int width = target.getWidth();
        int height = target.getHeight();

        final Insets insets = target.getInsets();
        int top = insets.top;
        final int bottom = height - insets.bottom;
        int left = insets.left;
        final int right = width - insets.right;

        ourNorthBoundary.setPosition(left, top, width);
        ourSouthBoundary.setPosition(left, bottom, width);

        int northHeight = ourNorthBoundary.getDepth();
        int southHeight = ourSouthBoundary.getDepth();
        if (northHeight > 0)
            northHeight += ourVerticalSpacing;
        if (southHeight > 0)
            southHeight += ourVerticalSpacing;
        height = bottom - top - northHeight - southHeight;
        top += northHeight;

        ourWestBoundary.setPosition(left, top, height);
        ourEastBoundary.setPosition(right, top, height);

        int eastWidth = ourEastBoundary.getDepth();
        int westWidth = ourWestBoundary.getDepth();
        if (eastWidth > 0)
            eastWidth += ourHorizontalSpacing;
        if (westWidth > 0)
            westWidth += ourHorizontalSpacing;
        width = right - left - eastWidth - westWidth;
        left += westWidth;

        if (ourContent != null) {
            ourContent.setBounds(left, top, width, height);
        }
    }
}