| package render_account;
import java.awt.*;
import java.io.*;
public class VFlowLayout implements LayoutManager,Serializable{
int hgap;
int vgap;
public VFlowLayout(){
this(5,5);
}
public VFlowLayout(int i,int j){
this.hgap=i;
this.vgap=j;
}
public void addLayoutComponent(String name, Component comp){
}
public void removeLayoutComponent(Component comp){
}
public Dimension preferredLayoutSize(Container container){
synchronized(container.getTreeLock()){
Dimension dimension1=new Dimension(0,0);
int i=container.getComponentCount();
for(int j=0;j Component component = container.getComponent(j);
if(component.isVisible()){
Dimension dimension2=component.getPreferredSize();
dimension1.width=Math.max(dimension1.width,dimension2.width);
if(j>0)
dimension1.height+=vgap;
dimension1.height+=dimension2.height;
}
}
Insets insets=container.getInsets();
dimension1.height+=insets.top+insets.bottom+vgap*2;
dimension1.width+=insets.left+insets.right+hgap*2;
Dimension dimension=dimension1;
return dimension;
file://return(new Dimension(50,200));
}
}
public Dimension minimumLayoutSize(Container container){
synchronized(container.getTreeLock()){
Dimension dimension1=new Dimension(0,0);
int i=container.getComponentCount();
for(int j=0;j Component component = container.getComponent(j);
if(component.isVisible()){
Dimension dimension2=component.getMinimumSize();
dimension1.width=Math.max(dimension1.width,dimension2.width);
if(j>0)
dimension1.height+=vgap;
dimension1.height+=dimension2.height;
}
}
Insets insets=container.getInsets();
dimension1.height+=insets.top+insets.bottom+vgap*2;
dimension1.width+=insets.left+insets.right+hgap*2;
Dimension dimension=dimension1;
return dimension;
}
}
public void layoutContainer(Container container){
synchronized(container.getTreeLock()){
Insets insets=container.getInsets();
int vSpace=container.getSize().height-(insets.top+insets.bottom+vgap*2);
int componentCount=container.getComponentCount();
int left=insets.left+hgap;
int totalHeight=0;
int width=0;
int componentStart=0;
for(int i=0;i Component component=container.getComponent(i);
if(component.isVisible()){
Dimension dimension=component.getPreferredSize();
component.setSize(dimension.width,dimension.height);
if(totalHeight==0 || totalHeight+dimension.height<=vSpace){
if(totalHeight>0)
totalHeight+=vgap;
totalHeight+=dimension.height;
width=Math.max(width,dimension.width);
}else{
moveComponents(container,insets.top+vgap,left,width,componentStart,i);
totalHeight=0;
left+=hgap+width;
width=dimension.width;
componentStart=i;
}
}
}
moveComponents(container,insets.top+vgap,left,width,componentStart,componentCount);
}
}
private void moveComponents(Container container,int top,int left,int width,int componentStart,int componentEnd){
synchronized(container.getTreeLock()){
for(int i=componentStart;i Component component=container.getComponent(i);
if(component.isVisible()){
component.setLocation(left,top);
top+=component.getPreferredSize().height+vgap;
}
}
}
}
public void setHgap(int i){
this.hgap=i;
}
public void setVgap(int i){
this.vgap=i;
}
public int getHgap(){
return(this.hgap);
}
public int getVgap(){
return(this.vgap);
}
}
|