formlayouteditpolicy.java

来自「基于eclipse的工具开发代码」· Java 代码 · 共 74 行

JAVA
74
字号
package com.cownew.uidesigner.policies;import org.eclipse.draw2d.geometry.Dimension;import org.eclipse.draw2d.geometry.Rectangle;import org.eclipse.gef.EditPart;import org.eclipse.gef.Request;import org.eclipse.gef.commands.Command;import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;import org.eclipse.gef.requests.ChangeBoundsRequest;import org.eclipse.gef.requests.CreateRequest;import com.cownew.uidesigner.commands.ComponentSetConstraintCommand;import com.cownew.uidesigner.commands.CreateComponentCommand;import com.cownew.uidesigner.model.Component;import com.cownew.uidesigner.model.Form;import com.cownew.uidesigner.parts.ComponentPart;public class FormLayoutEditPolicy extends XYLayoutEditPolicy{	protected Command createAddCommand(EditPart child, Object constraint)	{		return null; // no support for adding	}	protected Command createChangeConstraintCommand(			ChangeBoundsRequest request, EditPart child, Object constraint)	{		if (child instanceof ComponentPart && constraint instanceof Rectangle)		{			Component component = (Component) child.getModel();			Rectangle rect = (Rectangle) constraint;			// return a command that can move and/or resize a Shape			return new ComponentSetConstraintCommand(component, request, rect);		}		return super.createChangeConstraintCommand(request, child, constraint);	}	protected Command createChangeConstraintCommand(EditPart child,			Object constraint)	{		return null;	}	protected Command getCreateCommand(CreateRequest request)	{		Form form = (Form) getHost().getModel();		Component component = (Component) request.getNewObject();		Rectangle constraint = (Rectangle) getConstraintFor(request);		component.setBounds(constraint);		CreateComponentCommand command = new CreateComponentCommand(form,				component);		return command;	}	protected Object getConstraintFor(CreateRequest request)	{		Dimension size = request.getSize();		// 当控件被拖放上去或者用户没有拖出方框的时候size会为空		if (size == null || size.isEmpty())		{			Dimension newSize = new Dimension();			newSize.width = 60;			newSize.height = 22;			request.setSize(newSize);		}		return super.getConstraintFor(request);	}	protected Command getDeleteDependantCommand(Request request)	{		return null; // no support for deleting a dependant	}}

⌨️ 快捷键说明

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