读书人

draw2d胪陈(IFigure)

发布时间: 2012-06-29 15:48:47 作者: rapoo

draw2d详述(IFigure)

?

1.IFigure

IFigure接口是所有Figure的基础接口,里面有很多方法,这里只列出部分自己觉得有用的方法:

?

(1)add(IFigure figure, Object constraint, int index):添加一个子,并且指定其约束和位置:

?

?

public void layout(IFigure parent) {Iterator children = parent.getChildren().iterator();Point offset = getOrigin(parent);IFigure f;while (children.hasNext()) {f = (IFigure) children.next();Rectangle bounds = (Rectangle) getConstraint(f);if (bounds == null)continue;if (bounds.width == -1 || bounds.height == -1) {Dimension preferredSize = f.getPreferredSize(bounds.width,bounds.height);bounds = bounds.getCopy();if (bounds.width == -1)bounds.width = preferredSize.width;if (bounds.height == -1)bounds.height = preferredSize.height;}bounds = bounds.getTranslated(offset);f.setBounds(bounds);}}
?

计算布局:最终会把计算到的值,赋值给IFigure:f.setBounds(bounds);

?

?

(2)其他的以后再分析,其实就是按照某种规则算,算大小什么的,其它的都是浮云。

?

读书人网 >开源软件

热点推荐