import java.awt.*;

// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, hall@apl.jhu.edu.

public class SimpleRowLayout implements LayoutManager {
 
  public void addLayoutComponent(String s, Component c) {
  }
  
  public void removeLayoutComponent(Component c) {
  }

  public Dimension preferredLayoutSize(Container cont) {
    int count=0, maxWidth=0, maxHeight=0;
    Dimension componentSize;
    Component[] components = cont.getComponents();
    Component c;
    for(int i=0; i<components.length; i++) {
      c = components[i];
      componentSize = c.preferredSize();
      maxWidth = Math.max(componentSize.width, maxWidth);
      maxHeight = Math.max(componentSize.height,
                           maxHeight);
      count++;
    }
    return(new Dimension(count*maxWidth, maxHeight));
  }
  
  public Dimension minimumLayoutSize(Container cont) {
    return(preferredLayoutSize(cont));
  }
  
  public void layoutContainer(Container cont) {
    Component[] components = cont.getComponents();
    int width = cont.size().width/components.length,
      height= cont.size().height, left=0, top=0;
    Component c;
    for(int i=0; i<components.length; i++) {
      c = components[i];
      c.reshape(left, top, width, height);
      left = left + width;
    }
  }
}

