//////////////////////////////////////////////////
package gui;

import java.awt.*;
//////////////////////////////////////////////////
class PowerLayout extends GridBagLayout {
  private static final int gap = 5;
  private static final int defGridX = GridBagConstraints.RELATIVE;
  private static final int defGridY = GridBagConstraints.RELATIVE;
  private static final int defGridWidth = GridBagConstraints.REMAINDER;
  private static final int defGridHeight = 1;
  private static final int defFill = GridBagConstraints.BOTH;
  private static final int defAnchor = GridBagConstraints.WEST;
  private static final double defWeightx = 1.0;
  private static final double defWeighty = 1.0;
  private static final Insets defInsets = null;
  //------------------------------------------------
public void addInRow(Container container, Component component, int gridwidth, int fill) {
  addInRow(container, component, gridwidth, fill, new Insets(gap, gap, 0, 0));
}
  //------------------------------------------------
public void addInRow(Container container, Component component, int gridwidth, int fill, Insets insets) {
// Adds component in a row anchored to west, with it being resizable in the
// directions specified by fill.

  double weightx;
  double weighty;
  if(fill == GridBagConstraints.NONE) {
    weightx = 0.0;
    weighty = 0.0;
  }
  else if(fill == GridBagConstraints.VERTICAL) {
    weightx = 0.0;
    weighty = 1.0;
  }
  else if(fill == GridBagConstraints.HORIZONTAL) {
    weightx = 1.0;
    weighty = 0.0;
  }
  else if(fill == GridBagConstraints.BOTH) {
    weightx = 1.0;
    weighty = 1.0;
  }
  else 
    throw(new RuntimeException("Invalid fill type!"));
  constrain(container, component, GridBagConstraints.RELATIVE, GridBagConstraints.RELATIVE, gridwidth, 1, fill, GridBagConstraints.WEST, weightx, weighty, insets);
}
  //------------------------------------------------
public void constrain(Container container, Component component, 
		      int grid_x, int grid_y, 
		      int grid_width, int grid_height,
                      Insets insets) {
  constrain(container, component, grid_x, grid_y, 
	    grid_width, grid_height, GridBagConstraints.NONE, 
	    GridBagConstraints.NORTHWEST, 
	    0.0, 0.0, insets);
}
  //------------------------------------------------
public void constrain(Container container, Component component, 
		      int grid_x, int grid_y, 
		      int grid_width, int grid_height,
		      int fill, int anchor, 
                      double weight_x, double weight_y,
		      Insets insets) {
  GridBagConstraints c = new GridBagConstraints();
  c.gridx = grid_x; c.gridy = grid_y;
  c.gridwidth = grid_width; c.gridheight = grid_height;
  c.fill = fill; 
  c.anchor = anchor;
  c.weightx = weight_x; c.weighty = weight_y;
  if(insets != null)
    c.insets = insets;
      
  setConstraints(component, c);
  container.add(component);
}
//------------------------------------------------
}
//////////////////////////////////////////////////

