public class ColumnLayout implements LayoutManager2{
protected int marginWidth;
protected int marginHeight;
protected int spacing;
protected int alignment;
public static final int LEFT=0;
public static final int CENTER=1;
public static final int RIGHT=2;
public static final int JUSTIFY=3;
public static final int PREFERRED_SIZE=0;
public static final int MINIMUM_SIZE=1;
public static final int MAXIMUM_SIZE=2;
public ColumnLayout(int mW, int mH, int s, int a){
if(mW<0 || mH<0 || s<0){
throw new IllegalArgumentException("Size of margin cannot be negative!");
}
if(a<LEFT || a>JUSTIFY){
throw new IllegalArgumentException("Not an alignment!");
}
marginWidth=mW;
marginHeight=mH;
spacing=s;
alignment=a;
}
public ColumnLayout(){
this(5,5,5,JUSTIFY);
}
public ColumnLayout(int a){
this(5,5,5,a);
}
public int getMarginWidth(){
return marginWidth;
}
public int getMarginHeight(){
return marginHeight;
}
public int getSpacing(){
return spacing;
}
public int getAlignment(){
return alignment;
}
public void layoutContainer(Container parent){
Insets insets=parent.getInsets();
Dimension parentSize=parent.getSize();
Component kid;
int kidsCount=parent.getComponentCount();
int x0=insets.left+marginWidth;
int x;
int y=insets.top+marginHeight;