Example usage for java.awt Component isShowing

List of usage examples for java.awt Component isShowing

Introduction

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

Prototype

public boolean isShowing() 

Source Link

Document

Determines whether this component is showing on screen.

Usage

From source file:org.eclipse.wb.internal.swing.utils.SwingImageUtils.java

private static void fetchMenuVisualData_JMenu_JPopupMenu(MenuVisualData menuData, Container menuObject)
        throws Exception {
    JPopupMenu popupMenu = menuObject instanceof JPopupMenu ? (JPopupMenu) menuObject
            : ((JMenu) menuObject).getPopupMenu();
    // image//from  w  ww  .j a v  a  2  s  .com
    {
        prepareForPrinting(popupMenu);
        // OSX Java since jdk 1.6.0_20 requires menu invoker to be visible.
        // traverse parents until null or already visible and make sure that all are visible.
        // CHECK: it could flash on Windows.
        Point parentLocation = null;
        Component parent = popupMenu.getInvoker();
        while (parent != null && !parent.isShowing()) {
            Container parent2 = parent.getParent();
            if (parent2 != null) {
                parent = parent2;
            } else {
                break;
            }
        }
        if (parent != null) {
            parentLocation = parent.getLocation();
            prepareForPrinting(parent);
        }
        // fetch image
        try {
            Container popupMenuParent = popupMenu.getParent();
            if (popupMenuParent != null) {
                popupMenuParent.doLayout();
            }
            popupMenu.doLayout();
            menuData.m_menuImage = createComponentShot(popupMenu);
        } finally {
            setVisible(popupMenu, false);
            if (parent != null) {
                parent.setLocation(parentLocation);
                if (parent instanceof JPopupMenu) {
                    setVisible(parent, false);
                }
            }
        }
    }
    // bounds
    {
        org.eclipse.swt.graphics.Rectangle imageBounds = menuData.m_menuImage.getBounds();
        menuData.m_menuBounds = new Rectangle(0, 0, imageBounds.width, imageBounds.height);
    }
    // items
    fetchMenuVisualData_items(menuData, popupMenu);
}