Example usage for java.awt Container isVisible

List of usage examples for java.awt Container isVisible

Introduction

In this page you can find the example usage for java.awt Container 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 static boolean isVisible(Container container) {
    Container currentComponent = container;
    while (currentComponent != null) {
        if (!currentComponent.isVisible()) {
            return false;
        }// ww  w . ja va  2  s. c  o  m
        currentComponent = currentComponent.getParent();
    }
    return true;
}

From source file:Main.java

/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog            the dialog to be positioned.
 * @param horizontalPercent the relative location.
 * @param verticalPercent   the relative location.
 *//*  w  ww.  ja v  a 2  s.  c  o  m*/
public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent,
        final double verticalPercent) {
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false)) {
        positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
        return;
    }

    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();

    final int baseX = parent.getX();
    final int baseY = parent.getY();

    final int parentPointX = baseX + (int) (horizontalPercent * p.width);
    final int parentPointY = baseY + (int) (verticalPercent * p.height);

    final int dialogPointX = Math.max(0, parentPointX - (int) (horizontalPercent * d.width));
    final int dialogPointY = Math.max(0, parentPointY - (int) (verticalPercent * d.height));

    // make sure the dialog fits completely on the screen...
    final Rectangle s = parent.getGraphicsConfiguration().getBounds();
    final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height);
    final Rectangle intersectedDialogBounds = r.intersection(s);
    if (intersectedDialogBounds.width < d.width) {
        r.x = s.width - d.width;
        r.width = d.width;
    }
    if (intersectedDialogBounds.height < d.height) {
        r.y = s.height - d.height;
        r.height = d.height;
    }
    final Rectangle finalIntersection = r.intersection(s);
    dialog.setBounds(finalIntersection);
}

From source file:GUIUtils.java

/**
 * Centers <CODE>wind</CODE> within its parent. If it has no parent then
 * center within the screen. If centering would cause the title bar to go
 * above the parent (I.E. cannot see the titlebar and so cannot move the
 * window) then move the window down./*www  .  j av  a2s .c  om*/
 * 
 * @param wind
 *          The Window to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>wind</TT> is <TT>null</TT>.
 */
public static void centerWithinParent(Window wind) {
    if (wind == null) {
        throw new IllegalArgumentException("null Window passed");
    }
    final Container parent = wind.getParent();
    if (parent != null && parent.isVisible()) {
        center(wind, new Rectangle(parent.getLocationOnScreen(), parent.getSize()));
    } else {
        centerWithinScreen(wind);
    }
}

From source file:GUIUtils.java

/**
 * Centers passed internal frame within its desktop area. If centering would
 * cause the title bar to go off the top of the screen then move the window
 * down.//w w w .j  a v  a  2s.  c o m
 * 
 * @param frame
 *          The internal frame to be centered.
 * 
 * @throws IllegalArgumentException
 *           If <TT>frame</TT> is <TT>null</TT>.
 */
public static void centerWithinDesktop(JInternalFrame frame) {
    if (frame == null) {
        throw new IllegalArgumentException("null JInternalFrame passed");
    }
    final Container parent = frame.getDesktopPane();
    if (parent != null && parent.isVisible()) {
        center(frame, new Rectangle(new Point(0, 0), parent.getSize()));
    }
}

From source file:nl.xs4all.home.freekdb.b52reader.gui.ManyBrowsersPanelTest.java

private void assertManyBrowsersPanel(ManyBrowsersPanel manyBrowsersPanel, JWebBrowser expectedBrowser,
        boolean expectBrowserPanelVisible) {
    assertEquals(2, manyBrowsersPanel.getComponentCount());

    // The embedded browser is added to a browser panel, which is added to the manyBrowsersPanel.
    Container browserPanel = (Container) manyBrowsersPanel.getComponent(0);
    Component embeddedBrowser = browserPanel.getComponent(0);

    assertEquals(expectedBrowser, embeddedBrowser);
    assertEquals(expectBrowserPanelVisible, browserPanel.isVisible());
}

From source file:org.pentaho.reporting.libraries.designtime.swing.LibSwingUtil.java

/**
 * Positions the specified dialog at a position relative to its parent.
 *
 * @param dialog            the dialog to be positioned.
 * @param horizontalPercent the relative location.
 * @param verticalPercent   the relative location.
 *///from   w ww.  j a  va 2 s .  c o m
public static void positionDialogRelativeToParent(final Dialog dialog, final double horizontalPercent,
        final double verticalPercent) {
    final Container parent = dialog.getParent();
    if (parent == null || (parent.isVisible() == false)) {
        positionFrameOnScreen(dialog, horizontalPercent, verticalPercent);
        return;
    }

    final Dimension d = dialog.getSize();
    final Dimension p = parent.getSize();

    final int baseX = parent.getX();
    final int baseY = parent.getY();

    final int parentPointX = baseX + (int) (horizontalPercent * p.width);
    final int parentPointY = baseY + (int) (verticalPercent * p.height);

    final int dialogPointX = parentPointX - (int) (horizontalPercent * d.width);
    final int dialogPointY = parentPointY - (int) (verticalPercent * d.height);

    // make sure the dialog fits completely on the screen...
    final Rectangle s = parent.getGraphicsConfiguration().getBounds();
    final Rectangle r = new Rectangle(dialogPointX, dialogPointY, d.width, d.height);
    final Rectangle intersectedDialogBounds = r.intersection(s);
    if (intersectedDialogBounds.width < d.width) {
        r.x = s.width - d.width;
        r.width = d.width;
    }
    if (intersectedDialogBounds.height < d.height) {
        r.y = s.height - d.height;
        r.height = d.height;
    }
    final Rectangle finalIntersection = r.intersection(s);
    dialog.setBounds(finalIntersection);
}