blob: 72c1c6a41859f10334a90dfc89f0404ac85b8466 [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.resize;
import org.eclipse.graphiti.features.IFeatureProvider;
import org.eclipse.graphiti.features.context.IResizeShapeContext;
import org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature;
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm;
import org.eclipse.graphiti.mm.algorithms.MultiText;
import org.eclipse.graphiti.mm.algorithms.Polyline;
import org.eclipse.graphiti.mm.algorithms.Rectangle;
import org.eclipse.graphiti.mm.algorithms.styles.Orientation;
import org.eclipse.graphiti.mm.algorithms.styles.Point;
import org.eclipse.graphiti.services.Graphiti;
import org.eclipse.graphiti.services.IGaService;
/**
* Resizes the AreaBorder Shape.
*
* @author Heiko Witteborg
*
*/
public class AreaBorderResizeFeature extends DefaultResizeShapeFeature {
public AreaBorderResizeFeature(IFeatureProvider fp) {
super(fp);
}
@Override
public void resizeShape(IResizeShapeContext context) {
super.resizeShape(context);
IGaService ga = Graphiti.getGaService();
int w = context.getWidth();
int h = context.getHeight();
int min = 100;
// check that the longer dim is at least min
if (context.getWidth() > context.getHeight()) {
w = context.getWidth() < min ? min : w;
} else {
h = context.getHeight() < min ? min : h;
}
int margin = 2;
int lineWidth = 2;
int textHeight = 20;
int textWidth = 100;
Rectangle invRec = (Rectangle) context.getShape()
.getGraphicsAlgorithm();
Polyline line = null;
MultiText txt = null;
for (GraphicsAlgorithm gaChild : invRec.getGraphicsAlgorithmChildren()) {
if (gaChild instanceof Polyline) {
line = (Polyline) gaChild;
} else if (gaChild instanceof MultiText) {
txt = (MultiText) gaChild;
}
}
if (context.getWidth() > context.getHeight()) {
// position of containing rectangle
ga.setLocationAndSize(invRec, context.getX(), context.getY(), w, 3
* margin + lineWidth + textHeight);
// position of text field
txt.setHorizontalAlignment(Orientation.ALIGNMENT_RIGHT);
ga.setLocationAndSize(txt, margin, margin, w - (2 * margin),
textHeight);
// position of dashed line
ga.setLocationAndSize(line, 0, 2 * margin + textHeight, w, 2);
Point endPoint = line.getPoints().get(1);
endPoint.setX(w);
endPoint.setY(0);
// line.getPoints().add(ga.createPoint(w, 0));
} else {
// position of containing rectangle
ga.setLocationAndSize(invRec, context.getX(), context.getY(), 3
* margin + lineWidth + textWidth, h);
// position of text field
txt.setHorizontalAlignment(Orientation.ALIGNMENT_LEFT);
txt.setVerticalAlignment(Orientation.ALIGNMENT_BOTTOM);
ga.setLocationAndSize(txt, 2 * margin + lineWidth, margin,
textWidth, h - 2 * margin);
// position of dashed line
ga.setLocationAndSize(line, margin, 0, 2, h);
Point endPoint = line.getPoints().get(1);
endPoint.setX(0);
endPoint.setY(h);
}
// layoutPictogramElement(lineShape);
}
}