⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 formlayouteditpolicy.java

📁 基于eclipse的工具开发代码
💻 JAVA
字号:
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 + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -