Search in sources :

Example 1 with DeviceResourceException

use of org.eclipse.jface.resource.DeviceResourceException 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 2 with DeviceResourceException

use of org.eclipse.jface.resource.DeviceResourceException in project statecharts by Yakindu.

the class XtextDirectEditManager method getScaledFont.

/**
 * Given a label figure object, this will calculate the correct Font needed
 * to display into screen coordinates, taking into account the current
 * mapmode. This will typically be used by direct edit cell editors that
 * need to display independent of the zoom or any coordinate mapping that is
 * taking place on the drawing surface.
 *
 * @param label
 *            the label to use for the font calculation
 * @return the <code>Font</code> that is scaled to the screen coordinates.
 *         Note: the returned <code>Font</code> should not be disposed since
 *         it is cached by a common resource manager.
 */
protected Font getScaledFont(IFigure label) {
    Font scaledFont = label.getFont();
    FontData data = scaledFont.getFontData()[0];
    Dimension fontSize = new Dimension(0, MapModeUtil.getMapMode(label).DPtoLP(data.getHeight()));
    label.translateToAbsolute(fontSize);
    if (Math.abs(data.getHeight() - fontSize.height) < 2)
        fontSize.height = data.getHeight();
    try {
        FontDescriptor fontDescriptor = FontDescriptor.createFrom(data);
        cachedFontDescriptors.add(fontDescriptor);
        return getResourceManager().createFont(fontDescriptor);
    } catch (DeviceResourceException e) {
        Trace.catching(DiagramUIPlugin.getInstance(), DiagramUIDebugOptions.EXCEPTIONS_CATCHING, getClass(), "getScaledFont", // $NON-NLS-1$
        e);
        // $NON-NLS-1$
        Log.error(DiagramUIPlugin.getInstance(), DiagramUIStatusCodes.IGNORED_EXCEPTION_WARNING, "getScaledFont", e);
    }
    return JFaceResources.getDefaultFont();
}
Also used : DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) FontData(org.eclipse.swt.graphics.FontData) Dimension(org.eclipse.draw2d.geometry.Dimension) Font(org.eclipse.swt.graphics.Font) FontDescriptor(org.eclipse.jface.resource.FontDescriptor)

Example 3 with DeviceResourceException

use of org.eclipse.jface.resource.DeviceResourceException in project epp.mpc by eclipse.

the class MarketplaceDiscoveryResources method safeCreateImage.

private Image safeCreateImage(String imagePath, URL url) {
    try {
        ImageDescriptor descriptor = ImageDescriptor.createFromURL(url);
        Image image = resourceManager.createImage(descriptor);
        return image;
    } catch (DeviceResourceException ex) {
        logFailedLoadingImage(imagePath, url, ex);
    } catch (SWTException ex) {
        logFailedLoadingImage(imagePath, url, ex);
    }
    return null;
}
Also used : SWTException(org.eclipse.swt.SWTException) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) Image(org.eclipse.swt.graphics.Image)

Example 4 with DeviceResourceException

use of org.eclipse.jface.resource.DeviceResourceException in project liferay-ide by liferay.

the class WorkingSetGroup method _createControl.

private void _createControl(Composite container) {
    addToWorkingSetButton = new Button(container, SWT.CHECK);
    GridData gd_addToWorkingSetButton = new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1);
    gd_addToWorkingSetButton.verticalIndent = 12;
    addToWorkingSetButton.setLayoutData(gd_addToWorkingSetButton);
    addToWorkingSetButton.setSelection(true);
    addToWorkingSetButton.setData("name", "addToWorkingSetButton");
    addToWorkingSetButton.setText("Add project to working set");
    addToWorkingSetButton.setSelection(false);
    final Label workingsetLabel = new Label(container, SWT.NONE);
    GridData gd_workingsetLabel = new GridData();
    gd_workingsetLabel.horizontalIndent = 10;
    workingsetLabel.setLayoutData(gd_workingsetLabel);
    workingsetLabel.setEnabled(false);
    workingsetLabel.setData("name", "workingsetLabel");
    workingsetLabel.setText("Working set:");
    Combo workingsetCombo = new Combo(container, SWT.READ_ONLY);
    workingsetCombo.setEnabled(false);
    workingsetCombo.setData("name", "workingsetCombo");
    workingsetCombo.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    _workingsetComboViewer = new ComboViewer(workingsetCombo);
    _workingsetComboViewer.setContentProvider(new IStructuredContentProvider() {

        public void dispose() {
        }

        public Object[] getElements(Object input) {
            if (input instanceof IWorkingSet[]) {
                return (IWorkingSet[]) input;
            } else if (input instanceof List<?>) {
                return new Object[] { input };
            } else if (input instanceof Set<?>) {
                return ((Set<?>) input).toArray();
            }
            return new IWorkingSet[0];
        }

        public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
        }
    });
    _workingsetComboViewer.setLabelProvider(new LabelProvider() {

        public void dispose() {
            _images.dispose();
            super.dispose();
        }

        @SuppressWarnings("deprecation")
        public Image getImage(Object element) {
            if (element instanceof IWorkingSet) {
                ImageDescriptor imageDescriptor = ((IWorkingSet) element).getImage();
                if (imageDescriptor != null) {
                    try {
                        return (Image) _images.create(imageDescriptor);
                    } catch (DeviceResourceException dre) {
                        return null;
                    }
                }
            }
            return super.getImage(element);
        }

        public String getText(Object element) {
            if (element instanceof IWorkingSet) {
                return ((IWorkingSet) element).getLabel();
            } else if (element instanceof List<?>) {
                StringBuffer sb = new StringBuffer();
                for (Object o : (List<?>) element) {
                    if (o instanceof IWorkingSet) {
                        if (sb.length() > 0) {
                            sb.append(", ");
                        }
                        sb.append(((IWorkingSet) o).getLabel());
                    }
                }
                return sb.toString();
            }
            return super.getText(element);
        }

        private ResourceManager _images = new LocalResourceManager(JFaceResources.getResources());
    });
    _workingsetComboViewer.setComparator(new ViewerComparator());
    final Button newWorkingSetButton = new Button(container, SWT.NONE);
    newWorkingSetButton.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    newWorkingSetButton.setData("name", "configureButton");
    newWorkingSetButton.setText("More...");
    newWorkingSetButton.setEnabled(false);
    newWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(final SelectionEvent e) {
            IWorkingSetManager workingSetManager = PlatformUI.getWorkbench().getWorkingSetManager();
            IWorkingSetSelectionDialog dialog = workingSetManager.createWorkingSetSelectionDialog(_shell, true, _working_set_ids.toArray(new String[0]));
            if (dialog.open() == Window.OK) {
                IWorkingSet[] workingSets = dialog.getSelection();
                selectWorkingSets(Arrays.asList(workingSets));
            }
        }
    });
    if (selectWorkingSets(_workingSets)) {
        addToWorkingSetButton.setSelection(true);
        workingsetLabel.setEnabled(true);
        _workingsetComboViewer.getCombo().setEnabled(true);
        newWorkingSetButton.setEnabled(true);
    }
    addToWorkingSetButton.addSelectionListener(new SelectionAdapter() {

        public void widgetSelected(SelectionEvent e) {
            boolean addToWorkingingSet = addToWorkingSetButton.getSelection();
            workingsetLabel.setEnabled(addToWorkingingSet);
            _workingsetComboViewer.getCombo().setEnabled(addToWorkingingSet);
            newWorkingSetButton.setEnabled(addToWorkingingSet);
            if (addToWorkingingSet) {
                updateConfiguration();
            } else {
                _workingSets.clear();
            }
        }
    });
    _workingsetComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {

        public void selectionChanged(SelectionChangedEvent event) {
            updateConfiguration();
        }
    });
}
Also used : LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Label(org.eclipse.swt.widgets.Label) Combo(org.eclipse.swt.widgets.Combo) ComboViewer(org.eclipse.jface.viewers.ComboViewer) Viewer(org.eclipse.jface.viewers.Viewer) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) Image(org.eclipse.swt.graphics.Image) Button(org.eclipse.swt.widgets.Button) DeviceResourceException(org.eclipse.jface.resource.DeviceResourceException) SelectionEvent(org.eclipse.swt.events.SelectionEvent) IWorkingSetManager(org.eclipse.ui.IWorkingSetManager) IWorkingSetSelectionDialog(org.eclipse.ui.dialogs.IWorkingSetSelectionDialog) List(java.util.List) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) IWorkingSet(org.eclipse.ui.IWorkingSet) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ResourceManager(org.eclipse.jface.resource.ResourceManager) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) ComboViewer(org.eclipse.jface.viewers.ComboViewer) GridData(org.eclipse.swt.layout.GridData) IStructuredContentProvider(org.eclipse.jface.viewers.IStructuredContentProvider) LabelProvider(org.eclipse.jface.viewers.LabelProvider)

Aggregations

DeviceResourceException (org.eclipse.jface.resource.DeviceResourceException)4 FontDescriptor (org.eclipse.jface.resource.FontDescriptor)2 ImageDescriptor (org.eclipse.jface.resource.ImageDescriptor)2 FontData (org.eclipse.swt.graphics.FontData)2 Image (org.eclipse.swt.graphics.Image)2 List (java.util.List)1 Dimension (org.eclipse.draw2d.geometry.Dimension)1 ZoomManager (org.eclipse.gef.editparts.ZoomManager)1 LocalResourceManager (org.eclipse.jface.resource.LocalResourceManager)1 ResourceManager (org.eclipse.jface.resource.ResourceManager)1 ComboViewer (org.eclipse.jface.viewers.ComboViewer)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 IStructuredContentProvider (org.eclipse.jface.viewers.IStructuredContentProvider)1 LabelProvider (org.eclipse.jface.viewers.LabelProvider)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 Viewer (org.eclipse.jface.viewers.Viewer)1 ViewerComparator (org.eclipse.jface.viewers.ViewerComparator)1 SWTException (org.eclipse.swt.SWTException)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1