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;
}
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;
}
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;
}
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);
}
});
}
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);
}
Aggregations