|
|
|
@ -16,20 +16,17 @@ import java.awt.LayoutManager;
|
|
|
|
|
public class VerticalFlowLayout implements LayoutManager, java.io.Serializable { |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This value indicates that each row of components |
|
|
|
|
* should be left-justified. |
|
|
|
|
* 竖直方向上将子组件设置为顶对齐方式 |
|
|
|
|
*/ |
|
|
|
|
public static final int TOP = 0; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This value indicates that each row of components |
|
|
|
|
* should be centered. |
|
|
|
|
* 竖直方向上将子组件设置为居中对齐方式 |
|
|
|
|
*/ |
|
|
|
|
public static final int CENTER = 1; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* This value indicates that each row of components |
|
|
|
|
* should be right-justified. |
|
|
|
|
* 竖直方向上将子组件设置为底对齐方式 |
|
|
|
|
*/ |
|
|
|
|
public static final int BOTTOM = 2; |
|
|
|
|
|
|
|
|
@ -71,7 +68,9 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
*/ |
|
|
|
|
int newAlign; // This is the one we actually use
|
|
|
|
|
|
|
|
|
|
// 当列宽不一致时,是否需要左对齐(默认居中对齐)
|
|
|
|
|
/** |
|
|
|
|
* 当列宽不一致时,是否需要将水平方向设置成左对齐(默认水平方向为居中对齐) |
|
|
|
|
*/ |
|
|
|
|
boolean isAlignLeft = false; |
|
|
|
|
|
|
|
|
|
/** |
|
|
|
@ -220,6 +219,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* @param name the name of the component |
|
|
|
|
* @param comp the component to be added |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void addLayoutComponent(String name, Component comp) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -230,6 +230,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* @param comp the component to remove |
|
|
|
|
* @see java.awt.Container#removeAll |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void removeLayoutComponent(Component comp) { |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -244,6 +245,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* @see #minimumLayoutSize |
|
|
|
|
* @see java.awt.Container#getPreferredSize |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Dimension preferredLayoutSize(Container target) { |
|
|
|
|
synchronized (target.getTreeLock()) { |
|
|
|
|
Dimension dim = new Dimension(0, 0); |
|
|
|
@ -255,7 +257,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
if (m.isVisible()) { |
|
|
|
|
Dimension d = m.getPreferredSize(); |
|
|
|
|
|
|
|
|
|
firstVisibleComponent = dialWithDim4PreferredLayoutSize(dim, d, firstVisibleComponent); |
|
|
|
|
firstVisibleComponent = dealWithDim4PreferredLayoutSize(dim, d, firstVisibleComponent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Insets insets = target.getInsets(); |
|
|
|
@ -265,7 +267,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected boolean dialWithDim4PreferredLayoutSize(Dimension dim, Dimension d, boolean firstVisibleComponent) { |
|
|
|
|
protected boolean dealWithDim4PreferredLayoutSize(Dimension dim, Dimension d, boolean firstVisibleComponent) { |
|
|
|
|
dim.width = Math.max(dim.width, d.width); |
|
|
|
|
if (firstVisibleComponent) { |
|
|
|
|
firstVisibleComponent = false; |
|
|
|
@ -289,6 +291,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* @see java.awt.Container |
|
|
|
|
* @see java.awt.Container#doLayout |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public Dimension minimumLayoutSize(Container target) { |
|
|
|
|
synchronized (target.getTreeLock()) { |
|
|
|
|
Dimension dim = new Dimension(0, 0); |
|
|
|
@ -300,7 +303,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
if (m.isVisible()) { |
|
|
|
|
Dimension d = m.getMinimumSize(); |
|
|
|
|
|
|
|
|
|
firstVisibleComponent = dialWithDim4MinimumLayoutSize(dim, d, i, firstVisibleComponent); |
|
|
|
|
firstVisibleComponent = dealWithDim4MinimumLayoutSize(dim, d, i, firstVisibleComponent); |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
Insets insets = target.getInsets(); |
|
|
|
@ -310,7 +313,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
protected boolean dialWithDim4MinimumLayoutSize(Dimension dim, Dimension d, int i, boolean firstVisibleComponent) { |
|
|
|
|
protected boolean dealWithDim4MinimumLayoutSize(Dimension dim, Dimension d, int i, boolean firstVisibleComponent) { |
|
|
|
|
dim.width = Math.max(dim.width, d.width); |
|
|
|
|
if (i > 0) { |
|
|
|
|
dim.height += vgap; |
|
|
|
@ -370,6 +373,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* @see java.awt.Container |
|
|
|
|
* @see java.awt.Container#doLayout |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public void layoutContainer(Container target) { |
|
|
|
|
synchronized (target.getTreeLock()) { |
|
|
|
|
Insets insets = target.getInsets(); |
|
|
|
@ -410,7 +414,9 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
|
|
|
|
|
protected int[] dealWithDim4LayoutContainer(Container target, Insets insets, Dimension d, int x, int y, int roww, int start, int maxlen, int i, boolean ltr) { |
|
|
|
|
if ((y == 0) || ((y + d.height) <= maxlen)) { |
|
|
|
|
if (y > 0) y += vgap; |
|
|
|
|
if (y > 0) { |
|
|
|
|
y += vgap; |
|
|
|
|
} |
|
|
|
|
y += d.height; |
|
|
|
|
roww = Math.max(roww, d.width); |
|
|
|
|
} else { |
|
|
|
@ -449,6 +455,7 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
* |
|
|
|
|
* @return a string representation of this layout |
|
|
|
|
*/ |
|
|
|
|
@Override |
|
|
|
|
public String toString() { |
|
|
|
|
String str = ""; |
|
|
|
|
switch (this.newAlign) { |
|
|
|
@ -465,4 +472,4 @@ public class VerticalFlowLayout implements LayoutManager, java.io.Serializable {
|
|
|
|
|
|
|
|
|
|
return getClass().getName() + "[hgap=" + hgap + ",vgap=" + vgap + str + "]"; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|