java.awt.Container#isAncestorOf ( )源码实例Demo

下面列出了java.awt.Container#isAncestorOf ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: netbeans   文件: AdditionalWizardPanel.java
/** Resets panel back after monitoring search. Implements <code>ProgressMonitor</code> interface method. */
public void reset() {
    Container container = (Container) getComponent();
    
    if(!container.isAncestorOf(getUI())) {
        container.removeAll();
        GridBagConstraints constraints = new GridBagConstraints();
        constraints.weightx = 1.0;
        constraints.weighty = 1.0;
        constraints.fill = GridBagConstraints.BOTH;
        container.add(getUI(), constraints);
    }
}
 
源代码2 项目: netbeans   文件: ExtTestCase.java
public static Component waitForComponentOrChildToGetFocus(Container c) {
    Component foc = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    int ct=0;
    while (foc == null || (foc != c && !c.isAncestorOf(foc))) {
        try {
            Thread.currentThread().sleep(100);
        } catch (Exception e ) {}
        foc = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        ct++;
        if (ct > 200) {
            break;
        }
    }
    return foc;
}
 
源代码3 项目: netbeans   文件: SheetTable.java
/** See if a component is one we know about or one the current editor
 * knows about.  This affects whether we paint as if focused or not, and
 * is used to determine what kind of focus changes mean we should stop
 * editing, and what kind are ok */
@Override
protected boolean isKnownComponent(Component c) {
    boolean result = super.isKnownComponent(c);

    if (result) {
        return result;
    }

    if (c == null) {
        return false;
    }

    if (c instanceof ButtonPanel) {
        return true;
    }

    InplaceEditor ie = getEditor().getInplaceEditor();

    if (ie != null) {
        JComponent comp = ie.getComponent();

        if (comp == c) {
            return true;
        }

        if (comp.isAncestorOf(c)) {
            return true;
        }
    }

    if (c.getParent() instanceof ButtonPanel) {
        return true;
    }

    if ((getParent() != null) && (getParent().isAncestorOf(c))) {
        return true;
    }

    Container par = getParent();

    if ((par != null) && par.isAncestorOf(c)) {
        return true;
    }

    if (c instanceof InplaceEditor) {
        return true;
    }

    InplaceEditor ine = getEditor().getInplaceEditor();

    if (ine != null) {
        return ine.isKnownComponent(c);
    }

    return false;
}
 
源代码4 项目: netbeans   文件: ExtTestCase.java
/** Determine if a container or its child has focus.  If it is a window,
 * it must be the focused window */
protected static boolean checkFocusedContainer(Container c) throws Exception {
    synchronized (c.getTreeLock()) {
        c.getTreeLock().notifyAll();
    }
    if (SwingUtilities.isEventDispatchThread()) {
        //If the hide action is pending, allow it to happen before
        //checking if something happened
        drainEventQueue();
    } else {
        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                try {
                    drainEventQueue();
                } catch (Exception e) {
                    throw new RuntimeException(e);
                }
            }
        });
    }
    Toolkit.getDefaultToolkit().sync();
    
    //Here we're waiting for the native window system to do *its* focus
    //transferring.  So do some extra waiting - otherwise sometimes focus
    //hasn't arrived at the frame and the events handled by AWT
    sleep();
    sleep();
    sleep();
    sleep();
    sleep();
    
    Window w = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusedWindow();
    Component currowner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
    Component permowner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getPermanentFocusOwner();
    
    if (w == null) {
        return false;
    }
    
    if (w.isAncestorOf(currowner)) {
        //believe it or not this happens
        if (c instanceof Window && w != c) {
            System.err.println("Focused window is " + w);
            return false;
        }
    }
    if (c.isAncestorOf(currowner)) {
        return true;
    }
    if (c.isAncestorOf(permowner)) {
        return true;
    }
    return false;
}