/******************************************************************************* | |
* <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.AbstractText; | |
import org.eclipse.graphiti.mm.algorithms.GraphicsAlgorithm; | |
import org.eclipse.graphiti.mm.pictograms.ContainerShape; | |
import org.eclipse.graphiti.mm.pictograms.Shape; | |
import org.eclipse.graphiti.services.Graphiti; | |
/** | |
* Resize feature which automatically realigns the texts of the shapes. | |
* | |
* @author Benjamin Schmeling | |
* | |
*/ | |
public class ResizeFeature extends DefaultResizeShapeFeature { | |
public ResizeFeature(IFeatureProvider fp) { | |
super(fp); | |
} | |
@Override | |
/* | |
* (non-Javadoc) | |
* | |
* @see | |
* org.eclipse.graphiti.features.impl.DefaultResizeShapeFeature#resizeShape | |
* (org.eclipse.graphiti.features.context.IResizeShapeContext) | |
*/ | |
public void resizeShape(IResizeShapeContext context) { | |
int w, h; | |
int maxW = 0; | |
int maxH = 0; | |
if (context.getShape() instanceof ContainerShape) { | |
GraphicsAlgorithm sGa; | |
for (Shape s : ((ContainerShape) context.getShape()).getChildren()) { | |
sGa = s.getGraphicsAlgorithm(); | |
if (!(sGa instanceof AbstractText)) { | |
if (sGa.getWidth() + sGa.getX() > maxW) { | |
maxW = sGa.getWidth() + sGa.getX(); | |
} | |
if (sGa.getHeight() + sGa.getY() > maxH) { | |
maxH = sGa.getHeight() + sGa.getY(); | |
} | |
} | |
} | |
} | |
w = context.getWidth() >= maxW ? context.getWidth() : maxW; | |
h = context.getHeight() >= maxH ? context.getHeight() : maxH; | |
// ((ResizeShapeContext) context).setHeight(h); | |
// ((ResizeShapeContext) context).setWidth(w); | |
if (context.getShape() instanceof ContainerShape) { | |
for (Shape s : ((ContainerShape) context.getShape()).getChildren()) { | |
if (s.getGraphicsAlgorithm() instanceof AbstractText | |
&& !s.isActive()) { | |
Graphiti.getGaService().setLocationAndSize( | |
s.getGraphicsAlgorithm(), 5, 5, w - 5, h - 10); | |
} | |
/* | |
* else if (FMCUtil.getIndependentObject(context.getShape()) == | |
* FMCType.HumanAgent || FMCUtil.getBO(context.getShape()) | |
* instanceof HumanAgent) { | |
* | |
* int oldWidth = s.getGraphicsAlgorithm().getWidth(); int | |
* oldHeight = s.getGraphicsAlgorithm().getHeight(); | |
* Graphiti.getGaService().setLocation( | |
* s.getGraphicsAlgorithm(), w / 2 - 12, 10); } | |
*/ | |
} | |
} | |
super.resizeShape(context); | |
} | |
} |