starlayout.java

来自「mywork是rcp开发的很好的例子」· Java 代码 · 共 45 行

JAVA
45
字号
package net.sf.freenote.mindmap.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;

/**
 * mm图的星形布局
 * @author levin
 * @since 2008-2-14 下午08:48:39
 */
class StarLayout extends NormalLayout {

	StarLayout(TreeBranchFigure branch) {
		super(branch);
	}

	@Override
	void paintLines(Graphics g) {
		//用connection代替连线,见BranchShape.addChild()
	 }

	@Override
	public void layout(IFigure f) {
		Animation.recordInitialState(f);
		if (Animation.playbackState(f))
			return;
		branch.getContentsPane().validate();

		Rectangle clientArea = new Rectangle();
		branch.getClientArea(clientArea);
		Rectangle nodeBounds = new Rectangle();
		nodeBounds.setSize(branch.getNode().getPreferredSize());
		nodeBounds.setLocation(clientArea.x+clientArea.width/2-nodeBounds.width/2, clientArea.y+clientArea.height/2-nodeBounds.height/2);
		branch.getNode().setBounds(nodeBounds);

		IFigure contents = branch.getContentsPane();
		Rectangle contentsBounds = new Rectangle(
			clientArea.getLocation(),
			contents.getPreferredSize()
		);
		contents.setBounds(contentsBounds);
	}
}

⌨️ 快捷键说明

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