diagramlayouteditpolicy.java

来自「GEF基础源码」· Java 代码 · 共 40 行

JAVA
40
字号
package com.jixy.study.gef.util;

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.CreateRequest;

import com.jixy.study.gef.model.Ellipse;

// XYLayoutEditPolicy is a policy that constrains figures by a location and size
// This extends it with the capability to change the location 
public class DiagramLayoutEditPolicy extends XYLayoutEditPolicy {
	// Abstract methods from ConstrainedLayoutEditPolicy
	protected Command createAddCommand(EditPart child, Object constraint) {
		return null;
		// no support for adding
	}

	protected Command createChangeConstraintCommand(EditPart child,
			Object constraint) {
		// return a command to move the part to the location given by the
		// constraint
		MoveCommand locationCommand = new MoveCommand();
		locationCommand.setNode((Ellipse) child.getModel());
		locationCommand.setLocation(((Rectangle) constraint).getLocation());
		return locationCommand;
	}

	protected Command getCreateCommand(CreateRequest request) {
		return null;
		// no support for creating
	}

	protected Command getDeleteDependantCommand(Request request) {
		return null;
	}
}

⌨️ 快捷键说明

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