// gui_util.py : Various utility functions for AWT 
//
// Distributed under the terms described in the LICENCE file.
//
// Developed by akuchlin@mems-exchange.org
//

import java.awt.*;

public class gui_util {
    static String __revision__ = "$Id: gui_util.java,v 1.5 2001/12/17 19:33:37 akuchlin Exp $";

    static final int DEFAULT_GRIDWIDTH = 1;
    static final int DEFAULT_GRIDHEIGHT = 1;
    static final int DEFAULT_FILL = GridBagConstraints.BOTH;
    static final int DEFAULT_IPADX = 0;
    static final int DEFAULT_IPADY = 0;
    static final int DEFAULT_ANCHOR = GridBagConstraints.NORTHWEST;
    static final double DEFAULT_WEIGHTX = 0.0;
    static final double DEFAULT_WEIGHTY = 0.0;

    /** Create a GridBagConstraints() object in a more convenient fashion,
     * and use it to add component to container.
     */
    static public GridBagConstraints constrain(Container container, 
					Component component, 
					int gridx, int gridy, 
					int gridwidth, int gridheight, 
					int fill, 
					int anchor,
					int ipadx, int ipady, Insets insets,
					double weightx, double weighty) {
	GridBagConstraints g = new GridBagConstraints();
	g.gridx = gridx; g.gridy = gridy;
	g.gridwidth = gridwidth; g.gridheight = gridheight;
	g.fill = fill; g.anchor = anchor;
	if (insets != null)
	    g.insets = insets;
	g.ipadx = ipadx; g.ipady = ipady;
	g.weightx = weightx; g.weighty = weighty;
	
	GridBagLayout layout = (GridBagLayout) container.getLayout();
	layout.setConstraints(component, g);

	container.add( component );
	return g;
    }

    static public GridBagConstraints constrain(Container container, 
					Component component, 
					int gridx, int gridy) {
	return constrain(container, component, gridx, gridy, 
			 DEFAULT_GRIDWIDTH, DEFAULT_GRIDHEIGHT, 
			 DEFAULT_FILL, DEFAULT_ANCHOR, DEFAULT_IPADX, 
			 DEFAULT_IPADY, null, 
			 DEFAULT_WEIGHTX, DEFAULT_WEIGHTY);
    }

    static public GridBagConstraints constrain(Container container, 
					Component component, 
					int gridx, int gridy,
					int gridwidth, int gridheight) {
	return constrain(container, component, gridx, gridy, 
			 gridwidth, gridheight,  
			 DEFAULT_FILL, DEFAULT_ANCHOR, 
			 DEFAULT_IPADX, DEFAULT_IPADY, null,
			 DEFAULT_WEIGHTX, DEFAULT_WEIGHTY);
    }

    static public GridBagConstraints constrain(Container container, 
					Component component, 
					int gridx, int gridy,
					int gridwidth, int gridheight,
					int fill) {
	return constrain(container, component, gridx, gridy, 
			 gridwidth, gridheight,
			 fill, 
			 DEFAULT_ANCHOR, DEFAULT_IPADX, DEFAULT_IPADY, null,
			 DEFAULT_WEIGHTX, DEFAULT_WEIGHTY);
    }

    static public GridBagConstraints constrain(Container container, 
					Component component, 
					int gridx, int gridy,
					int gridwidth, int gridheight,
					int fill, int anchor) {
	return constrain(container, component, gridx, gridy, 
			 gridwidth, gridheight,
			 fill, anchor,
			 DEFAULT_IPADX, DEFAULT_IPADY, null,
			 DEFAULT_WEIGHTX, DEFAULT_WEIGHTY);
    }

    
}
