shapecelleditorlocator.java

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

JAVA
44
字号
package net.sf.freenote.directedit;

import org.eclipse.draw2d.IFigure;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.tools.CellEditorLocator;
import org.eclipse.jface.viewers.CellEditor;
import org.eclipse.swt.widgets.Text;

/**
 * 占据整个shape的directedit定位器
 * @author levin
 * @since 2008-1-26 下午03:30:26
 */
public class ShapeCellEditorLocator implements CellEditorLocator {
	private IFigure figure;
	private boolean ellipse;
	
	public ShapeCellEditorLocator(IFigure figure) {
		super();
		this.figure = figure;
	}
	public ShapeCellEditorLocator(IFigure figure,boolean ellipse) {
		this(figure);
		this.ellipse = ellipse;
	}
	

	@Override
	public void relocate(CellEditor celleditor) {
		Text text = (Text)celleditor.getControl();
		Rectangle rect = figure.getClientArea();
		figure.translateToAbsolute(rect);
		org.eclipse.swt.graphics.Rectangle trim = text.computeTrim(0, 0, 0, 0);
		rect.translate(trim.x, trim.y);
		rect.width += trim.width;
		rect.height += trim.height;
		//如果是椭圆,则应采用内切矩形,用0.2粗略代替
		if(ellipse){
			rect.shrink((int)(rect.width*0.2),(int) (rect.height*0.2));
		}
		text.setBounds(rect.x, rect.y, rect.width, rect.height);
	}
}

⌨️ 快捷键说明

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