Java Code Examples for java.awt.Container#isAncestorOf()

The following examples show how to use java.awt.Container#isAncestorOf() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AdditionalWizardPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** 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);
    }
}
 
Example 2
Source File: ExtTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
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;
}
 
Example 3
Source File: SheetTable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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;
}
 
Example 4
Source File: ExtTestCase.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/** 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;
}