Example usage for java.awt Container getParent

List of usage examples for java.awt Container getParent

Introduction

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

Prototype

public Container getParent() 

Source Link

Document

Gets the parent of this component.

Usage

From source file:Main.java

public static JFrame getFrame(Container component) {
    JFrame frame = null;// ww  w .  jav  a2 s  . c  o  m

    if (component != null) {
        if (component instanceof JFrame) {
            frame = (JFrame) component;
        } else {
            frame = getFrame(component.getParent());
        }
    }

    return frame;
}

From source file:Main.java

static public <T> T getAncestorOfType(JComponent component, Class<T> type) {
    Container ancestor = component.getParent();
    while (ancestor != null) {
        System.out.println("Check  parent : " + ancestor);
        if (type.isInstance(ancestor))
            return (T) ancestor;
        ancestor = ancestor.getParent();
    }/* w w w . j a  va2s . c om*/
    return null;
}

From source file:Main.java

public static void parentWindowToFront(Component component) {
    if (component == null) {
        throw new NullPointerException("component == null");
    }/* w w w. j av a2 s  .  c  o  m*/
    Container parent = component.getParent();
    while (parent != null) {
        if ((parent instanceof Window)) {
            Window parentWindow = (Window) parent;
            parentWindow.toFront();
            return;
        }
        parent = parent.getParent();
    }
}

From source file:Main.java

public static void scrollRectToVisible(Component component, Rectangle aRect) {
    Container parent;
    int dx = component.getX(), dy = component.getY();

    for (parent = component.getParent(); parent != null
            && (!(parent instanceof JViewport) || (((JViewport) parent)
                    .getClientProperty("HierarchicalTable.mainViewport") == null)); parent = parent
                            .getParent()) {
        Rectangle bounds = parent.getBounds();

        dx += bounds.x;//from  w ww .jav  a  2 s . co  m
        dy += bounds.y;
    }

    if (parent != null) {
        aRect.x += dx;
        aRect.y += dy;

        ((JComponent) parent).scrollRectToVisible(aRect);
        aRect.x -= dx;
        aRect.y -= dy;
    }
}

From source file:Main.java

public static boolean isActive(JComponent c) {
    if (c == null) {
        return false;
    }/*  w ww  . j a  v  a2 s . c om*/

    boolean active = true;
    if (c instanceof JInternalFrame) {
        active = ((JInternalFrame) c).isSelected();
    }
    if (active) {
        Container parent = c.getParent();
        while (parent != null) {
            if (parent instanceof JInternalFrame) {
                active = ((JInternalFrame) parent).isSelected();
                break;
            }
            parent = parent.getParent();
        }
    }
    if (active) {
        active = isFrameActive(c);
    }
    return active;
}

From source file:com.asprise.imaging.core.Imaging.java

/** Return the owning window handle of the given component or 0 if failed to determine. */
private static long getOwningWindowHandle(Component component) {
    if (component == null)
        return 0;

    Window window = null;// w ww . j a va2  s . c o  m
    Container container = component.getParent();
    while (true) {
        if (container == null) {
            return 0;
        }

        if (container instanceof Window) {
            window = (Window) container;
            break;
        }

        container = container.getParent();
    }

    return window.getPeer() != null ? ((WComponentPeer) window.getPeer()).getHWnd() : 0;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

/**
 * @return {@link TopLevelFrame} of container
 */// w ww . j a  v a  2s.  c  o  m
public static TopLevelFrame getTopLevelFrame(Container container) {
    Container prevContainer;
    Container parent = container;
    do {
        prevContainer = parent;
        if (parent instanceof DetachedFrame) {
            parent = ((DetachedFrame) parent).getParentContainer();
        }
        if (parent instanceof JPopupMenu) {
            parent = ((JPopupMenu) parent).getInvoker().getParent();
        } else {
            parent = parent.getParent();
        }
    } while (parent != null);

    if (!(prevContainer instanceof TopLevelFrame)) {
        if (prevContainer instanceof JComponent) {
            Object tableForEditor = ((JComponent) prevContainer)
                    .getClientProperty(DesktopTableCellEditor.CELL_EDITOR_TABLE);
            if (tableForEditor != null) {
                return getTopLevelFrame((java.awt.Component) tableForEditor);
            }
        }

        return App.getInstance().getMainFrame();
    }

    return (TopLevelFrame) prevContainer;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopComponentsHelper.java

/**
 * @return {@link TopLevelFrame} of component
 *///  w ww.j a  v  a  2 s .  c o m
public static TopLevelFrame getTopLevelFrame(java.awt.Component component) {
    Container prevContainer;
    Container parent = component instanceof Container ? (Container) component : component.getParent();
    do {
        prevContainer = parent;
        if (parent instanceof DetachedFrame) {
            parent = ((DetachedFrame) parent).getParentContainer();
        }
        if (parent instanceof JPopupMenu) {
            parent = ((JPopupMenu) parent).getInvoker().getParent();
        } else {
            parent = parent.getParent();
        }
    } while (parent != null);

    if (!(prevContainer instanceof TopLevelFrame)) {
        if (prevContainer instanceof JComponent) {
            Object tableForEditor = ((JComponent) prevContainer)
                    .getClientProperty(DesktopTableCellEditor.CELL_EDITOR_TABLE);
            if (tableForEditor != null) {
                return getTopLevelFrame((Container) tableForEditor);
            }
        }

        return App.getInstance().getMainFrame();
    }

    return (TopLevelFrame) prevContainer;
}

From source file:edu.ku.brc.af.core.NavBox.java

/**
 * Refreshes - meaning it makes sure it is resized (layed out) and drawn.
 * @param nbi the box to refresh// www .  j a v  a 2 s  .  c  o  m
 */
public static void refresh(final NavBoxItemIFace nbi) {
    if (nbi != null) {
        Component comp = nbi.getUIComponent();
        comp.invalidate();
        comp.doLayout();
        comp.setSize(comp.getPreferredSize());
        comp.repaint();
        log.debug("comp " + comp.getPreferredSize() + " " + comp.getSize()); //$NON-NLS-1$ //$NON-NLS-2$

        Container parentComp = nbi.getUIComponent().getParent();
        if (parentComp instanceof NavBox) {
            refresh((NavBox) parentComp);
        } else if (parentComp instanceof JScrollPane) {
            // this must be a scrollable NavBox;
            // let's get the actual NavBox
            // container heirarchy is NavBox -> JScrollPane -> NavBoxItem
            parentComp = parentComp.getParent().getParent();
            refresh((NavBox) parentComp);
        }
    }
}

From source file:MainClass.java

protected void configureEnclosingScrollPane() {
    Container container = getParent();
    if (container instanceof JViewport) {
        Container viewParent = container.getParent();
        if (viewParent instanceof JScrollPane) {
            JScrollPane scrollPane = (JScrollPane) viewParent;
            JViewport viewport = scrollPane.getViewport();
            if (viewport == null || viewport.getView() != this) {
                return;
            }/*www .j av a  2 s. co m*/
            scrollPane.setBorder(UIManager.getBorder("Table.scrollPaneBorder"));
        }
    }
}