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

/**
 * Returns the minimum size./*  w  w w .  ja  v a 2  s  .co m*/
 *
 * @param parent  the parent.
 *
 * @return The minimum size.
 * @see LayoutManager
 */
public Dimension minimumLayoutSize(final Container parent) {
    final Dimension dim = new Dimension(0, 0);

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

    this.sizeUnknown = false;
    return dim;
}

From source file:Main.java

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

    setSizes(parent);/* w  ww  .j  a  v a2 s.  c om*/

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

    sizeUnknown = false;

    return dim;
}

From source file:LCBLayout.java

/**
 * Lays out the components./*from   w  w  w.ja  va  2s. co  m*/
 *
 * @param parent  the parent.
 */
public void layoutContainer(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.colWidth[1] + this.colWidth[2];

        // adjust the width of the second column to use up all of parent
        final int available = parent.getWidth() - insets.left - insets.right - this.labelGap - this.buttonGap;
        this.colWidth[1] = this.colWidth[1] + (available - totalWidth);

        // *** DO THE LAYOUT ***
        int x = insets.left;
        for (int c = 0; c < COLUMNS; c++) {
            int y = insets.top;
            for (int r = 0; r < nrows; r++) {
                final int i = r * COLUMNS + c;
                if (i < ncomponents) {
                    final Component component = parent.getComponent(i);
                    final Dimension d = component.getPreferredSize();
                    final int h = d.height;
                    final int adjust = (this.rowHeight[r] - h) / 2;
                    parent.getComponent(i).setBounds(x, y + adjust, this.colWidth[c], h);
                }
                y = y + this.rowHeight[r] + this.vGap;
            }
            x = x + this.colWidth[c];
            if (c == 0) {
                x = x + this.labelGap;
            }
            if (c == 1) {
                x = x + this.buttonGap;
            }
        }

    }

}

From source file:RadialLayout.java

/**
 * Returns the preferred size.// w  w  w  . ja  va2 s .  c o m
 *
 * @param parent  the parent.
 *
 * @return The preferred size.
 * @see LayoutManager
 */
public Dimension preferredLayoutSize(final Container parent) {
    final Dimension dim = new Dimension(0, 0);
    setSizes(parent);

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

    this.sizeUnknown = false;
    return dim;
}

From source file:GraphPaperLayout.java

/**
 * Lays out the container in the specified container.
 * //from ww w .j  a  v  a 2 s  .co m
 * @param parent
 *          the component which needs to be laid out
 */
public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
        Insets insets = parent.getInsets();
        int ncomponents = parent.getComponentCount();

        if (ncomponents == 0) {
            return;
        }

        // Total parent dimensions
        Dimension size = parent.getSize();
        int totalW = size.width - (insets.left + insets.right);
        int totalH = size.height - (insets.top + insets.bottom);

        // Cell dimensions, including padding
        int totalCellW = totalW / gridSize.width;
        int totalCellH = totalH / gridSize.height;

        // Cell dimensions, without padding
        int cellW = (totalW - ((gridSize.width + 1) * hgap)) / gridSize.width;
        int cellH = (totalH - ((gridSize.height + 1) * vgap)) / gridSize.height;

        for (int i = 0; i < ncomponents; i++) {
            Component c = parent.getComponent(i);
            Rectangle rect = compTable.get(c);
            if (rect != null) {
                int x = insets.left + (totalCellW * rect.x) + hgap;
                int y = insets.top + (totalCellH * rect.y) + vgap;
                int w = (cellW * rect.width) - hgap;
                int h = (cellH * rect.height) - vgap;
                c.setBounds(x, y, w, h);
            }
        }
    }
}

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method/*  w ww.  j a v  a2  s  .c o  m*/
 *
 *@param  target  Description of Parameter
 */
public void layoutContainer(Container target) {
    synchronized (target.getTreeLock()) {
        Insets insets = target.getInsets();
        int maxheight = target.getHeight() - (insets.top + insets.bottom + _vgap * 2);
        int nmembers = target.getComponentCount();
        int y = 0;

        Dimension preferredSize = preferredLayoutSize(target);
        Dimension targetSize = target.getSize();

        switch (_valign) {
        case TOP:
            y = insets.top;
            break;
        case CENTER:
            y = (targetSize.height - preferredSize.height) / 2;
            break;
        case BOTTOM:
            y = targetSize.height - preferredSize.height - insets.bottom;
            break;
        }

        for (int i = 0; i < nmembers; i++) {
            Component m = target.getComponent(i);
            if (m.isVisible()) {
                Dimension d = m.getPreferredSize();
                m.setSize(d.width, d.height);

                if ((y + d.height) <= maxheight) {
                    if (y > 0) {
                        y += _vgap;
                    }

                    int x = 0;
                    switch (_halign) {
                    case LEFT:
                        x = insets.left;
                        break;
                    case CENTER:
                        x = (targetSize.width - d.width) / 2;
                        break;
                    case RIGHT:
                        x = targetSize.width - d.width - insets.right;
                        break;
                    }

                    m.setLocation(x, y);

                    y += d.getHeight();

                } else {
                    break;
                }
            }
        }
    }
}

From source file:GraphPaperLayout.java

/**
 * Algorithm for calculating layout size (minimum or preferred).
 * <P>/*from  w w w .ja  v a 2  s .  com*/
 * The width of a graph paper layout is the largest cell width (calculated in
 * <code>getLargestCellSize()</code> times the number of columns, plus the
 * horizontal padding times the number of columns plus one, plus the left and
 * right insets of the target container.
 * <P>
 * The height of a graph paper layout is the largest cell height (calculated
 * in <code>getLargestCellSize()</code> times the number of rows, plus the
 * vertical padding times the number of rows plus one, plus the top and bottom
 * insets of the target container.
 * 
 * @param parent
 *          the container in which to do the layout.
 * @param isPreferred
 *          true for calculating preferred size, false for calculating minimum
 *          size.
 * @return the dimensions to lay out the subcomponents of the specified
 *         container.
 * @see java.awt.GraphPaperLayout#getLargestCellSize
 */
protected Dimension getLayoutSize(Container parent, boolean isPreferred) {
    Dimension largestSize = getLargestCellSize(parent, isPreferred);
    Insets insets = parent.getInsets();
    largestSize.width = (largestSize.width * gridSize.width) + (hgap * (gridSize.width + 1)) + insets.left
            + insets.right;
    largestSize.height = (largestSize.height * gridSize.height) + (vgap * (gridSize.height + 1)) + insets.top
            + insets.bottom;
    return largestSize;
}

From source file:GraphPaperTest.java

/**
 * Lays out the container in the specified container.
 * //from ww  w. ja  va 2  s .com
 * @param parent
 *            the component which needs to be laid out
 */
public void layoutContainer(Container parent) {
    synchronized (parent.getTreeLock()) {
        Insets insets = parent.getInsets();
        int ncomponents = parent.getComponentCount();

        if (ncomponents == 0) {
            return;
        }

        // Total parent dimensions
        Dimension size = parent.getSize();
        int totalW = size.width - (insets.left + insets.right);
        int totalH = size.height - (insets.top + insets.bottom);

        // Cell dimensions, including padding
        int totalCellW = totalW / gridSize.width;
        int totalCellH = totalH / gridSize.height;

        // Cell dimensions, without padding
        int cellW = (totalW - ((gridSize.width + 1) * hgap)) / gridSize.width;
        int cellH = (totalH - ((gridSize.height + 1) * vgap)) / gridSize.height;

        for (int i = 0; i < ncomponents; i++) {
            Component c = parent.getComponent(i);
            Rectangle rect = (Rectangle) compTable.get(c);
            if (rect != null) {
                int x = insets.left + (totalCellW * rect.x) + hgap;
                int y = insets.top + (totalCellH * rect.y) + vgap;
                int w = (cellW * rect.width) - hgap;
                int h = (cellH * rect.height) - vgap;
                c.setBounds(x, y, w, h);
            }
        }
    }
}

From source file:pl.edu.icm.visnow.lib.utils.ImageUtilities.java

public static void sizeContainerToComponent(Container container, Component component) {
    if (container.isDisplayable() == false) {
        container.addNotify();/*  www  .  jav  a 2 s  .c o m*/
    }
    Insets insets = container.getInsets();
    Dimension size = component.getPreferredSize();
    int width = insets.left + insets.right + size.width;
    int height = insets.top + insets.bottom + size.height;
    container.setSize(width, height);
}

From source file:TableLayout.java

public Dimension minimumLayoutSize(Container parent) {
    Insets insets = parent.getInsets();
    measureComponents(parent);/*  ww  w  .ja v  a2  s .  c  o m*/
    // System.out.println("Min Size: "+MinWidth+","+MinHeight);
    return new Dimension(insets.left + insets.right + MinWidth, insets.top + insets.bottom + MinHeight);
}