Search in sources :

Example 16 with ZoomManager

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

the class DiagramViewer method getFitPageZoomValue.

public double getFitPageZoomValue() {
    double res = 1.0;
    ZoomManager manager = (ZoomManager) getGraphicalViewer().getProperty(ZoomManager.class.toString());
    Method m = null;
    try {
        // $NON-NLS-1$
        m = manager.getClass().getDeclaredMethod("getFitPageZoomLevel");
        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 17 with ZoomManager

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

the class DiagramViewer method loadProperties.

protected boolean loadProperties() {
    if (getOrmDiagram() == null || getGraphicalViewer() == null) {
        return false;
    }
    // Ruler properties
    DiagramRuler ruler = getOrmDiagram().getRuler(PositionConstants.WEST);
    RulerProvider provider = null;
    if (ruler != null) {
        provider = new DiagramRulerProvider(ruler);
    }
    getGraphicalViewer().setProperty(RulerProvider.PROPERTY_VERTICAL_RULER, provider);
    ruler = getOrmDiagram().getRuler(PositionConstants.NORTH);
    provider = null;
    if (ruler != null) {
        provider = new DiagramRulerProvider(ruler);
    }
    getGraphicalViewer().setProperty(RulerProvider.PROPERTY_HORIZONTAL_RULER, provider);
    getGraphicalViewer().setProperty(RulerProvider.PROPERTY_RULER_VISIBILITY, new Boolean(getOrmDiagram().getRulerVisibility()));
    // Snap to Geometry property
    getGraphicalViewer().setProperty(SnapToGeometry.PROPERTY_SNAP_ENABLED, new Boolean(getOrmDiagram().isSnapToGeometryEnabled()));
    // Grid properties
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_ENABLED, new Boolean(getOrmDiagram().isGridEnabled()));
    // We keep grid visibility and enablement in sync
    getGraphicalViewer().setProperty(SnapToGrid.PROPERTY_GRID_VISIBLE, new Boolean(getOrmDiagram().isGridEnabled()));
    // Zoom
    ZoomManager manager = (ZoomManager) getGraphicalViewer().getProperty(ZoomManager.class.toString());
    if (manager != null) {
        manager.setZoom(getOrmDiagram().getZoom());
    }
    return true;
}
Also used : DiagramRulerProvider(org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRulerProvider) RulerProvider(org.eclipse.gef.rulers.RulerProvider) DiagramRuler(org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRuler) ZoomManager(org.eclipse.gef.editparts.ZoomManager) DiagramRulerProvider(org.jboss.tools.hibernate.ui.diagram.rulers.DiagramRulerProvider)

Example 18 with ZoomManager

use of org.eclipse.gef.editparts.ZoomManager in project statecharts by Yakindu.

the class XtextDirectEditManager method getZoomLevelFont.

/**
 * This method obtains the fonts that are being used by the figure at its
 * zoom level.
 *
 * @param gep
 *            the associated <code>GraphicalEditPart</code> of the figure
 * @param actualFont
 *            font being used by the figure
 * @param display
 * @return <code>actualFont</code> if zoom level is 1.0 (or when there's an
 *         error), new Font otherwise.
 */
private Font getZoomLevelFont(Font actualFont, Display display) {
    Object zoom = getEditPart().getViewer().getProperty(ZoomManager.class.toString());
    if (zoom != null) {
        double zoomLevel = ((ZoomManager) zoom).getZoom();
        if (zoomLevel == 1.0f)
            return actualFont;
        FontData[] fd = new FontData[actualFont.getFontData().length];
        FontData tempFD = null;
        for (int i = 0; i < fd.length; i++) {
            tempFD = actualFont.getFontData()[i];
            fd[i] = new FontData(tempFD.getName(), (int) (zoomLevel * tempFD.getHeight()), tempFD.getStyle());
        }
        try {
            FontDescriptor fontDescriptor = FontDescriptor.createFrom(fd);
            cachedFontDescriptors.add(fontDescriptor);
            return getResourceManager().createFont(fontDescriptor);
        } catch (DeviceResourceException e) {
            Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getZoomLevelFonts", // $NON-NLS-1$
            e);
            Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getZoomLevelFonts", // $NON-NLS-1$
            e);
            return actualFont;
        }
    } else
        return actualFont;
}
Also used : DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) ZoomManager(org.eclipse.gef.editparts.ZoomManager) FontData(org.eclipse.swt.graphics.FontData) Point(org.eclipse.swt.graphics.Point) FontDescriptor(org.eclipse.jface.resource.FontDescriptor)

Example 19 with ZoomManager

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

the class ERDEditorPart method fillDefaultEditorContributions.

protected void fillDefaultEditorContributions(IContributionManager toolBarManager) {
    ZoomManager zoomManager = rootPart.getZoomManager();
    String[] zoomStrings = new String[] { ZoomManager.FIT_ALL, ZoomManager.FIT_HEIGHT, ZoomManager.FIT_WIDTH };
    // Init zoom combo with dummy part service
    // to prevent zoom disable on part change - as it is standalone zoom control, not global one
    zoomCombo = new ZoomComboContributionItem(new IPartService() {

        @Override
        public void addPartListener(IPartListener listener) {
        }

        @Override
        public void addPartListener(IPartListener2 listener) {
        }

        @Override
        public IWorkbenchPart getActivePart() {
            return ERDEditorPart.this;
        }

        @Override
        public IWorkbenchPartReference getActivePartReference() {
            return null;
        }

        @Override
        public void removePartListener(IPartListener listener) {
        }

        @Override
        public void removePartListener(IPartListener2 listener) {
        }
    }, zoomStrings);
    zoomCombo.setZoomManager(zoomManager);
    toolBarManager.add(zoomCombo);
    // toolBarManager.add(new UndoAction(ERDEditorPart.this));
    // toolBarManager.add(new RedoAction(ERDEditorPart.this));
    // toolBarManager.add(new PrintAction(ERDEditorPart.this));
    ZoomInAction zoomInAction = new ZoomInAction(zoomManager);
    zoomInAction.setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.ZOOM_IN));
    ZoomOutAction zoomOutAction = new ZoomOutAction(zoomManager);
    zoomOutAction.setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.ZOOM_OUT));
    toolBarManager.add(zoomInAction);
    toolBarManager.add(zoomOutAction);
    toolBarManager.add(new Separator());
    // toolBarManager.add(createAttributeVisibilityMenu());
    toolBarManager.add(new DiagramLayoutAction(ERDEditorPart.this));
    toolBarManager.add(new DiagramToggleGridAction());
    toolBarManager.add(new DiagramRefreshAction(ERDEditorPart.this));
    toolBarManager.add(new Separator());
    {
        toolBarManager.add(ActionUtils.makeCommandContribution(getSite(), IWorkbenchCommandConstants.FILE_PRINT, ERDUIMessages.erd_editor_control_action_print_diagram, UIIcon.PRINT));
        toolBarManager.add(ActionUtils.makeCommandContribution(getSite(), IWorkbenchCommandConstants.FILE_SAVE_AS, ERDUIMessages.erd_editor_control_action_save_external_format, UIIcon.PICTURE_SAVE));
        toolBarManager.add(ActionUtils.makeCommandContribution(getSite(), IWorkbenchCommandConstants.FILE_SAVE, null, UIIcon.SAVE));
    }
    toolBarManager.add(new Separator());
    {
        Action configAction = new Action(ERDUIMessages.erd_editor_control_action_configuration) {

            @Override
            public void run() {
                UIUtils.showPreferencesFor(getSite().getShell(), ERDEditorPart.this, ERDPreferencePage.PAGE_ID);
            }
        };
        configAction.setImageDescriptor(DBeaverIcons.getImageDescriptor(UIIcon.CONFIGURATION));
        toolBarManager.add(configAction);
    }
}
Also used : DiagramLayoutAction(org.jkiss.dbeaver.erd.ui.action.DiagramLayoutAction) SetPartColorAction(org.jkiss.dbeaver.erd.ui.editor.tools.SetPartColorAction) DiagramRefreshAction(org.jkiss.dbeaver.erd.ui.action.DiagramRefreshAction) SetPartSettingsAction(org.jkiss.dbeaver.erd.ui.editor.tools.SetPartSettingsAction) DiagramToggleGridAction(org.jkiss.dbeaver.erd.ui.action.DiagramToggleGridAction) ResetPartColorAction(org.jkiss.dbeaver.erd.ui.editor.tools.ResetPartColorAction) ChangeZOrderAction(org.jkiss.dbeaver.erd.ui.editor.tools.ChangeZOrderAction) DiagramToggleGridAction(org.jkiss.dbeaver.erd.ui.action.DiagramToggleGridAction) DiagramRefreshAction(org.jkiss.dbeaver.erd.ui.action.DiagramRefreshAction) ZoomManager(org.eclipse.gef.editparts.ZoomManager) DiagramLayoutAction(org.jkiss.dbeaver.erd.ui.action.DiagramLayoutAction)

Example 20 with ZoomManager

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

the class TextEditManager method initCellEditor.

@Override
protected void initCellEditor() {
    // update text
    var textFigure = getEditPart().getAdapter(ITextFigure.class);
    // var labelModel = (AbstractWidgetModel) getEditPart().getModel();
    getCellEditor().setValue(textFigure.getText());
    if (textFigure.isOpaque() || textFigure.getBorder() instanceof AbstractBackground) {
        getCellEditor().getControl().setBackground(textFigure.getBackgroundColor());
    } else {
        getCellEditor().getControl().setBackground(textFigure.getParent().getBackgroundColor());
    }
    getCellEditor().getControl().setForeground(textFigure.getForegroundColor());
    // update font
    var zoomMgr = (ZoomManager) getEditPart().getViewer().getProperty(ZoomManager.class.toString());
    if (zoomMgr != null) {
        // this will force the font to be set
        cachedZoom = -1.0;
        updateScaledFont(zoomMgr.getZoom());
        zoomMgr.addZoomListener(zoomListener);
    } else {
        getCellEditor().getControl().setFont(textFigure.getFont());
    }
    // Hook the cell editor's copy/paste actions to the actionBars so that they can
    // be invoked via keyboard shortcuts.
    var activeEditor = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getActiveEditor();
    if (activeEditor != null) {
        actionBars = activeEditor.getEditorSite().getActionBars();
        saveCurrentActions(actionBars);
        actionHandler = new CellEditorActionHandler(actionBars);
        actionHandler.addCellEditor(getCellEditor());
        actionBars.updateActionBars();
    }
}
Also used : ZoomManager(org.eclipse.gef.editparts.ZoomManager) AbstractBackground(org.eclipse.draw2d.AbstractBackground) CellEditorActionHandler(org.eclipse.ui.part.CellEditorActionHandler)

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