use of org.eclipse.draw2d.FreeformViewport in project tdi-studio-se by Talend.
the class NodeAnchor method getLocation.
/*
* (non-Javadoc)
*
* @see org.eclipse.draw2d.ChopboxAnchor#getLocation(org.eclipse.draw2d.geometry.Point)
*/
@Override
public Point getLocation(Point reference) {
if (target != null && !target.equals(source)) {
sourceLocation = new Point(source.getLocation());
targetLocation = new Point(target.getLocation());
Point diff = new Point(0, 0);
if (!isTargetAnchor) {
if (((reference.y - (target.getSize().height / 2)) != targetLocation.y) || ((reference.x - (target.getSize().width / 2)) != targetLocation.x)) {
FreeformViewport viewport = getViewport();
if (viewport != null) {
int y = viewport.getVerticalRangeModel().getValue();
int x = viewport.getHorizontalRangeModel().getValue();
diff = new Point(-x, -y);
}
}
} else {
if (((reference.y - (source.getSize().height / 2)) != sourceLocation.y) || ((reference.x - (source.getSize().width / 2)) != sourceLocation.x)) {
FreeformViewport viewport = getViewport();
if (viewport != null) {
int y = viewport.getVerticalRangeModel().getValue();
int x = viewport.getHorizontalRangeModel().getValue();
diff = new Point(-x, -y);
}
}
}
ScalableFreeformLayeredPane pane = getScalableFreeform();
sourceRect = new Rectangle(sourceLocation, source.getSize());
targetRect = new Rectangle(targetLocation, target.getSize());
if (pane != null) {
double scale = pane.getScale();
sourceLocation.performScale(scale);
targetLocation.performScale(scale);
sourceRect.performScale(scale);
targetRect.performScale(scale);
}
sourceLocation = sourceLocation.getTranslated(diff);
targetLocation = targetLocation.getTranslated(diff);
sourceRect = sourceRect.getTranslated(diff);
targetRect = targetRect.getTranslated(diff);
int nb = 0;
int connectionId = 0;
for (Connection connection : (List<Connection>) source.getOutgoingConnections()) {
if (connection.getTarget().equals(target)) {
nb++;
if (connection.equals(this.connection)) {
connectionId = nb;
}
}
}
if (nb <= 1) {
return getLocationForSimpleConnection(reference);
} else {
return getLocationForMultipleConnections(connectionId);
}
}
return super.getLocation(reference);
}
use of org.eclipse.draw2d.FreeformViewport in project archi by archimatetool.
the class GraphContainer method createContainerFigure.
private IFigure createContainerFigure() {
GraphContainer node = this;
IFigure containerFigure = new ContainerFigure();
containerFigure.setOpaque(true);
containerFigure.addLayoutListener(LayoutAnimator.getDefault());
containerFigure.setLayoutManager(new FreeformLayout());
expandGraphLabel = new ExpandGraphLabel(this, node.getText(), node.getImage(), false);
expandGraphLabel.setText(getText());
expandGraphLabel.setImage(getImage());
ContainerDimension containerDimension = computeContainerSize();
scrollPane = new ScrollPane();
scrollPane.addLayoutListener(LayoutAnimator.getDefault());
Viewport viewport = new FreeformViewport();
/*
* This is the code that helps remove the scroll bars moving when the
* nodes are dragged.
*
* viewport.setHorizontalRangeModel(new DefaultRangeModel() { public
* void setAll(int min, int ext, int max) { System.out.println("Max: " +
* max + " : current Max: " + getMaximum()); if (max < getMaximum()) {
* max = getMaximum(); } super.setAll(min, ext, max); }
*
* public void setMaximum(int maximum) { // TODO Auto-generated method
* stub System.out.println("Max: " + maximum + " : current Max: " +
* getMaximum()); if (maximum < getMaximum()) { return; }
* super.setMaximum(maximum); } });
*/
scrollPane.setViewport(viewport);
viewport.addLayoutListener(LayoutAnimator.getDefault());
scrollPane.setScrollBarVisibility(ScrollPane.AUTOMATIC);
// scalledLayer = new ScalableFreeformLayeredPane();
// $NON-NLS-1$
scalledLayer = new AspectRatioFreeformLayer("debug label");
scalledLayer.addLayoutListener(LayoutAnimator.getDefault());
// scalledLayer.setScale(computeChildScale());
scalledLayer.setScale(computeWidthScale(), computeHeightScale());
// container = new FreeformLayer();
// edgeLayer = new FreeformLayer();
zestLayer = new ZestRootLayer();
zestLayer.addLayoutListener(LayoutAnimator.getDefault());
// container.addLayoutListener(LayoutAnimator.getDefault());
// edgeLayer.addLayoutListener(LayoutAnimator.getDefault());
// scalledLayer.add(edgeLayer);
// scalledLayer.add(container);
scalledLayer.add(zestLayer);
// container.setLayoutManager(new FreeformLayout());
zestLayer.setLayoutManager(new FreeformLayout());
scrollPane.setSize(computeChildArea());
scrollPane.setLocation(new Point(0, containerDimension.labelHeight - SUBLAYER_OFFSET));
scrollPane.setForegroundColor(ColorConstants.gray);
expandGraphLabel.setBackgroundColor(getBackgroundColor());
expandGraphLabel.setForegroundColor(getForegroundColor());
expandGraphLabel.setLocation(new Point(0, 0));
containerFigure.add(scrollPane);
containerFigure.add(expandGraphLabel);
scrollPane.getViewport().setContents(scalledLayer);
scrollPane.setBorder(new LineBorder());
return containerFigure;
}
use of org.eclipse.draw2d.FreeformViewport in project archi by archimatetool.
the class FreeformGraphicalRootEditPart method createFigure.
/**
* @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
*/
@Override
protected IFigure createFigure() {
FreeformViewport viewport = new FreeformViewport();
innerLayers = new FreeformLayeredPane();
createLayers(innerLayers);
viewport.setContents(innerLayers);
return viewport;
}
use of org.eclipse.draw2d.FreeformViewport in project tdi-studio-se by Talend.
the class AbstractTalendEditor method saveOutlinePicture.
/**
* Save the outline picture for this editor.
*
* @param viewer
*/
protected void saveOutlinePicture(ScrollingGraphicalViewer viewer) {
GlobalConstant.generatingScreenShoot = true;
LayerManager layerManager = (LayerManager) viewer.getEditPartRegistry().get(LayerManager.ID);
// save image using swt
// get root figure
IFigure backgroundLayer = layerManager.getLayer(LayerConstants.GRID_LAYER);
IFigure contentLayer = layerManager.getLayer(LayerConstants.PRINTABLE_LAYERS);
// create image from root figure
FreeformViewport viewport = (FreeformViewport) ((TalendScalableFreeformRootEditPart) layerManager).getFigure();
viewport.getUpdateManager().performUpdate();
int width = contentLayer.getBounds().width;
int height = contentLayer.getBounds().height;
Image img = new Image(null, width, height);
GC gc = new GC(img);
Graphics graphics = new SWTGraphics(gc);
Point point = contentLayer.getBounds().getTopLeft();
graphics.translate(-point.x, -point.y);
IProcess2 process = getProcess();
process.setPropertyValue(IProcess.SCREEN_OFFSET_X, String.valueOf(-point.x));
process.setPropertyValue(IProcess.SCREEN_OFFSET_Y, String.valueOf(-point.y));
backgroundLayer.paint(graphics);
contentLayer.paint(graphics);
graphics.dispose();
gc.dispose();
process.getScreenshots().put("process", ImageUtils.saveImageToData(img));
img.dispose();
// service.getProxyRepositoryFactory().refreshJobPictureFolder(outlinePicturePath);
GlobalConstant.generatingScreenShoot = false;
}
Aggregations