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

public void layoutContainer(Container parent) {
    Insets insets = parent.getInsets();
    int maxWidth = parent.getWidth() - (insets.left + insets.right);
    int maxHeight = parent.getHeight() - (insets.top + insets.bottom);
    int nComps = parent.getComponentCount();
    int previousWidth = 0, previousHeight = 0;
    int x = 0, y = insets.top;
    int rowh = 0, start = 0;
    int xFudge = 0, yFudge = 0;
    boolean oneColumn = false;

    // Go through the components' sizes, if neither
    // preferredLayoutSize nor minimumLayoutSize has
    // been called.
    if (sizeUnknown) {
        setSizes(parent);//  www  .  j av a 2  s.c o m
    }

    if (maxWidth <= minWidth) {
        oneColumn = true;
    }

    if (maxWidth != preferredWidth) {
        xFudge = (maxWidth - preferredWidth) / (nComps - 1);
    }

    if (maxHeight > preferredHeight) {
        yFudge = (maxHeight - preferredHeight) / (nComps - 1);
    }

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

            // increase x and y, if appropriate
            if (i > 0) {
                if (!oneColumn) {
                    x += previousWidth / 2 + xFudge;
                }
                y += previousHeight + vgap + yFudge;
            }

            // If x is too large,
            if ((!oneColumn) && (x + d.width) > (parent.getWidth() - insets.right)) {
                // reduce x to a reasonable number.
                x = parent.getWidth() - insets.bottom - d.width;
            }

            // If y is too large,
            if ((y + d.height) > (parent.getHeight() - insets.bottom)) {
                // do nothing.
                // Another choice would be to do what we do to x.
            }

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

            previousWidth = d.width;
            previousHeight = d.height;
        }
    }
}

From source file:com.frostwire.gui.components.slides.MultimediaSlideshowPanel.java

private SlidePanel getCurrentSlidePanel() {
    Component[] components = getComponents();
    for (Component c : components) {
        if (c.isVisible() && c instanceof SlidePanel) {
            return ((SlidePanel) c);
        }//  w  ww .  j a v a  2  s  .  c om
    }
    return null;
}

From source file:com.frostwire.gui.components.slides.MultimediaSlideshowPanel.java

@Override
public int getCurrentSlideIndex() {
    Component[] components = getComponents();
    for (Component c : components) {
        if (c.isVisible() && c instanceof SlidePanel) {
            return ((SlidePanel) c).getIndex();
        }//w w w .ja  v  a2s  .  c  o m
    }
    return -1;
}

From source file:RadialLayout.java

/**
 * Sets the sizes attribute of the RadialLayout object.
 *
 * @param  parent  the parent./*from w ww  .j a  v a  2s.  com*/
 * 
 * @see LayoutManager
 */
private void setSizes(final Container parent) {
    final int nComps = parent.getComponentCount();
    //Reset preferred/minimum width and height.
    this.preferredWidth = 0;
    this.preferredHeight = 0;
    this.minWidth = 0;
    this.minHeight = 0;
    for (int i = 0; i < nComps; i++) {
        final Component c = parent.getComponent(i);
        if (c.isVisible()) {
            final Dimension d = c.getPreferredSize();
            if (this.maxCompWidth < d.width) {
                this.maxCompWidth = d.width;
            }
            if (this.maxCompHeight < d.height) {
                this.maxCompHeight = d.height;
            }
            this.preferredWidth += d.width;
            this.preferredHeight += d.height;
        }
    }
    this.preferredWidth = this.preferredWidth / 2;
    this.preferredHeight = this.preferredHeight / 2;
    this.minWidth = this.preferredWidth;
    this.minHeight = this.preferredHeight;
}

From source file:RadialLayout.java

/**
 * This is called when the panel is first displayed, and every time its size
 * changes./*from  w  w  w.j a  v  a 2s. co 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:VerticalFlowLayout.java

/**
 *  Description of the Method//from  w w w .  j a  v  a  2  s.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/*  www  .ja va  2  s  .  co 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:VerticalFlowLayout.java

/**
 *  Description of the Method// w  ww .  ja 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:it.imtech.configuration.StartWizard.java

/**
 * Returns the current active card/*from  ww  w.  j av  a 2s  .  c  o m*/
 * @return 
 */
public JPanel getCurrentCard() {
    JPanel card = null;

    for (Component comp : cardsPanel.getComponents()) {
        if (comp.isVisible() == true) {
            card = (JPanel) comp;
        }
    }

    return card;
}

From source file:FunLayout.java

public Dimension preferredLayoutSize(Container con) {
    Component comp;
    Rectangle rect;//from  w ww.  ja  v  a  2 s  .c om
    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;
}