import java.awt.Component; import java.awt.Container; import java.awt.GridBagConstraints; import java.awt.Insets; public class MyGridBagConstraints extends GridBagConstraints { /** DOCUMENT ME! */ private static final long serialVersionUID = 1L; /** default insets for the GridBagConstraints */ private static final Insets defaultInsets = new Insets(3, 3, 3, 3); /** * Creates a new MyGridBagConstraints object. */ public MyGridBagConstraints() { super(); anchor = GridBagConstraints.WEST; fill = GridBagConstraints.NONE; insets = defaultInsets; weightx = 0.0; weighty = 0.0; gridheight = 1; gridwidth = 1; } /** * set the insets to (0,0,0,0) */ public void setNoInsets() { insets = new Insets(0, 0, 0, 0); } /** * add the component to the container with the constraint this. If component * should be extendable (with the resize of the container), "extendable" must * be true * * * * @param container the container which will receive the component * @param component the component to add * @param xextendable true if the component may be extend with the resize * of the container */ public void addTo(Container container, Component component, boolean xextendable) { this.add(container, component, xextendable, false, 1, 1); } /** * add the component to the container with the constraint this. If component * should be extendable (with the resize of the container), "extendable" must * be true * * * * @param container the container which will receive the component * @param component the component to add * @param gridWidth DOCUMENT ME! * @param xextendable true if the component may be extend with the resize * of the container */ public void addTo(Container container, Component component, int gridWidth, boolean xextendable) { this.add(container, component, xextendable, false, gridWidth, 1); } /** * add the component to the container with the constraint this. If component * should be xextendable (with the resize of the container), "xextendable" * must be true * * * * @param container the container which will receive the component * @param component the component to add * @param xextendable true if the component may be extend with the resize * of the container * @param yxextendable true if the component may be extends vertically */ public void addTo(Container container, Component component, boolean xextendable, boolean yxextendable) { this.add(container, component, xextendable, yxextendable, 1, 1); } /** * add the component to the container with the constraint this. If component * should be xextendable (with the resize of the container), "xextendable" * must be true * * * * @param container the container which will receive the component * @param component the component to add * @param componentCount the width of the component (in a number of component) * @param xextendable true if the component may be extend with the resize * of the container * @param yxextendable true if the component may be extends vertically */ public void addTo(Container container, Component component, int componentCount, boolean xextendable, boolean yxextendable) { this.add(container, component, xextendable, yxextendable, componentCount, 1); } /** * add the component to the container with the constraint this in the end of * the current line. If component should be xextendable (with the resize of * the container), "xextendable" must be true * * * * @param container the container which will receive the component * @param component the component to add * @param xextendable true if the component may be extend with the resize * of the container */ public void addToTheEnd(Container container, Component component, boolean xextendable) { this.add(container, component, xextendable, false, GridBagConstraints.REMAINDER, 1); } /** * add the component to the container with the constraint this in the end of * the current line. If component should be xextendable (with the resize of * the container), "xextendable" must be true * * * * @param container the container which will receive the component * @param component the component to add * @param xextendable true if the component may be extend with the resize * of the container * @param yxextendable true if the component shoulb be extends vertically */ public void addToTheEnd(Container container, Component component, boolean xextendable, boolean yxextendable) { this.add(container, component, xextendable, yxextendable, GridBagConstraints.REMAINDER, 1); } public void addToTheColumnEnd(Container container, Component component, boolean xextendable, boolean yxextendable) { this.add(container, component, xextendable, yxextendable, 1, GridBagConstraints.REMAINDER); } public void addToTheColumnEndAndLineEnd(Container container, Component component, boolean xextendable, boolean yxextendable) { this.add(container, component, xextendable, yxextendable, GridBagConstraints.REMAINDER, GridBagConstraints.REMAINDER); } /** * add the component to the container with all the parameters * * * * @param container the container which will receive the component * @param component the component to add * @param xextendable true if the component may be extends vertically * @param yextendable DOCUMENT ME! * @param gridwidth the gridwith of the component in the container */ private void add(Container container, Component component, boolean xextendable, boolean yextendable, int gridwidth, int gridheight) { if (xextendable) this.weightx = 1.0; else this.weightx = 0.0; if (yextendable) this.weighty = 1.0; else this.weighty = 0.0; if (xextendable) { if (yextendable) this.fill = GridBagConstraints.BOTH; else this.fill = GridBagConstraints.HORIZONTAL; } else { if (yextendable) this.fill = GridBagConstraints.VERTICAL; else this.fill = GridBagConstraints.NONE; } this.gridwidth = gridwidth; this.gridheight = gridheight; container.add(component, this); } }