001    /*
002     * The contents of this file are subject to the Mozilla Public
003     * License Version 1.1 (the "License"); you may not use this file
004     * except in compliance with the License. You may obtain a copy of
005     * the License at http://www.mozilla.org/MPL/
006     *
007     * Software distributed under the License is distributed on an "AS
008     * IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
009     * implied. See the License for the specific language governing
010     * rights and limitations under the License.
011     *
012     * The Original Code is Knowtator.
013     *
014     * The Initial Developer of the Original Code is University of Colorado.  
015     * Copyright (C) 2005 - 2008.  All Rights Reserved.
016     *
017     * Knowtator was developed by the Center for Computational Pharmacology
018     * (http://compbio.uchcs.edu) at the University of Colorado Health 
019     *  Sciences Center School of Medicine with support from the National 
020     *  Library of Medicine.  
021     *
022     * Current information about Knowtator can be obtained at 
023     * http://knowtator.sourceforge.net/
024     *
025     * Contributor(s):
026     *   Brant Barney <brant.barney@hsc.utah.edu> (Original Author)
027     */
028    
029    package edu.uchsc.ccp.knowtator.ui;
030    
031    import java.awt.Component;
032    import java.awt.Container;
033    
034    /**
035     * Class designed to contain various static utility functions that can be useful
036     * when creating a Java Swing application.
037     * 
038     * @author Brant Barney
039     */
040    public class SwingUtils {
041    
042            /**
043             * Gets the index of the component inside the given panel.
044             * 
045             * @param container
046             *            The container where the components is located
047             * @param comp
048             *            The components to find the index of
049             * 
050             * @return The index of the component in the given panel, or -1 if the
051             *         component was not found in the panel or the panel contains no
052             *         components.
053             */
054            public static int indexOfComponent(Container container, Component comp) {
055                    Component[] components = container.getComponents();
056                    for (int i = 0; i < components.length; i++) {
057                            if (components[i] == comp) {
058                                    return i;
059                            }
060                    }
061    
062                    return -1;
063            }
064    }