use of org.eclipse.gmf.runtime.diagram.ui.render.editparts.RenderedDiagramRootEditPart in project elk by eclipse.
the class GmfDiagramLayoutConnector method applyLayout.
@Override
public void applyLayout(final LayoutMapping mapping, final IPropertyHolder settings) {
boolean zoomToFit = settings.getProperty(CoreOptions.ZOOM_TO_FIT);
IWorkbenchPart workbenchPart = mapping.getWorkbenchPart();
int animationTime = calcAnimationTime(mapping, settings, workbenchPart != null && !workbenchPart.getSite().getPage().isPartVisible(workbenchPart));
mapping.setProperty(ANIMATION_TIME, animationTime);
Object layoutGraphObj = mapping.getParentElement();
if (zoomToFit && layoutGraphObj instanceof EditPart) {
// determine pre- or post-layout zoom
DiagramEditPart diagramEditPart = GmfDiagramLayoutConnector.getDiagramEditPart((EditPart) layoutGraphObj);
if (diagramEditPart == null) {
applyLayout(mapping, animationTime);
return;
}
ZoomManager zoomManager = ((RenderedDiagramRootEditPart) diagramEditPart.getRoot()).getZoomManager();
ElkNode parentNode = mapping.getLayoutGraph();
Dimension available = zoomManager.getViewport().getClientArea().getSize();
double desiredWidth = parentNode.getWidth();
double scaleX = Math.min(available.width / desiredWidth, zoomManager.getMaxZoom());
double desiredHeight = parentNode.getHeight();
double scaleY = Math.min(available.height / desiredHeight, zoomManager.getMaxZoom());
final double scale = Math.min(scaleX, scaleY);
final double oldScale = zoomManager.getZoom();
if (scale < oldScale) {
// we're zooming out, so do it before layout is applied
zoomManager.setViewLocation(new Point(0, 0));
zoomManager.setZoom(scale);
zoomManager.setViewLocation(new Point(0, 0));
}
applyLayout(mapping, animationTime);
if (scale > oldScale) {
// we're zooming in, so do it after layout is applied
zoomManager.setViewLocation(new Point(0, 0));
zoomManager.setZoom(scale);
zoomManager.setViewLocation(new Point(0, 0));
}
} else {
applyLayout(mapping, animationTime);
}
}
Aggregations