FileDocCategorySizeDatePackage
LegacyGlueFocusTraversalPolicy.javaAPI DocJava SE 5 API6539Fri Aug 26 14:57:58 BST 2005javax.swing

LegacyGlueFocusTraversalPolicy

public final class LegacyGlueFocusTraversalPolicy extends FocusTraversalPolicy implements Serializable
A FocusTraversalPolicy which provides support for legacy applications which handle focus traversal via JComponent.setNextFocusableComponent or by installing a custom DefaultFocusManager. If a specific traversal has not been hard coded, then that traversal is provided either by the custom DefaultFocusManager, or by a wrapped FocusTraversalPolicy instance.
version
1.6, 12/19/03
author
David Mendenhall

Fields Summary
private transient FocusTraversalPolicy
delegatePolicy
private transient DefaultFocusManager
delegateManager
private HashMap
forwardMap
private HashMap
backwardMap
Constructors Summary
LegacyGlueFocusTraversalPolicy(FocusTraversalPolicy delegatePolicy)


      
        this.delegatePolicy = delegatePolicy;
    
LegacyGlueFocusTraversalPolicy(DefaultFocusManager delegateManager)

        this.delegateManager = delegateManager;
    
Methods Summary
private booleanaccept(java.awt.Component aComponent)

        if (!(aComponent.isVisible() && aComponent.isDisplayable() &&
              aComponent.isFocusable() && aComponent.isEnabled())) {
            return false;
        }

        // Verify that the Component is recursively enabled. Disabling a
        // heavyweight Container disables its children, whereas disabling
        // a lightweight Container does not.
        if (!(aComponent instanceof Window)) {
            for (Container enableTest = aComponent.getParent();
                 enableTest != null;
                 enableTest = enableTest.getParent())
            {
                if (!(enableTest.isEnabled() || enableTest.isLightweight())) {
                    return false;
                }
                if (enableTest instanceof Window) {
                    break;
                }
            }
        }

        return true;
    
public java.awt.ComponentgetComponentAfter(java.awt.Container focusCycleRoot, java.awt.Component aComponent)

        Component hardCoded = aComponent, prevHardCoded;
        HashSet sanity = new HashSet();

        do {
            prevHardCoded = hardCoded;
            hardCoded = (Component)forwardMap.get(hardCoded);
            if (hardCoded == null) {
                if (delegatePolicy != null &&
		    prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
                    return delegatePolicy.getComponentAfter(focusCycleRoot,
                                                            prevHardCoded);
                } else if (delegateManager != null) {
                    return delegateManager.
                        getComponentAfter(focusCycleRoot, aComponent);
                } else {
                    return null;
                }
            }
            if (sanity.contains(hardCoded)) {
                // cycle detected; bail
                return null;
            }
            sanity.add(hardCoded);
        } while (!accept(hardCoded));

        return hardCoded;
    
public java.awt.ComponentgetComponentBefore(java.awt.Container focusCycleRoot, java.awt.Component aComponent)

        Component hardCoded = aComponent, prevHardCoded;
        HashSet sanity = new HashSet();

        do {
            prevHardCoded = hardCoded;
            hardCoded = (Component)backwardMap.get(hardCoded);
            if (hardCoded == null) {
                if (delegatePolicy != null &&
		    prevHardCoded.isFocusCycleRoot(focusCycleRoot)) {
                    return delegatePolicy.getComponentBefore(focusCycleRoot,
                                                       prevHardCoded);
                } else if (delegateManager != null) {
                    return delegateManager.
                        getComponentBefore(focusCycleRoot, aComponent);
                } else {
                    return null;
                }
            }
            if (sanity.contains(hardCoded)) {
                // cycle detected; bail
                return null;
            }
            sanity.add(hardCoded);
        } while (!accept(hardCoded));

        return hardCoded;
    
public java.awt.ComponentgetDefaultComponent(java.awt.Container focusCycleRoot)

        if (delegatePolicy != null) {
            return delegatePolicy.getDefaultComponent(focusCycleRoot);
        } else {
            return getFirstComponent(focusCycleRoot);
        }
    
public java.awt.ComponentgetFirstComponent(java.awt.Container focusCycleRoot)

        if (delegatePolicy != null) {
            return delegatePolicy.getFirstComponent(focusCycleRoot);
        } else if (delegateManager != null) {
            return delegateManager.getFirstComponent(focusCycleRoot);
        } else {
            return null;
        }
    
public java.awt.ComponentgetLastComponent(java.awt.Container focusCycleRoot)

        if (delegatePolicy != null) {
            return delegatePolicy.getLastComponent(focusCycleRoot);
        } else if (delegateManager != null) {
            return delegateManager.getLastComponent(focusCycleRoot);
        } else {
            return null;
        }
    
private voidreadObject(java.io.ObjectInputStream in)

        in.defaultReadObject();
        delegatePolicy = (FocusTraversalPolicy)in.readObject();
        delegateManager = (DefaultFocusManager)in.readObject();
    
voidsetNextFocusableComponent(java.awt.Component left, java.awt.Component right)

        forwardMap.put(left, right);
        backwardMap.put(right, left);
    
voidunsetNextFocusableComponent(java.awt.Component left, java.awt.Component right)

        forwardMap.remove(left);
        backwardMap.remove(right);
    
private voidwriteObject(java.io.ObjectOutputStream out)

        out.defaultWriteObject();

        if (delegatePolicy instanceof Serializable) {
            out.writeObject(delegatePolicy);
        } else {
            out.writeObject(null);
        }

        if (delegateManager instanceof Serializable) {
            out.writeObject(delegateManager);
        } else {
            out.writeObject(null);
        }