All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.nuiton.jaxx.widgets.extra.CustomFocusTraversalPolicy Maven / Gradle / Ivy

Go to download

Widgets graphiques utiles pour tous les développements (pour le moment sans lien avec JAXX).

There is a newer version: 3.0-alpha-17
Show newest version
/*
 * #%L
 * JAXX :: Extra Widgets
 * %%
 * Copyright (C) 2004 - 2017 CodeLutin
 * %%
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as 
 * published by the Free Software Foundation, either version 3 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Lesser Public License for more details.
 * 
 * You should have received a copy of the GNU General Lesser Public 
 * License along with this program.  If not, see
 * .
 * #L%
 */
 
 /*
 * Created on 16 mai 2005
 *
 * TODO To change the template for this generated file go to
 * Window - Preferences - Java - Code Style - Code Templates
 */
package org.nuiton.jaxx.widgets.extra;

import java.awt.Component;
import java.awt.Container;
import java.awt.FocusTraversalPolicy;
import java.util.List;

/**
 * @author cedric
 *
 *         TODO To change the template for this generated type comment go to
 *         Window - Preferences - Java - Code Style - Code Templates
 */
public class CustomFocusTraversalPolicy extends FocusTraversalPolicy {

    protected List order = null;

    public CustomFocusTraversalPolicy(List order) {
        this.order = order;
    }

    @Override
    public Component getFirstComponent(Container focusCycleRoot) {
        if (order.size() != 0) {
            return (Component) order.get(0);
        }
        return null;
    }

    @Override
    public Component getLastComponent(Container focusCycleRoot) {
        if (order.size() > 0) {
            return (Component) order.get(order.size() - 1);
        }
        return null;
    }

    @Override
    public Component getComponentAfter(Container focusCycleRoot,
                                       Component aComponent) {
        int index = order.indexOf(aComponent);
        if (index != -1) {
            Component nextC = (Component) order.get((index + 1) % order.size());
            if (nextC.isEnabled()) {
                return nextC;
            }
            return getComponentAfter(focusCycleRoot, nextC);
        }
        return null;
    }

    @Override
    public Component getComponentBefore(Container focusCycleRoot,
                                        Component aComponent) {
        int index = order.indexOf(aComponent);
        if (index != -1) {
            Component nextC = (Component) order.get((index - 1 + order.size())
                                                            % order.size());
            if (nextC.isEnabled()) {
                return nextC;
            }
            return getComponentBefore(focusCycleRoot, nextC);
        }
        return null;
    }

    @Override
    public Component getDefaultComponent(Container focusCycleRoot) {
        if (order.size() > 0) {
            return (Component) order.get(0);
        }
        return null;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy