Search in sources :

Example 1 with RangeModel

use of org.eclipse.draw2d.RangeModel 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 2 with RangeModel

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

the class PaletteScrollBar method initialize.

@Override
protected void initialize() {
    super.initialize();
    setLayoutManager(new ScrollBarLayout(transposer) {

        @SuppressWarnings("deprecation")
        @Override
        protected Rectangle layoutButtons(ScrollBar scrollBar) {
            Rectangle bounds = transposer.t(scrollBar.getClientArea());
            Dimension buttonSize = new Dimension(BUTTON_WIDTH, BUTTON_HEIGHT);
            getButtonUp().setBounds(transposer.t(new Rectangle(bounds.getTop().getTranslated(-(buttonSize.width / 2), 0), buttonSize)));
            Rectangle r = new Rectangle(bounds.getBottom().getTranslated(-(buttonSize.width / 2), -buttonSize.height), buttonSize);
            getButtonDown().setBounds(transposer.t(r));
            Rectangle trackBounds = bounds.getCropped(new Insets(buttonSize.height, 0, buttonSize.height, 0));
            RangeModel model = scrollBar.getRangeModel();
            getButtonUp().setVisible(model.getValue() != model.getMinimum());
            getButtonDown().setVisible(model.getValue() != model.getMaximum() - model.getExtent());
            return trackBounds;
        }
    });
    setPageUp(null);
    setPageDown(null);
    setThumb(null);
    setOpaque(false);
}
Also used : Insets(org.eclipse.draw2d.geometry.Insets) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Dimension(org.eclipse.draw2d.geometry.Dimension) ScrollBarLayout(org.eclipse.draw2d.ScrollBarLayout) RangeModel(org.eclipse.draw2d.RangeModel) ScrollBar(org.eclipse.draw2d.ScrollBar)

Example 3 with RangeModel

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

the class ViewportMouseWheelHelper method handleMouseWheelScrolled.

/**
 * Finds the viewport of the given EditPart and scrolls it as requested. If
 * it can't be scrolled then leaves doit to be true so that the given
 * EditPart's ancestors might have a chance to scroll.
 *
 * @see org.eclipse.gef.MouseWheelHelper#handleMouseWheelScrolled(org.eclipse.swt.widgets.Event)
 */
@Override
public void handleMouseWheelScrolled(Event event) {
    Viewport viewport = findViewport(owner);
    if (viewport == null || !viewport.isShowing())
        return;
    RangeModel rModel = viewport.getVerticalRangeModel();
    if (rModel.getExtent() < (rModel.getMaximum() - rModel.getMinimum())) {
        int currentPos = rModel.getValue();
        int scrollHeight = lineHeight;
        if (event.detail == SWT.SCROLL_PAGE)
            scrollHeight = pageHeight > lineHeight ? pageHeight : Math.max(lineHeight, viewport.getClientArea(Rectangle.SINGLETON).height - 26);
        scrollHeight *= event.count;
        viewport.setVerticalLocation(currentPos - scrollHeight);
        if (rModel.getValue() != currentPos)
            event.doit = false;
    }
}
Also used : Viewport(org.eclipse.draw2d.Viewport) RangeModel(org.eclipse.draw2d.RangeModel)

Example 4 with RangeModel

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

the class RulerComposite method disposeRulerViewer.

private void disposeRulerViewer(GraphicalViewer viewer) {
    if (viewer == null)
        return;
    /*
         * There's a tie from the editor's range model to the RulerViewport (via
         * a listener) to the RulerRootEditPart to the RulerViewer. Break this
         * tie so that the viewer doesn't leak and can be garbage collected.
         */
    RangeModel rModel = new DefaultRangeModel();
    Viewport port = ((FigureCanvas) viewer.getControl()).getViewport();
    port.setHorizontalRangeModel(rModel);
    port.setVerticalRangeModel(rModel);
    rulerEditDomain.removeViewer(viewer);
    viewer.getControl().dispose();
}
Also used : FigureCanvas(org.eclipse.draw2d.FigureCanvas) Viewport(org.eclipse.draw2d.Viewport) DefaultRangeModel(org.eclipse.draw2d.DefaultRangeModel) DefaultRangeModel(org.eclipse.draw2d.DefaultRangeModel) RangeModel(org.eclipse.draw2d.RangeModel)

Example 5 with RangeModel

use of org.eclipse.draw2d.RangeModel in project cubrid-manager by CUBRID.

the class ERSchemaEditor method setLocatePoint.

/**
	 * Set the ERD focus location onto the gave point
	 * 
	 * @param x
	 * @param y
	 */
public void setLocatePoint(int x, int y) {
    int setMax = Math.max(x, y);
    RangeModel recModel = getViewPort().getVerticalRangeModel();
    int max = recModel.getMaximum();
    int extent = recModel.getExtent();
    if (setMax > max - extent) {
        getViewPort().getVerticalRangeModel().setMaximum(setMax + extent);
    }
    getViewPort().setViewLocation(x, y);
}
Also used : RangeModel(org.eclipse.draw2d.RangeModel) Point(org.eclipse.draw2d.geometry.Point)

Aggregations

RangeModel (org.eclipse.draw2d.RangeModel)7 Viewport (org.eclipse.draw2d.Viewport)3 Point (org.eclipse.draw2d.geometry.Point)2 Rectangle (org.eclipse.draw2d.geometry.Rectangle)2 DefaultRangeModel (org.eclipse.draw2d.DefaultRangeModel)1 FigureCanvas (org.eclipse.draw2d.FigureCanvas)1 ScrollBar (org.eclipse.draw2d.ScrollBar)1 ScrollBarLayout (org.eclipse.draw2d.ScrollBarLayout)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 Insets (org.eclipse.draw2d.geometry.Insets)1