Example usage for java.awt Container getInsets

List of usage examples for java.awt Container getInsets

Introduction

In this page you can find the example usage for java.awt Container getInsets.

Prototype

public Insets getInsets() 

Source Link

Document

Determines the insets of this container, which indicate the size of the container's border.

Usage

From source file:FormatLayout.java

/**
 * Returns the preferred size of the component using this layout manager.
 *
 * @param parent  the parent.//from   w  w w. j a  v  a  2  s  .  co m
 *
 * @return the preferred size of the component.
 */
public Dimension preferredLayoutSize(final Container parent) {

    Component c0, c1, c2, c3, c4, c5;

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        int componentIndex = 0;
        final int rowCount = this.rowHeights.length;
        for (int i = 0; i < this.columnWidths.length; i++) {
            this.columnWidths[i] = 0;
        }
        this.columns1and2Width = 0;
        this.columns4and5Width = 0;
        this.columns1to4Width = 0;
        this.columns1to5Width = 0;
        this.columns0to5Width = 0;

        this.totalHeight = 0;
        for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            final int format = this.rowFormats[rowIndex % this.rowFormats.length];
            switch (format) {
            case FormatLayout.C:
                c0 = parent.getComponent(componentIndex);
                updateC(rowIndex, c0.getPreferredSize());
                componentIndex = componentIndex + 1;
                break;
            case FormatLayout.LC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize());
                componentIndex = componentIndex + 2;
                break;
            case FormatLayout.LCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize());
                componentIndex = componentIndex + 3;
                break;
            case FormatLayout.LCLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize());
                componentIndex = componentIndex + 4;
                break;
            case FormatLayout.LCBLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize());
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize());
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCBLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                c5 = parent.getComponent(componentIndex + 5);
                updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize());
                componentIndex = componentIndex + 6;
                break;
            }
        }
        complete();
        return new Dimension(this.totalWidth + insets.left + insets.right,
                this.totalHeight + (rowCount - 1) * this.rowGap + insets.top + insets.bottom);
    }
}

From source file:FormatLayout.java

/**
 * Returns the minimum size of the component using this layout manager.
 *
 * @param parent  the parent.//w  w  w  . j a v a2  s  .com
 *
 * @return the minimum size of the component
 */
public Dimension minimumLayoutSize(final Container parent) {

    Component c0, c1, c2, c3, c4, c5;

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        int componentIndex = 0;
        final int rowCount = this.rowHeights.length;
        for (int i = 0; i < this.columnWidths.length; i++) {
            this.columnWidths[i] = 0;
        }
        this.columns1and2Width = 0;
        this.columns4and5Width = 0;
        this.columns1to4Width = 0;
        this.columns1to5Width = 0;
        this.columns0to5Width = 0;
        final int totalHeight = 0;
        for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {

            final int format = this.rowFormats[rowIndex % this.rowFormats.length];

            switch (format) {
            case FormatLayout.C:
                c0 = parent.getComponent(componentIndex);
                this.columns0to5Width = Math.max(this.columns0to5Width, c0.getMinimumSize().width);
                componentIndex = componentIndex + 1;
                break;
            case FormatLayout.LC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                updateLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize());
                componentIndex = componentIndex + 2;
                break;
            case FormatLayout.LCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                updateLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize());
                componentIndex = componentIndex + 3;
                break;
            case FormatLayout.LCLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                updateLCLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(),
                        c3.getMinimumSize());
                componentIndex = componentIndex + 3;
                break;
            case FormatLayout.LCBLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCBLC(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(),
                        c3.getMinimumSize(), c4.getMinimumSize());
                componentIndex = componentIndex + 4;
                break;
            case FormatLayout.LCLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(),
                        c3.getMinimumSize(), c4.getMinimumSize());
                componentIndex = componentIndex + 4;
                break;
            case FormatLayout.LCBLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                c5 = parent.getComponent(componentIndex + 5);
                updateLCBLCB(rowIndex, c0.getMinimumSize(), c1.getMinimumSize(), c2.getMinimumSize(),
                        c3.getMinimumSize(), c4.getMinimumSize(), c5.getMinimumSize());
                componentIndex = componentIndex + 5;
                break;
            }
        }
        complete();
        return new Dimension(this.totalWidth + insets.left + insets.right,
                totalHeight + (rowCount - 1) * this.rowGap + insets.top + insets.bottom);
    }
}

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method/*from   w  w  w . j  ava2  s  . c  o m*/
 *
 *@param  target  Description of Parameter
 *@return         Description of the Returned Value
 */
public Dimension preferredLayoutSize(Container target) {
    synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int nmembers = target.getComponentCount();
        boolean firstVisibleComponent = true;

        for (int ii = 0; ii < nmembers; ii++) {
            Component m = target.getComponent(ii);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                dim.width = Math.max(dim.width, d.width);
                if (firstVisibleComponent) {
                    firstVisibleComponent = false;
                } else {
                    dim.height += _vgap;
                }
                dim.height += d.height;
            }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right + _hgap * 2;
        dim.height += insets.top + insets.bottom + _vgap * 2;
        return dim;
    }
}

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method// w  ww.  ja  va  2 s.c  o  m
 *
 *@param  target  Description of Parameter
 *@return         Description of the Returned Value
 */
public Dimension minimumLayoutSize(Container target) {
    synchronized (target.getTreeLock()) {
        Dimension dim = new Dimension(0, 0);
        int nmembers = target.getComponentCount();
        boolean firstVisibleComponent = true;

        for (int ii = 0; ii < nmembers; ii++) {
            Component m = target.getComponent(ii);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                dim.width = Math.max(dim.width, d.width);
                if (firstVisibleComponent) {
                    firstVisibleComponent = false;
                } else {
                    dim.height += _vgap;
                }
                dim.height += d.height;
            }
        }
        Insets insets = target.getInsets();
        dim.width += insets.left + insets.right + _hgap * 2;
        dim.height += insets.top + insets.bottom + _vgap * 2;
        return dim;
    }
}

From source file:BeanContainer.java

public Dimension preferredLayoutSize(Container parent) {
        int divider = getDivider(parent);

        int w = 0;
        int h = 0;
        for (int k = 1; k < parent.getComponentCount(); k += 2) {
            Component comp = parent.getComponent(k);
            Dimension d = comp.getPreferredSize();
            w = Math.max(w, d.width);
            h += d.height + m_vGap;/* w  w w  .  j a  v  a2 s  .  c  o  m*/
        }
        h -= m_vGap;

        Insets insets = parent.getInsets();
        return new Dimension(divider + w + insets.left + insets.right, h + insets.top + insets.bottom);
    }

From source file:StackLayout.java

/**
 * Returns the preferred size for this layout to arrange the
 * indicated parent's children at the specified orientation.
 */// w  w w  . j ava 2 s.c o m
// public, because it's useful - not one of the LayoutManager methods
public Dimension preferredLayoutSize(Container parent, int orientation) {
    synchronized (parent.getTreeLock()) {
        Component[] comps = parent.getComponents();
        Dimension total = new Dimension(0, 0);

        int depth = calculatePreferredDepth(comps, orientation);

        int length = (ourLengthsMatched ? calculateAdjustedLength(comps, orientation, ourSpacing)
                : calculatePreferredLength(comps, orientation, ourSpacing));

        total.width = (orientation == HORIZONTAL ? length : depth);
        total.height = (orientation == HORIZONTAL ? depth : length);

        Insets in = parent.getInsets();
        total.width += in.left + in.right;
        total.height += in.top + in.bottom;

        return total;
    }
}

From source file:FormatLayout.java

/**
 * Performs the layout of the container.
 *
 * @param parent  the parent./*from  w  w w .ja v  a  2  s  .c o  m*/
 */
public void layoutContainer(final Container parent) {
    Component c0, c1, c2, c3, c4, c5;

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        int componentIndex = 0;
        final int rowCount = this.rowHeights.length;
        for (int i = 0; i < this.columnWidths.length; i++) {
            this.columnWidths[i] = 0;
        }
        this.columns1and2Width = 0;
        this.columns4and5Width = 0;
        this.columns1to4Width = 0;
        this.columns1to5Width = 0;
        this.columns0to5Width = parent.getBounds().width - insets.left - insets.right;

        this.totalHeight = 0;
        for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            final int format = this.rowFormats[rowIndex % this.rowFormats.length];
            switch (format) {
            case FormatLayout.C:
                c0 = parent.getComponent(componentIndex);
                updateC(rowIndex, c0.getPreferredSize());
                componentIndex = componentIndex + 1;
                break;
            case FormatLayout.LC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                updateLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize());
                componentIndex = componentIndex + 2;
                break;
            case FormatLayout.LCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                updateLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize());
                componentIndex = componentIndex + 3;
                break;
            case FormatLayout.LCLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                updateLCLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize());
                componentIndex = componentIndex + 4;
                break;
            case FormatLayout.LCBLC:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCBLC(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize());
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                updateLCLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize());
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCBLCB:
                c0 = parent.getComponent(componentIndex);
                c1 = parent.getComponent(componentIndex + 1);
                c2 = parent.getComponent(componentIndex + 2);
                c3 = parent.getComponent(componentIndex + 3);
                c4 = parent.getComponent(componentIndex + 4);
                c5 = parent.getComponent(componentIndex + 5);
                updateLCBLCB(rowIndex, c0.getPreferredSize(), c1.getPreferredSize(), c2.getPreferredSize(),
                        c3.getPreferredSize(), c4.getPreferredSize(), c5.getPreferredSize());
                componentIndex = componentIndex + 6;
                break;
            }
        }
        complete();

        componentIndex = 0;
        int rowY = insets.top;
        final int[] rowX = new int[6];
        rowX[0] = insets.left;
        rowX[1] = rowX[0] + this.columnWidths[0] + this.columnGaps[0];
        rowX[2] = rowX[1] + this.columnWidths[1] + this.columnGaps[1];
        rowX[3] = rowX[2] + this.columnWidths[2] + this.columnGaps[2];
        rowX[4] = rowX[3] + this.columnWidths[3] + this.columnGaps[3];
        rowX[5] = rowX[4] + this.columnWidths[4] + this.columnGaps[4];
        final int w1to2 = this.columnWidths[1] + this.columnGaps[1] + this.columnWidths[2];
        final int w4to5 = this.columnWidths[4] + this.columnGaps[4] + this.columnWidths[5];
        final int w1to4 = w1to2 + this.columnGaps[2] + this.columnWidths[3] + this.columnGaps[3]
                + this.columnWidths[4];
        final int w1to5 = w1to4 + this.columnGaps[4] + this.columnWidths[5];
        final int w0to5 = w1to5 + this.columnWidths[0] + this.columnGaps[0];
        for (int rowIndex = 0; rowIndex < rowCount; rowIndex++) {
            final int format = this.rowFormats[rowIndex % this.rowFormats.length];

            switch (format) {
            case FormatLayout.C:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY, w0to5, c0.getPreferredSize().height);
                componentIndex = componentIndex + 1;
                break;
            case FormatLayout.LC:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        w1to5, c1.getPreferredSize().height);
                componentIndex = componentIndex + 2;
                break;
            case FormatLayout.LCB:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        w1to4, c1.getPreferredSize().height);
                c2 = parent.getComponent(componentIndex + 2);
                c2.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
                        this.columnWidths[5], c2.getPreferredSize().height);
                componentIndex = componentIndex + 3;
                break;
            case FormatLayout.LCLC:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        w1to2, c1.getPreferredSize().height);
                c2 = parent.getComponent(componentIndex + 2);
                c2.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
                        this.columnWidths[3], c2.getPreferredSize().height);
                c3 = parent.getComponent(componentIndex + 3);
                c3.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
                        w4to5, c3.getPreferredSize().height);
                componentIndex = componentIndex + 4;
                break;
            case FormatLayout.LCBLC:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        this.columnWidths[1], c1.getPreferredSize().height);
                c2 = parent.getComponent(componentIndex + 2);
                c2.setBounds(rowX[2], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
                        this.columnWidths[2], c2.getPreferredSize().height);
                c3 = parent.getComponent(componentIndex + 3);
                c3.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
                        this.columnWidths[3], c3.getPreferredSize().height);
                c4 = parent.getComponent(componentIndex + 4);
                c4.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2,
                        w4to5, c4.getPreferredSize().height);
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCLCB:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        w1to2, c1.getPreferredSize().height);
                c2 = parent.getComponent(componentIndex + 2);
                c2.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
                        this.columnWidths[3], c2.getPreferredSize().height);
                c3 = parent.getComponent(componentIndex + 3);
                c3.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
                        this.columnWidths[4], c3.getPreferredSize().height);
                c4 = parent.getComponent(componentIndex + 4);
                c4.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2,
                        this.columnWidths[5], c4.getPreferredSize().height);
                componentIndex = componentIndex + 5;
                break;
            case FormatLayout.LCBLCB:
                c0 = parent.getComponent(componentIndex);
                c0.setBounds(rowX[0], rowY + (this.rowHeights[rowIndex] - c0.getPreferredSize().height) / 2,
                        this.columnWidths[0], c0.getPreferredSize().height);
                c1 = parent.getComponent(componentIndex + 1);
                c1.setBounds(rowX[1], rowY + (this.rowHeights[rowIndex] - c1.getPreferredSize().height) / 2,
                        this.columnWidths[1], c1.getPreferredSize().height);
                c2 = parent.getComponent(componentIndex + 2);
                c2.setBounds(rowX[2], rowY + (this.rowHeights[rowIndex] - c2.getPreferredSize().height) / 2,
                        this.columnWidths[2], c2.getPreferredSize().height);
                c3 = parent.getComponent(componentIndex + 3);
                c3.setBounds(rowX[3], rowY + (this.rowHeights[rowIndex] - c3.getPreferredSize().height) / 2,
                        this.columnWidths[3], c3.getPreferredSize().height);
                c4 = parent.getComponent(componentIndex + 4);
                c4.setBounds(rowX[4], rowY + (this.rowHeights[rowIndex] - c4.getPreferredSize().height) / 2,
                        this.columnWidths[4], c4.getPreferredSize().height);
                c5 = parent.getComponent(componentIndex + 5);
                c5.setBounds(rowX[5], rowY + (this.rowHeights[rowIndex] - c5.getPreferredSize().height) / 2,
                        this.columnWidths[5], c5.getPreferredSize().height);
                componentIndex = componentIndex + 6;
                break;
            }
            rowY = rowY + this.rowHeights[rowIndex] + this.rowGap;
        }
    }
}

From source file:StackLayout.java

/**
 * Returns the minimum size for this layout to arrange the
 * indicated parent's children at the specified orientation.
 *///from w  w w.  j  a v  a2s  .c  o m
public Dimension minimumLayoutSize(Container parent) {
    synchronized (parent.getTreeLock()) {
        if (parent instanceof JToolBar) {
            setOrientation(((JToolBar) parent).getOrientation());
        }

        Component[] comps = parent.getComponents();
        Dimension total = new Dimension(0, 0);

        int depth = calculatePreferredDepth(comps, ourOrientation);
        int length = calculateMinimumLength(comps, ourOrientation, ourSpacing);

        total.width = (ourOrientation == HORIZONTAL ? length : depth);
        total.height = (ourOrientation == HORIZONTAL ? depth : length);

        Insets in = parent.getInsets();
        total.width += in.left + in.right;
        total.height += in.top + in.bottom;

        return total;
    }
}

From source file:TableLayout.java

/**
 * Calculates the preferred layout size for the specified preferred column
 * widths and row heights.//from w  w w  .j  av a2  s  .  co  m
 */

private Dimension calculatePreferredLayoutSize(Container parent, int[] columnWidths, int[] rowHeights) {
    int prefWidth = 0;
    int prefHeight = 0;

    for (int i = 0; i < columnWidths.length; i++)
        prefWidth += columnWidths[i];
    for (int i = 0; i < rowHeights.length; i++)
        prefHeight += rowHeights[i];

    // Add the gaps
    prefWidth += xGap * (columnWidths.length - 1);
    prefHeight += yGap * (rowHeights.length - 1);

    // Add parent insets
    Insets parentInsets = parent.getInsets();
    prefWidth += parentInsets.left + parentInsets.right;
    prefHeight += parentInsets.top + parentInsets.bottom;

    return new Dimension(prefWidth, prefHeight);
}

From source file:org.kineticsystem.commons.layout.TetrisLayout.java

/** 
 * Return the maximum size of this container.
 * @param parent The container to be laid out.
 * @return The maximum container size dimension.
 *//*from w w w  .  j  a  v  a 2  s.c o m*/
public Dimension maximumLayoutSize(Container parent) {
    if (containerSize == null) {
        setup(parent);
    }

    Insets insets = parent.getInsets();
    double maxWidth = maxGapFreeWidth + insets.left + insets.right + cGaps[cBars.length].getIncSize();
    double maxHeight = maxGapFreeHeight + insets.top + insets.bottom + rGaps[rBars.length].getIncSize();

    // Return minimal container size.

    Dimension d = new Dimension((int) Math.round(maxWidth), (int) Math.round(maxHeight));
    return d;
}