stacklayout.java

来自「This is Layout manager for java using sw」· Java 代码 · 共 61 行

JAVA
61
字号
/* * Copyright (C) Jerry Huxtable 1998 */package com.jhlabs.awt;import java.awt.*;public class StackLayout extends ConstraintLayout {	private final static Integer DEFAULT = new Integer(Direction.CENTER);		public StackLayout() {	}	public static Integer alignment(int fill, int alignment) {		return new Integer(fill << 8 | alignment);	}	public void setConstraint(Component c, Object constraint) {		if (constraint == null)			constraint = DEFAULT;		if (!(constraint instanceof Integer))			throw new IllegalArgumentException("Constraint must be an Integer");		super.setConstraint(c, constraint);	}		public void measureLayout(Container target, Dimension dimension, int type)  {		int count = target.getComponentCount();		if (dimension != null) {			for (int i = 0 ; i < count ; i++) {				Component m = target.getComponent(i);				if (m.isVisible()) {					Dimension d = getComponentSize(m, type);					dimension.width = Math.max(d.width, dimension.width);					dimension.height = Math.max(d.height, dimension.height);				}			}		} else {			Insets insets = target.getInsets();			Dimension size = target.getSize();			int w = size.width - (insets.left + insets.right);			int h = size.height - (insets.top + insets.bottom);			Rectangle cell = new Rectangle(insets.left, insets.top, w, h);			for (int i = 0 ; i < count ; i++) {				Component m = target.getComponent(i);				int n = ((Integer)getConstraint(m)).intValue();				int alignment = n & 0xff;				int fill = (n >> 8) & 0xff;				if (m.isVisible()) {					Dimension d = getComponentSize(m, type);					Rectangle r = new Rectangle(0, 0, d.width, d.height);					Alignment.alignInCell(r, cell, alignment, fill);					m.setBounds(r.x, r.y, r.width, r.height);				}			}		}	}}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?