Search in sources :

Example 1 with FreeformViewport

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);
}
Also used : ScalableFreeformLayeredPane(org.eclipse.draw2d.ScalableFreeformLayeredPane) FreeformViewport(org.eclipse.draw2d.FreeformViewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) IConnection(org.talend.core.model.process.IConnection) Connection(org.talend.designer.core.ui.editor.connections.Connection) ArrayList(java.util.ArrayList) List(java.util.List) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point) KeyPoint(org.talend.commons.ui.gmf.draw2d.LineSeg.KeyPoint) Point(org.eclipse.draw2d.geometry.Point)

Example 2 with FreeformViewport

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;
}
Also used : LineBorder(org.eclipse.draw2d.LineBorder) FreeformViewport(org.eclipse.draw2d.FreeformViewport) Viewport(org.eclipse.draw2d.Viewport) Point(org.eclipse.draw2d.geometry.Point) FreeformLayout(org.eclipse.draw2d.FreeformLayout) ScrollPane(org.eclipse.draw2d.ScrollPane) AspectRatioFreeformLayer(org.eclipse.zest.core.widgets.internal.AspectRatioFreeformLayer) FreeformViewport(org.eclipse.draw2d.FreeformViewport) ZestRootLayer(org.eclipse.zest.core.widgets.internal.ZestRootLayer) ExpandGraphLabel(org.eclipse.zest.core.widgets.internal.ExpandGraphLabel) IFigure(org.eclipse.draw2d.IFigure) ContainerFigure(org.eclipse.zest.core.widgets.internal.ContainerFigure)

Example 3 with FreeformViewport

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;
}
Also used : FreeformViewport(org.eclipse.draw2d.FreeformViewport) FreeformLayeredPane(org.eclipse.draw2d.FreeformLayeredPane)

Example 4 with FreeformViewport

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;
}
Also used : Graphics(org.eclipse.draw2d.Graphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) SWTGraphics(org.eclipse.draw2d.SWTGraphics) FreeformViewport(org.eclipse.draw2d.FreeformViewport) IProcess2(org.talend.core.model.process.IProcess2) Point(org.eclipse.draw2d.geometry.Point) Image(org.eclipse.swt.graphics.Image) GC(org.eclipse.swt.graphics.GC) LayerManager(org.eclipse.gef.editparts.LayerManager) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

Aggregations

FreeformViewport (org.eclipse.draw2d.FreeformViewport)4 Point (org.eclipse.draw2d.geometry.Point)3 IFigure (org.eclipse.draw2d.IFigure)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FreeformLayeredPane (org.eclipse.draw2d.FreeformLayeredPane)1 FreeformLayout (org.eclipse.draw2d.FreeformLayout)1 Graphics (org.eclipse.draw2d.Graphics)1 LineBorder (org.eclipse.draw2d.LineBorder)1 SWTGraphics (org.eclipse.draw2d.SWTGraphics)1 ScalableFreeformLayeredPane (org.eclipse.draw2d.ScalableFreeformLayeredPane)1 ScrollPane (org.eclipse.draw2d.ScrollPane)1 Viewport (org.eclipse.draw2d.Viewport)1 Rectangle (org.eclipse.draw2d.geometry.Rectangle)1 LayerManager (org.eclipse.gef.editparts.LayerManager)1 GC (org.eclipse.swt.graphics.GC)1 Image (org.eclipse.swt.graphics.Image)1 AspectRatioFreeformLayer (org.eclipse.zest.core.widgets.internal.AspectRatioFreeformLayer)1 ContainerFigure (org.eclipse.zest.core.widgets.internal.ContainerFigure)1 ExpandGraphLabel (org.eclipse.zest.core.widgets.internal.ExpandGraphLabel)1