Example usage for java.awt Container countComponents

List of usage examples for java.awt Container countComponents

Introduction

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

Prototype

@Deprecated
public int countComponents() 

Source Link

Document

Returns the number of components in this container.

Usage

From source file:FunLayout.java

public Dimension preferredLayoutSize(Container con) {
    Component comp;/*from w w w.  ja  v a2  s  .  c  o  m*/
    Rectangle rect;
    int i, count;
    Dimension d;

    d = new Dimension(0, 0);
    count = con.countComponents();
    for (i = 0; i < count; i++) {
        comp = con.getComponent(i);
        if (!comp.isVisible())
            continue;
        rect = comp.getBounds();
        if (d.width < rect.x + rect.width)
            d.width = rect.x + rect.width;
        if (d.height < rect.y + rect.height)
            d.height = rect.y + rect.height;
    }
    return d;
}

From source file:FunLayout.java

public void layoutContainer(Container con) {
    int i, count, deltax, deltay, move;
    Dimension conSize;/*from  ww w.  j  a  v a  2  s . com*/
    Rectangle rect;
    Component comp;

    conSize = con.getSize();
    if (_prevContainerSize == null) {
        _prevContainerSize = conSize;
        return;
    }
    deltax = conSize.width - _prevContainerSize.width;
    deltay = conSize.height - _prevContainerSize.height;
    _prevContainerSize = conSize;
    count = con.countComponents();
    for (i = 0; i < count; i++) {
        comp = con.getComponent(i);
        if (!comp.isVisible())
            continue;
        move = _getMove(comp);
        if (move == 0)
            continue;
        rect = comp.getBounds();
        if (_negSized.containsKey(comp)) {
            // the component is really at a negative size
            rect = (Rectangle) _negSized.get(comp);
            _negSized.remove(comp);
        }
        if ((move & MOVES_RIGHT) > 0)
            rect.x += deltax;
        else if ((move & WIDTH_CHANGES) > 0)
            rect.width += deltax;
        if ((move & MOVES_DOWN) > 0)
            rect.y += deltay;
        else if ((move & HEIGHT_CHANGES) > 0)
            rect.height += deltay;
        // if a components size becomes negative, we track it since the AWT
        // does not allow components to have a size < (0, 0)
        if (rect.width < 0 || rect.height < 0)
            _negSized.put(comp, rect);
        comp.setBounds(rect.x, rect.y, rect.width, rect.height);
    }
}

From source file:CircleOfSquares.java

public Dimension minimumLayoutSize(Container parent) {

    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();
    int rowCount = rows;
    int colCount = cols;

    if (rowCount > 0) {
        colCount = (componentCount + rowCount - 1) / rowCount;
    } else {/* ww  w .  j av a2s  . co  m*/
        rowCount = (componentCount + colCount - 1) / colCount;
    }

    // Find the maximum "minimum width" and the maximum "minimum height"
    // of any component.
    int w = 0;
    int h = 0;
    for (int i = 0; i < componentCount; i++) {

        Component comp = parent.getComponent(i);
        Dimension d = comp.minimumSize();
        if (w < d.width) {
            w = d.width;
        }
        if (h < d.height) {
            h = d.height;
        }
    }

    // Return the maximum "minimum component width and height" times the number
    // of columns and rows, respectively, plus any insets in the parent.
    return new Dimension(parentInsets.left + parentInsets.right + colCount * w,
            parentInsets.top + parentInsets.bottom + rowCount * h);
}

From source file:CircleOfSquares.java

public Dimension preferredLayoutSize(Container parent) {

    int rowCount = rows;
    int colCount = cols;
    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();

    if (rowCount > 0) {
        colCount = (componentCount + rowCount - 1) / rowCount;
    } else {/*from w  w  w  .  jav  a  2  s  .  c  o  m*/
        rowCount = (componentCount + colCount - 1) / colCount;
    }

    // Find the maximum preferred width and the maximum preferred height
    // of any component.
    int w = 0;
    int h = 0;
    for (int i = 0; i < componentCount; i++) {

        Component comp = parent.getComponent(i);
        Dimension d = comp.preferredSize();
        if (w < d.width) {
            w = d.width;
        }
        if (h < d.height) {
            h = d.height;
        }
    }

    // Return the maximum preferred component width and height times the number
    // of columns and rows, respectively, plus any insets in the parent.
    return new Dimension(parentInsets.left + parentInsets.right + colCount * w,
            parentInsets.top + parentInsets.bottom + rowCount * h);
}

From source file:CircleOfSquares.java

public void layoutContainer(Container parent) {

    int rowCount = rows;
    int colCount = hComponentCellWidths.length;
    Insets parentInsets = parent.insets();
    int componentCount = parent.countComponents();

    if (componentCount == 0) {
        return;//from   www .j  a  v a 2s. c o  m
    }

    // Calculate the width and height of each grid cell. The height will
    // be the height of each component, but the width may not. The width
    // of a component will be some multiple of a grid cell width. The
    // number of grid cells for each component is defined by the
    // hComponentCellWidths array. w is width of each grid cell. h is
    // height of each grid cell.
    Dimension parentDim = parent.size();
    int w = parentDim.width - (parentInsets.left + parentInsets.right);
    int h = parentDim.height - (parentInsets.top + parentInsets.bottom);
    w /= cols;
    h /= rowCount;

    // For each row and column of components (not grid cells) position
    // the component.
    for (int c = 0, x = parentInsets.left; c < colCount; c++) {
        for (int r = 0, y = parentInsets.top; r < rowCount; r++) {

            int i = r * colCount + c;
            if (i < componentCount) {
                parent.getComponent(i).reshape(x, y, w * hComponentCellWidths[c], h);
            }
            y += h;
        }
        x += (w * hComponentCellWidths[c]);
    }
}