/******************************************************************************* | |
* <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.algorithm.node; | |
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; | |
import org.eclipse.graphiti.mm.algorithms.MultiText; | |
/** | |
* This abstract class is the super class for all rectangle algorithms and | |
* provides common methods for them. For example, there is a general rotate | |
* method. | |
* | |
* @author Benjamin Schmeling | |
* @author Heiko Witteborg | |
* | |
*/ | |
public abstract class AbstractRectangleAlgorithm extends AbstractNode implements | |
RectangleAlgorithm{ | |
// ---------------------------------------- | |
// ----------- Named Node ----------------- | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.NamedNode#relocateText(org.eclipse.graphiti | |
* .mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public void relocateText(GraphicsAlgorithm graphicsAlgorithm) { | |
MultiText text = this.getText(graphicsAlgorithm); | |
if (text != null) { | |
int multipleOffset = 0; | |
if (this.isMultipleInstances(this | |
.getContainerShape(graphicsAlgorithm))) { | |
multipleOffset = MULTI_INSTANCE_GAP; | |
} | |
int x = super.textMargin; | |
int width = graphicsAlgorithm.getWidth() - 2 * super.textMargin | |
- multipleOffset; | |
int y = super.textMargin + multipleOffset; | |
int height = graphicsAlgorithm.getHeight() - 2 * super.textMargin | |
- multipleOffset; | |
ga.setLocationAndSize(text, x, y, width, height); | |
} | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.RotatableNode#getAngle(org.eclipse.graphiti | |
* .mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public int getAngle(GraphicsAlgorithm graphicsAlgorithm) { | |
return 0; | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.RotatableNode#isFlipped(org.eclipse. | |
* graphiti.mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public boolean isFlipped(GraphicsAlgorithm graphicsAlgorithm) { | |
return false; | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.RotatableNode#rotate90Right(org.eclipse | |
* .graphiti.mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public void rotate90Right(GraphicsAlgorithm graphicsAlgorithm) { | |
translateForRotation(graphicsAlgorithm); | |
doRotate(graphicsAlgorithm); | |
relocateText(graphicsAlgorithm); | |
for (GraphicsAlgorithm algorithm : graphicsAlgorithm | |
.getGraphicsAlgorithmChildren()) { | |
doRotate(algorithm); | |
} | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.RotatableNode#flipHorizontally(org.eclipse | |
* .graphiti.mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public void flipHorizontally(GraphicsAlgorithm graphicsAlgorithm) { | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.fmc.blockdiagram.editor.node.RotatableNode#flipVertically(org.eclipse | |
* .graphiti.mm.algorithms.GraphicsAlgorithm) | |
*/ | |
public void flipVertically(GraphicsAlgorithm graphicsAlgorithm) { | |
} | |
/** | |
* Moves algorithm to the point to simulate rotation around center. | |
* | |
* @param graphicsAlgorithm | |
* Algorithm to translate. | |
*/ | |
protected void translateForRotation(GraphicsAlgorithm graphicsAlgorithm) { | |
graphicsAlgorithm | |
.setX(graphicsAlgorithm.getX() | |
+ (graphicsAlgorithm.getWidth() - graphicsAlgorithm | |
.getHeight()) / 2); | |
graphicsAlgorithm | |
.setY(graphicsAlgorithm.getY() | |
- (graphicsAlgorithm.getWidth() - graphicsAlgorithm | |
.getHeight()) / 2); | |
} | |
/** | |
* Rotates algorithm by simply switching width and height. | |
* | |
* @param graphicsAlgorithm | |
* Algorithm to rotate. | |
*/ | |
protected void doRotate(GraphicsAlgorithm graphicsAlgorithm) { | |
int width = graphicsAlgorithm.getWidth(); | |
graphicsAlgorithm.setWidth(graphicsAlgorithm.getHeight()); | |
graphicsAlgorithm.setHeight(width); | |
} | |
} |