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:StackLayout.java

public void layoutContainer(Container parent) {
    Component visibleComp = getVisibleComponent();
    if (visibleComp != null) {
        synchronized (parent.getTreeLock()) {
            Insets insets = parent.getInsets();
            visibleComp.setBounds(insets.left, insets.top, parent.getWidth() - (insets.left + insets.right),
                    parent.getHeight() - (insets.top + insets.bottom));
        }// ww w. j  a  va2 s  . c  om
    }
}

From source file:SquareLayout.java

/**
 * Calculates the minimum size dimensions for the specified panel given the 
 * components in the specified parent container. 
 *//*from   w w w .j  av  a 2 s.  co  m*/

public Dimension minimumLayoutSize(Container container) {
    Component child = getChild(container);
    if (child == null)
        return new Dimension(0, 0);

    Dimension childMinSize = child.getMinimumSize();
    Insets insets = container.getInsets();

    int width = childMinSize.width + insets.left + insets.right;
    int height = childMinSize.height + insets.top + insets.bottom;
    int maxSize = Math.max(width, height);
    return new Dimension(maxSize, maxSize);
}

From source file:SquareLayout.java

/**
 * Calculates the preferred size dimensions for the specified panel given the
 * components in the specified parent container. 
 *//*  w w  w .  j ava2  s .  com*/

public Dimension preferredLayoutSize(Container container) {
    Component child = getChild(container);
    if (child == null)
        return new Dimension(0, 0);

    Dimension childPrefSize = child.getPreferredSize();
    Insets insets = container.getInsets();

    int width = childPrefSize.width + insets.left + insets.right;
    int height = childPrefSize.height + insets.top + insets.bottom;
    int maxSize = Math.max(width, height);
    return new Dimension(maxSize, maxSize);
}

From source file:CircleLayoutDemo.java

/**
 * Arranges the parent's Component objects in either an Ellipse or a Circle.
 * Ellipse is not yet implemented./*  ww  w.  ja va2 s .c o m*/
 */
public void layoutContainer(Container parent) {
    int x, y, w, h, s, c;
    int n = parent.getComponentCount();
    double parentWidth = parent.getSize().width;
    double parentHeight = parent.getSize().height;
    Insets insets = parent.getInsets();
    int centerX = (int) (parentWidth - (insets.left + insets.right)) / 2;
    int centerY = (int) (parentHeight - (insets.top + insets.bottom)) / 2;

    Component comp = null;
    Dimension compPS = null;
    if (n == 1) {
        comp = parent.getComponent(0);
        x = centerX;
        y = centerY;
        compPS = comp.getPreferredSize();
        w = compPS.width;
        h = compPS.height;
        comp.setBounds(x, y, w, h);
    } else {
        double r = (Math.min(parentWidth - (insets.left + insets.right),
                parentHeight - (insets.top + insets.bottom))) / 2;
        r *= 0.75; // Multiply by .75 to account for extreme right and bottom
                   // Components
        for (int i = 0; i < n; i++) {
            comp = parent.getComponent(i);
            compPS = comp.getPreferredSize();
            if (isCircle) {
                c = (int) (r * Math.cos(2 * i * Math.PI / n));
                s = (int) (r * Math.sin(2 * i * Math.PI / n));
            } else {
                c = (int) ((centerX * 0.75) * Math.cos(2 * i * Math.PI / n));
                s = (int) ((centerY * 0.75) * Math.sin(2 * i * Math.PI / n));
            }
            x = c + centerX;
            y = s + centerY;

            w = compPS.width;
            h = compPS.height;

            comp.setBounds(x, y, w, h);
        }
    }

}

From source file:Main.java

public Dimension minimumLayoutSize(Container parent) {
    Dimension dim = new Dimension(0, 0);
    int nComps = parent.getComponentCount();

    //Always add the container's insets!
    Insets insets = parent.getInsets();
    dim.width = minWidth + insets.left + insets.right;
    dim.height = minHeight + insets.top + insets.bottom;

    sizeUnknown = false;/*from w ww . ja v  a2s. co m*/

    return dim;
}

From source file:EdgeLayoutExample.java

public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
        Insets insets = parent.getInsets();
        int top = insets.top;
        int left = insets.left;

        Dimension minimumSize = minimumLayoutSize(parent);

        int height = minimumSize.height;
        int width = minimumSize.width;

        int availableHeight = parent.getHeight() - insets.bottom - insets.top;
        int availableWidth = parent.getWidth() - insets.left - insets.right;
        if (height < availableHeight) {
            height = availableHeight;//www .  j av  a2  s. c  o  m
        }
        if (width < availableWidth) {
            width = availableWidth;
        }

        int bottom = availableHeight;
        int right = availableWidth;

        Dimension preferredSize = preferredLayoutSize(parent);

        int preferredWidthAvailable = width - preferredSize.width;
        int preferredHeightAvailable = height - preferredSize.height;

        Component centerComp = null;

        for (int i = 0; i < this.components.size(); i++) {
            Component c = (Component) this.components.get(i);
            String constraint = (String) this.constraints.get(c);

            if (constraint.equals(CENTER)) {
                centerComp = c;
            } else {
                int compHeight;
                int compWidth;
                int xOrigin;
                int yOrigin;

                if (constraint.equals(NORTH) || constraint.equals(SOUTH)) {
                    compWidth = width;

                    if (preferredHeightAvailable > 0) {
                        int preferredHeightNeeded = c.getPreferredSize().height - c.getMinimumSize().height;
                        if (preferredHeightAvailable > preferredHeightNeeded) {
                            compHeight = c.getPreferredSize().height;
                            preferredHeightAvailable -= preferredHeightNeeded;
                        } else {
                            compHeight = c.getMinimumSize().height + preferredHeightAvailable;
                            preferredHeightAvailable = 0;
                        }
                    } else {
                        compHeight = c.getMinimumSize().height;
                    }
                    height = height - compHeight;

                    xOrigin = left;

                    if (constraint.equals(NORTH)) {
                        yOrigin = top;
                        top += compHeight;
                    } else {
                        yOrigin = bottom - compHeight;
                        bottom = yOrigin;
                    }
                } else {
                    compHeight = height;
                    if (preferredWidthAvailable > 0) {
                        int preferredWidthNeeded = c.getPreferredSize().width - c.getMinimumSize().width;
                        if (preferredWidthAvailable > preferredWidthNeeded) {
                            compWidth = c.getPreferredSize().width;
                            preferredWidthAvailable -= preferredWidthNeeded;
                        } else {
                            compWidth = c.getMinimumSize().width + preferredWidthAvailable;
                            preferredWidthAvailable = 0;
                        }
                    } else {
                        compWidth = c.getMinimumSize().width;
                    }
                    width = width - compWidth;

                    yOrigin = top;

                    if (constraint.equals(WEST)) {
                        xOrigin = left;
                        left += compWidth;
                    } else {
                        xOrigin = right - compWidth;
                        right = xOrigin;
                    }
                }
                c.setSize(compWidth, compHeight);
                c.setBounds(xOrigin, yOrigin, compWidth, compHeight);
            }
            if (centerComp != null) {
                c.setSize(width, height);
                c.setBounds(left, top, width, height);
            }
        }
    }
}

From source file:TreeLinkTest.java

public Dimension minimumLayoutSize(Container target) {
    Dimension d = root.getMinimumSize();
    Insets insets = target.getInsets();
    d.width += insets.left + insets.right;
    d.height += insets.top + insets.bottom;
    return d;//from   www  .ja v  a 2  s.  c o  m
}

From source file:TreeLinkTest.java

public Dimension preferredLayoutSize(Container target) {
    Dimension d = root.getPreferredSize();
    Insets insets = target.getInsets();
    d.width += insets.left + insets.right;
    d.height += insets.top + insets.bottom;
    return d;/*from   ww  w  . j a  v  a2  s.co  m*/
}

From source file:LCBLayout.java

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

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        final int ncomponents = parent.getComponentCount();
        final int nrows = ncomponents / COLUMNS;
        for (int c = 0; c < COLUMNS; c++) {
            for (int r = 0; r < nrows; r++) {
                final Component component = parent.getComponent(r * COLUMNS + c);
                final Dimension d = component.getPreferredSize();
                if (this.colWidth[c] < d.width) {
                    this.colWidth[c] = d.width;
                }
                if (this.rowHeight[r] < d.height) {
                    this.rowHeight[r] = d.height;
                }
            }
        }
        int totalHeight = this.vGap * (nrows - 1);
        for (int r = 0; r < nrows; r++) {
            totalHeight = totalHeight + this.rowHeight[r];
        }
        final int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap
                + this.colWidth[2];
        return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap,
                insets.top + insets.bottom + totalHeight + this.vGap);
    }

}

From source file:LCBLayout.java

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

    synchronized (parent.getTreeLock()) {
        final Insets insets = parent.getInsets();
        final int ncomponents = parent.getComponentCount();
        final int nrows = ncomponents / COLUMNS;
        for (int c = 0; c < COLUMNS; c++) {
            for (int r = 0; r < nrows; r++) {
                final Component component = parent.getComponent(r * COLUMNS + c);
                final Dimension d = component.getMinimumSize();
                if (this.colWidth[c] < d.width) {
                    this.colWidth[c] = d.width;
                }
                if (this.rowHeight[r] < d.height) {
                    this.rowHeight[r] = d.height;
                }
            }
        }
        int totalHeight = this.vGap * (nrows - 1);
        for (int r = 0; r < nrows; r++) {
            totalHeight = totalHeight + this.rowHeight[r];
        }
        final int totalWidth = this.colWidth[0] + this.labelGap + this.colWidth[1] + this.buttonGap
                + this.colWidth[2];
        return new Dimension(insets.left + insets.right + totalWidth + this.labelGap + this.buttonGap,
                insets.top + insets.bottom + totalHeight + this.vGap);
    }

}