Search in sources :

Example 21 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project archi by archimatetool.

the class DragGuidePolicy method getCommand.

@Override
public Command getCommand(Request request) {
    Command cmd;
    final ChangeBoundsRequest req = (ChangeBoundsRequest) request;
    if (isDeleteRequest(req)) {
        cmd = getGuideEditPart().getRulerProvider().getDeleteGuideCommand(getHost().getModel());
    } else {
        int pDelta;
        if (getGuideEditPart().isHorizontal()) {
            pDelta = req.getMoveDelta().y;
        } else {
            pDelta = req.getMoveDelta().x;
        }
        if (isMoveValid(getGuideEditPart().getZoomedPosition() + pDelta)) {
            ZoomManager zoomManager = getGuideEditPart().getZoomManager();
            if (zoomManager != null) {
                pDelta = (int) Math.round(pDelta / zoomManager.getZoom());
            }
            cmd = getGuideEditPart().getRulerProvider().getMoveGuideCommand(getHost().getModel(), pDelta);
        } else {
            cmd = UnexecutableCommand.INSTANCE;
        }
    }
    return cmd;
}
Also used : ChangeBoundsRequest(org.eclipse.gef.requests.ChangeBoundsRequest) UnexecutableCommand(org.eclipse.gef.commands.UnexecutableCommand) Command(org.eclipse.gef.commands.Command) ZoomManager(org.eclipse.gef.editparts.ZoomManager) Point(org.eclipse.draw2d.geometry.Point)

Example 22 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project archi by archimatetool.

the class RulerDragTracker method getCurrentPosition.

protected int getCurrentPosition() {
    int position = getCurrentPositionZoomed();
    ZoomManager zoomManager = source.getZoomManager();
    if (zoomManager != null) {
        position = (int) Math.round(position / zoomManager.getZoom());
    }
    return position;
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) Point(org.eclipse.draw2d.geometry.Point)

Example 23 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project archi by archimatetool.

the class ExtendedConnectionBendpointTracker method setNearestSnapPoint.

/**
 * Set the snap point according to grid size
 * @param pt
 * @param gridSize
 */
protected Point setNearestSnapPoint(Point pt, double gridSize) {
    // Compensate viewport area and multiple zoom levels
    int x_offset = 0, y_offset = 0;
    if (getCurrentViewer() != null && getCurrentViewer().getControl() instanceof FigureCanvas) {
        Rectangle ca = ((FigureCanvas) getCurrentViewer().getControl()).getViewport().getClientArea();
        x_offset = ca.x;
        y_offset = ca.y;
        ZoomManager zm = (ZoomManager) getCurrentViewer().getProperty(ZoomManager.class.toString());
        if (zm != null) {
            gridSize = gridSize * zm.getZoom();
        }
    }
    pt.setX((int) (Math.round(((float) pt.x + (float) x_offset) / gridSize) * gridSize - x_offset));
    pt.setY((int) (Math.round(((float) pt.y + (float) y_offset) / gridSize) * gridSize - y_offset));
    return pt;
}
Also used : FigureCanvas(org.eclipse.draw2d.FigureCanvas) ZoomManager(org.eclipse.gef.editparts.ZoomManager) Rectangle(org.eclipse.draw2d.geometry.Rectangle) Point(org.eclipse.draw2d.geometry.Point)

Example 24 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project dbeaver by serge-rider.

the class ERDEditorPart method configureGraphicalViewer.

@Override
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer graphicalViewer = getGraphicalViewer();
    /*
        MenuManager manager = new MenuManager(getClass().getName(), getClass().getName());
        manager.setRemoveAllWhenShown(true);
        getEditorSite().registerContextMenu(getClass().getName() + ".EditorContext", manager, graphicalViewer, true); //$NON-NLS-1$
*/
    IPreferenceStore store = ERDActivator.getDefault().getPreferenceStore();
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, store.getBoolean(ERDConstants.PREF_GRID_ENABLED));
    graphicalViewer.setProperty(SnapToGrid.PROPERTY_GRID_SPACING, new Dimension(store.getInt(ERDConstants.PREF_GRID_WIDTH), store.getInt(ERDConstants.PREF_GRID_HEIGHT)));
    // initialize actions
    createActions();
    // Setup zoom manager
    ZoomManager zoomManager = rootPart.getZoomManager();
    List<String> zoomLevels = new ArrayList<>(3);
    zoomLevels.add(ZoomManager.FIT_ALL);
    zoomLevels.add(ZoomManager.FIT_WIDTH);
    zoomLevels.add(ZoomManager.FIT_HEIGHT);
    zoomManager.setZoomLevelContributions(zoomLevels);
    zoomManager.setZoomLevels(new double[] { .1, .25, .5, .75, 1.0, 1.5, 2.0, 2.5, 3, 4 });
    IAction zoomIn = new ZoomInAction(zoomManager);
    IAction zoomOut = new ZoomOutAction(zoomManager);
    addAction(zoomIn);
    addAction(zoomOut);
    graphicalViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(SelectionChangedEvent event) {
            String status;
            IStructuredSelection selection = (IStructuredSelection) event.getSelection();
            if (selection.isEmpty()) {
                status = "";
            } else if (selection.size() == 1) {
                status = CommonUtils.toString(selection.getFirstElement());
            } else {
                status = String.valueOf(selection.size()) + " objects";
            }
            progressControl.setInfo(status);
            updateActions(editPartActionIDs);
        }
    });
}
Also used : ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Dimension(org.eclipse.draw2d.geometry.Dimension) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ZoomManager(org.eclipse.gef.editparts.ZoomManager) IPreferenceStore(org.eclipse.jface.preference.IPreferenceStore)

Example 25 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project cubrid-manager by CUBRID.

the class ReplicationEditor method configureGraphicalViewer.

/**
	 * @see org.eclipse.gef.ui.parts.GraphicalEditor#configureGraphicalViewer()
	 */
protected void configureGraphicalViewer() {
    super.configureGraphicalViewer();
    GraphicalViewer viewer = getGraphicalViewer();
    ScalableRootEditPart rootEditPart = new ScalableRootEditPart();
    viewer.setRootEditPart(rootEditPart);
    viewer.setEditPartFactory(new PartFactory(this));
    ZoomManager manager = rootEditPart.getZoomManager();
    getActionRegistry().registerAction(new ZoomInAction(manager));
    getActionRegistry().registerAction(new ZoomOutAction(manager));
    double[] zoomLevels = new double[] { 0.25, 0.5, 0.75, 1.0, 1.5, 2.0, 2.5, 3.0, 4.0, 5.0, 10.0, 20.0 };
    manager.setZoomLevels(zoomLevels);
    List<String> zoomContributions = new ArrayList<String>();
    zoomContributions.add(ZoomManager.FIT_ALL);
    zoomContributions.add(ZoomManager.FIT_HEIGHT);
    zoomContributions.add(ZoomManager.FIT_WIDTH);
    manager.setZoomLevelContributions(zoomContributions);
    KeyHandler keyHandler = new KeyHandler();
    if (isEditable) {
        keyHandler.put(KeyStroke.getPressed(SWT.DEL, 127, 0), getActionRegistry().getAction(ActionFactory.DELETE.getId()));
    }
    keyHandler.put(KeyStroke.getPressed('+', SWT.KEYPAD_ADD, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_IN));
    keyHandler.put(KeyStroke.getPressed('-', SWT.KEYPAD_SUBTRACT, 0), getActionRegistry().getAction(GEFActionConstants.ZOOM_OUT));
    keyHandler.put(KeyStroke.getPressed('a', 97, 0), getActionRegistry().getAction(ActionFactory.SELECT_ALL.getId()));
    viewer.setProperty(MouseWheelHandler.KeyGenerator.getKey(SWT.NONE), MouseWheelZoomHandler.SINGLETON);
    viewer.setKeyHandler(keyHandler);
    ContextMenuProvider provider = new ReplEditorContextMenuProvider(viewer, getActionRegistry());
    viewer.setContextMenu(provider);
}
Also used : GraphicalViewer(org.eclipse.gef.GraphicalViewer) ZoomOutAction(org.eclipse.gef.ui.actions.ZoomOutAction) PartFactory(com.cubrid.cubridmanager.ui.replication.editor.parts.PartFactory) ScalableRootEditPart(org.eclipse.gef.editparts.ScalableRootEditPart) ArrayList(java.util.ArrayList) ContextMenuProvider(org.eclipse.gef.ContextMenuProvider) ZoomManager(org.eclipse.gef.editparts.ZoomManager) KeyHandler(org.eclipse.gef.KeyHandler) ZoomInAction(org.eclipse.gef.ui.actions.ZoomInAction)

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