Search in sources :

Example 1 with Viewport

use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.

the class ZoneContentLayout method layout.

@Override
public void layout(IFigure parent) {
    Rectangle vBounds = null;
    if (parent.getParent() instanceof Viewport) {
        vBounds = ((Viewport) parent.getParent()).getBounds();
    }
    int wHint = -1;
    int hHint = -1;
    if (isHorizontal()) {
        hHint = parent.getClientArea(Rectangle.SINGLETON).height;
    } else {
        wHint = parent.getClientArea(Rectangle.SINGLETON).width;
    }
    List children = parent.getChildren();
    int numChildren = children.size();
    Rectangle clientArea = transposer.t(parent.getClientArea());
    int x = clientArea.x;
    int y = clientArea.y;
    int availableHeight = clientArea.height;
    Dimension[] prefSizes = new Dimension[numChildren];
    Dimension[] minSizes = new Dimension[numChildren];
    IFigure child;
    int totalHeight = 0;
    int totalMinHeight = 0;
    int prefMinSumHeight = 0;
    int connSize = 0;
    // boolean isLookupConnMax = true;
    for (int i = 0; i < numChildren; i++) {
        child = (IFigure) children.get(i);
        prefSizes[i] = transposer.t(getChildPreferredSize(child, wHint, hHint));
        minSizes[i] = transposer.t(getChildMinimumSize(child, wHint, hHint));
        totalHeight += prefSizes[i].height;
        totalMinHeight += minSizes[i].height;
        if (child instanceof AbstractTableContainer) {
            connSize = getLookupConnectionSize((AbstractTableContainer) child);
        }
    }
    totalHeight += (numChildren - 1) * spacing;
    totalMinHeight += (numChildren - 1) * spacing;
    prefMinSumHeight = totalHeight - totalMinHeight;
    int defaultSize = DEFAULT_OFFSET;
    for (int i = 0; i < numChildren; i++) {
        int amntShrinkCurrentHeight = 0;
        int prefHeight = prefSizes[i].height;
        int minHeight = minSizes[i].height;
        int prefWidth = prefSizes[i].width;
        int minWidth = minSizes[i].width;
        child = (IFigure) children.get(i);
        Rectangle newBounds = new Rectangle(x, y, prefWidth, prefHeight);
        if (connSize > 0) {
            newBounds = new Rectangle(x + (connSize - 1) * defaultSize, y, prefWidth, prefHeight);
        }
        Border border = parent.getBorder();
        Insets insets = border.getInsets(child);
        if (vBounds != null) {
            newBounds.width = vBounds.width - insets.left - insets.right;
            if (connSize > 0) {
                newBounds.width = newBounds.width - (connSize - 1) * defaultSize;
            }
        }
        newBounds.height -= amntShrinkCurrentHeight;
        child.setBounds(transposer.t(newBounds));
        prefMinSumHeight -= (prefHeight - minHeight);
        y += newBounds.height + spacing;
    }
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) List(java.util.List) Dimension(org.eclipse.draw2d.geometry.Dimension) AbstractTableContainer(org.talend.designer.gefabstractmap.figures.table.AbstractTableContainer) Border(org.eclipse.draw2d.Border) IFigure(org.eclipse.draw2d.IFigure)

Example 2 with Viewport

use of org.eclipse.draw2d.Viewport in project tdi-studio-se by Talend.

the class MapperScalableRootEditPart method createFigure.

/*
     * (non-Javadoc)
     * 
     * @see org.eclipse.gef.editparts.ScalableRootEditPart#createFigure()
     */
@Override
protected IFigure createFigure() {
    Viewport figure = (Viewport) super.createFigure();
    figure.setContentsTracksWidth(true);
    return figure;
}
Also used : Viewport(org.eclipse.draw2d.Viewport)

Example 3 with Viewport

use of org.eclipse.draw2d.Viewport in project dbeaver by serge-rider.

the class ERDOutlinePage method createControl.

/* (non-Javadoc)
     * @see org.eclipse.ui.part.IPage#createControl(org.eclipse.swt.widgets.Composite)
     */
@Override
public void createControl(Composite parent) {
    // create canvas and lws
    overview = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(overview);
    // create thumbnail
    thumbnail = new ScrollableThumbnail((Viewport) rootEditPart.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
}
Also used : Canvas(org.eclipse.swt.widgets.Canvas) MarginBorder(org.eclipse.draw2d.MarginBorder) Viewport(org.eclipse.draw2d.Viewport) LightweightSystem(org.eclipse.draw2d.LightweightSystem) ScrollableThumbnail(org.eclipse.draw2d.parts.ScrollableThumbnail)

Example 4 with Viewport

use of org.eclipse.draw2d.Viewport in project xtext-eclipse by eclipse.

the class RailroadView method reveal.

public void reveal(IFigure figure) {
    Viewport viewport = canvas.getViewport();
    Rectangle viewportBounds = viewport.getBounds().getCopy();
    viewportBounds.translate(viewport.getViewLocation());
    Rectangle figureBounds = figure.getBounds().getCopy();
    figure.translateToAbsolute(figureBounds);
    figureBounds.translate(viewport.getViewLocation());
    if (!viewportBounds.contains(figureBounds)) {
        int newX = viewportBounds.x;
        int newY = viewportBounds.y;
        if (viewportBounds.x > figureBounds.x) {
            newX = figureBounds.x;
        } else if (viewportBounds.x + viewportBounds.getRight().x < figureBounds.getRight().x) {
            newX = figureBounds.getRight().x - viewportBounds.width;
        }
        if (viewportBounds.y > figureBounds.y) {
            newY = figureBounds.y;
        } else if (viewportBounds.getBottom().y < figureBounds.getBottom().y) {
            newY = figureBounds.getBottom().y - viewportBounds.height;
        }
        canvas.scrollSmoothTo(newX, newY);
    }
}
Also used : Viewport(org.eclipse.draw2d.Viewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 5 with Viewport

use of org.eclipse.draw2d.Viewport in project archi by archimatetool.

the class ExtendedViewportAutoexposeHelper method step.

@Override
public boolean step(Point where) {
    Viewport port = findViewport(owner);
    Rectangle rect = Rectangle.SINGLETON;
    port.getClientArea(rect);
    port.translateToParent(rect);
    port.translateToAbsolute(rect);
    if (!(continueIfOutside || rect.contains(where)) || rect.shrink(threshold).contains(where))
        return false;
    // set scroll offset (speed factor)
    int scrollOffset = 0;
    // calculate time based scroll offset
    if (lastStepTime == 0)
        lastStepTime = System.currentTimeMillis();
    long difference = System.currentTimeMillis() - lastStepTime;
    if (difference > 0) {
        scrollOffset = ((int) difference / 3);
        lastStepTime = System.currentTimeMillis();
    }
    if (scrollOffset == 0)
        return true;
    rect.shrink(threshold);
    int region = rect.getPosition(where);
    Point loc = port.getViewLocation();
    if ((region & PositionConstants.SOUTH) != 0)
        loc.y += scrollOffset;
    else if ((region & PositionConstants.NORTH) != 0)
        loc.y -= scrollOffset;
    if ((region & PositionConstants.EAST) != 0)
        loc.x += scrollOffset;
    else if ((region & PositionConstants.WEST) != 0)
        loc.x -= scrollOffset;
    port.setViewLocation(loc);
    return true;
}
Also used : Viewport(org.eclipse.draw2d.Viewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

Viewport (org.eclipse.draw2d.Viewport)31 Point (org.eclipse.draw2d.geometry.Point)12 Rectangle (org.eclipse.draw2d.geometry.Rectangle)11 LightweightSystem (org.eclipse.draw2d.LightweightSystem)9 MarginBorder (org.eclipse.draw2d.MarginBorder)9 ScrollableThumbnail (org.eclipse.draw2d.parts.ScrollableThumbnail)9 Canvas (org.eclipse.swt.widgets.Canvas)9 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)6 IFigure (org.eclipse.draw2d.IFigure)5 FigureCanvas (org.eclipse.draw2d.FigureCanvas)3 Dimension (org.eclipse.draw2d.geometry.Dimension)3 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)3 RootEditPart (org.eclipse.gef.RootEditPart)3 Iterator (java.util.Iterator)2 EditPart (org.eclipse.gef.EditPart)2 ZoomManager (org.eclipse.gef.editparts.ZoomManager)2 HL7FileNode (org.talend.core.model.metadata.builder.connection.HL7FileNode)2 XMLFileNode (org.talend.core.model.metadata.builder.connection.XMLFileNode)2 IExternalNode (org.talend.core.model.process.IExternalNode)2 INode (org.talend.core.model.process.INode)2