Search in sources :

Example 11 with Viewport

use of org.eclipse.draw2d.Viewport in project whole by wholeplatform.

the class WholeViewportAutoexposeHelper 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 (!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);
    RangeModel hm = port.getHorizontalRangeModel();
    RangeModel vm = port.getVerticalRangeModel();
    final Point loc = port.getViewLocation();
    if ((region & PositionConstants.SOUTH) != 0)
        loc.y = Math.min(loc.y + scrollOffset, vm.getMaximum() - vm.getExtent());
    else if ((region & PositionConstants.NORTH) != 0)
        loc.y = Math.max(loc.y - scrollOffset, 0);
    if ((region & PositionConstants.EAST) != 0)
        loc.x = Math.min(loc.x + scrollOffset, hm.getMaximum() - hm.getExtent());
    else if ((region & PositionConstants.WEST) != 0)
        loc.x = Math.max(loc.x - scrollOffset, 0);
    if (loc.x != hm.getValue() || loc.y != vm.getValue())
        Display.getCurrent().asyncExec(new Runnable() {

            public void run() {
                exposeLocation(loc);
            }
        });
    return true;
}
Also used : Viewport(org.eclipse.draw2d.Viewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) RangeModel(org.eclipse.draw2d.RangeModel) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with Viewport

use of org.eclipse.draw2d.Viewport in project webtools.sourceediting by eclipse.

the class CategoryEditPart method createFigure.

protected IFigure createFigure() {
    outerPane = new Figure();
    outerPane.setBorder(new RoundedLineBorder(1, 6));
    createHeadingFigure();
    int minHeight = SWT.DEFAULT;
    switch(getType()) {
        case CategoryAdapter.DIRECTIVES:
            {
                minHeight = 80;
                break;
            }
        case CategoryAdapter.ATTRIBUTES:
        case CategoryAdapter.GROUPS:
            {
                minHeight = 100;
                break;
            }
    }
    final int theMinHeight = minHeight;
    ToolbarLayout outerLayout = new ToolbarLayout(false) {

        protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
            Dimension d = super.calculatePreferredSize(parent, width, height);
            d.union(new Dimension(250, theMinHeight));
            return d;
        }
    };
    outerLayout.setStretchMinorAxis(true);
    outerPane.setLayoutManager(outerLayout);
    RectangleFigure line = new RectangleFigure() {

        public Dimension getPreferredSize(int wHint, int hHint) {
            Dimension d = super.getPreferredSize(wHint, hHint);
            d.width += 20;
            d.height = 1;
            return d;
        }
    };
    ToolbarLayout lineLayout = new ToolbarLayout(false);
    lineLayout.setVertical(true);
    lineLayout.setStretchMinorAxis(true);
    line.setLayoutManager(lineLayout);
    outerPane.add(line);
    scrollpane = new ScrollPane();
    // ScrollPane.ALWAYS);
    scrollpane.setVerticalScrollBarVisibility(ScrollPane.AUTOMATIC);
    outerPane.add(scrollpane);
    Figure pane = new Figure();
    pane.setBorder(new MarginBorder(5, 8, 5, 8));
    ContainerLayout layout = new ContainerLayout();
    layout.setHorizontal(false);
    layout.setSpacing(0);
    pane.setLayoutManager(layout);
    Viewport viewport = new Viewport();
    viewport.setContentsTracksHeight(true);
    ViewportLayout viewportLayout = new ViewportLayout() {

        protected Dimension calculatePreferredSize(IFigure parent, int width, int height) {
            Dimension d = super.calculatePreferredSize(parent, width, height);
            if (theMinHeight > 0)
                d.height = Math.min(d.height, theMinHeight);
            else {
                double factor = getZoomManager().getZoom();
                // adjust for other categories and spaces
                int scaledHeight = (int) Math.round((getViewer().getControl().getBounds().height - minimumHeight) / factor);
                d.height = Math.max(250, scaledHeight);
            }
            d.width = Math.min(d.width, 300);
            return d;
        }
    };
    viewport.setLayoutManager(viewportLayout);
    scrollpane.setViewport(viewport);
    scrollpane.setContents(pane);
    return outerPane;
}
Also used : RectangleFigure(org.eclipse.draw2d.RectangleFigure) ContainerLayout(org.eclipse.wst.xsd.ui.internal.design.layouts.ContainerLayout) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) IFigure(org.eclipse.draw2d.IFigure) RectangleFigure(org.eclipse.draw2d.RectangleFigure) Figure(org.eclipse.draw2d.Figure) HeadingFigure(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.HeadingFigure) ToolbarLayout(org.eclipse.draw2d.ToolbarLayout) RoundedLineBorder(org.eclipse.wst.xsd.ui.internal.adt.typeviz.design.figures.RoundedLineBorder) ScrollPane(org.eclipse.draw2d.ScrollPane) MarginBorder(org.eclipse.draw2d.MarginBorder) ViewportLayout(org.eclipse.draw2d.ViewportLayout) IFigure(org.eclipse.draw2d.IFigure)

Example 13 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 14 with Viewport

use of org.eclipse.draw2d.Viewport in project yamcs-studio by yamcs.

the class OverviewOutlinePage method createControl.

@Override
public void createControl(Composite parent) {
    overview = new Canvas(parent, SWT.NONE);
    var lws = new LightweightSystem(overview);
    thumbnail = new ScrollableThumbnail((Viewport) rootEP.getFigure());
    thumbnail.setBorder(new MarginBorder(3));
    thumbnail.setSource(rootEP.getLayer(LayerConstants.PRINTABLE_LAYERS));
    lws.setContents(thumbnail);
    disposeListener = e -> {
        if (thumbnail != null) {
            thumbnail.deactivate();
            thumbnail = null;
        }
    };
    rootEP.getViewer().getControl().addDisposeListener(disposeListener);
}
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 15 with Viewport

use of org.eclipse.draw2d.Viewport in project yamcs-studio by yamcs.

the class AbstractSWTWidgetFigure method relocateWidget.

/**
 * relocate the widget so it follows the figure position.
 */
protected void relocateWidget() {
    if (wrapComposite != null && getParent().getParent() instanceof Viewport) {
        var viewPortArea = getParent().getParent().getClientArea();
        var clientArea = getClientArea();
        getParent().translateToAbsolute(viewPortArea);
        translateToAbsolute(clientArea);
        isIntersectViewPort = viewPortArea.intersects(clientArea);
    // isIntersectViewPort = getParent().getParent().getClientArea()
    // .intersects(getClientArea());
    }
    GUIRefreshThread.getInstance(runmode).addIgnorableTask(new WidgetIgnorableUITask(this, () -> {
        if (!getSWTWidget().isDisposed() && getParent() != null) {
            doRelocateWidget();
        }
    }, composite.getDisplay()));
}
Also used : WidgetIgnorableUITask(org.csstudio.opibuilder.datadefinition.WidgetIgnorableUITask) Viewport(org.eclipse.draw2d.Viewport)

Aggregations

Viewport (org.eclipse.draw2d.Viewport)44 Point (org.eclipse.draw2d.geometry.Point)16 Rectangle (org.eclipse.draw2d.geometry.Rectangle)16 IFigure (org.eclipse.draw2d.IFigure)9 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 Dimension (org.eclipse.draw2d.geometry.Dimension)7 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)6 Iterator (java.util.Iterator)4 FigureCanvas (org.eclipse.draw2d.FigureCanvas)4 ScrollPane (org.eclipse.draw2d.ScrollPane)4 LayeredPane (org.eclipse.draw2d.LayeredPane)3 RangeModel (org.eclipse.draw2d.RangeModel)3 PrecisionPoint (org.eclipse.draw2d.geometry.PrecisionPoint)3 GraphicalEditPart (org.eclipse.gef.GraphicalEditPart)3 RootEditPart (org.eclipse.gef.RootEditPart)3 Insets (org.eclipse.draw2d.geometry.Insets)2 EditPart (org.eclipse.gef.EditPart)2