Search in sources :

Example 11 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project knime-core by knime.

the class PasteActionContextMenu method newShiftCalculator.

/**
 * {@inheritDoc}
 */
@Override
protected ShiftCalculator newShiftCalculator() {
    return new ShiftCalculator() {

        /**
         * {@inheritDoc}
         */
        @Override
        public int[] calculateShift(final Iterable<int[]> boundsList, final WorkflowManager manager, final ClipboardObject clipObject) {
            int x = getEditor().getSelectionTool().getXLocation();
            int y = getEditor().getSelectionTool().getYLocation();
            int smallestX = Integer.MAX_VALUE;
            int smallestY = Integer.MAX_VALUE;
            for (int[] bounds : boundsList) {
                int currentX = bounds[0];
                int currentY = bounds[1];
                if (currentX < smallestX) {
                    smallestX = currentX;
                }
                if (currentY < smallestY) {
                    smallestY = currentY;
                }
            }
            ZoomManager zoomManager = (ZoomManager) getEditor().getViewer().getProperty(ZoomManager.class.toString());
            Point viewPortLocation = zoomManager.getViewport().getViewLocation();
            x += viewPortLocation.x;
            y += viewPortLocation.y;
            double zoom = zoomManager.getZoom();
            x /= zoom;
            y /= zoom;
            int shiftx = x - smallestX;
            int shifty = y - smallestY;
            if (getEditor().getEditorSnapToGrid()) {
                shiftx = getEditor().getEditorGridXOffset(shiftx);
                shifty = getEditor().getEditorGridYOffset(shifty);
            }
            return new int[] { shiftx, shifty };
        }
    };
}
Also used : ClipboardObject(org.knime.workbench.editor2.ClipboardObject) ZoomManager(org.eclipse.gef.editparts.ZoomManager) WorkflowManager(org.knime.core.node.workflow.WorkflowManager) Point(org.eclipse.draw2d.geometry.Point) ShiftCalculator(org.knime.workbench.editor2.commands.PasteFromWorkflowPersistorCommand.ShiftCalculator) Point(org.eclipse.draw2d.geometry.Point)

Example 12 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project yamcs-studio by yamcs.

the class DisplayEditpart method deactivate.

@Override
public void deactivate() {
    final Control control = getViewer().getControl();
    if (getViewer() != null && !control.isDisposed()) {
        // This needs to be executed in UI Thread
        final ZoomManager zoomManager = getZoomManager();
        control.getDisplay().asyncExec(new Runnable() {

            @Override
            public void run() {
                if (zoomListener != null && !control.isDisposed()) {
                    // recover zoom
                    zoomManager.setZoom(1.0);
                    control.removeControlListener(zoomListener);
                }
                if (scaleListener != null && !control.isDisposed()) {
                    control.removeControlListener(scaleListener);
                }
            }
        });
    }
    super.deactivate();
}
Also used : Control(org.eclipse.swt.widgets.Control) ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Example 13 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project yamcs-studio by yamcs.

the class TextEditManager method bringDown.

/**
 * @see org.eclipse.gef.tools.DirectEditManager#bringDown()
 */
@Override
protected void bringDown() {
    ZoomManager zoomMgr = (ZoomManager) getEditPart().getViewer().getProperty(ZoomManager.class.toString());
    if (zoomMgr != null)
        zoomMgr.removeZoomListener(zoomListener);
    if (actionHandler != null) {
        actionHandler.dispose();
        actionHandler = null;
    }
    if (actionBars != null) {
        restoreSavedActions(actionBars);
        actionBars.updateActionBars();
        actionBars = null;
    }
    super.bringDown();
    // dispose any scaled fonts that might have been created
    disposeScaledFont();
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Example 14 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project jbosstools-hibernate by jbosstools.

the class DiagramViewer method getFitHeightZoomValue.

public double getFitHeightZoomValue() {
    double res = 1.0;
    ZoomManager manager = (ZoomManager) getGraphicalViewer().getProperty(ZoomManager.class.toString());
    Method m = null;
    try {
        // $NON-NLS-1$
        m = manager.getClass().getDeclaredMethod("getFitHeightZoomLevel");
        m.setAccessible(true);
        res = (Double) m.invoke(manager);
    } catch (SecurityException e) {
    } catch (NoSuchMethodException e) {
    } catch (IllegalArgumentException e) {
    } catch (IllegalAccessException e) {
    } catch (InvocationTargetException e) {
    }
    return res;
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) Method(java.lang.reflect.Method) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 15 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project jbosstools-hibernate by jbosstools.

the class DiagramViewer method getZoom.

/**
 * Returns the current zoom level.
 * @return double the zoom level
 */
public double getZoom() {
    double zoom = 1.0;
    ZoomManager manager = (ZoomManager) getGraphicalViewer().getProperty(ZoomManager.class.toString());
    if (manager != null) {
        zoom = manager.getZoom();
    }
    return zoom;
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager)

Aggregations

ZoomManager (org.eclipse.gef.editparts.ZoomManager)46 Point (org.eclipse.draw2d.geometry.Point)14 ArrayList (java.util.ArrayList)7 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)5 Dimension (org.eclipse.draw2d.geometry.Dimension)4 ScalableFreeformRootEditPart (org.eclipse.gef.editparts.ScalableFreeformRootEditPart)4 ZoomInAction (org.eclipse.gef.ui.actions.ZoomInAction)4 ZoomOutAction (org.eclipse.gef.ui.actions.ZoomOutAction)4 Iterator (java.util.Iterator)3 Rectangle (org.eclipse.draw2d.geometry.Rectangle)3 GraphicalViewer (org.eclipse.gef.GraphicalViewer)3 IAction (org.eclipse.jface.action.IAction)3 ConnectionContainerEditPart (org.knime.workbench.editor2.editparts.ConnectionContainerEditPart)3 InvocationTargetException (java.lang.reflect.InvocationTargetException)2 Method (java.lang.reflect.Method)2 AbsoluteBendpoint (org.eclipse.draw2d.AbsoluteBendpoint)2 Bendpoint (org.eclipse.draw2d.Bendpoint)2 FigureCanvas (org.eclipse.draw2d.FigureCanvas)2 Viewport (org.eclipse.draw2d.Viewport)2 KeyHandler (org.eclipse.gef.KeyHandler)2