titlecelleditorlocator.java

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

JAVA
34
字号
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;
/**
 * 含有title的figure直接编辑定位器
 * @author levin
 * @since 2008-2-7 下午08:40:59
 */
public class TitleCellEditorLocator implements CellEditorLocator {
	private IFigure figure;
	
	public TitleCellEditorLocator(IFigure figure) {
		super();
		this.figure=figure;
	}

	@Override
	public void relocate(CellEditor celleditor) {
		Text text = (Text)celleditor.getControl();
		Rectangle rect = figure.getClientArea();
		figure.translateToParent(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;
		//直接假设字高为20
		text.setBounds(rect.x+2, rect.y-20, Math.max(rect.width-4,30),20);
	}
}

⌨️ 快捷键说明

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