Search in sources :

Example 16 with Viewport

use of org.eclipse.draw2d.Viewport in project dbeaver by dbeaver.

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 17 with Viewport

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

the class OverviewOutlinePage method createControl.

@Override
public void createControl(Composite parent) {
    if (fEditPart == null) {
        return;
    }
    // create canvas and lws
    fCanvas = new Canvas(parent, SWT.NONE);
    LightweightSystem lws = new LightweightSystem(fCanvas);
    fThumbnail = new ScrollableThumbnail((Viewport) fEditPart.getFigure());
    fThumbnail.setUseScaledGraphics(false);
    fThumbnail.setSource(fEditPart.getLayer(LayerConstants.PRINTABLE_LAYERS));
    fThumbnail.setBorder(new MarginBorder(3));
    lws.setContents(fThumbnail);
    // Help
    PlatformUI.getWorkbench().getHelpSystem().setHelp(fCanvas, HELP_ID);
}
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 18 with Viewport

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

the class OverlayScrollPaneLayout method layout.

/**
 * {@inheritDoc}
 */
@Override
public void layout(IFigure parent) {
    ScrollPane scrollpane = (ScrollPane) parent;
    Rectangle clientArea = parent.getClientArea();
    ScrollBar hBar = scrollpane.getHorizontalScrollBar(), vBar = scrollpane.getVerticalScrollBar();
    Viewport viewport = scrollpane.getViewport();
    Insets insets = new Insets();
    insets.bottom = hBar.getPreferredSize(clientArea.width, clientArea.height).height;
    insets.right = vBar.getPreferredSize(clientArea.width, clientArea.height).width;
    int hVis = scrollpane.getHorizontalScrollBarVisibility(), vVis = scrollpane.getVerticalScrollBarVisibility();
    Dimension available = clientArea.getSize(), preferred = viewport.getPreferredSize(available.width, available.height).getCopy();
    boolean none = available.contains(preferred), both = !none && vVis != NEVER && hVis != NEVER && preferred.contains(available), showV = both || preferred.height > available.height, showH = both || preferred.width > available.width;
    // Adjust for visibility override flags
    showV = !(vVis == NEVER) && (showV || vVis == ALWAYS);
    showH = !(hVis == NEVER) && (showH || hVis == ALWAYS);
    if (!showV)
        insets.right = 0;
    if (!showH)
        insets.bottom = 0;
    Rectangle bounds, viewportArea = clientArea;
    if (showV) {
        bounds = new Rectangle(viewportArea.right() - insets.right, viewportArea.y, insets.right, viewportArea.height);
        vBar.setBounds(bounds);
    // vBar.setMaximum(preferred.height);
    }
    if (showH) {
        bounds = new Rectangle(viewportArea.x, viewportArea.bottom() - insets.bottom, viewportArea.width, insets.bottom);
        hBar.setBounds(bounds);
    // hBar.setMaximum(preferred.width);
    }
    vBar.setVisible(showV);
    hBar.setVisible(showH);
    viewport.setBounds(viewportArea);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) ScrollPane(org.eclipse.draw2d.ScrollPane) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) ScrollBar(org.eclipse.draw2d.ScrollBar)

Example 19 with Viewport

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

the class GraphicalRootEditPart method createFigure.

/**
 * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
 */
@Override
protected IFigure createFigure() {
    innerLayers = new LayeredPane();
    printableLayers = new LayeredPane();
    Layer layer = new Layer();
    layer.setLayoutManager(new StackLayout());
    printableLayers.add(layer, PRIMARY_LAYER);
    layer = new ConnectionLayer();
    layer.setPreferredSize(new Dimension(5, 5));
    printableLayers.add(layer, CONNECTION_LAYER);
    innerLayers.add(printableLayers, PRINTABLE_LAYERS);
    layer = new Layer();
    layer.setPreferredSize(new Dimension(5, 5));
    innerLayers.add(layer, HANDLE_LAYER);
    layer = new FeedbackLayer();
    layer.setPreferredSize(new Dimension(5, 5));
    innerLayers.add(layer, FEEDBACK_LAYER);
    ScrollPane pane = new ScrollPane();
    pane.setViewport(new Viewport(true));
    pane.setContents(innerLayers);
    return pane;
}
Also used : LayeredPane(org.eclipse.draw2d.LayeredPane) ScrollPane(org.eclipse.draw2d.ScrollPane) StackLayout(org.eclipse.draw2d.StackLayout) Viewport(org.eclipse.draw2d.Viewport) Dimension(org.eclipse.draw2d.geometry.Dimension) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer) Layer(org.eclipse.draw2d.Layer) ConnectionLayer(org.eclipse.draw2d.ConnectionLayer)

Example 20 with Viewport

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

the class ViewportExposeHelper method exposeDescendant.

/**
 * Exposes the descendant EditPart by smoothly scrolling the
 * <code>Viewport</code>. The smoothness is determined by the minimum and
 * maximum frame count, and the overall amount being scrolled.
 *
 * @see org.eclipse.gef.ExposeHelper#exposeDescendant(EditPart)
 */
@Override
public void exposeDescendant(EditPart part) {
    Viewport port = findViewport(owner);
    if (port == null)
        return;
    IFigure target = ((GraphicalEditPart) part).getFigure();
    /*
         * All calculations are done relative to the contents of the viewport.
         * The expose margin is added in absolute coordinates, and then taken
         * back to relative viewport coordinates.
         */
    Rectangle exposeRegion = target.getBounds().getCopy();
    target.translateToAbsolute(exposeRegion);
    if (exposeMargin != null)
        exposeRegion.expand(exposeMargin);
    port.getContents().translateToRelative(exposeRegion);
    Point offset = port.getContents().getBounds().getLocation();
    // By substracting the offset, the region is now the difference from the
    // contents origin.
    exposeRegion.translate(offset.negate());
    exposeRegion.translate(port.getHorizontalRangeModel().getMinimum(), port.getVerticalRangeModel().getMinimum());
    Dimension viewportSize = port.getClientArea().getSize();
    Point topLeft = exposeRegion.getTopLeft();
    Point bottomRight = exposeRegion.getBottomRight().translate(viewportSize.getNegated());
    Point finalLocation = new Point();
    if (viewportSize.width < exposeRegion.width)
        finalLocation.x = Math.min(bottomRight.x, Math.max(topLeft.x, port.getViewLocation().x));
    else
        finalLocation.x = Math.min(topLeft.x, Math.max(bottomRight.x, port.getViewLocation().x));
    if (viewportSize.height < exposeRegion.height)
        finalLocation.y = Math.min(bottomRight.y, Math.max(topLeft.y, port.getViewLocation().y));
    else
        finalLocation.y = Math.min(topLeft.y, Math.max(bottomRight.y, port.getViewLocation().y));
    Point startLocation = port.getViewLocation();
    int dx = finalLocation.x - startLocation.x;
    int dy = finalLocation.y - startLocation.y;
    int frames = (Math.abs(dx) + Math.abs(dy)) / 15;
    frames = Math.max(frames, getMinimumFrameCount());
    frames = Math.min(frames, getMaximumFrameCount());
    int stepX = Math.min((dx / frames), (viewportSize.width / 3));
    int stepY = Math.min((dy / frames), (viewportSize.height / 3));
    for (int i = 1; i < frames; i++) {
        port.setViewLocation(startLocation.x + stepX * i, startLocation.y + stepY * i);
        port.getUpdateManager().performUpdate();
    }
    port.setViewLocation(finalLocation);
}
Also used : Viewport(org.eclipse.draw2d.Viewport) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point) Dimension(org.eclipse.draw2d.geometry.Dimension) GraphicalEditPart(org.eclipse.gef.GraphicalEditPart) Point(org.eclipse.draw2d.geometry.Point) IFigure(org.eclipse.draw2d.IFigure)

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