package gui;

import java.awt.*;

/** A Panel with GridBagLayout as the Layout manager. */
class GridBagPanel extends Panel {
  protected GridBagLayout gbl;
  protected GridBagConstraints gbc;

  public GridBagPanel() {
    gbl = new GridBagLayout();
    setLayout(gbl);
    gbc = new GridBagConstraints();
  }

  /**
   * set the current GridBagConstraints to the Component,
   * add the Component to the Panel.
   */
  public Component add(Component c) {
    gbl.setConstraints(c, gbc);
    return super.add(c);
  }

  /**
   * change gbc, add the Component to the Panel.
   * when return, gbc.gridx = x, gbc.gridy = y, 
   * gbc.gridwidth = 1, gbc.gridheight = 1.
   */
  public Component add(Component c, int x, int y) {
    return add(c, x, y, 1, 1);
  }
     
  /**
   * change gbc with x, y, w, h, add the Component to the Panel.
   * when return, gbc.gridx = x, gbc.gridy = y,
   * gbc.gridwidth = 1, gbc.gridheight = 1.
   */  
  public Component add(Component c, int x, int y, int w, int h) {
    gbc.gridx = x;
    gbc.gridy = y;
    gbc.gridwidth = w;
    gbc.gridheight = h;
    return add(c);
  }
}  
