Example usage for java.awt Component isVisible

List of usage examples for java.awt Component isVisible

Introduction

In this page you can find the example usage for java.awt Component isVisible.

Prototype

@Transient
public boolean isVisible() 

Source Link

Document

Determines whether this component should be visible when its parent is visible.

Usage

From source file:CircleLayoutTest.java

public void setSizes(Container parent) {
    if (sizesSet)
        return;//  w  w w .  j  a v a2 s .  c  om
    int comCount = parent.getComponentCount();

    for (int i = 0; i < comCount; i++) {
        Component c = parent.getComponent(i);
        if (c.isVisible()) {
            Dimension size = c.getPreferredSize();
            maxComponentWidth = Math.max(maxComponentWidth, size.width);
            maxComponentHeight = Math.max(maxComponentWidth, size.height);
            preferredHeight += size.height;
        }
    }
    preferredHeight += maxComponentHeight;
    preferredWidth = 2 * maxComponentWidth;
    minHeight = preferredHeight;
    minWidth = preferredWidth;
    sizesSet = true;
}

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);/*from   w w w.  j a v  a2  s . com*/
    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);
        }
    }
}

From source file:CircleLayoutTest.java

public void setSizes(Container parent) {
    if (sizesSet)
        return;//from   w  w  w  . j a v  a 2  s  . c o m
    int n = parent.getComponentCount();

    preferredWidth = 0;
    preferredHeight = 0;
    minWidth = 0;
    minHeight = 0;
    maxComponentWidth = 0;
    maxComponentHeight = 0;

    // compute the maximum component widths and heights
    // and set the preferred size to the sum of the component sizes.
    for (int i = 0; i < n; i++) {
        Component c = parent.getComponent(i);
        if (c.isVisible()) {
            Dimension d = c.getPreferredSize();
            maxComponentWidth = Math.max(maxComponentWidth, d.width);
            maxComponentHeight = Math.max(maxComponentHeight, d.height);
            preferredWidth += d.width;
            preferredHeight += d.height;
        }
    }
    minWidth = preferredWidth / 2;
    minHeight = preferredHeight / 2;
    sizesSet = true;
}

From source file:CircleLayoutTest.java

public void layoutContainer(Container parent) {
    setSizes(parent);/*w  w w .jav a2 s  .  c  om*/

    // compute center of the circle

    Insets insets = parent.getInsets();
    int containerWidth = parent.getSize().width - insets.left - insets.right;
    int containerHeight = parent.getSize().height - insets.top - insets.bottom;

    int xcenter = insets.left + containerWidth / 2;
    int ycenter = insets.top + containerHeight / 2;

    // compute radius of the circle

    int xradius = (containerWidth - maxComponentWidth) / 2;
    int yradius = (containerHeight - maxComponentHeight) / 2;
    int radius = Math.min(xradius, yradius);

    // lay out components along the circle

    int n = parent.getComponentCount();
    for (int i = 0; i < n; i++) {
        Component c = parent.getComponent(i);
        if (c.isVisible()) {
            double angle = 2 * Math.PI * i / n;

            // center point of component
            int x = xcenter + (int) (Math.cos(angle) * radius);
            int y = ycenter + (int) (Math.sin(angle) * radius);

            // move component so that its center is (x, y)
            // and its size is its preferred size
            Dimension d = c.getPreferredSize();
            c.setBounds(x - d.width / 2, y - d.height / 2, d.width, d.height);
        }
    }
}

From source file:com.equitysoft.cellspark.ProportionalLayout.java

private Dimension layoutSize(Container parent, boolean minimum) {
    Dimension dim = new Dimension(0, 0);
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            int maxhgt = 0;
            if (c.isVisible()) {
                Dimension d = (minimum) ? c.getMinimumSize() : c.getPreferredSize();
                dim.width += d.width;/*  ww w . ja  va2 s  .  c  om*/
                if (d.height > dim.height)
                    dim.height = d.height;
            }
            cnt++;
            if (cnt == num)
                break;
        }
    }
    Insets insets = parent.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom;
    return dim;
}

From source file:ColumnLayout.java

protected Dimension layoutSize(Container parent, int sizetype) {
    int nkids = parent.getComponentCount();
    Dimension size = new Dimension(0, 0);
    Insets insets = parent.getInsets();
    int num_visible_kids = 0;

    // Compute maximum width and total height of all visible kids
    for (int i = 0; i < nkids; i++) {
        Component kid = parent.getComponent(i);
        Dimension d;//  w ww  .  j av a 2 s  . c o m
        if (!kid.isVisible())
            continue;
        num_visible_kids++;
        if (sizetype == 1)
            d = kid.getPreferredSize();
        else if (sizetype == 2)
            d = kid.getMinimumSize();
        else
            d = kid.getMaximumSize();
        if (d.width > size.width)
            size.width = d.width;
        size.height += d.height;
    }

    // Now add in margins and stuff
    size.width += insets.left + insets.right + 2 * margin_width;
    size.height += insets.top + insets.bottom + 2 * margin_height;
    if (num_visible_kids > 1)
        size.height += (num_visible_kids - 1) * spacing;
    return size;
}

From source file:VerticalLayout.java

private Dimension layoutSize(Container parent, boolean minimum) {
    Dimension dim = new Dimension(0, 0);
    Dimension d;//from w ww .  j  a v a2 s . c  o  m
    synchronized (parent.getTreeLock()) {
        int n = parent.getComponentCount();
        for (int i = 0; i < n; i++) {
            Component c = parent.getComponent(i);
            if (c.isVisible()) {
                d = minimum ? c.getMinimumSize() : c.getPreferredSize();
                dim.width = Math.max(dim.width, d.width);
                dim.height += d.height;
                if (i > 0)
                    dim.height += vgap;
            }
        }
    }
    Insets insets = parent.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom + vgap + vgap;
    return dim;
}

From source file:Main.java

private void setSizes(Container parent) {
    int nComps = parent.getComponentCount();
    Dimension d = null;//from w ww . j  a v  a2s.c  o  m

    //Reset preferred/minimum width and height.
    preferredWidth = 0;
    preferredHeight = 0;
    minWidth = 0;
    minHeight = 0;

    for (int i = 0; i < nComps; i++) {
        Component c = parent.getComponent(i);
        if (c.isVisible()) {
            d = c.getPreferredSize();

            if (i > 0) {
                preferredWidth += d.width / 2;
                preferredHeight += vgap;
            } else {
                preferredWidth = d.width;
            }
            preferredHeight += d.height;

            minWidth = Math.max(c.getMinimumSize().width, minWidth);
            minHeight = preferredHeight;
        }
    }
}

From source file:XYLayout.java

public void layoutContainer(Container target) {
    Insets insets = target.getInsets();
    int count = target.getComponentCount();
    for (int i = 0; i < count; i++) {
        Component component = target.getComponent(i);
        if (component.isVisible()) {
            Rectangle r = getComponentBounds(component, true);
            component.setBounds(insets.left + r.x, insets.top + r.y, r.width, r.height);
        }/*from  w w w . j  a va2 s.  co m*/
    }

}

From source file:XYLayout.java

Dimension getLayoutSize(Container target, boolean doPreferred) {
    Dimension dim = new Dimension(0, 0);
    if (width <= 0 || height <= 0) {
        int count = target.getComponentCount();
        for (int i = 0; i < count; i++) {
            Component component = target.getComponent(i);
            if (component.isVisible()) {
                Rectangle r = getComponentBounds(component, doPreferred);
                dim.width = Math.max(dim.width, r.x + r.width);
                dim.height = Math.max(dim.height, r.y + r.height);
            }//w  w  w  . ja  v  a  2  s. co  m
        }

    }
    if (width > 0)
        dim.width = width;
    if (height > 0)
        dim.height = height;
    Insets insets = target.getInsets();
    dim.width += insets.left + insets.right;
    dim.height += insets.top + insets.bottom;
    return dim;
}