/******************************************************************************* | |
* <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.fmc.blockdiagram.editor.algorithm.comment.BraceAlgorithm; | |
import org.eclipse.fmc.blockdiagram.editor.algorithm.comment.CommentAlgorithmFactory; | |
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; | |
/** | |
* Resizes the Brace Shape. | |
* | |
* @author Rainer Thome | |
* @author Benjamin Schmeling | |
* @author Heiko Witteborg | |
* | |
*/ | |
public class BraceResizeFeature extends DefaultResizeShapeFeature { | |
public BraceResizeFeature(IFeatureProvider fp) { | |
super(fp); | |
} | |
@Override | |
public void resizeShape(IResizeShapeContext context) { | |
// super.resizeShape(context); | |
GraphicsAlgorithm resizeGa = context.getPictogramElement() | |
.getGraphicsAlgorithm(); | |
BraceAlgorithm braceAlgorithm = CommentAlgorithmFactory.getInstance() | |
.getBrace(); | |
int oldContainerWidth = resizeGa.getWidth(); | |
int oldContainerHeight = resizeGa.getHeight(); | |
int oldContainerX = resizeGa.getX(); | |
int oldContainerY = resizeGa.getY(); | |
int newContainerWidth = context.getWidth(); | |
int newContainerHeight = context.getHeight(); | |
int newContainerX = context.getX(); | |
int newContainerY = context.getY(); | |
// ensure minimum size of braces | |
if (context.getWidth() < braceAlgorithm.getMinimumWidth()) { | |
if (oldContainerX != context.getX()) | |
newContainerX = oldContainerX + oldContainerWidth | |
- braceAlgorithm.getMinimumWidth(); | |
newContainerWidth = braceAlgorithm.getMinimumWidth(); | |
} | |
if (context.getHeight() < braceAlgorithm.getMinimumHeight()) { | |
if (oldContainerY != context.getY()) | |
newContainerY = oldContainerY + oldContainerHeight | |
- braceAlgorithm.getMinimumHeight(); | |
newContainerHeight = braceAlgorithm.getMinimumHeight(); | |
} | |
// Resize visible polyline | |
braceAlgorithm.resize(resizeGa, newContainerX, newContainerY, | |
newContainerWidth, newContainerHeight); | |
} | |
} |