/*
 * Copyright (c) 1995-1997 Sun Microsystems, Inc. All Rights Reserved.
 *
 * Permission to use, copy, modify, and distribute this software
 * and its documentation for NON-COMMERCIAL purposes and without
 * fee is hereby granted provided that this copyright notice
 * appears in all copies. Please refer to the file "copyright.html"
 * for further important copyright and licensing information.
 *
 * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
 * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
 * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
 * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
 * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
 */
package bingo.shared;

import java.awt.*;
import com.sun.java.swing.*;

public class Utilities {

    /**
     * Create a horizontal Box and add a group of evenly spaced
     * JComponents to it.
     */
    public static Box makeEvenlySpacedBox(JComponent compList[]) {
	Box box = Box.createHorizontalBox();
	int numComponents = compList.length;
        int i = 0;

        while (i < numComponents) {
            box.add(Box.createGlue());
            box.add(compList[i++]);
        }
        box.add(Box.createGlue());
	return box;
    }

    /**
     * Add a label-value pair to a container that uses
     * GridBagLayout.
     */
    public static void addParameterRow(Container container,
                                       JLabel label,
                                       Component component) {
        GridBagLayout gridbag = null;
        try {
            gridbag = (GridBagLayout)(container.getLayout());
        } catch (Exception e) {
            System.err.println("Hey!  You called addRow with"
                               + " a container that doesn't "
                               + " use GridBagLayout!");
            return;
        }

        GridBagConstraints c = new GridBagConstraints();
        c.fill = GridBagConstraints.HORIZONTAL;
        //c.weighty = 1.0;
        c.insets = new Insets(0, 5, 0, 5);

        gridbag.setConstraints(label, c);
        container.add(label);
        c.gridwidth = GridBagConstraints.REMAINDER;
        c.weightx = 1.0;
        gridbag.setConstraints(component, c);
        container.add(component);
    }

}
