Java Code Examples for java.awt.FocusTraversalPolicy#getComponentAfter()

The following examples show how to use java.awt.FocusTraversalPolicy#getComponentAfter() . 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: DefaultFocusManager.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 2
Source File: DefaultFocusManager.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 3
Source File: DefaultFocusManager.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 4
Source File: DefaultFocusManager.java    From JDKSourceCode1.8 with MIT License 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 5
Source File: DefaultFocusManager.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 6
Source File: DefaultFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 7
Source File: CategoryList.java    From netbeans with Apache License 2.0 6 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    int selIndexBefore = getSelectedIndex();
    defaultAction.actionPerformed( e );
    int selIndexCurrent = getSelectedIndex();
    if( selIndexBefore != selIndexCurrent )
        return;
    
    if( focusNext && 0 == selIndexCurrent && getModel().getSize() > 1 && getModel().getSize() > getColumnCount() )
        return;
    
    KeyboardFocusManager kfm = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    Container container = kfm.getCurrentFocusCycleRoot();
    FocusTraversalPolicy policy = container.getFocusTraversalPolicy();
    if( null == policy )
        policy = kfm.getDefaultFocusTraversalPolicy();
    Component next = focusNext ? policy.getComponentAfter( container, CategoryList.this )
                              : policy.getComponentBefore( container, CategoryList.this );
    if( null != next && next instanceof CategoryButton ) {
        clearSelection();
        next.requestFocus();
    }
}
 
Example 8
Source File: DefaultFocusManager.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 9
Source File: DefaultFocusManager.java    From jdk1.8-source-analysis with Apache License 2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 10
Source File: DefaultFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 11
Source File: DefaultFocusManager.java    From Java8CN with Apache License 2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 12
Source File: DefaultFocusManager.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 13
Source File: DefaultFocusManager.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 14
Source File: DefaultFocusManager.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public Component getComponentAfter(Container aContainer,
                                   Component aComponent)
{
    Container root = (aContainer.isFocusCycleRoot())
        ? aContainer
        : aContainer.getFocusCycleRootAncestor();

    // Support for mixed 1.4/pre-1.4 focus APIs. If a particular root's
    // traversal policy is non-legacy, then honor it.
    if (root != null) {
        FocusTraversalPolicy policy = root.getFocusTraversalPolicy();
        if (policy != gluePolicy) {
            return policy.getComponentAfter(root, aComponent);
        }

        comparator.setComponentOrientation(root.getComponentOrientation());
        return layoutPolicy.getComponentAfter(root, aComponent);
    }

    return null;
}
 
Example 15
Source File: CefClient.java    From APICloud-Studio with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onTakeFocus(CefBrowser browser, boolean next) {
	if (browser == null) 
		return;
	
	browser.setFocus(false);
	Container parent = browser.getUIComponent().getParent();
	if (parent != null) {
		FocusTraversalPolicy policy = null;
		while (parent != null) {
			policy = parent.getFocusTraversalPolicy();
			if (policy != null)
				break;
			parent = parent.getParent();
		}
		if (policy != null) {
			Component nextComp = next ? policy.getComponentAfter(parent, browser.getUIComponent()) 
                                               : policy.getComponentBefore(parent, browser.getUIComponent());
			if (nextComp == null) {
				policy.getDefaultComponent(parent).requestFocus();
			} else {
				nextComp.requestFocus();
			}
		}
	}
	if (focusHandler_ != null)
		focusHandler_.onTakeFocus(browser, next);
}
 
Example 16
Source File: FocusArrowListener.java    From pumpernickel with MIT License 5 votes vote down vote up
/**
 * Returns a set of all the components that can have the keyboard focus.
 * <P>
 * My first implementation involved of this concept simply involved asking
 * JCompnonents if they were focusable, but in the
 * <code>FilledButtonTest</code> this resulted in shifting focus to the
 * ContentPane. Although it is technically focusable: if I used the tab key
 * I did <i>not</i> get this result. So I studied the inner workings for
 * Component.transferFocus() and ended up with a method that involved calls
 * to <code>getFocusCycleRootAncestor()</code>, and
 * <code>getFocusTraversalPolicy()</code>.
 * <P>
 * (Also credit goes to Werner for originally tipping me off towards looking
 * at FocusTraversalPolicies.)
 * 
 * @param currentFocusOwner
 *            the current focus owner.
 * @return all the JComponents that can receive the focus.
 */
public static Set<Component> getFocusableComponents(
		Component currentFocusOwner) {
	HashSet<Component> set = new HashSet<Component>();
	set.add(currentFocusOwner);

	Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
	Component comp = currentFocusOwner;
	while (rootAncestor != null
			&& !(rootAncestor.isShowing() && rootAncestor.isFocusable() && rootAncestor
					.isEnabled())) {
		comp = rootAncestor;
		rootAncestor = comp.getFocusCycleRootAncestor();
	}
	if (rootAncestor != null) {
		FocusTraversalPolicy policy = rootAncestor
				.getFocusTraversalPolicy();
		Component toFocus = policy.getComponentAfter(rootAncestor, comp);

		while (toFocus != null && set.contains(toFocus) == false) {
			set.add(toFocus);
			toFocus = policy.getComponentAfter(rootAncestor, toFocus);
		}

		toFocus = policy.getComponentBefore(rootAncestor, comp);

		while (toFocus != null && set.contains(toFocus) == false) {
			set.add(toFocus);
			toFocus = policy.getComponentBefore(rootAncestor, toFocus);
		}
	}
	return set;
}
 
Example 17
Source File: FocusArrowListener.java    From Pixelitor with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns a set of all the components that
 * can have the keyboard focus.
 * <P>My first implementation involved of this concept
 * simply involved asking JCompnonents if they were
 * focusable, but in the <code>FilledButtonTest</code> this
 * resulted in shifting focus to the ContentPane.  Although
 * it is technically focusable: if I used the tab key
 * I did <i>not</i> get this result.  So I studied
 * the inner workings for Component.transferFocus()
 * and ended up with a method that involved
 * calls to <code>getFocusCycleRootAncestor()</code>,
 * and <code>getFocusTraversalPolicy()</code>.
 * <P>(Also credit goes to Werner for originally tipping me off
 * towards looking at FocusTraversalPolicies.)
 *
 * @param currentFocusOwner the current focus owner.
 * @return all the JComponents that can receive the focus.
 */
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
    Set<Component> set = new HashSet<>();
    set.add(currentFocusOwner);

    Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
    Component comp = currentFocusOwner;
    while (rootAncestor != null &&
            !(rootAncestor.isShowing() &&
                    rootAncestor.isFocusable() &&
                    rootAncestor.isEnabled())) {
        comp = rootAncestor;
        rootAncestor = comp.getFocusCycleRootAncestor();
    }
    if (rootAncestor != null) {
        FocusTraversalPolicy policy =
                rootAncestor.getFocusTraversalPolicy();
        Component toFocus = policy.getComponentAfter(rootAncestor, comp);

        while (toFocus != null && !set.contains(toFocus)) {
            set.add(toFocus);
            toFocus = policy.getComponentAfter(rootAncestor, toFocus);
        }

        toFocus = policy.getComponentBefore(rootAncestor, comp);

        while (toFocus != null && !set.contains(toFocus)) {
            set.add(toFocus);
            toFocus = policy.getComponentBefore(rootAncestor, toFocus);
        }
    }
    return set;
}
 
Example 18
Source File: FocusArrowListener.java    From PyramidShader with GNU General Public License v3.0 5 votes vote down vote up
/** Returns a set of all the components that
 * can have the keyboard focus.
 * <P>My first implementation involved of this concept
 * simply involved asking JCompnonents if they were
 * focusable, but in the <code>FilledButtonTest</code> this
 * resulted in shifting focus to the ContentPane.  Although
 * it is technically focusable: if I used the tab key
 * I did <i>not</i> get this result.  So I studied
 * the inner workings for Component.transferFocus()
 * and ended up with a method that involved
 * calls to <code>getFocusCycleRootAncestor()</code>,
 * and <code>getFocusTraversalPolicy()</code>.
 * <P>(Also credit goes to Werner for originally tipping me off
 * towards looking at FocusTraversalPolicies.)
 * @param currentFocusOwner the current focus owner.
 * @return all the JComponents that can receive the focus.
 */
public static Set<Component> getFocusableComponents(Component currentFocusOwner) {
	HashSet<Component> set = new HashSet<Component>();
	set.add(currentFocusOwner);

       Container rootAncestor = currentFocusOwner.getFocusCycleRootAncestor();
       Component comp = currentFocusOwner;
       while (rootAncestor != null && 
              !(rootAncestor.isShowing() && 
                rootAncestor.isFocusable() && 
                rootAncestor.isEnabled())) 
       {
           comp = rootAncestor;
           rootAncestor = comp.getFocusCycleRootAncestor();
       }
       if (rootAncestor != null) {
           FocusTraversalPolicy policy =
               rootAncestor.getFocusTraversalPolicy();
           Component toFocus = policy.getComponentAfter(rootAncestor, comp);
           
           while(toFocus!=null && set.contains(toFocus)==false) {
           	set.add(toFocus);
               toFocus = policy.getComponentAfter(rootAncestor, toFocus);
           }
           
           toFocus = policy.getComponentBefore(rootAncestor, comp);
           
           while(toFocus!=null && set.contains(toFocus)==false) {
           	set.add(toFocus);
               toFocus = policy.getComponentBefore(rootAncestor, toFocus);
           }
       }
	return set;
}
 
Example 19
Source File: FormFocusTransversalPolicy.java    From jdal with Apache License 2.0 4 votes vote down vote up
@Override
public Component getComponentAfter(Container container,
		Component component) {
	
	// Fix awt bug looking for ComboBoxEditor instead ComboBox
	// see http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6205817
	if (component.getParent() instanceof JComboBox)
			component = component.getParent();

	int index = components.indexOf(component);
	
	if (index == -1) { // not owner
		Container childContainer =  getTopmostProvider(container, component);
		if (childContainer == null)
			return getFirstComponent(container);
		
		FocusTraversalPolicy ftp = childContainer.getFocusTraversalPolicy();
		if (ftp != null && ftp != this) {
			Component next =  ftp.getComponentAfter(childContainer, component);
			if (next != ftp.getFirstComponent(container)) 
				return next;
			
			// child cycle
			do {
				index = components.indexOf(childContainer);
				childContainer = childContainer.getParent();
			} while (index == -1 || childContainer == null);
			
			if (index == -1) {
				log.warn("I can't figure what is the next component");
				return getFirstComponent(container);
			}
		}
	}
	
	index++;
	
	if (index < components.size() && index >= 0) {
		Component c = getComponent(index);
		if (c.isEnabled() && c.isFocusable()) 
			return c;
		else 
			return getComponentAfter(container, c);
	}
	
	return getFirstComponent(container);
}
 
Example 20
Source File: ETable.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    setFocusCycleRoot(false);
    try {
        Container con = ETable.this.getFocusCycleRootAncestor();
        if (con != null) {
            /*
            Component target = ETable.this;
            if (getParent() instanceof JViewport) {
                target = getParent().getParent();
                if (target == con) {
                    target = ETable.this;
                }
            }
            */

            EventObject eo = EventQueue.getCurrentEvent();
            boolean backward = false;
            if (eo instanceof KeyEvent) {
                backward = 
                    (((KeyEvent) eo).getModifiers() 
                    & KeyEvent.SHIFT_MASK) 
                    != 0 && (((KeyEvent) eo).getModifiersEx() & 
                    KeyEvent.SHIFT_DOWN_MASK) != 0;
            }

            Component c = ETable.this;
            Component to;
            Container parentWithFTP = null;
            do {
                FocusTraversalPolicy ftp = con.getFocusTraversalPolicy();
                to = backward ? ftp.getComponentBefore(con, c)
                              : ftp.getComponentAfter(con, c);


                if (to == ETable.this) {
                    to = backward ? ftp.getFirstComponent(con)
                                  : ftp.getLastComponent(con);
                }
                if (to == ETable.this) {
                    parentWithFTP = con.getParent();
                    if (parentWithFTP != null) {
                        parentWithFTP = parentWithFTP.getFocusCycleRootAncestor();
                    }
                    if (parentWithFTP != null) {
                        c = con;
                        con = parentWithFTP;
                    }
                }
            } while (to == ETable.this && parentWithFTP != null);
            if (to != null) {
                to.requestFocus();
            }
        }
    } finally {
        setFocusCycleRoot(true);
    }
}