Example usage for java.awt Container getComponentCount

List of usage examples for java.awt Container getComponentCount

Introduction

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

Prototype

public int getComponentCount() 

Source Link

Document

Gets the number of components in this panel.

Usage

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method//from w w w  .  java2s .c om
 *
 *@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 w  w .j  a  v  a2  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:GraphPaperLayout.java

/**
 * Lays out the container in the specified container.
 * /*w w w  . j  a v a 2s .  c o 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:nl.xs4all.home.freekdb.b52reader.gui.MainGuiTest.java

private Component findComponent(Container parent, Class<?> searchClass) {
    Component result = null;// w w  w  .j a  v a2  s  .co  m

    int componentIndex = 0;
    while (componentIndex < parent.getComponentCount() && result == null) {
        Component component = parent.getComponent(componentIndex);

        if (searchClass.isInstance(component)) {
            result = component;
        } else if (component instanceof Container) {
            result = findComponent((Container) component, searchClass);
        }

        componentIndex++;
    }

    return result;
}

From source file:GraphPaperTest.java

/**
 * Lays out the container in the specified container.
 * /*from  w  w  w .  j a va2s .c o  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 = (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:org.pentaho.reporting.ui.datasources.kettle.EmbeddedKettleDataSourceDialog.java

/**
 * This method makes it possible to control any panel that gets rendered via XUL, without having to create hooks or
 * listeners into the XUL dialog. The presence of a query object dictates whether the panel should be enabled or
 * disabled./* w w w . j  a  va2  s.co  m*/
 *
 * @param enable enable/disable the configuration panel
 * @param c
 */
private void setPanelEnabled(boolean enable, Component c) {
    if (null == c) {
        return;
    }

    Container container = null;
    if (c instanceof Container) {
        container = (Container) c;
    }

    if (container != null) {
        Component[] components = container.getComponents();
        for (int i = 0; i < container.getComponentCount(); i++) {
            Component component = components[i];
            setPanelEnabled(enable, component);
        }

    }
    c.setEnabled(enable);
}

From source file:RadialLayout.java

/**
 * This is called when the panel is first displayed, and every time its size
 * changes.//from   ww w .  ja  v  a  2s.c o  m
 * Note: You CAN'T assume preferredLayoutSize or minimumLayoutSize will be
 * called -- in the case of applets, at least, they probably won't be.
 *
 * @param  parent  the parent.
 * @see LayoutManager
 */
public void layoutContainer(final Container parent) {
    final Insets insets = parent.getInsets();
    final int maxWidth = parent.getSize().width - (insets.left + insets.right);
    final int maxHeight = parent.getSize().height - (insets.top + insets.bottom);
    final int nComps = parent.getComponentCount();
    int x = 0;
    int y = 0;

    // Go through the components' sizes, if neither preferredLayoutSize nor
    // minimumLayoutSize has been called.
    if (this.sizeUnknown) {
        setSizes(parent);
    }

    if (nComps < 2) {
        final Component c = parent.getComponent(0);
        if (c.isVisible()) {
            final Dimension d = c.getPreferredSize();
            c.setBounds(x, y, d.width, d.height);
        }
    } else {
        double radialCurrent = Math.toRadians(90);
        final double radialIncrement = 2 * Math.PI / nComps;
        final int midX = maxWidth / 2;
        final int midY = maxHeight / 2;
        final int a = midX - this.maxCompWidth;
        final int b = midY - this.maxCompHeight;
        for (int i = 0; i < nComps; i++) {
            final Component c = parent.getComponent(i);
            if (c.isVisible()) {
                final Dimension d = c.getPreferredSize();
                x = (int) (midX - (a * Math.cos(radialCurrent)) - (d.getWidth() / 2) + insets.left);
                y = (int) (midY - (b * Math.sin(radialCurrent)) - (d.getHeight() / 2) + insets.top);

                // Set the component's size and position.
                c.setBounds(x, y, d.width, d.height);
            }
            radialCurrent += radialIncrement;
        }
    }
}

From source file:ome.formats.importer.gui.FileQueueChooser.java

/**
 * Get all JLists and JTables if the LAF uses lists/tables
 * /*from   w  w  w  . ja va2s  .  c  o m*/
 * @param fileChooser fileChooser
 * @return fileListObjects
 */
public Component[] getFileListObjects(JFileChooser fileChooser) {
    Vector<Component> v = new Vector<Component>();
    Stack<Component> s = new Stack<Component>();
    s.push(fileChooser);
    while (!s.isEmpty()) {
        Component c = (Component) s.pop();

        if (c instanceof Container) {
            Container d = (Container) c;
            for (int i = 0; i < d.getComponentCount(); i++) {

                if (d.getComponent(i) instanceof JTable) {
                    v.add(d.getComponent(i));
                } else
                    s.push(d.getComponent(i));
            }
        }
    }
    Component[] arr = new Component[v.size()];
    for (int i = 0; i < arr.length; i++)
        arr[i] = v.get(i);

    return arr;
}

From source file:VerticalFlowLayout.java

/**
 *  Description of the Method//from w w  w  . j  a v  a  2 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:CircleLayoutTest.java

public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    int containerWidth = parent.getSize().width - insets.left - insets.right;
    int containerHeight = parent.getSize().height - insets.top - insets.bottom;
    int xradius = (containerWidth - maxComponentWidth) / 2;
    int yradius = (containerHeight - maxComponentHeight) / 2;

    setSizes(parent);/* ww  w . j av a  2  s. c o m*/
    int centerX = insets.left + containerWidth / 2;
    int centerY = insets.top + containerHeight / 2;

    int comCount = parent.getComponentCount();
    for (int i = 0; i < comCount; i++) {
        Component c = parent.getComponent(i);
        if (c.isVisible()) {
            Dimension size = c.getPreferredSize();
            double angle = 2 * Math.PI * i / comCount;
            int x = centerX + (int) (Math.cos(angle) * xradius);
            int y = centerY + (int) (Math.sin(angle) * yradius);

            c.setBounds(x - size.width / 2, y - size.height / 2, size.width, size.height);
        }
    }
}