blob: 86067fd95b2e41736f35b054b842e28f7c625aa8 [file] [log] [blame]
/*******************************************************************************
* <copyright>
*
* Copyright (c) 2013, 2013 SAP AG.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* SAP AG - initial API, implementation and documentation
*
* </copyright>
*
*******************************************************************************/
package org.eclipse.fmc.blockdiagram.editor.features.add;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.AgentAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.LAgentAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.RectangleAgentAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.FMCNodeAlgorithmFactory;
import org.eclipse.fmc.blockdiagram.editor.algorithm.node.UAgentAlgorithm;
import org.eclipse.fmc.blockdiagram.editor.model.ShapeStyle;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IAddContext;
import org.eclipse.graphiti.mm.GraphicsAlgorithmContainer;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
/**
* Add Feature class responsible for creating Agent shapes. Supports all shape
* styles.
*
* @author Benjamin Schmeling
*
*/
public class AgentAddFeature extends FMCNodeAddFeature {
/**
* Default constructor with default rectangle width.
*
* @param featureProvider
* The feature provider.
*/
public AgentAddFeature(IFeatureProvider featureProvider) {
super(featureProvider);
minimumWidth = RectangleAgentAlgorithm.AGENT_DEFAULT_WIDTH;;
minimumHeight = RectangleAgentAlgorithm.AGENT_DEFAULT_HEIGHT;
}
/**
* Constructor which allows to set the minimum width, height, angle and
* title.
*
* @param featureProvider
* The feature provider.
* @param title
* The title text of the agent shape
* @param width
* The minimum shape width.
* @param height
* The minimum shape height.
* @param angle
* The angle.
*/
public AgentAddFeature(IFeatureProvider featureProvider, String title, int width,
int height, int angle) {
super(featureProvider, title, angle);
super.minimumHeight = height;
super.minimumWidth = width;
}
/**
* Constructor which initializes the agent with a particular style.
*
* @param featureProvider
* The feature provider.
* @param style
* The style to be used, e.g. RECT, L, U are supported.
*/
public AgentAddFeature(IFeatureProvider featureProvider, ShapeStyle style) {
super(featureProvider, style);
setDefaultSize(style);
}
/**
* Sets the default size based on the style.
*
* @param style
* The style to determine the default size from.
*/
private void setDefaultSize(ShapeStyle style) {
if (style != null) {
switch (style) {
case RECT:
minimumWidth = RectangleAgentAlgorithm.AGENT_DEFAULT_WIDTH;
minimumHeight = RectangleAgentAlgorithm.AGENT_DEFAULT_HEIGHT;
break;
case L:
minimumWidth = LAgentAlgorithm.LAGENT_DEFAULT_WIDTH;
minimumHeight = LAgentAlgorithm.LAGENT_DEFAULT_HEIGHT;
break;
case U:
minimumWidth = UAgentAlgorithm.UAGENT_DEFAULT_WIDTH;
minimumHeight = UAgentAlgorithm.UAGENT_DEFAULT_HEIGHT;
break;
default:
assert false : "No style literal matched in switch";
break;
}
} else {
minimumWidth = RectangleAgentAlgorithm.AGENT_DEFAULT_WIDTH;
minimumHeight = RectangleAgentAlgorithm.AGENT_DEFAULT_HEIGHT;
}
}
/*
* (non-Javadoc)
*
* @see
* org.eclipse.fmc.blockdiagram.editor.features.add.FMCNodeAddFeature#createGraphics
* (org.eclipse.graphiti.mm.GraphicsAlgorithmContainer,
* org.eclipse.graphiti.features.context.IAddContext)
*/
@Override
protected GraphicsAlgorithm createGraphics(
GraphicsAlgorithmContainer gaContainer, IAddContext context) {
AgentAlgorithm algorithm = FMCNodeAlgorithmFactory.getInstance()
.getAgentByShapestyle(this.shapeType);
return algorithm.createGraphics(getDiagram(), gaContainer, 0, 0,
getWidth(context), getHeight(context));
}
}