00001
import java.awt.*;
00002
00003 public class VerticalFlowLayout extends FlowLayout {
00004 int wrapWidth = 0;
00005 public VerticalFlowLayout(
int i,
int j,
int k) {
00006 super(i,j,k);
00007 }
00008 public int getWrapWidth(Container container) {
00009
if (
wrapWidth!=0)
return wrapWidth;
00010 Component parent = container.getParent();
00011
if (parent!=null)
return parent.getSize().width;
00012
return 0;
00013 }
00014 public Dimension
preferredLayoutSize(Container container) {
00015 Dimension dimension2;
00016
synchronized(container.getTreeLock())
00017 {
00018
int hgap = getHgap();
00019
int vgap = getHgap();
00020
int wrapWidth = getWrapWidth(container);
00021 Dimension dimension =
new Dimension(0, 0);
00022 Dimension line =
new Dimension(0,0);
00023
int i = container.getComponentCount();
00024
boolean firstInLine =
true;
00025
for(
int j = 0; j < i; j++)
00026 {
00027 Component component = container.getComponent(j);
00028
if(component.isVisible())
00029 {
00030 Dimension compSize = component.getPreferredSize();
00031
00032 Dimension oldLine =
new Dimension(line);
00033
boolean oldFirstInLine = firstInLine;
00034 line.height = Math.max(line.height, compSize.height);
00035
if(firstInLine)
00036 firstInLine =
false;
00037
else
00038 line.width += hgap;
00039 line.width += compSize.width;
00040
if (line.width > wrapWidth && !oldFirstInLine) {
00041 dimension.height += vgap + oldLine.height;
00042 dimension.width += Math.max(dimension.width,oldLine.width);
00043 line =
new Dimension(0,0); firstInLine =
true;
00044 j--;
00045 }
00046 }
00047 }
00048
if (!firstInLine) {
00049 dimension.height += vgap + line.height;
00050 dimension.width += Math.max(dimension.width,line.width);
00051 }
00052
00053 Insets insets = container.getInsets();
00054 dimension.width += insets.left + insets.right + hgap * 2;
00055 dimension.height += insets.top + insets.bottom + vgap * 2;
00056 dimension2 = dimension;
00057 }
00058
return dimension2;
00059 }
00060
00061
00062
00063 public Dimension
oldpreferredLayoutSize(Container container)
00064 {
00065 Dimension dimension2;
00066
int hgap = getHgap();
00067
int vgap = getHgap();
00068
synchronized(container.getTreeLock())
00069 {
00070 Dimension dimension =
new Dimension(0, 0);
00071
int i = container.getComponentCount();
00072
boolean flag =
true;
00073
for(
int j = 0; j < i; j++)
00074 {
00075 Component component = container.getComponent(j);
00076
if(component.isVisible())
00077 {
00078 Dimension dimension1 = component.getPreferredSize();
00079 dimension.height = Math.max(dimension.height, dimension1.height);
00080
if(flag)
00081 flag =
false;
00082
else
00083 dimension.width += hgap;
00084 dimension.width += dimension1.width;
00085 }
00086 }
00087
00088 Insets insets = container.getInsets();
00089 dimension.width += insets.left + insets.right + hgap * 2;
00090 dimension.height += insets.top + insets.bottom + vgap * 2;
00091 dimension2 = dimension;
00092 }
00093
return dimension2;
00094 }
00095 }