componentsetconstraintcommand.java

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

JAVA
63
字号
package com.cownew.uidesigner.commands;

import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.gef.RequestConstants;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.requests.ChangeBoundsRequest;

import com.cownew.uidesigner.model.Component;

public class ComponentSetConstraintCommand extends Command
{
	private final Rectangle newEditorBounds;

	private Rectangle oldTermBounds;

	private final ChangeBoundsRequest request;

	private final Component component;

	public ComponentSetConstraintCommand(Component component,
			ChangeBoundsRequest req, Rectangle newBounds)
	{
		if (component == null || req == null || newBounds == null)
		{
			throw new IllegalArgumentException();
		}
		this.component = component;
		this.request = req;
		this.newEditorBounds = newBounds.getCopy();
	}
	
	public String getLabel()
	{
		return "move / resize";
	}

	public boolean canExecute()
	{
		Object type = request.getType();
		return (RequestConstants.REQ_MOVE.equals(type)
				|| RequestConstants.REQ_MOVE_CHILDREN.equals(type)
				|| RequestConstants.REQ_RESIZE.equals(type)
				|| RequestConstants.REQ_RESIZE_CHILDREN.equals(type) 
				|| RequestConstants.REQ_ALIGN_CHILDREN.equals(type));
	}

	public void execute()
	{
		oldTermBounds = component.getBounds();
		component.setBounds(newEditorBounds);
	}

	public void redo()
	{
		component.setBounds(newEditorBounds);
	}

	public void undo()
	{
		component.setBounds(oldTermBounds);
	}
}

⌨️ 快捷键说明

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